00001 00002 #ifndef CHPT_H 00003 #define CHPT_H 00004 extern POSE_Config pose_config; 00005 00007 00009 template<class StateType> class chpt : public rep { 00010 public: 00011 int sinceLast; 00013 chpt() : sinceLast(pose_config.store_rate){ } 00015 virtual ~chpt() { } 00016 void registerTimestamp(int idx, eventMsg *m, POSE_TimeType offset); 00018 void checkpoint(StateType *data); 00020 00025 void restore(StateType *data); 00026 virtual void pup(PUP::er &p) { rep::pup(p); } 00027 virtual void dump() { rep::dump(); } 00028 }; 00029 00030 00032 template<class StateType> 00033 inline void chpt<StateType>::registerTimestamp(int idx, eventMsg *m, POSE_TimeType offset) 00034 { 00035 m->Timestamp(ovt+offset); 00036 m->setPriority(ovt+offset-POSE_TimeMax); 00037 parent->registerSent(ovt+offset); 00038 ((opt *)myStrat)->AddSpawnedEvent(idx, m->evID, m->timestamp); 00039 } 00040 00042 template<class StateType> 00043 void chpt<StateType>::checkpoint(StateType *data) 00044 { 00045 #if !CMK_TRACE_DISABLED 00046 localStat *localStats = (localStat *)CkLocalBranch(theLocalStats); 00047 if(pose_config.stats) 00048 localStats->SwitchTimer(CP_TIMER); 00049 #endif 00050 if (usesAntimethods()) { 00051 myStrat->currentEvent->cpData = new rep; 00052 *(myStrat->currentEvent->cpData) = *(rep *)data; 00053 } 00054 else { 00055 #ifdef MEM_TEMPORAL 00056 CmiAssert(!(parent->myStrat->currentEvent->serialCPdata)); 00057 #else 00058 CmiAssert(!(parent->myStrat->currentEvent->cpData)); 00059 #endif 00060 // if ((myStrat->currentEvent->timestamp > 00061 //myStrat->currentEvent->prev->timestamp) || (sinceLast == STORE_RATE)) { 00062 if ((sinceLast == ((opt *)myStrat)->cpRate) || 00063 //(CpvAccess(stateRecovery) == 1) || 00064 (myStrat->currentEvent->prev == parent->eq->front())) { 00065 #ifdef MEM_TEMPORAL 00066 PUP::sizer sp; 00067 ((StateType *)data)->cpPup(sp); 00068 myStrat->currentEvent->serialCPdataSz = sp.size(); 00069 myStrat->currentEvent->serialCPdata = localTimePool->tmp_alloc(myStrat->currentEvent->timestamp, myStrat->currentEvent->serialCPdataSz); 00070 00071 PUP::toMem tp(myStrat->currentEvent->serialCPdata); 00072 ((StateType *)data)->cpPup(tp); 00073 if (tp.size()!=myStrat->currentEvent->serialCPdataSz) 00074 CmiAbort("PUP packing size mismatch!"); 00075 #else 00076 myStrat->currentEvent->cpData = new StateType; 00077 *((StateType *)myStrat->currentEvent->cpData) = *data; 00078 #endif 00079 sinceLast = 0; 00080 #if !CMK_TRACE_DISABLED 00081 //localStats->Checkpoint(); 00082 //localStats->CPbytes(sizeof(StateType)); 00083 #endif 00084 } 00085 else sinceLast++; 00086 } 00087 #if !CMK_TRACE_DISABLED 00088 if(pose_config.stats) 00089 localStats->SwitchTimer(SIM_TIMER); 00090 #endif 00091 } 00092 00094 template<class StateType> 00095 void chpt<StateType>::restore(StateType *data) 00096 { 00097 if (usesAntimethods()) { 00098 *(rep *)data = *(myStrat->currentEvent->cpData); 00099 delete myStrat->currentEvent->cpData; 00100 myStrat->currentEvent->cpData = NULL; 00101 } 00102 else { 00103 if (myStrat->currentEvent == myStrat->targetEvent) { 00104 #ifdef MEM_TEMPORAL 00105 if (myStrat->targetEvent->serialCPdata) { 00106 // data should be a pre-allocated PUP::able object 00107 PUP::fromMem fp(myStrat->targetEvent->serialCPdata); 00108 ((StateType *)data)->cpPup(fp); 00109 if (fp.size()!=myStrat->targetEvent->serialCPdataSz) 00110 CmiAbort("PUP unpack size mismatch!"); 00111 localTimePool->tmp_free(myStrat->targetEvent->timestamp, myStrat->targetEvent->serialCPdata); 00112 myStrat->targetEvent->serialCPdata = NULL; 00113 myStrat->targetEvent->serialCPdataSz = 0; 00114 } 00115 #else 00116 if (myStrat->targetEvent->cpData) { 00117 *data = *((StateType *)myStrat->targetEvent->cpData); 00118 delete myStrat->targetEvent->cpData; 00119 myStrat->targetEvent->cpData = NULL; 00120 } 00121 #endif 00122 } 00123 #ifdef MEM_TEMPORAL 00124 if (myStrat->currentEvent->serialCPdata) { 00125 localTimePool->tmp_free(myStrat->currentEvent->timestamp, myStrat->currentEvent->serialCPdata); 00126 myStrat->currentEvent->serialCPdata = NULL; 00127 myStrat->currentEvent->serialCPdataSz = 0; 00128 } 00129 #else 00130 if (myStrat->currentEvent->cpData) { 00131 delete myStrat->currentEvent->cpData; 00132 myStrat->currentEvent->cpData = NULL; 00133 } 00134 #endif 00135 } 00136 } 00137 00138 #endif