00001
00002
00005 #ifndef REP_H
00006 #define REP_H
00007 #include "sim.decl.h"
00008
00009 extern CProxy_sim POSE_Objects_RO;
00010
00011
00012 extern POSE_Config pose_config;
00013
00015 class rep
00016 {
00017 public:
00018 #if POSE_COMM_ON
00019 CProxy_sim POSE_Objects;
00020 #endif
00022 strat *myStrat;
00024 sim *parent;
00026
00027 int myHandle;
00029 POSE_TimeType ovt;
00031 double ort;
00033 unsigned int prand_seed;
00035 unsigned short int prand48_seed[3];
00037 int anti_methods;
00039
00040 POSE_TimeType simulationStartGVT;
00041 #ifdef MEM_TEMPORAL
00042 TimePool *localTimePool;
00043 #endif
00045 rep() {
00046 ovt = 0; ort = 0.0; parent = NULL; myStrat = NULL;
00047 anti_methods = 0;
00048 simulationStartGVT = (POSE_TimeType)-1;
00049 #ifndef SEQUENTIAL_POSE
00050 #ifdef POSE_COMM_ON
00051 POSE_Objects = POSE_Objects_RO;
00052 ComlibDelegateProxy(&POSE_Objects);
00053 #endif
00054 #endif
00055 #ifdef MEM_TEMPORAL
00056 localTimePool = (TimePool *)CkLocalBranch(TempMemID);
00057 #endif
00058 }
00060 rep(POSE_TimeType init_ovt) {
00061 ovt = init_ovt; ort = 0.0; anti_methods = 0;
00062 simulationStartGVT = (POSE_TimeType)-1;
00063 }
00065 virtual ~rep() {
00066 }
00068 void init(eventMsg *m);
00070 inline POSE_TimeType OVT() { return ovt; }
00072 inline void SetOVT(POSE_TimeType t) { ovt = t; }
00074 inline void useAntimethods() { anti_methods = 1; }
00076 inline void turnOffAntimethods() { anti_methods = 0; }
00078 inline int usesAntimethods() { return anti_methods; }
00080 inline void elapse(POSE_TimeType dt) { ovt += dt; }
00082
00084 void update(POSE_TimeType t, double rt);
00086 virtual void terminus() {
00087
00088 }
00090 virtual void registerTimestamp(int idx, eventMsg *m, POSE_TimeType offset);
00092 void setSimulationStartGVT(POSE_TimeType startGVT) {
00093 CkAssert(startGVT >= 0);
00094 simulationStartGVT = startGVT;
00095 }
00097
00098 inline virtual rep& operator=(const rep& obj) {
00099 ovt = obj.ovt;
00100 ort = obj.ort;
00101 myHandle = obj.myHandle;
00102 anti_methods = obj.anti_methods;
00103 prand_seed = obj.prand_seed;
00104 prand48_seed[0]=obj.prand48_seed[0];
00105 prand48_seed[1]=obj.prand48_seed[1];
00106 prand48_seed[2]=obj.prand48_seed[2];
00107 simulationStartGVT = obj.simulationStartGVT;
00108 return *this;
00109 }
00111 #if USE_LONG_TIMESTAMPS
00112 virtual void dump() { CkPrintf("[REP: ovt=%lld]\n", ovt); }
00113 #else
00114 virtual void dump() { CkPrintf("[REP: ovt=%d]\n", ovt); }
00115 #endif
00117
00118 virtual void pup(PUP::er &p) {
00119 p(ovt); p(ort); p(myHandle); p(anti_methods); p(prand_seed); p(prand48_seed,3); p(simulationStartGVT);
00120 }
00121 #ifdef SEQUENTIAL_POSE
00122 inline void checkpoint(rep *) { }
00123 inline void restore(rep *) { }
00124 #endif
00125 inline void POSE_srand(unsigned int pseed) { prand_seed = pseed; }
00126 inline int POSE_rand() {
00127 int rnum;
00128 srand(prand_seed);
00129 rnum = rand();
00130 prand_seed = rnum+INT_MAX;
00131 return rnum;
00132 }
00133 inline unsigned int POSE_urand() {
00134 int rnum;
00135 srand(prand_seed);
00136 rnum = rand();
00137 prand_seed = rnum+INT_MAX;
00138 return prand_seed;
00139 }
00140 #if !defined(_WIN32) || defined(__CYGWIN__)
00141 inline long int POSE_Linear_rand() { return nrand48(prand48_seed); }
00142 inline double POSE_Uniform_rand() { return erand48(prand48_seed); }
00143 #else
00144 inline long int POSE_Linear_rand() { return CrnRand(); }
00145 inline double POSE_Uniform_rand() { return 1.0*CrnRand()/MAXINT; }
00146 #endif
00147
00148 };
00149
00150 #endif