Make notifyMsg local to each helper instead of being local to the node helper
authorChao Mei <chaomei2@illinois.edu>
Thu, 23 Feb 2012 00:11:34 +0000 (18:11 -0600)
committerChao Mei <chaomei2@illinois.edu>
Thu, 23 Feb 2012 00:11:34 +0000 (18:11 -0600)
NodeHelper.C
NodeHelper.h

index 6f821b6ae5ec5965075d20411a49d3b2ac27d6b9..d2539af8fd87fba6768b2874f3a0db7e58730660 100644 (file)
@@ -10,10 +10,6 @@ FuncNodeHelper::FuncNodeHelper()
     
        numHelpers = CkMyNodeSize();
        helperPtr = new FuncSingleHelper *[numHelpers];
-       
-       notifyMsgs = (ConverseNotifyMsg *)malloc(sizeof(ConverseNotifyMsg)*numHelpers);
-       for(int i=0; i<numHelpers; i++) notifyMsgs[i].srcRank = -1;
-       
        useTreeBcast = (numHelpers >= USE_TREE_BROADCAST_THRESHOLD);
        
        int pestart = CkNodeFirst(CkMyNode());
@@ -64,11 +60,8 @@ void FuncNodeHelper::parallelizeFunc(HelperFn func, int paramNum, void * param,
        FuncSingleHelper *thisHelper = helperPtr[CkMyRank()];
        CurLoopInfo *curLoop = thisHelper->curLoop;
        curLoop->set(numChunks, func, lowerRange, upperRange, paramNum, param);
-       ConverseNotifyMsg *notifyMsg = &(notifyMsgs[CmiMyRank()]);
-       notifyMsg->ptr = (void *)curLoop;
-       
-       if(useTreeBcast){
-               notifyMsg->srcRank = CmiMyRank();
+    ConverseNotifyMsg *notifyMsg = thisHelper->notifyMsg;      
+       if(useTreeBcast){               
                int loopTimes = TREE_BCAST_BRANCH>(CmiMyNodeSize()-1)?CmiMyNodeSize()-1:TREE_BCAST_BRANCH;
                //just implicit binary tree
                int pe = CmiMyRank()+1;        
index c18c7c61205c61affdc67952f1e4cf3e95314651..abe9fa6805a9592671f99780252b20d34b558b54 100644 (file)
@@ -88,8 +88,7 @@ class FuncNodeHelper : public CBase_FuncNodeHelper {
        
 public:
     static int MAX_CHUNKS;
-private:
-    ConverseNotifyMsg *notifyMsgs;
+private:    
     int numHelpers;    
     FuncSingleHelper **helperPtr; /* ptrs to the FuncSingleHelpers it manages */
        int useTreeBcast;
@@ -98,13 +97,11 @@ public:
        FuncNodeHelper();
     ~FuncNodeHelper() {
         delete [] helperPtr;
-        delete [] notifyMsgs;
     }
 
     /* handler is only useful when converse msg is used to initiate tasks on the pseudo-thread */
-    void oneHelperCreated(int hid, FuncSingleHelper* cptr, int handler) {
+    void oneHelperCreated(int hid, FuncSingleHelper* cptr) {
         helperPtr[hid] = cptr;
-        CmiSetHandler(&(notifyMsgs[hid]), handler);
     }
     
     void parallelizeFunc(HelperFn func, /* the function that finishes a partial work on another thread */
@@ -123,8 +120,8 @@ void SingleHelperStealWork(ConverseNotifyMsg *msg);
 class FuncSingleHelper: public CBase_FuncSingleHelper {
        friend class FuncNodeHelper;
 private: 
-    int stealWorkHandler;
     FuncNodeHelper *thisNodeHelper;
+    ConverseNotifyMsg *notifyMsg;
     CurLoopInfo *curLoop; /* Points to the current loop that is being processed */
     
 public:
@@ -132,19 +129,29 @@ public:
         CProxy_FuncNodeHelper fh(nid);
         thisNodeHelper = fh[CkMyNode()].ckLocalBranch();
         CmiAssert(thisNodeHelper!=NULL);        
-        stealWorkHandler = CmiRegisterHandler((CmiHandler)SingleHelperStealWork);
+        int stealWorkHandler = CmiRegisterHandler((CmiHandler)SingleHelperStealWork);
         curLoop = new CurLoopInfo(FuncNodeHelper::MAX_CHUNKS);
+        
+        notifyMsg = (ConverseNotifyMsg *)malloc(sizeof(ConverseNotifyMsg));
+        if(thisNodeHelper->useTreeBcast){
+            notifyMsg->srcRank = CmiMyRank();
+        }else{
+            notifyMsg->srcRank = -1;
+        }
+        notifyMsg->ptr = (void *)curLoop;
+        CmiSetHandler(notifyMsg, stealWorkHandler);
     }
 
     ~FuncSingleHelper() {
         delete curLoop;
+        delete notifyMsg;
     }
     
     FuncSingleHelper(CkMigrateMessage *m) {}
                
     void reportCreated() {
         //CkPrintf("Single helper %d is created on rank %d\n", CkMyPe(), CkMyRank());
-               thisNodeHelper->oneHelperCreated(CkMyRank(), this, stealWorkHandler);
+               thisNodeHelper->oneHelperCreated(CkMyRank(), this);
     }    
 };