00001 #ifndef _QD_H
00002 #define _QD_H
00003
00004 #include "ckcallback.h"
00005 #include "envelope.h"
00006 #include "init.h"
00007
00008 class QdMsg;
00009 class QdCallback;
00010
00011 class QdState {
00012 private:
00013 int stage;
00014 char cDirty;
00015 CmiInt8 oProcessed;
00016 CmiInt8 mCreated, mProcessed;
00017 CmiInt8 cCreated, cProcessed;
00018 int nReported;
00019 PtrQ *callbacks;
00020 int nChildren;
00021 int parent;
00022 std::vector<int> children;
00023 public:
00024 CmiInt8 oldCount;
00025
00026 QdState():stage(0),mCreated(0),mProcessed(0),nReported(0) {
00027 cCreated = 0; cProcessed = 0; cDirty = 0;
00028 oProcessed = 0;
00029 oldCount = -1;
00030 callbacks = new PtrQ();
00031 _MEMCHECK(callbacks);
00032 nChildren = CmiNumSpanTreeChildren(CmiMyPe());
00033 parent = CmiSpanTreeParent(CmiMyPe());
00034 if (nChildren != 0) {
00035 children.resize(nChildren);
00036 _MEMCHECK(children.data());
00037 CmiSpanTreeChildren(CmiMyPe(), children.data());
00038 }
00039
00040 }
00041 void propagate(QdMsg *msg) {
00042 envelope *env = UsrToEnv((void *)msg);
00043 CmiSetHandler(env, _qdHandlerIdx);
00044 for(int i=0; i<nChildren; i++) {
00045 #if CMK_BIGSIM_CHARM
00046 CmiSyncSendFn(children[i], env->getTotalsize(), (char *)env);
00047 #else
00048 CmiSyncSend(children[i], env->getTotalsize(), (char *)env);
00049 #endif
00050 }
00051 }
00052 int getParent(void) { return parent; }
00053 QdCallback *deq(void) { return (QdCallback*) callbacks->deq(); }
00054 void enq(QdCallback *c) { callbacks->enq((void *) c); }
00055 void create(int n=1) {
00056 mCreated += n;
00057 #if CMK_IMMEDIATE_MSG
00058 sendCount(false, n);
00059 #endif
00060 }
00061 void sendCount(bool isCreated, int count);
00062 void process(int n=1) {
00063 mProcessed += n;
00064 #if CMK_IMMEDIATE_MSG
00065 sendCount(true, n);
00066 #endif
00067 }
00068 CmiInt8 getCreated(void) { return mCreated; }
00069 CmiInt8 getProcessed(void) { return mProcessed; }
00070 CmiInt8 getCCreated(void) { return cCreated; }
00071 CmiInt8 getCProcessed(void) { return cProcessed; }
00072 void subtreeCreate(CmiInt8 c) { cCreated += c; }
00073 void subtreeProcess(CmiInt8 p) { cProcessed += p; }
00074 int getStage(void) { return stage; }
00075 void setStage(int p) { stage = p; }
00076 void reported(void) { nReported++; }
00077 int allReported(void) {return nReported==(nChildren+1);}
00078 void reset(void) { nReported=0; cCreated=0; cProcessed=0; cDirty=0; }
00079 void markProcessed(void) { oProcessed = mProcessed; }
00080 int isDirty(void) { return ((mProcessed > oProcessed) || cDirty); }
00081 void subtreeSetDirty(char d) { cDirty = cDirty || d; }
00082 void flushStates() {
00083 stage = mCreated = mProcessed = nReported = 0;
00084 cCreated = 0; cProcessed = 0; cDirty = 0;
00085 oProcessed = 0;
00086 }
00087 };
00088
00089 extern void _qdHandler(envelope *);
00090 extern void _qdCommHandler(envelope *);
00091 CpvExtern(QdState*, _qd);
00092
00093 #endif