Merge branch 'charm' of charmgit:charm into xiang/optChkp
[charm.git] / src / ck-perf / trace-bluegene.h
1 /**
2  * \addtogroup CkPerf
3 */
4 /*@{*/
5
6 #ifndef _TRACE_BIGSIM_H
7 #define _TRACE_BIGSIM_H
8
9 #include "trace.h"
10
11 // Bigsim emulator specific tracing subroutines.
12 class TraceBluegene : public Trace {
13
14  private:
15     FILE* pfp;
16  public:
17     TraceBluegene(char** argv);
18     ~TraceBluegene();
19     virtual void setTraceOnPE(int flag) { _traceOn = 1; }  // always on
20     int traceOnPE() { return 1; }
21     void getForwardDep(void* log, void** fDepPtr);
22     void getForwardDepForAll(void** logs1, void** logs2, int logsize,void* fDepPtr);
23     void tlineEnd(void** parentLogPtr);
24     void bgAddTag(const char *str);
25     void bgDummyBeginExec(const char* name,void** parentLogPtr, int split);
26     void bgBeginExec(char* msg, char *str);
27     void bgAmpiBeginExec(char *msg, char *str, void **logs, int count);
28     void bgAmpiLog(unsigned short op, unsigned int size);
29     void bgSetInfo(char *msg, const char *str, void **logs, int count);
30     void bgEndExec(int);
31     virtual void beginExecute(envelope *);
32     virtual void beginExecute(char *) {}
33     virtual void beginExecute(CmiObjId *tid) {}
34     virtual void beginExecute(int event,int msgType,int ep,int srcPe, int mlen,CmiObjId *idx);
35     void addBackwardDep(void *log);
36     void userBracketEvent(int eventID, double bt, double et) {} // from trace.h
37     void userBracketEvent(const char* name, double bt, double et, void** parentLogPtr);
38     void userBracketEvent(const char* name, double bt, double et, void** parentLogPtr, CkVec<void*> bgLogList);
39     void bgPrint(const char* str);
40     void bgMark(char* str);
41     void creatFiles();
42     void writePrint(char *, double t);
43     void traceClose();
44 };
45
46 CkpvExtern(TraceBluegene*, _tracebg);
47 extern int traceBluegeneLinked;
48
49 #if CMK_TRACE_ENABLED
50 #  define _TRACE_BG_ONLY(code) do{ BgGetTime(); if(traceBluegeneLinked && CpvAccess(traceOn)){ code; } resetVTime(); } while(0)
51 #else
52 #  define _TRACE_BG_ONLY(code) /*empty*/
53 #endif
54
55 /* tracing for Blue Gene - before trace projector era */
56 #if CMK_TRACE_ENABLED && CMK_TRACE_IN_CHARM
57 // for Sdag only
58 // fixme - think of better api for tracing sdag code
59 #define BgPrint(x)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgPrint(x))
60 #define BgMark_(x)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgMark(x))
61 #define _TRACE_BG_BEGIN_EXECUTE_NOMSG(x,pLogPtr,split)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgDummyBeginExec(x,pLogPtr,split))
62 #define _TRACE_BG_BEGIN_EXECUTE(msg, str)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgBeginExec(msg, str))
63 #define _TRACE_BG_SET_INFO(msg, str, logs, count)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgSetInfo(msg, str, logs, count))
64 #define _TRACE_BG_AMPI_BEGIN_EXECUTE(msg, str, logs, count)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgAmpiBeginExec(msg, str, logs, count))
65 #define _TRACE_BG_END_EXECUTE(commit)   _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgEndExec(commit))
66 #define _TRACE_BG_TLINE_END(pLogPtr) _TRACE_BG_ONLY(CkpvAccess(_tracebg)->tlineEnd(pLogPtr))
67 #define _TRACE_BG_FORWARD_DEPS(logs1,logs2,size,fDep)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->getForwardDepForAll(logs1,logs2, size,fDep))
68 #define _TRACE_BG_ADD_BACKWARD_DEP(log)  _TRACE_BG_ONLY(CkpvAccess(_tracebg)->addBackwardDep(log))
69 #define _TRACE_BG_USER_EVENT_BRACKET(x,bt,et,pLogPtr) _TRACE_BG_ONLY(CkpvAccess(_tracebg)->userBracketEvent(x,bt,et,pLogPtr))
70 #define _TRACE_BGLIST_USER_EVENT_BRACKET(x,bt,et,pLogPtr,bgLogList) _TRACE_BG_ONLY(CkpvAccess(_tracebg)->userBracketEvent(x,bt,et,pLogPtr,bgLogList))
71 #define TRACE_BG_ADD_TAG(str)   _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgAddTag(str))
72
73 # define TRACE_BG_AMPI_LOG(op,size)                                     \
74     _TRACE_BG_ONLY(CkpvAccess(_tracebg)->bgAmpiLog(op,size))
75
76 # define TRACE_BG_AMPI_SUSPEND()     \
77         _TRACE_BG_END_EXECUTE(1); \
78         /* if(CpvAccess(traceOn)) traceSuspend(); */
79
80 # define TRACE_BG_AMPI_START(t, str)  { \
81         void* _bgParentLog = NULL;      \
82         /*_TRACE_BG_TLINE_END(&_bgParentLog);*/ \
83         if(CpvAccess(traceOn) && t) CthTraceResume(t);  \
84         _TRACE_BG_BEGIN_EXECUTE_NOMSG(str, &_bgParentLog, 1);      \
85         }
86
87 # define TRACE_BG_AMPI_BREAK(t, str, event, count, connect)     \
88         {       \
89         void *curLog;    /* store current log in timeline */    \
90         _TRACE_BG_TLINE_END(&curLog);   \
91         TRACE_BG_AMPI_SUSPEND();        \
92         /* TRACE_BG_AMPI_START(t, str);  */  \
93         void * _bgParentLog = NULL;      \
94          _TRACE_BG_BEGIN_EXECUTE_NOMSG(str, &_bgParentLog, 1);  \
95         for(int i=0;i<count;i++) {      \
96                 _TRACE_BG_ADD_BACKWARD_DEP(((void**)event)[i]);      \
97         }       \
98         if (connect) _TRACE_BG_ADD_BACKWARD_DEP(curLog);      \
99         }
100         
101
102 #define TRACE_BG_AMPI_WAITALL(reqs)     \
103         {       \
104         /* TRACE_BG_AMPI_SUSPEND(); */  \
105         CthThread th = getAmpiInstance(MPI_COMM_WORLD)->getThread();    \
106         TRACE_BG_AMPI_BREAK(th, "AMPI_WAITALL", NULL, 0, 0);    \
107         _TRACE_BG_ADD_BACKWARD_DEP(curLog);     \
108         for(int i=0;i<count;i++) {      \
109           if (request[i] == MPI_REQUEST_NULL) continue; \
110           void *log = (*reqs)[request[i]]->event;       \
111           _TRACE_BG_ADD_BACKWARD_DEP(log);      \
112         }       \
113         }
114 extern "C" void BgSetStartEvent();
115 #else
116 # define BgPrint(x)  
117 # define BgMark_(x)  
118 #define _TRACE_BG_BEGIN_EXECUTE_NOMSG(x,pLogPtr,split)
119 #define _TRACE_BG_BEGIN_EXECUTE(msg, str)
120 #define _TRACE_BG_SET_INFO(msg, str, logs, count) 
121 #define _TRACE_BG_AMPI_BEGIN_EXECUTE(msg, str, logs, count)
122 #define _TRACE_BG_END_EXECUTE(commit)
123 #define _TRACE_BG_TLINE_END(x)  
124 #define _TRACE_BG_FORWARD_DEP(logs1,logs2,size,fDep)
125 #define _TRACE_BG_BACKWARD_DEP(log)     
126 #define _TRACE_BG_USER_EVENT_BRACKET(x,bt,et,pLogPtr)
127 #define _TRACE_BGLIST_USER_EVENT_BRACKET(x,bt,et,pLogPtr,bgLogList)
128 #define _TRACE_BG_ADD_TAG(str)
129         
130 # define TRACE_BG_AMPI_LOG(op, size)
131 # define TRACE_BG_AMPI_SUSPEND()
132 # define TRACE_BG_AMPI_RESUME(t, msg, str, log)
133 # define TRACE_BG_AMPI_START(t, str)
134 # define TRACE_BG_NEWSTART(t, str, events, count)
135 # define TRACE_BG_AMPI_BREAK(t, str, event, count)
136 # define TRACE_BG_AMPI_WAITALL(reqs)
137 # define TRACE_BG_AMPI_SET_SIZE(size)
138 #endif   /* CMK_TRACE_IN_CHARM */
139
140 extern "C" void BgPrintf(const char *str);
141 extern "C" void BgMark(char *str);
142
143 #endif
144
145 /*@}*/