implement a scheme for user to register a callback to be called when migration is...
authorGengbin Zheng <gzheng@illinois.edu>
Wed, 20 Jul 2011 02:18:26 +0000 (21:18 -0500)
committerGengbin Zheng <gzheng@illinois.edu>
Wed, 20 Jul 2011 02:18:26 +0000 (21:18 -0500)
src/ck-ldb/CentralLB.C
src/ck-ldb/LBDBManager.C
src/ck-ldb/LBDBManager.h
src/ck-ldb/LBDatabase.h
src/ck-ldb/lbdb.C
src/ck-ldb/lbdb.h

index 4fb0efe56ef91137b5990d98504bbdc3b3ee9a61..8192c198287851b22983dba52a45de55a8e73bd5 100644 (file)
@@ -904,6 +904,8 @@ void CentralLB::MigrationDone(int balancing)
     startLoadBalancingMlog(&resumeCentralLbAfterChkpt,(void *)this);
 #endif
 
+  LBDatabase::Object()->MigrationDone();    // call registered callbacks
+
   LoadbalanceDone(balancing);        // callback
 #if (!defined(_FAULT_MLOG_) && !defined(_FAULT_CAUSAL_))
   // if sync resume invoke a barrier
index 92dd4ea72c8806770b12c123a908778a3584eaa7..94f991064836d5847f62fbbd9a822a909566e3e4 100644 (file)
@@ -35,9 +35,12 @@ void LBDB::batsyncer::resumeFromSync(void *bs)
 {
   LBDB::batsyncer *s=(LBDB::batsyncer *)bs;
 //  CmiPrintf("[%d] LBDB::batsyncer::resumeFromSync with %gs\n", CkMyPe(), s->period);
+
+#if 0
   double curT = CmiWallTimer();
   if (s->nextT<curT)  s->period *= 2;
   s->nextT = curT + s->period;
+#endif
 
   CcdCallFnAfterOnPE((CcdVoidFn)gotoSync, (void *)s, 1000*s->period, CkMyPe());
 }
@@ -398,6 +401,34 @@ void LBDB::StartLB()
   }
 }
 
+int LBDB::AddMigrationDoneFn(LDMigrationDoneFn fn, void* data) {
+  // Save migrationDone callback function
+  MigrationDoneCB* callbk = new MigrationDoneCB;
+
+  callbk->fn = fn;
+  callbk->data = data;
+  migrationDoneCBList.push_back(callbk);
+  return migrationDoneCBList.size()-1;
+}
+
+void LBDB::RemoveMigrationDoneFn(LDMigrationDoneFn fn) {
+  for (int i=0; i<migrationDoneCBList.length(); i++) {
+    MigrationDoneCB* callbk = migrationDoneCBList[i];
+    if (callbk && callbk->fn == fn) {
+      delete callbk;
+      migrationDoneCBList[i] = 0; 
+      break;
+    }
+  }
+}
+
+void LBDB::MigrationDone() {
+  for (int i=0; i<migrationDoneCBList.length(); i++) {
+    MigrationDoneCB *callbk = migrationDoneCBList[i];
+    if (callbk) callbk->fn(callbk->data);
+  }
+}
+
 void LBDB::SetupPredictor(LDPredictModelFn on, LDPredictWindowFn onWin, LDPredictFn off, LDPredictModelFn change, void* data)
 {
   if (predictCBFn==NULL) predictCBFn = new PredictCB;
index 5658cb73d762b5e6bf9b6c126d7e0f314ec8e82d..ec296796ae7f01d7546acb87c2f096e6752aacf0 100644 (file)
@@ -165,6 +165,10 @@ public:
   void RemoveStartLBFn(LDStartLBFn fn);
   void StartLB();
 
+  int AddMigrationDoneFn(LDMigrationDoneFn fn, void* data);
+  void RemoveMigrationDoneFn(LDMigrationDoneFn fn);
+  void MigrationDone();
+
   inline void IdleTime(LBRealType* walltime) 
        { machineUtil.IdleTime(walltime); };
   inline void TotalTime(LBRealType* walltime, LBRealType* cputime) 
@@ -242,6 +246,11 @@ private:
     int on;
   };
 
