fix for migration
[charm.git] / src / libs / ck-libs / tcharm / tcharm.C
index 7e5ff57bc2a9d3dd915c34fdcb54b48e6a6898f1..aca121847d7ffba30c68799312af9a1afe2551f3 100644 (file)
@@ -161,7 +161,6 @@ TCharm::TCharm(TCharmInitMsg *initMsg_)
   initMsg=initMsg_;
   initMsg->opts.sanityCheck();
   timeOffset=0.0;
-  threadGlobals=CtgCreate();
   if (tcharm_nothreads)
   { //Don't even make a new thread-- just use main thread
     tid=CthSelf();
@@ -178,6 +177,7 @@ TCharm::TCharm(TCharmInitMsg *initMsg_)
     BgUnsetStartOutOfCore();
 #endif
   }
+  threadGlobals=CtgCreate(tid);
   CtvAccessOther(tid,_curTCharm)=this;
   isStopped=true;
   resumeAfterMigration=false;
@@ -196,6 +196,8 @@ TCharm::TCharm(TCharmInitMsg *initMsg_)
   nUd=0;
   usesAtSync=CmiTrue;
   run();
+  CkCallback cb(CkIndex_TCharm::ResumeFromChkpSync(),thisProxy(thisIndex));
+  setChkpResumeClient(cb);
 }
 
 TCharm::TCharm(CkMigrateMessage *msg)
@@ -222,13 +224,16 @@ void checkPupMismatch(PUP::er &p,int expected,const char *where)
 void TCharm::pup(PUP::er &p) {
 //Pup superclass
   ArrayElement1D::pup(p);
-
   //BIGSIM_OOC DEBUGGING
   //if(!p.isUnpacking()){
   //  CmiPrintf("TCharm[%d] packing: ", thisIndex);
   //  CthPrintThdStack(tid);
   //}
-
+  //if(p.isUnpacking()&&CkInRestarting()){
+  if(p.isUnpacking()){
+    CkCallback cb(CkIndex_TCharm::ResumeFromChkpSync(),thisProxy(thisIndex));
+    setChkpResumeClient(cb);
+  }
   checkPupMismatch(p,5134,"before TCHARM");
 #if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
     if(!isStopped){
@@ -498,6 +503,7 @@ void TCharm::start(void)
 #else
   CthAwaken(tid);
 #endif
+  DBG("thread resuming soon");
 }
 
 //Block our thread, schedule, and come back:
@@ -520,6 +526,16 @@ void TCharm::migrate(void)
 }
 
 
+void TCharm::chkpsync(void)
+{
+#if CMK_LBDB_ON
+  DBG("going to sync");
+  AtChkpSync();
+  stop();
+#else
+  DBG("skipping sync, because there is no load balancer");
+#endif
+}
 
 void TCharm::evacuate(){
        /*
@@ -574,8 +590,13 @@ void TCharm::ResumeFromSync(void)
   //if(isSelfDone) return;
   //if (exitWhenDone) return; //for bigsim ooc execution
   if (!skipResume) start();
+  CkPrintf("thread ResumeFromSync\n");
 }
 
+void TCharm::ResumeFromChkpSync(void)
+{
+  start();
+}
 
 /****** TcharmClient ******/
 void TCharmClient1D::ckJustMigrated(void) {
@@ -887,7 +908,20 @@ CDECL void TCHARM_Migrate(void)
         }
        TCharm::get()->migrate();
 }
+
+CDECL void TCHARM_ChkpSync(void)
+{
+       TCHARMAPI("TCHARM_ChkpSync");
+       if (CthMigratable() == 0) {
+         if(CkMyPe() == 0)
+           CkPrintf("Warning> thread migration is not supported!\n");
+          return;
+        }
+       TCharm::get()->chkpsync();
+}
+
 FORTRAN_AS_C(TCHARM_MIGRATE,TCHARM_Migrate,tcharm_migrate,(void),())
+FORTRAN_AS_C(TCHARM_CHKPSYNC,TCHARM_ChkpSync,tcharm_chkpsync,(void),())
 
 CDECL void TCHARM_Async_Migrate(void)
 {