Fixed a bug in the case when a busy helper cannot run the previous
authorChao Mei <chaomei2@illinois.edu>
Wed, 22 Feb 2012 00:02:17 +0000 (18:02 -0600)
committerChao Mei <chaomei2@illinois.edu>
Wed, 22 Feb 2012 00:02:17 +0000 (18:02 -0600)
loop task in time, but then happens to run stealWork (the msg from
the previous task) during the initialization of a new loop task.

NodeHelper.C
NodeHelper.h

index 08ff8988703bbaab7e14cf73c7b3a5dd8b74450d..454a325c71cfc2091338caed621ce2c73e75454e 100644 (file)
@@ -450,6 +450,10 @@ void FuncSingleHelper::processWork(int filler) {
 }
 
 void CurLoopInfo::stealWork(){
+    //indicate the current work hasn't been initialized
+    //or the old work has finished.
+    if(inited == 0) return;
+    
     int first, last;
     int unit = (upperIndex-lowerIndex+1)/numChunks;
     int remainder = (upperIndex-lowerIndex+1)-unit*numChunks;
index 900254692f16f2bfd938fa3b5f622abdc9609a17..c27988a70743969ff6626a9f6d853fdbc9790d14 100644 (file)
@@ -88,9 +88,13 @@ private:
     
     volatile int finishFlag;
     
+    //a tag to indicate whether the task for this new loop has been inited
+    //this tag is needed to prevent other helpers to run the old task
+    int inited;
+    
 public:    
     CurLoopInfo():numChunks(0),fnPtr(NULL), lowerIndex(-1), upperIndex(0), 
-    paramNum(0), param(NULL), curChunkIdx(-1), finishFlag(0), redBufs(NULL) {}
+    paramNum(0), param(NULL), curChunkIdx(-1), finishFlag(0), redBufs(NULL), inited(0) {}
     
     ~CurLoopInfo() { delete [] redBufs; }
     
@@ -103,10 +107,13 @@ public:
         param = p;
         curChunkIdx = -1;
         finishFlag = 0;
+        //needs to be set last
+        inited = 1;
     }
       
     void waitLoopDone(){
         while(!__sync_bool_compare_and_swap(&finishFlag, numChunks, 0));
+        inited = 0;
     }
     int getNextChunkIdx(){
         return __sync_add_and_fetch(&curChunkIdx, 1);