+  struct MigrationDoneCB {
+    LDMigrationDoneFn fn;
+    void* data;
+  };
+
   struct PredictCB {
     LDPredictModelFn on;
     LDPredictWindowFn onWin;
@@ -254,6 +263,7 @@ private:
   typedef CkVec<LBObj*> ObjList;
   typedef CkVec<MigrateCB*> MigrateCBList;
   typedef CkVec<StartLBCB*> StartLBCBList;
+  typedef CkVec<MigrationDoneCB*> MigrationDoneCBList;
 
   LBCommTable* commTable;
   OMList oms;
@@ -266,6 +276,8 @@ private:
   CmiBool statsAreOn;
   MigrateCBList migrateCBList;
 
+  MigrationDoneCBList migrationDoneCBList;
+
   PredictCB* predictCBFn;
 
   CmiBool obj_running;
index a414439eb78675728c82fd31df37d8032e3d98f3..1798448bf697b830908ff9f400f6538eee3ee05e 100644 (file)
@@ -265,8 +265,21 @@ public:
     LDRemoveStartLBFn(myLDHandle,fn);
   };
 
-public:
   inline void StartLB() { LDStartLB(myLDHandle); }
+
+  inline void AddMigrationDoneFn(LDMigrationDoneFn fn, void *data) 
+  {
+    LDAddMigrationDoneFn(myLDHandle,fn,data);
+  };
+
+  inline void RemoveMigrationDoneFn(LDMigrationDoneFn fn) 
+  {
+    LDRemoveMigrationDoneFn(myLDHandle,fn);
+  };
+
+  inline void MigrationDone() { LDMigrationDone(myLDHandle); }
+
+public:
   inline void TurnManualLBOn() { LDTurnManualLBOn(myLDHandle); }
   inline void TurnManualLBOff() { LDTurnManualLBOff(myLDHandle); }
  
index 9d322ee96295b52c3f8e24967c75867f74317ec4..66c6a33c24e9296266618c4c5732d9b308f23fbc 100644 (file)
@@ -146,6 +146,24 @@ extern "C" void LDTurnManualLBOff(LDHandle _db)
   db->TurnManualLBOff();
 }
 
+extern "C" int LDAddMigrationDoneFn(LDHandle _db, LDMigrationDoneFn fn,  void* data) 
+{
+  LBDB *const db = (LBDB*)(_db.handle);
+  db->AddMigrationDoneFn(fn,data);
+}
+
+extern "C" void  LDRemoveMigrationDoneFn(LDHandle _db, LDMigrationDoneFn fn)
+{
+  LBDB *const db = (LBDB*)(_db.handle);
+  db->RemoveMigrationDoneFn(fn);
+}
+
+extern "C" void LDMigrationDone(LDHandle _db)
+{
+  LBDB *const db = (LBDB*)(_db.handle);
+  db->MigrationDone();
+}
+
 extern "C" void LDTurnPredictorOn(LDHandle _db, void *model)
 {
   LBDB *const db = (LBDB*)(_db.handle);
index 5830d9e7723cf61ecb48f7931d3738d631fd53df..f6d85c8397866dd0a21b3c5587c7ddf3217e1dfc 100644 (file)
@@ -283,6 +283,11 @@ void LDStartLB(LDHandle _db);
 void LDTurnManualLBOn(LDHandle _lbdb);
 void LDTurnManualLBOff(LDHandle _lbdb);
 
+typedef void (*LDMigrationDoneFn)(void *user_ptr);
+int LDAddMigrationDoneFn(LDHandle _lbdb, LDMigrationDoneFn fn,  void* data);
+void  LDRemoveMigrationDoneFn(LDHandle _lbdb, LDMigrationDoneFn fn);
+void LDMigrationDone(LDHandle _lbdb);
+
 typedef void (*LDPredictFn)(void* user_ptr);
 typedef void (*LDPredictModelFn)(void* user_ptr, void* model);
 typedef void (*LDPredictWindowFn)(void* user_ptr, void* model, int wind);