Link conv-cpm as C++
[charm.git] / src / ck-perf / trace-bluegene.C
blob512ecdb963aacbfc6996675cae2dbeadde53a2b9
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"
14 #include "memory-isomalloc.h"
16 #undef DEBUGF
17 #define DEBUGF(x)  // CmiPrintf x
19 void _createTracebluegene(char** argv)
21   DEBUGF(("%d createTraceBluegene\n", CkMyPe()));
22   CkpvInitialize(TraceBluegene*, _tracebg);
23   CkpvAccess(_tracebg) = new  TraceBluegene(argv);
24   CkpvAccess(_traces)->addTrace(CkpvAccess(_tracebg));
25   traceBluegeneLinked = 1;
29 // this PE must be trace-enabled(in trace-common.C) to be able to do bgPrint()
30 static void writeData(void *data, double t, double recvT, void *ptr)
32   TraceBluegene *traceBluegene = (TraceBluegene *)ptr;
33   CmiAssert(traceBluegene);
34   traceBluegene->writePrint((char*)data, t);
37 void TraceBluegene::writePrint(char* str, double t){
38   if (pfp == NULL)
39     creatFiles();
40   fprintf(pfp,"[%d] ", CkMyPe());
41   fprintf(pfp,str,t);
44 TraceBluegene::TraceBluegene(char** argv): pfp(NULL)
48 void TraceBluegene::traceClose() {
49   DEBUGF(("%d TraceBluegene::traceClose\n", CkMyPe()));
50   bgUpdateProj(2);
51   if(pfp != 0)  fclose(pfp);
52   pfp = NULL;
53   CkpvAccess(_traces)->removeTrace(this);
56 TraceBluegene::~TraceBluegene(){
59 CpvExtern(BGMach, bgMach);
60 void TraceBluegene::creatFiles()
62   char* fname = new char[1024];
63   sprintf(fname, "%sbgPrintFile.%d", cva(bgMach).traceroot?cva(bgMach).traceroot:"", CkMyPe()); 
64   pfp = fopen(fname,"w");     
65   if(pfp==NULL)
66     CmiAbort("Cannot open Bluegene print file for writing.\n");
67   delete[] fname;
70 void TraceBluegene::tlineEnd(void** parentLogPtr){
71   if(genTimeLog)
72     *parentLogPtr = (void*)BgLastLog(tTIMELINEREC);
73   else
74     *parentLogPtr = NULL;
77 void TraceBluegene::bgAddTag(const char* str){
78   if (!genTimeLog) return;
79   BgTimeLog * log = BgLastLog(tTIMELINEREC);
80   CmiAssert(log != NULL);
81   log->setName(str);
84 void TraceBluegene::bgDummyBeginExec(const char* name,void** parentLogPtr, int split)
86   if (genTimeLog) {
87   CmiAssert(parentLogPtr!=NULL);
88   double startTime = BgGetCurTime();
89   BgTimeLog* newLog = BgStartLogByName(tTIMELINEREC, _threadEP, name, startTime, *(BgTimeLog**)parentLogPtr);
90   // if event's mesgID is (-1:-1) and there is no backward dependence
91   // to avoid timestamp correction, set a fake recv time so that it stays here
92   if (*parentLogPtr == NULL)
93     newLog->recvTime = startTime;
94   else {
95     if (split) {
96       newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;
97       newLog->charm_ep = (*(BgTimeLog**)parentLogPtr)->charm_ep;
98     }
99   }
100   *parentLogPtr = newLog;
101   }
102   startVTimer();
105 void TraceBluegene::bgBeginExec(char* msg, char *name)
107   startVTimer();
108   if (!genTimeLog) return;
109   BgTimeLog* newLog = new BgTimeLog(msg, name);
110   tTIMELINEREC.logEntryStart(newLog);
113 // mark a new log, which depends on log
114 void TraceBluegene::bgSetInfo(char *msg, const char *name, void **logs, int count)
116   if (!genTimeLog) return;
117   BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
118   if (name != NULL) curlog->setName(name);
119   for (int i=0; i<count; i++)
120       curlog->addBackwardDep((BgTimeLog*)logs[i]);
121   if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
124 // mark a new log, which depends on log
125 void TraceBluegene::bgAmpiBeginExec(char *msg, char *name, void **logs, int count)
127   startVTimer();
128   if (!genTimeLog) return;
129   BgTimeLog * curlog = BgLastLog(tTIMELINEREC);
130   curlog->setName(name);
131   for (int i=0; i<count; i++)
132       curlog->addBackwardDep((BgTimeLog*)logs[i]);
133   if (msg) curlog->addMsgBackwardDep(tTIMELINEREC, msg);
136 void TraceBluegene::bgAmpiLog(unsigned short op, unsigned int dataSize)
138     if (!genTimeLog) return;
139     BgTimeLog *curlog = BgLastLog(tTIMELINEREC);
140     curlog->mpiOp = op;
141     curlog->mpiSize = dataSize;
144 void TraceBluegene::bgEndExec(int commit)
146   stopVTimer();
147   if (!genTimeLog) return;
148   if (commit) 
149     BgLogEntryCommit(tTIMELINEREC);
150   else
151     BgEndLastLog(tTIMELINEREC);
154 void TraceBluegene::beginExecute(envelope *e, void *obj)
156   if (e==NULL || !genTimeLog) return;
157   BgTimeLog* log = tTIMELINE[tTIMELINE.length()-1];
158   CmiAssert(log!=NULL);
159   log->setCharmEP(e->getEpIdx());
162 void TraceBluegene::beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx, void *obj)
164   //printf("SET OBJ ID\n");
165   BgTimeLog* log;
166   if(genTimeLog)
167     log = tTIMELINE[tTIMELINE.length()-1];
168   else
169     return;
170   if (idx!=NULL) log->setObjId(idx);
171   log->setCharmEP(ep);
174 void TraceBluegene::getForwardDep(void* log, void** fDepPtr){
176   BgTimeLog* cLog = (BgTimeLog*) log;
177   
178   if(cLog->forwardDeps.length() !=1) {
179     cLog->write(stdout);
180     CkAbort("Quitting\n");
181   }
182   *fDepPtr = (void*)(cLog->forwardDeps[0]);
185 void TraceBluegene::getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr){
186   if(!genTimeLog) return;
188   CmiAssert(logsize>0);
189   BgTimeLog* cLog = (BgTimeLog*)fDepPtr;
191   int i=0;
193   // find the valid sdag overlap pointer
194   for(i=0;i< logsize+1;i++)
195     if(logs2[i])
196       break;    
197   
198   if (i<logsize+1) {
199     cLog->addBackwardDep((BgTimeLog*)logs2[i]);
200   }
201   // CmiAssert(i<logsize+1);
202   
203   cLog->objId = ((BgTimeLog*)logs1[0])->objId;    // sdag objID
204   for(int j=0;j<logsize;j++)  {
205       cLog->addBackwardDep((BgTimeLog*)(logs1[j]));
206       CmiAssert(cLog->objId == ((BgTimeLog*)logs1[j])->objId);
207   }
210 void TraceBluegene::addBackwardDep(void *log)
212   if(!genTimeLog || log==NULL) return;
213   BgTimeLog  *parentLogPtr = BgLastLog(tTIMELINEREC);
214   CmiAssert(parentLogPtr);
215   BgAddBackwardDep(parentLogPtr, (BgTimeLog*)log);
218 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr){
220   if (!genTimeLog) return;
222   BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
223   if(*parentLogPtr) {
224     newLog->addBackwardDep(*(BgTimeLog**)parentLogPtr);
225     newLog->objId = (*(BgTimeLog**)parentLogPtr)->objId;        // sdag objID
226   }
227   *parentLogPtr = newLog;
228   CmiAssert(*parentLogPtr != NULL);
229   tTIMELINEREC.logEntryInsert(newLog);
232 void TraceBluegene::userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList){
233    
234   if (!genTimeLog) return;
236   BgTimeLog* newLog = new BgTimeLog(_threadEP,name,bt,et);
237   newLog->addBackwardDeps(bgLogList);
238   CmiAssert(bgLogList.size()>0);
239   newLog->objId = ((BgTimeLog*)bgLogList[0])->objId;   // for sdag
240   *parentLogPtr = newLog;
241   tTIMELINEREC.logEntryInsert(newLog);
244 void TraceBluegene::bgPrint(const char* str){
245   if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiDisableIsomalloc();
246   double curT = BgGetTime();
247   if (genTimeLog)
248     bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_PRINT);
249   CmiPrintf(str, curT);
250   if (CmiMemoryIs(CMI_MEMORY_IS_ISOMALLOC)) CmiEnableIsomalloc();
253 extern "C" void BgPrintf(const char *str)
255   BgPrint(str);
258 void TraceBluegene::bgMark(const char* str){
259   double curT = BgGetTime();
260   if (genTimeLog)
261     bgAddProjEvent(strdup(str), -1, curT, writeData, this, BG_EVENT_MARK);
264 extern "C" void BgMark(const char *str)
266   BgMark_(str);
269 extern "C" void BgSetStartEvent()
271   BgTimeLog* log;
272   if(genTimeLog)
273     log = tTIMELINE[tTIMELINE.length()-1];
274   else
275     return;
276   log->setStartEvent();
279 /*@}*/