changa 3.5
Loading...
Searching...
No Matches
Compute.h
Go to the documentation of this file.
1#ifndef __COMPUTE_H__
2#define __COMPUTE_H__
3
4#ifdef COOLING_MOLECULARH
5#include "Vector3D.h"
6#endif /*COOLING_MOLECULARH*/
7
8#include "codes.h"
9#include "ParallelGravity.h"
10
11class State;
12class DoubleWalkState;
13
17
18class TreeWalk;
19class Opt;
20
26class Compute{
27 protected:
28 Opt *opt;
29 void *computeEntity;
30 int activeRung;
31 ComputeType type;
32
33 Compute(ComputeType t) : type(t) /*state(0)*/{}
34
35 public:
36 int nActive; // accumulate total number of active particles.
37 void setOpt(Opt *opt);
38 // should the dowork method have a state argument?
39 // yes, allows listcompute object to keep modifying state
40 // which will have within it the checklist, clist and plist
42 virtual int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi) = 0;
43 // should return int, not bool
44 virtual int openCriterion(TreePiece *ownerTP,
45 GenericTreeNode *node, int reqID, State *state) = 0;
46
47 virtual void stateReady(State *state, TreePiece *owner, int chunk, int start, int end) {}
48
49 virtual void stateReadyPar(TreePiece *tp, int start, int end,
50 CkVec<OffsetNode>& clist, CkVec<RemotePartInfo>& rpilist,
51 CkVec<LocalPartInfo>& lpilist){}
52
53 virtual void fillLists(State *state_, TreePiece *tp, int chunk, int start,
54 int end, CkVec<OffsetNode>& clistforb, CkVec<RemotePartInfo>& rplistforb,
55 CkVec<LocalPartInfo>& lplistforb) {}
56
59 virtual void init(void *cE, int activeRung, Opt *opt);
60 virtual void reassoc(void *cE, int aR, Opt *opt){}
61 ComputeType getSelfType(){ return type;}
62 OptType getOptType();
63 int getActiveRung() {return activeRung;}
64
65 // Default impl is empty. Currently only redefined by ListCompute
66 // Initializes state.
67 virtual void initState(State *state){}
73 virtual void startNodeProcessEvent(State *state) {}
75 virtual void finishNodeProcessEvent(TreePiece *owner, State *state) {}
77 virtual void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp) {}
79 virtual void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket){}
81 virtual void recvdParticles(ExternalGravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket){}
83 virtual void recvdParticlesFull(GravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket){}
84 virtual ~Compute(){}
85 virtual void walkDone(State *state){}
86 virtual void setComputeEntity(void *ce){
87 computeEntity = ce;
88 }
89
90 virtual void *getComputeEntity(){
91 return computeEntity;
92 }
93
94 virtual State *getNewState(int d1, int d2);
95 virtual State *getNewState(int d1);
96 virtual State *getNewState();
97 virtual void freeState(State *state);
98};
99
100#include "SSEdefs.h"
101
105class GravityCompute : public Compute{
106#ifdef BENCHMARK_TIME_COMPUTE
107 double computeTimePart;
108 double computeTimeNode;
109#endif
110
111 void updateInterMass(GravityParticle *p, int start, int end, double mass);
112 void updateInterMass(GravityParticle *p, int start, int end, GravityParticle *s, Vector3D<cosmoType> &offset);
113
114 public:
115 GravityCompute() : Compute(Gravity){
116#ifdef BENCHMARK_TIME_COMPUTE
117 computeTimePart = 0.0;
118 computeTimeNode = 0.0;
119#endif
120 }
121 ~GravityCompute() {
122#ifdef BENCHMARK_TIME_COMPUTE
123 CkPrintf("Compute time part: %f\n",computeTimePart);
124 CkPrintf("Compute time node: %f\n",computeTimeNode);
125#endif
126 }
127
128 int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi);
129
130 int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
131 int computeParticleForces(TreePiece *owner, GenericTreeNode *node, ExternalGravityParticle *part, int reqID);
132
133 // book keeping on notifications
134 void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp);
135 void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
136 void recvdParticles(ExternalGravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket);
137
138 void reassoc(void *cE, int activeRung, Opt *o);
139
140};
141
142#if INTERLIST_VER > 0
148class ListCompute : public Compute{
149
150 public:
151 ListCompute() : Compute(List) {
152 bUseCpu = 0;
153 }
154
155 int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi);
156
157 int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
158
159 // book keeping on notifications
160 void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp);
161 void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
162 void recvdParticles(ExternalGravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket);
163
164 void initState(State *state);
165
166 void stateReady(State *, TreePiece *, int chunk, int start, int end);
167
168 void stateReadyPar(TreePiece *tp, int start, int end,
169 CkVec<OffsetNode>& clist, CkVec<RemotePartInfo>& rpilist,
170 CkVec<LocalPartInfo>& lpilist);
171
172 void fillLists(State *state_, TreePiece *tp, int chunk, int start,
173 int end, CkVec<OffsetNode>& clistforb, CkVec<RemotePartInfo>& rplistforb,
174 CkVec<LocalPartInfo>& lplistforb);
175
176// void printUndlist(DoubleWalkState *state, int level, TreePiece *tp);
177// void printClist(DoubleWalkState *state, int level, TreePiece *tp);
178 void reassoc(void *cE, int activeRung, Opt *o);
179 State *getNewState(int d1, int d2);
180 State *getNewState(int d1);
182 void freeState(State *state);
185 void enableCpu() {bUseCpu = 1;}
186
187#ifdef CUDA
188#ifdef GPU_LOCAL_TREE_WALK
189 void sendLocalTreeWalkTriggerToGpu(State *state, TreePiece *tp, int activeRung, int startBucket, int endBucket);
190#endif //GPU_LOCAL_TREE_WALK
191 void sendNodeInteractionsToGpu(DoubleWalkState *state, TreePiece *tp);
192 void sendPartInteractionsToGpu(DoubleWalkState *state, TreePiece *tp);
193#endif
194
195 private:
196
197 void addChildrenToCheckList(GenericTreeNode *node, int reqID, int chunk, int awi, State *s, CheckList &chklist, TreePiece *tp);
198 void addNodeToInt(GenericTreeNode *node, int offsetID, DoubleWalkState *s);
199
200 DoubleWalkState *allocDoubleWalkState();
202 int bUseCpu;
203
204#if defined CHANGA_REFACTOR_PRINT_INTERACTIONS || defined CHANGA_REFACTOR_WALKCHECK_INTERLIST || defined CUDA
205 void addRemoteParticlesToInt(ExternalGravityParticle *parts, int n,
206 Vector3D<cosmoType> &offset, DoubleWalkState *s,
207 NodeKey key);
208 void addLocalParticlesToInt(GravityParticle *parts, int n,
209 Vector3D<cosmoType> &offset, DoubleWalkState *s,
210 NodeKey key, GenericTreeNode *gtn);
211#else
212 void addRemoteParticlesToInt(ExternalGravityParticle *parts, int n,
213 Vector3D<cosmoType> &offset, DoubleWalkState *s);
214 void addLocalParticlesToInt(GravityParticle *parts, int n,
215 Vector3D<cosmoType> &offset, DoubleWalkState *s);
216#endif
217
218#ifdef CUDA
219 void getBucketParameters(TreePiece *tp, int bucket, int &bucketStart, int &bucketSize, std::map<NodeKey, int>&lpref);
220
221 public:
222 void resetCudaNodeState(DoubleWalkState *state);
223 void resetCudaPartState(DoubleWalkState *state);
224 void initCudaState(DoubleWalkState *state, int numBuckets, int nodeThreshold, int partThreshold, bool resume);
225
226#endif
227
228};
229#endif
230
232class PrefetchCompute : public Compute{
233
234 public:
235 PrefetchCompute() : Compute(Prefetch) {
236 computeEntity = 0;
237 }
238 virtual int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi);
239 int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqIDD, State *state);
240
241 // book-keeping on notifications
242 void startNodeProcessEvent(State *state);
243 void finishNodeProcessEvent(TreePiece *owner, State *state);
244
245 void recvdParticles(ExternalGravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket);
246};
247
250class DummyPrefetchCompute : public PrefetchCompute {
251 public:
253 int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi){
254 return DUMP;
255 }
256};
257
259
261 prefetchAwi = 0,
262 interListAwi = 1,
263 remoteGravityAwi = 2,
264 smoothAwi = 3,
265 maxAwi = 4
266};
267
270class ActiveWalk {
271 public:
272 TreeWalk *tw;
273 Compute *c;
274 Opt *o;
275 State *s;
276
277 ActiveWalk(TreeWalk *_tw, Compute *_c, Opt *_o, State *state) :
278 tw(_tw), c(_c), o(_o), s(state){}
279 ActiveWalk(){}
280};
281
284
285 public:
286 virtual bool work(GenericTreeNode *node, int level) = 0;
287 virtual void doneChildren(GenericTreeNode *node, int level) {}
288};
289
292class RemoteTreeBuilder : public TreeNodeWorker {
293 TreePiece *tp;
294 bool requestNonLocalMoments;
295
296 public:
297 RemoteTreeBuilder(TreePiece *owner, bool req) :
298 tp(owner),
299 requestNonLocalMoments(req)
300 {}
301
302 bool work(GenericTreeNode *node, int level);
303 void doneChildren(GenericTreeNode *node, int level);
304
305 private:
306 void registerNode(GenericTreeNode *node);
307
308};
309
311class LocalTreeBuilder : public TreeNodeWorker {
312 TreePiece *tp;
313
314 public:
315 LocalTreeBuilder(TreePiece *owner) :
316 tp(owner)
317 {}
318
319 bool work(GenericTreeNode *node, int level);
320 void doneChildren(GenericTreeNode *node, int level);
321
322 private:
323 void registerNode(GenericTreeNode *node);
324};
325
329class LocalTreePrinter : public TreeNodeWorker {
330 int index;
331 std::ofstream file;
332 string description;
333
334 void openFile();
335
336 public:
337 LocalTreePrinter(string d, int idx) :
338 index(idx),
339 description(d)
340 {
341 openFile();
342 }
343
344 ~LocalTreePrinter(){
345 file << "}" << std::endl;
346 file.close();
347 }
348
349 bool work(GenericTreeNode *node, int level);
350 void doneChildren(GenericTreeNode *node, int level);
351};
352
353#ifdef COOLING_MOLECULARH
354class LocalLymanWernerDistributor : public TreeNodeWorker {
355 /*Defining a new class inherited from TreeNodeWorker to use while distributing LW over a depth-first walk */
356 TreePiece *tp; /*Defined in ParallelGravity.h. Fundamental structure that holds particle and tree data.*/
357
358 public:
359 /*Constructor. Only argment is the TreePiece*/
360 LocalLymanWernerDistributor(TreePiece *owner) :
361 tp(owner)
362 {}
363
364 bool work(GenericTreeNode *node, int level); /*virtually defined in TreeNodeWorker Class (Compute.h)*/
365 void doneChildren(GenericTreeNode *node, int level); /*virtually defined in TreeNodeWorker Class*/
366
367 private:
368};
369#endif /*COOLING_MOLECULARH*/
370
371#endif
WalkIndices
distingish between the walks that could be running.
Definition Compute.h:260
KeyType NodeKey
This key is the identification of a node inside the global tree, and it is unique for the node....
Definition GenericTreeNode.h:35
CkQ< OffsetNode > CheckList
Queue of nodes to check for interactions.
Definition ParallelGravity.h:654
Base clase for all tree based computations.
Definition Compute.h:26
virtual void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Allow book-keeping of a cache miss.
Definition Compute.h:77
virtual void recvdParticlesFull(GravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Allow book-keeping of a cache receive event.
Definition Compute.h:83
virtual void startNodeProcessEvent(State *state)
Definition Compute.h:73
virtual void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition Compute.h:79
virtual void recvdParticles(ExternalGravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Allow book-keeping of a cache receive event.
Definition Compute.h:81
virtual int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)=0
Work to be done at each node.
virtual void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition Compute.h:75
virtual void init(void *cE, int activeRung, Opt *opt)
Associate computeEntity (target bucket or node), activeRung and Optimization with this Compute object...
Definition Compute.cpp:22
Hold state where both the targets and sources are tree walked.
Definition State.h:117
Definition Compute.h:250
int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Immediately stop the walk.
Definition Compute.h:253
Information needed to calculate gravity.
Definition GravityParticle.h:33
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition Compute.cpp:335
void recvdParticles(ExternalGravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Allow book-keeping of a cache receive event.
Definition Compute.cpp:269
void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Allow book-keeping of a cache miss.
Definition Compute.cpp:220
int computeParticleForces(TreePiece *owner, GenericTreeNode *node, ExternalGravityParticle *part, int reqID)
Calculate forces due to particles in a node.
Definition Compute.cpp:590
int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Work to be done at each node.
Definition Compute.cpp:406
Fundamental type for a particle.
Definition GravityParticle.h:364
int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Process a node.
Definition Compute.cpp:690
void fillLists(State *state_, TreePiece *tp, int chunk, int start, int end, CkVec< OffsetNode > &clistforb, CkVec< RemotePartInfo > &rplistforb, CkVec< LocalPartInfo > &lplistforb)
Populate CkLoop Data.
Definition Compute.cpp:1241
void stateReadyPar(TreePiece *tp, int start, int end, CkVec< OffsetNode > &clist, CkVec< RemotePartInfo > &rpilist, CkVec< LocalPartInfo > &lpilist)
CkLoop version of stateReady()
Definition Compute.cpp:1929
void initState(State *state)
Clear lists.
Definition Compute.cpp:180
void recvdParticles(ExternalGravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Process received remote particles.
Definition Compute.cpp:893
void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Update state on a node miss.
Definition Compute.cpp:244
void enableCpu()
Flag the cpu (instead of gpu) for usage for the next walk.
Definition Compute.h:185
void stateReady(State *, TreePiece *, int chunk, int start, int end)
Check for computation Computation can be done on buckets indexed from start to end.
Definition Compute.cpp:1543
State * getNewState()
Version that allocates a DoubleWalkState.
Definition Compute.cpp:165
void reassoc(void *cE, int activeRung, Opt *o)
Reassociate the target node.
Definition Compute.cpp:213
void freeDoubleWalkState(DoubleWalkState *state)
Free up all the lists.
Definition Compute.cpp:83
void freeState(State *state)
Version that frees a DoubleWalkState.
Definition Compute.cpp:77
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state)
apply node opening criterion to this node.
Definition Compute.cpp:973
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Update state upon receiving a remote node.
Definition Compute.cpp:356
Base class for optimizing walk actions.
Definition Opt.h:12
void startNodeProcessEvent(State *state)
Definition Compute.cpp:227
void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition Compute.cpp:233
void recvdParticles(ExternalGravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Allow book-keeping of a cache receive event.
Definition Compute.cpp:322
virtual int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Work to be done at each node.
Definition Compute.cpp:625
Base class for maintaining the state of a tree walk.
Definition State.h:6
Interface for work in LocalTreeTraversal.
Definition Compute.h:283
Fundamental structure that holds particle and tree data.
Definition ParallelGravity.h:755
Base class for walking trees.
Definition TreeWalk.h:11
Base class for tree nodes.
Definition GenericTreeNode.h:59