Fix breakages caused by commit 48ed568c6
[charm.git] / src / ck-perf / trace-bluegene.C
blobb71823db49607fb91e52de021650e6abf3d3af94
2 /**
3  * \addtogroup CkPerf
4 */
5 /*@{*/
8 #include "charm++.h"
9 #include "envelope.h"
10 #include "trace-common.h"
11 #include "trace-bluegene.h"
12 #include "blue.h"
13 #include "blue_impl.h"
15 #undef DEBUGF
16 #define DEBUGF(x)  // CmiPrintf x
18 void _createTracebluegene(char** argv)
20   DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
21   CkpvInitialize(TraceBluegene*, _tracebg);
22   CkpvAccess(_tracebg) = new  TraceBluegene(argv);
23   CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
24   traceBluegeneLinked = 1;
28 // this PE must be trace-enabled(in trace-common.C) to be able to do bgPrint()
29 static void writeData(void *data, double t, double recvT, void *ptr)
31   TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
32   CmiAssert(traceBluegene);
33   traceBluegene->writePrint((char*)data, t);
36 void TraceBluegene::writePrint(char* str, double t){
37   if (pfp == NULL)
38     creatFiles();
39   fprintf(pfp,"[%d] ", CkMyPe());
40   fprintf(pfp,str,t);
43 TraceBluegene::TraceBluegene(char** argv): pfp(NULL)
47 void TraceBluegene::traceClose() {
48   DEBUGF(("%d TraceBluegene::traceClose\n", CkMyPe()));
49   bgUpdateProj(2);
50   if(pfp != 0)  fclose(pfp);
51   pfp = NULL;
52   CkpvAccess(_traces)->removeTrace(this);
55 TraceBluegene::~TraceBluegene(){
58 CpvExtern(BGMach, bgMach);
59 void TraceBluegene::creatFiles()
61   char* fname = new char[1024];
62   sprintf(fname, "%sbgPrintFile.%d", cva(bgMach).traceroot?cva(bgMach).traceroot:"", CkMyPe()); 
63   pfp = fopen(fname,"w");     
64   if(pfp==NULL)
65     CmiAbort("Cannot open Bluegene print file for writing.\n");
66   delete[] fname;
69 void TraceBluegene::tlineEnd(void** parentLogPtr){
70   if(genTimeLog)
71     *parentLogPtr = (void*)BgLastLog(tTIMELINEREC);
72   else
73     *parentLogPtr = NULL;
76 void TraceBluegene::bgAddTag(const char* str){
77   if (!genTimeLog) return;
78   BgTimeLog * log = BgLastLog(tTIMELINEREC);
79   CmiAssert(log != NULL);
80   log->setName(str);
83 void TraceBluegene::bgDummyBeginExec(const char* name,void** parentLogPtr, int split)
85   if (genTimeLog) {
86   CmiAssert(parentLogPtr!=NULL);
87   double startTime = BgGetCurTime();
88   BgTimeLog* newLog = BgStartLogByName(tTIMELINEREC, _threadEP, name, startTime, *(BgTimeLog**)parentLogPtr);
89   // if event's mesgID is (-1:-1) and there is no backward dependence
90   // to avoid timestamp correction, set a fake recv time so that it stays here
91   if (*parentLogPtr == NULL)
92     newLog->recvTime = startTime;
93   else {
94     if (split) {
95       newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
96       newLog->charm_ep = (*(BgTimeLog**)parentLogPtr)->charm_ep;
97     }
98   }
99   *parentLogPtr = newLog;
100   }
101   startVTimer();
104 void TraceBluegene::bgBeginExec(char* msg, char *name)
106   startVTimer();
107   if (!genTimeLog) return;
108   BgTimeLog* newLog = new BgTimeLog(msg, name);
109   tTIMELINEREC.logEntryStart(newLog);
112 // mark a new log, which depends on log
113 void TraceBluegene::bgSetInfo(char *msg, const char *name, void **logs, int count)
115   if (!genTimeLog) return;
116   BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
117   if (name != NULL) curlog->setName(name);
118   for (int i=0; i<count; i++)
119       curlog->addBackwardDep((BgTimeLog*)logs[i]);
120   if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
123 // mark a new log, which depends on log
124 void TraceBluegene::bgAmpiBeginExec(char *msg, char *name, void **logs, int count)
126   startVTimer();
127   if (!genTimeLog) return;
128   BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
129   curlog->setName(name);
130   for (int i=0; i<count; i++)
131       curlog->addBackwardDep((BgTimeLog*)logs[i]);
132   if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
135 void TraceBluegene::bgAmpiLog(unsigned short op, unsigned int dataSize)
137     if (!genTimeLog) return;
138     BgTimeLog *curlog = BgLastLog(tTIMELINEREC);
139     curlog->mpiOp = op;
140     curlog->mpiSize = dataSize;
143 void TraceBluegene::bgEndExec(int commit)
145   stopVTimer();
146   if (!genTimeLog) return;
147   if (commit) 
148     BgLogEntryCommit(tTIMELINEREC);
149   else
150     BgEndLastLog(tTIMELINEREC);
153 void TraceBluegene::beginExecute(envelope *e, void *obj)
155   if (e==NULL || !genTimeLog) return;
156   BgTimeLog* log = tTIMELINE[tTIMELINE.length()-1];
157   CmiAssert(log!=NULL);
158   log->setCharmEP(e->getEpIdx());
161 void TraceBluegene::beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx, void *obj)
163   //printf("SET OBJ ID\n");
164   BgTimeLog* log;
165   if(genTimeLog)
166     log = tTIMELINE[tTIMELINE.length()-1];
167   else
168     return;
169   if (idx!=NULL) log->setObjId(idx);
170   log->setCharmEP(ep);
173 void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
175   BgTimeLog* cLog = (BgTimeLog*) log;
176   
177   if(cLog->forwardDeps.length() !=1) {
178     cLog->write(stdout);
179     CkAbort("Quitting\n");
180   }
181   *fDepPtr = (void*)(cLog->forwardDeps[0]);
184 void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
185   if(!genTimeLog) return;
187   CmiAssert(logsize>0);
188   BgTimeLog* cLog = (BgTimeLog*)fDepPtr;
190   int i=0;
192   // find the valid sdag overlap pointer
193   for(i=0;i< logsize+1;i++)
194     if(logs2[i])
195       break;    
196   
197   if (i<logsize+1) {
198     cLog->addBackwardDep((BgTimeLog*)logs2[i]);
199   }
200   // CmiAssert(i<logsize+1);
201   
202   cLog->objId = ((BgTimeLog*)logs1[0])->objId;    // sdag objID
203   for(int j=0;j<logsize;j++)  {
204       cLog->addBackwardDep((BgTimeLog*)(logs1[j]));
205       CmiAssert(cLog->objId == ((BgTimeLog*)logs1[j])->objId);
206   }
209 void TraceBluegene::addBackwardDep(void *log)
211   if(!genTimeLog || log==NULL) return;
212   BgTimeLog  *parentLogPtr = BgLastLog(tTIMELINEREC);
213   CmiAssert(parentLogPtr);
214   BgAddBackwardDep(parentLogPtr, (BgTimeLog*)log);
217 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr){
219   if (!genTimeLog) return;
221   BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
222   if(*parentLogPtr) {
223     newLog->addBackwardDep(*(BgTimeLog**)parentLogPtr);
224     newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;        // sdag objID
225   }
226   *parentLogPtr = newLog;
227   CmiAssert(*parentLogPtr != NULL);
228   tTIMELINEREC.logEntryInsert(newLog);
231 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){
232    
233   if (!genTimeLog) return;
235   BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
236   newLog->addBackwardDeps(bgLogList);
237   CmiAssert(bgLogList.size()>0);
238   newLog->objId = ((BgTimeLog*)bgLogList[0])->objId;   // for sdag
239   *parentLogPtr = newLog;
240   tTIMELINEREC.logEntryInsert(newLog);
243 void TraceBluegene::bgPrint(const char* str){
244   if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiDisableIsomalloc();
245   double curT = BgGetTime();
246   if (genTimeLog)
247     bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_PRINT);
248   CmiPrintf(str, curT);
249   if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiEnableIsomalloc();
252 extern "C" void BgPrintf(const char *str)
254   BgPrint(str);
257 void TraceBluegene::bgMark(const char* str){
258   double curT = BgGetTime();
259   if (genTimeLog)
260     bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_MARK);
263 extern "C" void BgMark(const char *str)
265   BgMark_(str);
268 extern "C" void BgSetStartEvent()
270   BgTimeLog* log;
271   if(genTimeLog)
272     log = tTIMELINE[tTIMELINE.length()-1];
273   else
274     return;
275   log->setStartEvent();
278 /*@}*/