00001 #ifndef CKMIGRATABLE_H
00002 #define CKMIGRATABLE_H
00003 
00004 class CkMigratable : public Chare {
00005 protected:
00006   CkLocRec *myRec;
00007 private:
00008   int thisChareType;
00009   int atsync_iteration;
00010   double prev_load;
00011   enum state : uint8_t {
00012     OFF,
00013     ON,
00014     PAUSE,
00015     DECIDED,
00016     LOAD_BALANCE
00017   } local_state;
00018   bool can_reset;
00019 protected:
00020   bool usesAtSync;
00021   bool usesAutoMeasure; 
00022   bool barrierRegistered;
00023 
00024 private: 
00025   LDBarrierClient ldBarrierHandle;
00026   LDBarrierReceiver ldBarrierRecvHandle;
00027 public:
00028   CkArrayIndex thisIndexMax;
00029 
00030 private:
00031   void commonInit(void);
00032 public:
00033   CkMigratable(void);
00034   CkMigratable(CkMigrateMessage *m);
00035   virtual ~CkMigratable();
00036   virtual void pup(PUP::er &p);
00037   virtual void CkAddThreadListeners(CthThread tid, void *msg);
00038 
00039   virtual int ckGetChareType(void) const;
00040   const CkArrayIndex &ckGetArrayIndex(void) const {return myRec->getIndex();}
00041   CmiUInt8 ckGetID(void) const { return myRec->getID(); }
00042 
00043 #if CMK_LBDB_ON  //For load balancing:
00044   
00045   inline void ckStopTiming(void) {myRec->stopTiming();}
00046   
00047   inline void ckStartTiming(void) {myRec->startTiming();}
00048   inline LBDatabase *getLBDB(void) const {return myRec->getLBDB();}
00049   inline MetaBalancer *getMetaBalancer(void) const {return myRec->getMetaBalancer();}
00050 #else
00051   inline void ckStopTiming(void) { }
00052   inline void ckStartTiming(void) { }
00053 #endif
00054 
00056   LDObjHandle timingBeforeCall(int *objstopped);
00057   void timingAfterCall(LDObjHandle objHandle,int *objstopped);
00058 
00059   
00060   inline void ckMigrate(int toPe) {myRec->migrateMe(toPe);}
00061   
00063   virtual void ckAboutToMigrate(void); 
00064   virtual void ckJustMigrated(void); 
00065 
00066   void recvLBPeriod(void *data);
00067   void metaLBCallLB();
00068   void clearMetaLBData(void);
00069 
00070   
00071   virtual void ckJustRestored(void); 
00072 
00074   virtual void ckDestroy(void);
00075 
00078   inline bool ckInvokeEntry(int epIdx,void *msg,bool doFree) 
00079       {return myRec->invokeEntry(this,msg,epIdx,doFree);}
00080 
00081 protected:
00083   virtual void CkAbort(const char *str) const;
00084 
00085 public:
00086   virtual void ResumeFromSync(void);
00087   virtual void UserSetLBLoad(void);  
00088   void setObjTime(double cputime);
00089   double getObjTime();
00090 #if CMK_LB_USER_DATA
00091   void *getObjUserData(int idx);
00092 #endif
00093 
00094 #if CMK_LBDB_ON  //For load balancing:
00095   void AtSync(int waitForMigration=1);
00096   int MigrateToPe()  { return myRec->MigrateToPe(); }
00097 
00098 private:
00099   static void staticResumeFromSync(void* data);
00100 public:
00101   void ReadyMigrate(bool ready);
00102   void ckFinishConstruction(void);
00103   void setMigratable(int migratable);
00104   void setPupSize(size_t obj_pup_size);
00105 #else
00106   void AtSync(int waitForMigration=1) { ResumeFromSync();}
00107   void setMigratable(int migratable)  { }
00108   void setPupSize(size_t obj_pup_size) { }
00109 public:
00110   void ckFinishConstruction(void) { }
00111 #endif
00112 
00113 #if CMK_OUT_OF_CORE
00114 private:
00115   friend class CkLocMgr;
00116   friend int CkArrayPrefetch_msg2ObjId(void *msg);
00117   friend void CkArrayPrefetch_writeToSwap(FILE *swapfile,void *objptr);
00118   friend void CkArrayPrefetch_readFromSwap(FILE *swapfile,void *objptr);
00119   int prefetchObjID; 
00120   bool isInCore; 
00121 #endif
00122 
00123 #if CMK_FAULT_EVAC
00124 private:
00125   bool asyncEvacuate;
00126   void AsyncEvacuate(bool set){myRec->AsyncEvacuate(set);asyncEvacuate = set;};
00127 public:
00128   bool isAsyncEvacuate(){return asyncEvacuate;};
00129 #endif
00130 };
00131 
00132 #endif // CKMIGRATABLE_H