Cleaning up shutdown code of control point module to allow various things to complete...
authorIsaac Dooley <isaacdooley@hope.cs.uiuc.edu>
Mon, 21 Dec 2009 19:17:49 +0000 (13:17 -0600)
committerIsaac Dooley <isaacdooley@hope.cs.uiuc.edu>
Mon, 21 Dec 2009 19:17:49 +0000 (13:17 -0600)
src/ck-cp/controlPoints.C
src/ck-cp/controlPoints.h

index 15520ecc15763a6275997ea141b30cad2fa539bd..ef7efaca9269cfbc173d913dd75fc86675557fb8 100644 (file)
@@ -109,6 +109,7 @@ unsigned int randInt(unsigned int num, const char* name, int seed=0){
 
 controlPointManager::controlPointManager(){
 
+    exitWhenReady = false;
     newControlPointsAvailable = false;
     alreadyRequestedMemoryUsage = false;   
     alreadyRequestedIdleTime = false;
@@ -248,20 +249,7 @@ controlPointManager::controlPointManager(){
 
     CkPrintf("[%d] processControlPoints() haveGranularityCallback=%d frameworkShouldAdvancePhase=%d\n", CkMyPe(), (int)haveGranularityCallback, (int)frameworkShouldAdvancePhase);
 
-    if(shouldGatherMemoryUsage && CkMyPe() == 0 && !alreadyRequestedMemoryUsage){
-      alreadyRequestedMemoryUsage = true;
-      CkCallback *cb = new CkCallback(CkIndex_controlPointManager::gatherMemoryUsage(NULL), 0, thisProxy);
-      thisProxy.requestMemoryUsage(*cb);
-      delete cb;
-    }
-
-    if(shouldGatherUtilization && CkMyPe() == 0 && !alreadyRequestedIdleTime){
-      alreadyRequestedIdleTime = true;
-      CkCallback *cb = new CkCallback(CkIndex_controlPointManager::gatherIdleTime(NULL), 0, thisProxy);
-      thisProxy.requestIdleTime(*cb);
-      delete cb;
-    }
-
+   
     //==========================================================================================
     // Print the data for each phase
 
@@ -512,6 +500,23 @@ controlPointManager::controlPointManager(){
     
 #endif    
     
+    if(shouldGatherMemoryUsage && CkMyPe() == 0 && !alreadyRequestedMemoryUsage){
+      alreadyRequestedMemoryUsage = true;
+      CkCallback *cb = new CkCallback(CkIndex_controlPointManager::gatherMemoryUsage(NULL), 0, thisProxy);
+      thisProxy.requestMemoryUsage(*cb);
+      delete cb;
+    }
+
+    if(shouldGatherUtilization && CkMyPe() == 0 && !alreadyRequestedIdleTime){
+      alreadyRequestedIdleTime = true;
+      CkCallback *cb = new CkCallback(CkIndex_controlPointManager::gatherIdleTime(NULL), 0, thisProxy);
+      thisProxy.requestIdleTime(*cb);
+      delete cb;
+    }
+
+
+
+
     
     // increment phase id
     phase_id++;
@@ -578,11 +583,27 @@ controlPointManager::controlPointManager(){
     }
     
     alreadyRequestedIdleTime = false;
+    checkForShutdown();
     delete msg;
   }
-  
 
 
+  /// Call CkExit for this module once all outstanding operations have completed
+  void controlPointManager::checkForShutdown(){
+    if( exitWhenReady && !alreadyRequestedMemoryUsage && !alreadyRequestedIdleTime && CkMyPe()==0){
+      CkExit();
+    }
+  }
+
+
+  void controlPointManager::exitIfReady(){
+     if( !alreadyRequestedMemoryUsage && !alreadyRequestedIdleTime && CkMyPe()==0){
+      CkExit();
+     } else {
+       exitWhenReady = true;
+     }
+  }
+
   /// Entry method called on all PEs to request memory usage
   void controlPointManager::requestMemoryUsage(CkCallback cb){
     int m = CmiMaxMemoryUsage() / 1024 / 1024;
@@ -607,6 +628,7 @@ controlPointManager::controlPointManager(){
     }
 
     alreadyRequestedMemoryUsage = false;
+    checkForShutdown();
     delete msg;
   }
 
@@ -782,7 +804,10 @@ extern "C" void controlPointShutdown(){
       CkPrintf("[%d] controlPointShutdown() at CkExit()\n", CkMyPe());
       controlPointManagerProxy.ckLocalBranch()->writeDataFile();
     }
-    CkExit();
+
+    // wait for gathering of idle time & memory usage to complete
+    controlPointManagerProxy.ckLocalBranch()->exitIfReady();
+
   }
 }
 
index edc2dd69e956f063b4f5c7e03c77dae1628d9cb5..3401ac690edbd6a0bfd1c82a5b9b5fe30a648b73 100644 (file)
@@ -548,6 +548,9 @@ public:
   bool alreadyRequestedMemoryUsage;
   bool alreadyRequestedIdleTime;
 
+  bool exitWhenReady;
+
+
   controlPointManager();
      
   ~controlPointManager();
@@ -587,7 +590,11 @@ public:
   /// All processors reduce their memory usages in requestIdleTime() to this method
   void gatherIdleTime(CkReductionMsg *msg);
   
+  /// Call CkExit once all outstanding operations have completed (e.g. waiting for idle time & memory usage to be gathered)
+  void checkForShutdown();
 
+  /// Call CkExit once all outstanding operations have completed (e.g. waiting for idle time & memory usage to be gathered)
+  void exitIfReady();
 
   /// Entry method called on all PEs to request memory usage
   void requestMemoryUsage(CkCallback cb);