105 #define DBG_PROF_MPI 0 110 realmain(
int argc,
char*
const* argv);
114 vector<uint>& groupIdToGroupSizeMap,
115 int myRank,
int numRanks);
122 const vector<uint>& groupIdToGroupSizeMap,
123 int myRank,
int numRanks);
129 const vector<uint>& groupIdToGroupSizeMap,
130 int myRank,
int numRanks);
137 vector<VMAIntervalSet*>& groupIdToGroupMetricsMap,
138 const vector<uint>& groupIdToGroupSizeMap,
143 const string& profileFile,
145 vector<VMAIntervalSet*>& groupIdToGroupMetricsMap,
150 const string& profileFile,
159 const string& metricDBFnm);
171 makeFileName(
const char* baseNm,
const char* ext,
int myRank);
182 MPI_Abort(MPI_COMM_WORLD, error_code);
187 main(
int argc,
char*
const* argv)
198 catch (
const std::bad_alloc& x) {
199 DIAG_EMsg(
"[std::bad_alloc] " << x.what());
202 catch (
const std::exception& x) {
203 DIAG_EMsg(
"[std::exception] " << x.what());
207 DIAG_EMsg(
"Unknown exception encountered!");
224 char *error_timeout = getenv(
"HPCPROF_ABORT_TIMEOUT");
226 int seconds = atoi(error_timeout);
228 struct sigaction act;
230 act.sa_flags = SA_SIGINFO;
231 sigaction(SIGALRM, &act,
NULL);
242 args.
parse(argc, argv);
252 int myRank, numRanks;
253 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
254 MPI_Comm_size(MPI_COMM_WORLD, &numRanks);
259 const char* HPCPROF_WAIT = getenv(
"HPCPROF_WAIT");
262 if (strlen(HPCPROF_WAIT) > 0) {
263 waitRank = atoi(HPCPROF_WAIT);
267 if (myRank == waitRank) {
268 while (DEBUGGER_WAIT);
278 char dbDirBuf[PATH_MAX];
280 memset(dbDirBuf,
'\0', PATH_MAX);
281 strncpy(dbDirBuf, args.
db_dir.c_str(), PATH_MAX);
282 dbDirBuf[PATH_MAX - 1] =
'\0';
285 MPI_Bcast((
void*)dbDirBuf, PATH_MAX, MPI_CHAR, 0, MPI_COMM_WORLD);
293 vector<uint> groupIdToGroupSizeMap;
299 if (nArgs.
paths->size() == 0 && myRank == 0) {
300 std::cerr <<
"ERROR: command line directories" 301 " contain no .hpcrun files; no database generated\n";
357 bool printProgress = (myRank == 0);
385 uint8_t* prunedNodes =
new uint8_t[prunedNodesSz];
386 memset(prunedNodes, 0, prunedNodesSz *
sizeof(uint8_t));
399 MPI_Bcast(prunedNodes, prunedNodesSz, MPI_BYTE, 0, MPI_COMM_WORLD);
404 delete[] prunedNodes;
435 if (args.
title.empty()) {
469 vector<uint>& groupIdToGroupSizeMap,
470 int myRank,
int numRanks)
474 char* sendFilesBuf =
NULL;
475 uint sendFilesBufSz = 0;
476 uint sendFilesChunkSz = 0;
477 const uint groupIdLen = 1;
493 DIAG_Assert(nArgs.
groupMax <= UCHAR_MAX,
"myNormalizeProfileArgs: 'groupMax' cannot be packed into a uchar!");
496 ceil( (
double)canonicalFiles->size() / (double)numRanks);
498 sendFilesChunkSz = chunkSz * (groupIdLen + pathLenMax + 1);
499 sendFilesBufSz = sendFilesChunkSz * numRanks;
500 sendFilesBuf =
new char[sendFilesBufSz];
501 memset(sendFilesBuf,
'\0', sendFilesBufSz);
503 groupIdToGroupSizeMap.resize(groupIdMax + 1);
505 for (
uint i = 0, j = 0; i < canonicalFiles->size();
506 i++, j += (groupIdLen + pathLenMax + 1)) {
507 const std::string& nm = (*canonicalFiles)[i];
510 groupIdToGroupSizeMap[groupId]++;
513 sendFilesBuf[j] = (char)groupId;
514 strncpy(&(sendFilesBuf[j + groupIdLen]), nm.c_str(), pathLenMax);
515 sendFilesBuf[j + groupIdLen + pathLenMax] =
'\0';
525 const uint metadataBufSz = 3;
526 uint metadataBuf[metadataBufSz];
527 metadataBuf[0] = sendFilesChunkSz;
528 metadataBuf[1] = pathLenMax;
529 metadataBuf[2] = groupIdMax;
531 MPI_Bcast((
void*)metadataBuf, metadataBufSz, MPI_UNSIGNED,
535 sendFilesChunkSz = metadataBuf[0];
536 pathLenMax = metadataBuf[1];
537 groupIdMax = metadataBuf[2];
544 uint recvFilesChunkSz = sendFilesChunkSz;
545 const char* recvFilesBuf =
new char[recvFilesChunkSz];
547 MPI_Scatter((
void*)sendFilesBuf, sendFilesChunkSz, MPI_CHAR,
548 (
void*)recvFilesBuf, recvFilesChunkSz, MPI_CHAR,
551 delete[] sendFilesBuf;
554 for (
uint i = 0; i < recvFilesChunkSz; i += (groupIdLen + pathLenMax + 1)) {
555 uint groupId = recvFilesBuf[i];
556 const char* nm_cstr = &recvFilesBuf[i + groupIdLen];
559 out.
paths->push_back(nm);
567 delete[] recvFilesBuf;
570 for (
uint i = 0; i < out.
paths->size(); ++i) {
571 const std::string& nm = (*out.
paths)[i];
572 std::cout <<
"[" << myRank <<
"]: " << nm << std::endl;
588 const vector<uint>& groupIdToGroupSizeMap,
589 int myRank,
int numRanks)
591 uint mDrvdBeg = 0, mDrvdEnd = 0;
592 uint mXDrvdBeg = 0, mXDrvdEnd = 0;
594 vector<VMAIntervalSet*> groupIdToGroupMetricsMap(nArgs.
groupMax + 1,
NULL);
597 mDrvdBeg, mDrvdEnd, mXDrvdBeg, mXDrvdEnd,
598 groupIdToGroupMetricsMap, groupIdToGroupSizeMap,
610 for (
uint i = 0; i < nArgs.
paths->size(); ++i) {
611 const string& fnm = (*nArgs.
paths)[i];
614 groupIdToGroupMetricsMap, myRank);
625 for (
uint i = mDrvdBeg, j = mXDrvdBeg; i < mDrvdEnd; ++i) {
660 for (
uint i = 0; i < mMgrGbl.
size(); ++i) {
666 for (
uint grpId = 1; grpId < groupIdToGroupMetricsMap.size(); ++grpId) {
667 delete groupIdToGroupMetricsMap[grpId];
670 delete packedMetrics;
678 const vector<uint>& groupIdToGroupSizeMap,
679 int myRank,
int numRanks)
681 for (
uint i = 0; i < nArgs.
paths->size(); ++i) {
682 string& fnm = (*nArgs.
paths)[i];
694 vector<VMAIntervalSet*>& groupIdToGroupMetricsMap,
695 const vector<uint>& groupIdToGroupSizeMap,
701 uint mSrcBeg = 0, mSrcEnd = numSrc;
704 mDrvdBeg = mDrvdEnd = 0;
705 mXDrvdBeg = mXDrvdEnd = 0;
717 mDrvdEnd = mMgrGbl.
size();
718 numDrvd = (mDrvdEnd - mDrvdBeg);
721 for (
uint i = mSrcBeg; i < mSrcEnd; ++i) {
726 for (
uint i = mDrvdBeg; i < mDrvdEnd; ++i) {
732 const string& nmPfx = m->
namePfx();
733 if (!nmPfx.empty()) {
746 uint numInputs = groupIdToGroupSizeMap[groupId];
757 ivalset->
insert(i, i + 1);
765 mXDrvdEnd = mMgrGbl.
size();
768 for (
uint i = mXDrvdBeg; i < mXDrvdEnd; ++i) {
792 const string& profileFile,
794 vector<VMAIntervalSet*>& groupIdToGroupMetricsMap,
806 uint rGroupId = (groupMax > 1) ? groupId : 0;
831 uint mBeg = profGbl.
merge(*prof, mergeTy, mergeFlg);
842 for (
uint mId = mBeg; mId < mEnd; ++mId) {
857 const VMAIntervalSet* ivalsetDrvd = groupIdToGroupMetricsMap[groupId];
864 DIAG_MsgIf(0,
"[" << myRank <<
"] grp " << groupId <<
": [" << mDrvdBeg <<
", " << mDrvdEnd <<
")");
893 const string& profileFile,
906 uint rGroupId = (groupMax > 1) ? groupId : 0;
932 uint mBeg = profGbl.
merge(*prof, mergeTy, mergeFlg);
944 for (
uint mId = mBeg; mId < mEnd; ++mId) {
985 string metricDBFnm = dbDir +
"/" + fnm;
993 const string& metricDBFnm)
1013 std::string errorString;
1016 DIAG_EMsg(
"failed opening profile result file for writing " <<
1017 errorString <<
"; aborting.");
1021 DIAG_MsgIf(0,
"writeMetricsDB: " << metricDBFnm);
1039 for (
uint nodeId = 1; nodeId < numNodes + 1; ++nodeId) {
1040 for (
uint mId1 = 0, mId2 = mBegId; mId2 < mEndId; ++mId1, ++mId2) {
1041 double mval = packedMetrics.
idx(nodeId, mId1);
1042 DIAG_MsgIf(0,
" " << nodeId <<
" -> " << mval);
1053 std::string errorString;
1056 DIAG_EMsg(
"failed writing profile result file" <<
1057 errorString <<
"; aborting.");
1096 return string(baseNm) +
"-" +
StrUtil::toStr(myRank) +
"." + ext;
void prof_abort(int error_code)
void aggregateMetricsIncl(uint mBegId, uint mEndId)
void CloseStream(std::istream *s)
void readStructure(Prof::Struct::Tree *structure, const Analysis::Args &args)
void srcId(int i, uint x)
void applySummaryMetricAgents(Prof::CallPath::Profile &prof, string agent)
NormalizeProfileArgs_t normalizeProfileArgs(const StringVec &inPaths)
void normalize(Prof::CallPath::Profile &prof, string agent, bool doNormalizeTy)
uint64_t toUInt64(const char *str, unsigned *endidx)
string toStr(const int x, int base)
static void makeSummaryMetrics(Prof::CallPath::Profile &profGbl, const Analysis::Args &args, const Analysis::Util::NormalizeProfileArgs_t &nArgs, const vector< uint > &groupIdToGroupSizeMap, int myRank, int numRanks)
static void makeSummaryMetrics_Lcl(Prof::CallPath::Profile &profGbl, const string &profileFile, const Analysis::Args &args, uint groupId, uint groupMax, vector< VMAIntervalSet *> &groupIdToGroupMetricsMap, int myRank)
std::vector< std::string > structureFiles
void writeXML(std::ostream &os, const Prof::Struct::Tree &strctTree, bool prettyPrint)
static uint makeDerivedMetricDescs(Prof::CallPath::Profile &profGbl, const Analysis::Args &args, uint &mDrvdBeg, uint &mDrvdEnd, uint &mXDrvdBeg, uint &mXDrvdEnd, vector< VMAIntervalSet *> &groupIdToGroupMetricsMap, const vector< uint > &groupIdToGroupSizeMap, int myRank)
static void writeProfile(const Prof::CallPath::Profile &prof, const char *baseNm, int myRank) __attribute__((unused))
static void abort_timeout_handler(int sig, siginfo_t *siginfo, void *context)
void overlayStaticStructureMain(Prof::CallPath::Profile &prof, string agent, bool doNormalizeTy, bool printProgress)
void reduce(T object, int myRank, int numRanks, MPI_Comm comm=MPI_COMM_WORLD)
void pruneStructTree(Prof::CallPath::Profile &prof)
static void makeThreadMetrics(Prof::CallPath::Profile &profGbl, const Analysis::Args &args, const Analysis::Util::NormalizeProfileArgs_t &nArgs, const vector< uint > &groupIdToGroupSizeMap, int myRank, int numRanks)
const StringSet & traceFileNameSet() const
std::vector< uint > UIntVec
static RealPathMgr & singleton()
std::string searchPathStr
uint makeSummaryMetricsIncr(bool needAllStats, uint srcBegId=Mgr::npos, uint srcEndId=Mgr::npos)
void mergePerfEventStatistics_finalize(int num_profiles)
void makeDatabase(Prof::CallPath::Profile &prof, const Analysis::Args &args)
int MPI_Init(int *argc, char ***argv)
static Analysis::Util::NormalizeProfileArgs_t myNormalizeProfileArgs(const Analysis::Util::StringVec &profileFiles, vector< uint > &groupIdToGroupSizeMap, int myRank, int numRanks)
void parse(int argc, const char *const argv[])
static bool MetricFlg_isSet(uint flags, MetricFlg x)
std::ostream * OpenOStream(const char *filenm)
#define DIAG_MsgIf(ifexpr,...)
virtual std::string message() const
static void writeStructure(const Prof::Struct::Tree &structure, const char *baseNm, int myRank) __attribute__((unused))
void copyTraceFiles(const std::string &dstDir, const std::set< string > &srcFiles)
void zeroMetricsDeep(uint mBegId, uint mEndId)
ComputedTy computedType() const
static std::string makeFileName(const char *baseNm, const char *ext, int myRank)
static void writeMetricsDB(Prof::CallPath::Profile &profGbl, uint mBegId, uint mEndId, const string &metricDBFnm)
void computeMetricsIncr(const Metric::Mgr &mMgr, uint mBegId, uint mEndId, Metric::AExprIncr::FnTy fn)
int main(int argc, char *argv[])
uint merge(Profile &y, int mergeTy, uint mrgFlag=0)
void broadcast(Prof::CallPath::Profile *&profile, int myRank, MPI_Comm comm)
std::pair< iterator, bool > insert(const VMA beg, const VMA end)
static void hpcprof_set_abort_timeout()
std::vector< std::string > profileFiles
volatile int DEBUGGER_WAIT
static int realmain(int argc, char *const *argv)
const std::string & searchPaths() const
const Metric::Mgr * metricMgr() const
const char * DIAG_UnexpectedInput
Prof::Struct::Tree * structure() const
void aggregateMetricsExcl(uint mBegId, uint mEndId)
StringSet & directorySet()
void pruneBySummaryMetrics(Prof::CallPath::Profile &prof, uint8_t *prunedNodes)
uint makeDensePreorderIds()
static string makeDBFileName(const string &dbDir, uint groupId, const string &profileFile)
void noteStaticStructureOnLeaves(Prof::CallPath::Profile &prof)
static const char HPCPROF_MetricDBSfx[]
const std::string & namePfx() const
Prof::CallPath::Profile * read(const Util::StringVec &profileFiles, const Util::UIntVec *groupMap, int mergeTy, uint rFlags, uint mrgFlags)
void pruneCCTByNodeId(const uint8_t *prunedNodes)
double idx(uint idxNodes, uint idxMetrics) const
Metric::ADesc * metric(uint i)
std::ostream & writeXML(std::ostream &os, const Metric::Mgr *metricMgr, uint metricBeg=Metric::IData::npos, uint metricEnd=Metric::IData::npos, uint oFlags=0) const
void packMetrics(const Prof::CallPath::Profile &profile, ParallelAnalysis::PackedMetrics &packedMetrics)
virtual uint numSrcFxd() const
string basename(const char *fName)
static void makeThreadMetrics_Lcl(Prof::CallPath::Profile &profGbl, const string &profileFile, const Analysis::Args &args, uint groupId, uint groupMax, int myRank)
int hpcio_fclose(FILE *fs)
static int hpcfmt_real8_fwrite(double val, FILE *outfs)
const std::string & name() const
int hpcmetricDB_fmt_hdr_fwrite(hpcmetricDB_fmt_hdr_t *hdr, FILE *outfs)
std::vector< std::string > StringVec
void hpcrun_getFileErrorString(const std::string &fnm, std::string &errorString)
FILE * hpcio_fopen_w(const char *fnm, int overwrite)
Metric::AExprIncr * expr() const
bool isMetricMgrVirtual() const
virtual uint numAccum() const
string rmSuffix(const char *fName)