00001
00006
00007
00008 #include "charm++.h"
00009 #include "envelope.h"
00010 #include "trace-common.h"
00011 #include "trace-bluegene.h"
00012 #include "blue.h"
00013 #include "blue_impl.h"
00014 #include "memory-isomalloc.h"
00015
00016 #undef DEBUGF
00017 #define DEBUGF(x) // CmiPrintf x
00018
00019 void _createTracebluegene(char** argv)
00020 {
00021 DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
00022 CkpvInitialize(TraceBluegene*, _tracebg);
00023 CkpvAccess(_tracebg) = new TraceBluegene(argv);
00024 CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
00025 traceBluegeneLinked = 1;
00026 }
00027
00028
00029
00030 static void writeData(void *data, double t, double recvT, void *ptr)
00031 {
00032 TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
00033 CmiAssert(traceBluegene);
00034 traceBluegene->writePrint((char*)data, t);
00035 }
00036
00037 void TraceBluegene::writePrint(char* str, double t){
00038 if (pfp == NULL)
00039 creatFiles();
00040 fprintf(pfp,"[%d] ", CkMyPe());
00041 fprintf(pfp,str,t);
00042 }
00043
00044 TraceBluegene::TraceBluegene(char** argv): pfp(NULL)
00045 {
00046 }
00047
00048 void TraceBluegene::traceClose() {
00049 DEBUGF(("%d TraceBluegene::traceClose\n", CkMyPe()));
00050 bgUpdateProj(2);
00051 if(pfp != 0) fclose(pfp);
00052 pfp = NULL;
00053 CkpvAccess(_traces)->removeTrace(this);
00054 }
00055
00056 TraceBluegene::~TraceBluegene(){
00057 }
00058
00059 CpvExtern(BGMach, bgMach);
00060 void TraceBluegene::creatFiles()
00061 {
00062 char* fname = new char[1024];
00063 sprintf(fname, "%sbgPrintFile.%d", cva(bgMach).traceroot?cva(bgMach).traceroot:"", CkMyPe());
00064 pfp = fopen(fname,"w");
00065 if(pfp==NULL)
00066 CmiAbort("Cannot open Bluegene print file for writing.\n");
00067 delete[] fname;
00068 }
00069
00070 void TraceBluegene::tlineEnd(void** parentLogPtr){
00071 if(genTimeLog)
00072 *parentLogPtr = (void*)BgLastLog(tTIMELINEREC);
00073 else
00074 *parentLogPtr = NULL;
00075 }
00076
00077 void TraceBluegene::bgAddTag(const char* str){
00078 if (!genTimeLog) return;
00079 BgTimeLog * log = BgLastLog(tTIMELINEREC);
00080 CmiAssert(log != NULL);
00081 log->setName(str);
00082 }
00083
00084 void TraceBluegene::bgDummyBeginExec(const char* name,void** parentLogPtr, int split)
00085 {
00086 if (genTimeLog) {
00087 CmiAssert(parentLogPtr!=NULL);
00088 double startTime = BgGetCurTime();
00089 BgTimeLog* newLog = BgStartLogByName(tTIMELINEREC, _threadEP, name, startTime, *(BgTimeLog**)parentLogPtr);
00090
00091
00092 if (*parentLogPtr == NULL)
00093 newLog->recvTime = startTime;
00094 else {
00095 if (split) {
00096 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
00097 newLog->charm_ep = (*(BgTimeLog**)parentLogPtr)->charm_ep;
00098 }
00099 }
00100 *parentLogPtr = newLog;
00101 }
00102 startVTimer();
00103 }
00104
00105 void TraceBluegene::bgBeginExec(char* msg, char *name)
00106 {
00107 startVTimer();
00108 if (!genTimeLog) return;
00109 BgTimeLog* newLog = new BgTimeLog(msg, name);
00110 tTIMELINEREC.logEntryStart(newLog);
00111 }
00112
00113
00114 void TraceBluegene::bgSetInfo(char *msg, const char *name, void **logs, int count)
00115 {
00116 if (!genTimeLog) return;
00117 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
00118 if (name != NULL) curlog->setName(name);
00119 for (int i=0; i<count; i++)
00120 curlog->addBackwardDep((BgTimeLog*)logs[i]);
00121 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
00122 }
00123
00124
00125 void TraceBluegene::bgAmpiBeginExec(char *msg, char *name, void **logs, int count)
00126 {
00127 startVTimer();
00128 if (!genTimeLog) return;
00129 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
00130 curlog->setName(name);
00131 for (int i=0; i<count; i++)
00132 curlog->addBackwardDep((BgTimeLog*)logs[i]);
00133 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
00134 }
00135
00136 void TraceBluegene::bgAmpiLog(unsigned short op, unsigned int dataSize)
00137 {
00138 if (!genTimeLog) return;
00139 BgTimeLog *curlog = BgLastLog(tTIMELINEREC);
00140 curlog->mpiOp = op;
00141 curlog->mpiSize = dataSize;
00142 }
00143
00144 void TraceBluegene::bgEndExec(int commit)
00145 {
00146 stopVTimer();
00147 if (!genTimeLog) return;
00148 if (commit)
00149 BgLogEntryCommit(tTIMELINEREC);
00150 else
00151 BgEndLastLog(tTIMELINEREC);
00152 }
00153
00154 void TraceBluegene::beginExecute(envelope *e, void *obj)
00155 {
00156 if (e==NULL || !genTimeLog) return;
00157 BgTimeLog* log = tTIMELINE[tTIMELINE.length()-1];
00158 CmiAssert(log!=NULL);
00159 log->setCharmEP(e->getEpIdx());
00160 }
00161
00162 void TraceBluegene::beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx, void *obj)
00163 {
00164
00165 BgTimeLog* log;
00166 if(genTimeLog)
00167 log = tTIMELINE[tTIMELINE.length()-1];
00168 else
00169 return;
00170 if (idx!=NULL) log->setObjId(idx);
00171 log->setCharmEP(ep);
00172 }
00173
00174 void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
00175
00176 BgTimeLog* cLog = (BgTimeLog*) log;
00177
00178 if(cLog->forwardDeps.length() !=1) {
00179 cLog->write(stdout);
00180 CkAbort("Quitting\n");
00181 }
00182 *fDepPtr = (void*)(cLog->forwardDeps[0]);
00183 }
00184
00185 void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
00186 if(!genTimeLog) return;
00187
00188 CmiAssert(logsize>0);
00189 BgTimeLog* cLog = (BgTimeLog*)fDepPtr;
00190
00191 int i=0;
00192
00193
00194 for(i=0;i< logsize+1;i++)
00195 if(logs2[i])
00196 break;
00197
00198 if (i<logsize+1) {
00199 cLog->addBackwardDep((BgTimeLog*)logs2[i]);
00200 }
00201
00202
00203 cLog->objId = ((BgTimeLog*)logs1[0])->objId;
00204 for(int j=0;j<logsize;j++) {
00205 cLog->addBackwardDep((BgTimeLog*)(logs1[j]));
00206 CmiAssert(cLog->objId == ((BgTimeLog*)logs1[j])->objId);
00207 }
00208 }
00209
00210 void TraceBluegene::addBackwardDep(void *log)
00211 {
00212 if(!genTimeLog || log==NULL) return;
00213 BgTimeLog *parentLogPtr = BgLastLog(tTIMELINEREC);
00214 CmiAssert(parentLogPtr);
00215 BgAddBackwardDep(parentLogPtr, (BgTimeLog*)log);
00216 }
00217
00218 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr){
00219
00220 if (!genTimeLog) return;
00221
00222 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
00223 if(*parentLogPtr) {
00224 newLog->addBackwardDep(*(BgTimeLog**)parentLogPtr);
00225 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
00226 }
00227 *parentLogPtr = newLog;
00228 CmiAssert(*parentLogPtr != NULL);
00229 tTIMELINEREC.logEntryInsert(newLog);
00230 }
00231
00232 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){
00233
00234 if (!genTimeLog) return;
00235
00236 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
00237 newLog->addBackwardDeps(bgLogList);
00238 CmiAssert(bgLogList.size()>0);
00239 newLog->objId = ((BgTimeLog*)bgLogList[0])->objId;
00240 *parentLogPtr = newLog;
00241 tTIMELINEREC.logEntryInsert(newLog);
00242 }
00243
00244 void TraceBluegene::bgPrint(const char* str){
00245 if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiDisableIsomalloc();
00246 double curT = BgGetTime();
00247 if (genTimeLog)
00248 bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_PRINT);
00249 CmiPrintf(str, curT);
00250 if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiEnableIsomalloc();
00251 }
00252
00253 extern "C" void BgPrintf(const char *str)
00254 {
00255 BgPrint(str);
00256 }
00257
00258 void TraceBluegene::bgMark(const char* str){
00259 double curT = BgGetTime();
00260 if (genTimeLog)
00261 bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_MARK);
00262 }
00263
00264 extern "C" void BgMark(const char *str)
00265 {
00266 BgMark_(str);
00267 }
00268
00269 extern "C" void BgSetStartEvent()
00270 {
00271 BgTimeLog* log;
00272 if(genTimeLog)
00273 log = tTIMELINE[tTIMELINE.length()-1];
00274 else
00275 return;
00276 log->setStartEvent();
00277 }
00278