LRTS Comm Thread Tracing in message recieve
[charm.git] / src / ck-core / qd.h
blob822ae02fd3e7ec5c301e1356c38fcc92499bc4bf
1 #ifndef _QD_H
2 #define _QD_H
4 class QdMsg {
5 private:
6 int phase; // 0..2
7 union {
8 struct { /* none */ } p1;
9 struct { int created; int processed; } p2;
10 struct { /* none */ } p3;
11 struct { int dirty; } p4;
12 } u;
13 CkCallback cb;
14 public:
15 int getPhase(void) { return phase; }
16 void setPhase(int p) { phase = p; }
17 CkCallback getCb(void) { CkAssert(phase==0); return cb; }
18 void setCb(CkCallback cb_) { CkAssert(phase==0); cb = cb_; }
19 int getCreated(void) { CkAssert(phase==1); return u.p2.created; }
20 void setCreated(int c) { CkAssert(phase==1); u.p2.created = c; }
21 int getProcessed(void) { CkAssert(phase==1); return u.p2.processed; }
22 void setProcessed(int p) { CkAssert(phase==1); u.p2.processed = p; }
23 int getDirty(void) { CkAssert(phase==2); return u.p4.dirty; }
24 void setDirty(int d) { CkAssert(phase==2); u.p4.dirty = d; }
27 class QdCommMsg {
28 public:
29 int flag; // 0: create 1: process
30 int count;
33 class QdCallback {
34 public:
35 CkCallback cb;
36 public:
37 QdCallback(int e, CkChareID c) : cb(e, c) {}
38 QdCallback(CkCallback cb_) : cb(cb_) {}
39 // void send(void) { CkSendMsg(ep,CkAllocMsg(0,0,0),&cid); }
40 void send(void) {
41 // pretending pe 0 in blue gene mode, switch back after the call.
42 #if CMK_CONDS_USE_SPECIAL_CODE
43 int old = CmiSwitchToPE(0);
44 #endif
45 cb.send(NULL);
46 #if CMK_CONDS_USE_SPECIAL_CODE
47 CmiSwitchToPE(old);
48 #endif
52 class QdState {
53 private:
54 int stage; // 0..2
55 int oProcessed;
56 int mCreated, mProcessed;
57 int cCreated, cProcessed;
58 int cDirty;
59 int nReported;
60 PtrQ *callbacks;
61 int nChildren;
62 int parent;
63 int *children;
64 public:
65 QdState():stage(0),mCreated(0),mProcessed(0),nReported(0) {
66 cCreated = 0; cProcessed = 0; cDirty = 0;
67 oProcessed = 0;
68 callbacks = new PtrQ();
69 _MEMCHECK(callbacks);
70 nChildren = CmiNumSpanTreeChildren(CmiMyPe());
71 parent = CmiSpanTreeParent(CmiMyPe());
72 if (nChildren != 0) {
73 children = new int[nChildren];
74 _MEMCHECK(children);
75 CmiSpanTreeChildren(CmiMyPe(), children);
77 /* CmiPrintf("[%d] n:%d parent:%d - %d %d %d %d %d %d.\n", CmiMyPe(), nChildren, parent, nChildren?children[0]:-1, nChildren?children[1]:-1, nChildren?children[2]:-1, nChildren?children[3]:-1, nChildren?children[4]:-1, nChildren?children[5]:-1); */
79 void propagate(QdMsg *msg) {
80 envelope *env = UsrToEnv((void *)msg);
81 CmiSetHandler(env, _qdHandlerIdx);
82 for(int i=0; i<nChildren; i++) {
83 #if CMK_BIGSIM_CHARM
84 CmiSyncSendFn(children[i], env->getTotalsize(), (char *)env);
85 #else
86 CmiSyncSend(children[i], env->getTotalsize(), (char *)env);
87 #endif
90 int getParent(void) { return parent; }
91 QdCallback *deq(void) { return (QdCallback*) callbacks->deq(); }
92 void enq(QdCallback *c) { callbacks->enq((void *) c); }
93 void create(int n=1) {
94 mCreated += n;
95 #if CMK_IMMEDIATE_MSG
96 sendCount(0, n);
97 #endif
99 void sendCount(int flag, int count); // send msg to rank 0 for counting
100 void process(int n=1) {
101 mProcessed += n;
102 #if CMK_IMMEDIATE_MSG
103 sendCount(1, n);
104 #endif
106 int getCreated(void) { return mCreated; }
107 int getProcessed(void) { return mProcessed; }
108 int getCCreated(void) { return cCreated; }
109 int getCProcessed(void) { return cProcessed; }
110 void subtreeCreate(int c) { cCreated += c; }
111 void subtreeProcess(int p) { cProcessed += p; }
112 int getStage(void) { return stage; }
113 void setStage(int p) { stage = p; }
114 void reported(void) { nReported++; }
115 int allReported(void) {return nReported==(nChildren+1);}
116 void reset(void) { nReported=0; cCreated=0; cProcessed=0; cDirty=0; }
117 void markProcessed(void) { oProcessed = mProcessed; }
118 int isDirty(void) { return ((mProcessed > oProcessed) || cDirty); }
119 void subtreeSetDirty(int d) { cDirty = cDirty || d; }
120 void flushStates() {
121 stage = mCreated = mProcessed = nReported = 0;
122 cCreated = 0; cProcessed = 0; cDirty = 0;
123 oProcessed = 0;
127 extern void _qdHandler(envelope *);
128 extern void _qdCommHandler(envelope *);
129 CpvExtern(QdState*, _qd);
131 #endif