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
00015 #undef DEBUGF
00016 #define DEBUGF(x) // CmiPrintf x
00017
00018 void _createTracebluegene(char** argv)
00019 {
00020 DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
00021 CkpvInitialize(TraceBluegene*, _tracebg);
00022 CkpvAccess(_tracebg) = new TraceBluegene(argv);
00023 CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
00024 traceBluegeneLinked = 1;
00025 }
00026
00027
00028
00029 static void writeData(void *data, double t, double recvT, void *ptr)
00030 {
00031 FILE *fp = (FILE *)ptr;
00032 TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
00033 CmiAssert(fp && 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 }
00068
00069 void TraceBluegene::tlineEnd(void** parentLogPtr){
00070 if(genTimeLog)
00071 *parentLogPtr = (void*)BgLastLog(tTIMELINEREC);
00072 else
00073 *parentLogPtr = NULL;
00074 }
00075
00076 void TraceBluegene::bgAddTag(const char* str){
00077 if (!genTimeLog) return;
00078 BgTimeLog * log = BgLastLog(tTIMELINEREC);
00079 CmiAssert(log != NULL);
00080 log->setName(str);
00081 }
00082
00083 void TraceBluegene::bgDummyBeginExec(const char* name,void** parentLogPtr, int split)
00084 {
00085 if (genTimeLog) {
00086 CmiAssert(parentLogPtr!=NULL);
00087 double startTime = BgGetCurTime();
00088 BgTimeLog* newLog = BgStartLogByName(tTIMELINEREC, _threadEP, name, startTime, *(BgTimeLog**)parentLogPtr);
00089
00090
00091 if (*parentLogPtr == NULL)
00092 newLog->recvTime = startTime;
00093 else {
00094 if (split) {
00095 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
00096 newLog->charm_ep = (*(BgTimeLog**)parentLogPtr)->charm_ep;
00097 }
00098 }
00099 *parentLogPtr = newLog;
00100 }
00101 startVTimer();
00102 }
00103
00104 void TraceBluegene::bgBeginExec(char* msg, char *name)
00105 {
00106 startVTimer();
00107 if (!genTimeLog) return;
00108 BgTimeLog* newLog = new BgTimeLog(msg, name);
00109 tTIMELINEREC.logEntryStart(newLog);
00110 }
00111
00112
00113 void TraceBluegene::bgSetInfo(char *msg, const char *name, void **logs, int count)
00114 {
00115 if (!genTimeLog) return;
00116 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
00117 if (name != NULL) curlog->setName(name);
00118 for (int i=0; i<count; i++)
00119 curlog->addBackwardDep((BgTimeLog*)logs[i]);
00120 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
00121 }
00122
00123
00124 void TraceBluegene::bgAmpiBeginExec(char *msg, char *name, void **logs, int count)
00125 {
00126 startVTimer();
00127 if (!genTimeLog) return;
00128 BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
00129 curlog->setName(name);
00130 for (int i=0; i<count; i++)
00131 curlog->addBackwardDep((BgTimeLog*)logs[i]);
00132 if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
00133 }
00134
00135 void TraceBluegene::bgAmpiLog(unsigned short op, unsigned int dataSize)
00136 {
00137 if (!genTimeLog) return;
00138 BgTimeLog *curlog = BgLastLog(tTIMELINEREC);
00139 curlog->mpiOp = op;
00140 curlog->mpiSize = dataSize;
00141 }
00142
00143 void TraceBluegene::bgEndExec(int commit)
00144 {
00145 stopVTimer();
00146 if (!genTimeLog) return;
00147 if (commit)
00148 BgLogEntryCommit(tTIMELINEREC);
00149 else
00150 BgEndLastLog(tTIMELINEREC);
00151 }
00152
00153 void TraceBluegene::beginExecute(envelope *e)
00154 {
00155 if (e==NULL || !genTimeLog) return;
00156 BgTimeLog* log = tTIMELINE[tTIMELINE.length()-1];
00157 CmiAssert(log!=NULL);
00158 log->setCharmEP(e->getEpIdx());
00159 }
00160
00161 void TraceBluegene::beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx)
00162 {
00163
00164 BgTimeLog* log;
00165 if(genTimeLog)
00166 log = tTIMELINE[tTIMELINE.length()-1];
00167 else
00168 return;
00169 if (idx!=NULL) log->setObjId(idx);
00170 log->setCharmEP(ep);
00171 }
00172
00173 void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
00174
00175 BgTimeLog* cLog = (BgTimeLog*) log;
00176
00177 if(cLog->forwardDeps.length() !=1) {
00178 cLog->write(stdout);
00179 CkAbort("Quitting\n");
00180 }
00181 *fDepPtr = (void*)(cLog->forwardDeps[0]);
00182 }
00183
00184 void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
00185 if(!genTimeLog) return;
00186
00187 CmiAssert(logsize>0);
00188 BgTimeLog* cLog = (BgTimeLog*)fDepPtr;
00189
00190 int i=0;
00191
00192
00193 for(i=0;i< logsize+1;i++)
00194 if(logs2[i])
00195 break;
00196
00197 if (i<logsize+1) {
00198 cLog->addBackwardDep((BgTimeLog*)logs2[i]);
00199 }
00200
00201
00202 cLog->objId = ((BgTimeLog*)logs1[0])->objId;
00203 for(int j=0;j<logsize;j++) {
00204 cLog->addBackwardDep((BgTimeLog*)(logs1[j]));
00205 CmiAssert(cLog->objId == ((BgTimeLog*)logs1[j])->objId);
00206 }
00207 }
00208
00209 void TraceBluegene::addBackwardDep(void *log)
00210 {
00211 if(!genTimeLog || log==NULL) return;
00212 BgTimeLog *parentLogPtr = BgLastLog(tTIMELINEREC);
00213 CmiAssert(parentLogPtr);
00214 BgAddBackwardDep(parentLogPtr, (BgTimeLog*)log);
00215 }
00216
00217 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr){
00218
00219 if (!genTimeLog) return;
00220
00221 BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
00222 if(*parentLogPtr) {
00223 newLog->addBackwardDep(*(BgTimeLog**)parentLogPtr);
00224 newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
00225 }
00226 *parentLogPtr = newLog;
00227 CmiAssert(*parentLogPtr != NULL);
00228 tTIMELINEREC.logEntryInsert(newLog);
00229 }
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(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(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