00001
00002 #include "charm++.h"
00003 #include "stats.h"
00004 #include "stats.def.h"
00005
00006 CkChareID theGlobalStats;
00007 CkGroupID theLocalStats;
00008
00009 extern void POSE_exit();
00010
00012 void localStat::SendStats()
00013 {
00014 if (pose_config.dop) {
00015
00016 fclose(dopFilePtr);
00017
00018
00019 dopFilePtr = fopen(dopFileName, "a");
00020 if (dopFilePtr == NULL) {
00021 CkPrintf("WARNING: unable to open DOP file %s for append...this probably doesn't matter, though, as long as this is at the end of the simulation\n",
00022 dopFileName);
00023 }
00024 }
00025 CProxy_globalStat gstat(theGlobalStats);
00026 localStatSummary *m = new localStatSummary;
00027 m->doTime = totalTime;
00028 m->rbTime = rollbackTime;
00029 m->gvtTime = gvtTime;
00030 m->simTime = simTime;
00031 m->cpTime = cpTime;
00032 m->canTime = canTime;
00033 m->lbTime = lbTime;
00034 m->fcTime = fcTime;
00035 m->commTime = commTime;
00036 m->cpBytes = cpBytes;
00037 m->maxDo = maxDo;
00038 m->minDo = minDo;
00039 m->pe = CkMyPe();
00040 m->dos = dos;
00041 m->undos = undos;
00042 m->commits = commits;
00043 m->loops = loops;
00044 m->gvts = gvts;
00045 m->maxChkPts = maxChkPts;
00046 m->maxGVT = maxGVT;
00047 m->maxGRT = maxGRT;
00048 gstat.localStatReport(m);
00049 }
00050
00051
00052 globalStat::globalStat(void): doAvg (0.0), doMax (0.0), rbAvg (0.0), rbMax (0.0), gvtAvg (0.0), gvtMax (0.0), simAvg (0.0), simMax (0.0),
00053 cpAvg (0.0), cpMax (0.0), canAvg (0.0), canMax (0.0), lbAvg (0.0), lbMax (0.0), fcAvg (0.0), fcMax (0.0),
00054 commAvg (0.0), commMax (0.0),
00055 maxTime (0.0), maxDo (0.0), minDo (0.0), avgDo (0.0), GvtTime (0.0), maxGRT (0.0),
00056 cpBytes (0), reporting (0), totalDos (0), totalUndos (0), totalCommits (0), totalLoops (0),
00057 totalGvts (0), maxChkPts (0), maxGVT (0)
00058 {
00059 #ifdef VERBOSE_DEBUG
00060 CkPrintf("[%d] constructing globalStat\n",CkMyPe());
00061 #endif
00062
00063 }
00064
00065
00066 void globalStat::localStatReport(localStatSummary *m)
00067 {
00068 double tmpMax;
00069
00070 totalDos += m->dos;
00071 totalUndos += m->undos;
00072 totalCommits += m->commits;
00073 totalLoops += m->loops;
00074 totalGvts += m->gvts;
00075 maxChkPts += m->maxChkPts;
00076 doAvg += m->doTime;
00077 if (maxGRT < m->maxGRT) maxGRT = m->maxGRT;
00078 if (maxGVT < m->maxGVT) maxGVT = m->maxGVT;
00079 if (m->maxDo > maxDo)
00080 maxDo = m->maxDo;
00081 if ((minDo < 0.0) || (m->minDo < minDo))
00082 minDo = m->minDo;
00083 if (m->doTime > doMax)
00084 doMax = m->doTime;
00085 rbAvg += m->rbTime;
00086 if (m->rbTime > rbMax)
00087 rbMax = m->rbTime;
00088 gvtAvg += m->gvtTime;
00089 if (m->gvtTime > gvtMax)
00090 gvtMax = m->gvtTime;
00091 simAvg += m->simTime;
00092 if (m->simTime > simMax)
00093 simMax = m->simTime;
00094 cpAvg += m->cpTime;
00095 if (m->cpTime > cpMax)
00096 cpMax = m->cpTime;
00097 canAvg += m->canTime;
00098 if (m->canTime > canMax)
00099 canMax = m->canTime;
00100 lbAvg += m->lbTime;
00101 if (m->lbTime > lbMax)
00102 lbMax = m->lbTime;
00103 fcAvg += m->fcTime;
00104 if (m->fcTime > fcMax)
00105 fcMax = m->fcTime;
00106 commAvg += m->commTime;
00107 if (m->commTime > commMax)
00108 commMax = m->commTime;
00109 cpBytes += m->cpBytes;
00110 tmpMax = m->doTime + m->rbTime + m->gvtTime + m->simTime + m->cpTime
00111 + m->canTime + m->lbTime + m->fcTime + m->commTime;
00112 CkFreeMsg(m);
00113 if (tmpMax > maxTime)
00114 maxTime = tmpMax;
00115 reporting++;
00116
00117 #ifdef SEQUENTIAL_POSE
00118 totalLoops = totalDos;
00119 totalGvts = 1;
00120 #endif
00121 CkAssert(totalGvts > 0);
00122 CkAssert(totalDos > 0);
00123 CkAssert(totalLoops > 0);
00124 GvtTime = gvtAvg/totalGvts;
00125 if (reporting == CkNumPes()) {
00126 avgDo = doAvg / totalDos;
00127 doAvg /= CkNumPes();
00128 rbAvg /= CkNumPes();
00129 gvtAvg /= CkNumPes();
00130 simAvg /= CkNumPes();
00131 cpAvg /= CkNumPes();
00132 canAvg /= CkNumPes();
00133 lbAvg /= CkNumPes();
00134 fcAvg /= CkNumPes();
00135 commAvg /= CkNumPes();
00136 maxChkPts /= CkNumPes();
00137
00138 CkPrintf("------------------------------------------------------------------------------------\n | DO | RB | GVT | SIM | CP | CAN | LB | FC | COMM |\n---|--------|--------|--------|--------|--------|--------|--------|--------|--------|\nmax| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f|\navg| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f| %7.2f|\n------------------------------------------------------------------------------------\nMax time on a PE:%7.2f, Speculative Events:%d Actual Events:%d Commits:%d\nGRAINSIZE INFO: Avg: %10.6f Max: %10.6f Min: %10.6f\nGVT iterations=%d Avg time per iteration=%f\ntotalLoops=%d effectiveGS=%10.6f\n",
00139 doMax, rbMax, gvtMax, simMax, cpMax, canMax, lbMax, fcMax, commMax, doAvg, rbAvg, gvtAvg, simAvg, cpAvg, canAvg, lbAvg, fcAvg, commAvg, maxTime, totalDos, totalDos-totalUndos, totalCommits, avgDo, maxDo, minDo, totalGvts, GvtTime, totalLoops, (doAvg*CkNumPes())/totalLoops);
00140
00141
00142 if(pose_config.dop){
00143 CkPrintf("Overhead-free maximally parallel runtime=%f Max GVT=%lld\n", maxGRT, maxGVT);
00144 if (pose_config.dopSkipCalcs) {
00145 CkPrintf("\n");
00146 CkPrintf("WARNING: Skipping DOP calculations. Not writing dop_mod.out or dop_sim.out files.\n");
00147 CkPrintf("Save the following parameters for use with the DOPCalc tool in the\n");
00148 CkPrintf("BigNetSim/trunk/tools/DOPCalc directory of the BigNetSim svn repository:\n");
00149 CkPrintf(" #PEs=%d, maxGRT=%f, maxGVT=%lld, and the starting virtual time\n", CkNumPes(), maxGRT, maxGVT);
00150 CkPrintf(" of the simulation (which should be 0 unless there are skip points)\n");
00151 CkPrintf("\n");
00152 } else {
00153 DOPcalc(maxGVT, maxGRT);
00154 }
00155 }
00156
00157 POSE_exit();
00158
00159
00160
00161
00162
00163
00164
00165
00166 }
00167 }
00168
00169
00170 void globalStat::DOPcalc(POSE_TimeType gvt, double grt)
00171 {
00172 CmiInt8 i, j;
00173 POSE_TimeType vinStart, vinEnd, gvtp = gvt + 1;
00174 double rinStart, rinEnd;
00175 FILE *fp;
00176 char filename[20], line[80];
00177 unsigned short int *gvtDOP, *grtDOP;
00178 unsigned long int grtp = (unsigned long int)(grt*1000000.0) + 1, usStart, usEnd;
00179 int modelPEs=0, simulationPEs=0;
00180
00181 CkPrintf("Generating DOP measures...\n");
00182 gvtDOP = (unsigned short int *)malloc(gvtp*sizeof(unsigned short int));
00183 grtDOP = (unsigned short int *)malloc(grtp*sizeof(unsigned short int));
00184 for (i=0; i<gvtp; i++) gvtDOP[i] = 0;
00185 for (i=0; i<grtp; i++) grtDOP[i] = 0;
00186 for (i=0; i<CkNumPes(); i++) {
00187 sprintf(filename, "dop%lld.log\0", i);
00188 fp = fopen(filename, "r");
00189 if (!fp) {
00190 CkPrintf("Cannot open file %s... exiting.\n", filename);
00191 POSE_exit();
00192 return;
00193 }
00194 CkPrintf("Reading file %s...\n", filename);
00195 #if USE_LONG_TIMESTAMPS
00196 const char* format = "%lf %lf %lld %lld\n";
00197 #else
00198 const char* format = "%lf %lf %d %d\n";
00199 #endif
00200 while (fgets(line, 80, fp)) {
00201 if (sscanf(line, format, &rinStart, &rinEnd, &vinStart, &vinEnd) == 4) {
00202 usStart = (unsigned long int)(rinStart * 1000000.0);
00203 usEnd = (unsigned long int)(rinEnd * 1000000.0);
00204 for (j=usStart; j<usEnd; j++) grtDOP[j]++;
00205 if (usStart == usEnd) grtDOP[usStart]++;
00206 if (vinStart > -1)
00207 for (j=vinStart; j<=vinEnd; j++) gvtDOP[j]++;
00208 }
00209 else CkPrintf("WARNING: DOP post-processing corrupted... likely NFS to blame.\n");
00210 }
00211 fclose(fp);
00212 }
00213 CmiInt8 avgPEs = 0LL;
00214 int zed = 0;
00215 fp = fopen("dop_mod.out", "w");
00216 for (i=0; i<gvtp; i++) {
00217
00218 if ((i & 0x03FFFFFF) == 0) CkPrintf(" current index: %lld of %lld\n", i, gvtp);
00219 if ((gvtDOP[i] != 0) || (zed == 0))
00220 fprintf(fp, "%lld %d\n", i, gvtDOP[i]);
00221 if (gvtDOP[i] == 0) zed = 1;
00222 else zed = 0;
00223 avgPEs += gvtDOP[i];
00224 if (gvtDOP[i] > modelPEs) modelPEs = gvtDOP[i];
00225 }
00226 avgPEs /= gvtp;
00227 fclose(fp);
00228 fp = fopen("dop_sim.out", "w");
00229 for (i=0; i<grtp; i++) {
00230 fprintf(fp, "%lld %d\n", i, grtDOP[i]);
00231 if (grtDOP[i] > simulationPEs) simulationPEs = grtDOP[i];
00232 }
00233 fclose(fp);
00234 CkPrintf("Max model PEs: %d Max simulation PEs: %d Recommended #PEs: %lld\n",
00235 modelPEs, simulationPEs, avgPEs);
00236 }