/home/runner/work/charm/charm/src/ck-ldb/LBObj.h
Line | Count | Source |
1 | | /** |
2 | | * \addtogroup CkLdb |
3 | | */ |
4 | | /*@{*/ |
5 | | |
6 | | #ifndef LBOBJ_H |
7 | | #define LBOBJ_H |
8 | | |
9 | | #include "lbdb.h" |
10 | | |
11 | | class LBDatabase; |
12 | | |
13 | | class LBObj |
14 | | { |
15 | | friend class LBDatabase; |
16 | | |
17 | | public: |
18 | 1.43M | LBObj(const LDObjHandle &_h, void *usr_ptr = NULL, bool _migratable=true, bool _asyncArrival = false) { |
19 | 1.43M | data.handle = _h; |
20 | 1.43M | data.migratable = _migratable; |
21 | 1.43M | data.asyncArrival = _asyncArrival; |
22 | 1.43M | Clear(); |
23 | | // data.cpuTime = 0.; |
24 | | // data.wallTime = 0.; |
25 | | // data.minWall = 1e6; |
26 | | // data.maxWall = 0.; |
27 | 1.43M | localUserData = usr_ptr; |
28 | | // migratable = _migratable; |
29 | | // registered = true; |
30 | 1.43M | startWTime = -1.0; |
31 | 1.43M | lastWallTime = .0; |
32 | | #if CMK_LB_CPUTIMER |
33 | | startCTime = -1.0; |
34 | | lastCpuTime = .0; |
35 | | #endif |
36 | 1.43M | } |
37 | | |
38 | 527k | ~LBObj() { }; |
39 | | |
40 | | void Clear(void); |
41 | | |
42 | | void IncrementTime(LBRealType walltime, LBRealType cputime); |
43 | | void IncrementGPUTime(LBRealType gputime); |
44 | | |
45 | 1.97M | inline void StartTimer(void) { |
46 | 1.97M | startWTime = CkWallTimer(); |
47 | | #if CMK_LB_CPUTIMER |
48 | | startCTime = CkCpuTimer(); |
49 | | #endif |
50 | 1.97M | } |
51 | | inline void StopTimer(LBRealType* walltime, LBRealType* cputime) { |
52 | | if (startWTime >= 0.0) { // in case startOn in middle of entry |
53 | | const double endWTime = CkWallTimer(); |
54 | | *walltime = endWTime - startWTime; |
55 | | #if CMK_LB_CPUTIMER |
56 | | const double endCTime = CkCpuTimer(); |
57 | | *cputime = endCTime - startCTime; |
58 | | #else |
59 | | *cputime = *walltime; |
60 | | #endif |
61 | | } |
62 | | else { |
63 | | *walltime = *cputime = 0.0; |
64 | | } |
65 | | } |
66 | | |
67 | | inline void getTime(LBRealType *w, LBRealType *c) { |
68 | | *w = data.wallTime; |
69 | | #if CMK_LB_CPUTIMER |
70 | | *c = data.cpuTime; |
71 | | #else |
72 | | *c = *w; |
73 | | #endif |
74 | | } |
75 | | |
76 | | inline void setTiming(LBRealType cputime) |
77 | 10.9k | { |
78 | 10.9k | data.wallTime = cputime; |
79 | | #if CMK_LB_CPUTIMER |
80 | | data.cpuTime = cputime; |
81 | | #endif |
82 | 10.9k | } |
83 | | |
84 | | inline void getGPUTime(LBRealType *w) |
85 | | { |
86 | | #if CMK_CUDA |
87 | | *w = data.gpuTime; |
88 | | #else |
89 | | CmiAbort("LBObj::getGPUTime called but CMK_CUDA is not set"); |
90 | | #endif |
91 | | } |
92 | | |
93 | | inline void setGPUTiming(LBRealType gputime) |
94 | | { |
95 | | #if CMK_CUDA |
96 | | data.gpuTime = gputime; |
97 | | #else |
98 | | CmiAbort("LBObj::setGPUTiming called but CMK_CUDA is not set"); |
99 | | #endif |
100 | | } |
101 | | |
102 | 51.7k | inline LDOMHandle &parentOM() { return data.handle.omhandle; } |
103 | 1.63k | inline const LDObjHandle &GetLDObjHandle() const { return data.handle; } |
104 | | inline void SetMigratable(bool mig) { data.migratable = mig; } |
105 | | inline void setPupSize(size_t obj_pup_size) { |
106 | | data.pupSize = pup_encodeSize(obj_pup_size); |
107 | | } |
108 | | inline void setGPUPupSize(size_t obj_gpu_pup_size) { |
109 | | #if CMK_CUDA |
110 | | data.gpuPupSize = obj_gpu_pup_size; |
111 | | #else |
112 | | CmiAbort("LBObj::setGPUPupSize called but CMK_CUDA is not set"); |
113 | | #endif |
114 | | } |
115 | | inline void UseAsyncMigrate(bool async) { data.asyncArrival = async; } |
116 | 62.7k | inline LDObjData &ObjData() { return data; }; |
117 | | inline void lastKnownLoad(LBRealType *w, LBRealType *c) { |
118 | | *w = lastWallTime; |
119 | | #if CMK_LB_CPUTIMER |
120 | | *c = lastCpuTime; |
121 | | #else |
122 | | *c = *w; |
123 | | #endif |
124 | | } |
125 | | inline void *getLocalUserData() { return localUserData; } |
126 | | #if CMK_LB_USER_DATA |
127 | | inline void *getDBUserData(int idx) { return data.getUserData(idx); } |
128 | | #endif |
129 | | private: |
130 | | |
131 | | void *localUserData; // local user data, not in database |
132 | | // LDOMHandle parentOM; |
133 | | // LDObjHandle myhandle; |
134 | | LDObjData data; |
135 | | // bool registered; |
136 | | double startWTime; // needs double precision |
137 | | LBRealType lastWallTime; |
138 | | #if CMK_LB_CPUTIMER |
139 | | double startCTime; |
140 | | LBRealType lastCpuTime; |
141 | | #endif |
142 | | // bool migratable; // temp |
143 | | }; |
144 | | |
145 | | #endif |
146 | | |
147 | | /*@}*/ |