changa  3.5
 All Classes Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
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 
11 class State;
12 class DoubleWalkState;
13 
18 class TreeWalk;
19 class Opt;
20 
26 class 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 
105 class 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
143 class ListCompute : public Compute{
149 
150  public:
151  ListCompute() : Compute(List) {}
152 
153  int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi);
154 
155  int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state);
156 
157  // book keeping on notifications
158  void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp);
159  void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket);
160  void recvdParticles(ExternalGravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket);
161 
162  void initState(State *state);
163 
164  void stateReady(State *, TreePiece *, int chunk, int start, int end);
165 
166  void stateReadyPar(TreePiece *tp, int start, int end,
167  CkVec<OffsetNode>& clist, CkVec<RemotePartInfo>& rpilist,
168  CkVec<LocalPartInfo>& lpilist);
169 
170  void fillLists(State *state_, TreePiece *tp, int chunk, int start,
171  int end, CkVec<OffsetNode>& clistforb, CkVec<RemotePartInfo>& rplistforb,
172  CkVec<LocalPartInfo>& lplistforb);
173 
174 // void printUndlist(DoubleWalkState *state, int level, TreePiece *tp);
175 // void printClist(DoubleWalkState *state, int level, TreePiece *tp);
176  void reassoc(void *cE, int activeRung, Opt *o);
177  State *getNewState(int d1, int d2);
178  State *getNewState(int d1);
179  State *getNewState();
180  void freeState(State *state);
182 
183 #ifdef CUDA
184 #ifdef GPU_LOCAL_TREE_WALK
185  void sendLocalTreeWalkTriggerToGpu(State *state, TreePiece *tp, int activeRung, int startBucket, int endBucket);
186 #endif //GPU_LOCAL_TREE_WALK
187  void sendNodeInteractionsToGpu(DoubleWalkState *state, TreePiece *tp);
188  void sendPartInteractionsToGpu(DoubleWalkState *state, TreePiece *tp);
189 #endif
190 
191  private:
192 
193  void addChildrenToCheckList(GenericTreeNode *node, int reqID, int chunk, int awi, State *s, CheckList &chklist, TreePiece *tp);
194  void addNodeToInt(GenericTreeNode *node, int offsetID, DoubleWalkState *s);
195 
196  DoubleWalkState *allocDoubleWalkState();
197 
198 #if defined CHANGA_REFACTOR_PRINT_INTERACTIONS || defined CHANGA_REFACTOR_WALKCHECK_INTERLIST || defined CUDA
199  void addRemoteParticlesToInt(ExternalGravityParticle *parts, int n,
200  Vector3D<cosmoType> &offset, DoubleWalkState *s,
201  NodeKey key);
202  void addLocalParticlesToInt(GravityParticle *parts, int n,
203  Vector3D<cosmoType> &offset, DoubleWalkState *s,
204  NodeKey key, GenericTreeNode *gtn);
205 #else
206  void addRemoteParticlesToInt(ExternalGravityParticle *parts, int n,
207  Vector3D<cosmoType> &offset, DoubleWalkState *s);
208  void addLocalParticlesToInt(GravityParticle *parts, int n,
209  Vector3D<cosmoType> &offset, DoubleWalkState *s);
210 #endif
211 
212 #ifdef CUDA
213  void getBucketParameters(TreePiece *tp, int bucket, int &bucketStart, int &bucketSize, std::map<NodeKey, int>&lpref);
214 
215  public:
216  void resetCudaNodeState(DoubleWalkState *state);
217  void resetCudaPartState(DoubleWalkState *state);
218  void initCudaState(DoubleWalkState *state, int numBuckets, int nodeThreshold, int partThreshold, bool resume);
219 
220 #endif
221 
222 };
223 #endif
224 
226 class PrefetchCompute : public Compute{
227 
228  public:
229  PrefetchCompute() : Compute(Prefetch) {
230  computeEntity = 0;
231  }
232  virtual int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi);
233  int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqIDD, State *state);
234 
235  // book-keeping on notifications
236  void startNodeProcessEvent(State *state);
237  void finishNodeProcessEvent(TreePiece *owner, State *state);
238 
239  void recvdParticles(ExternalGravityParticle *egp,int num,int chunk,int reqID,State *state, TreePiece *tp, Tree::NodeKey &remoteBucket);
240 };
241 
245  public:
247  int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi){
248  return DUMP;
249  }
250 };
251 
253 
255  prefetchAwi = 0,
256  interListAwi = 1,
257  remoteGravityAwi = 2,
258  smoothAwi = 3,
259  maxAwi = 4
260 };
261 
264 class ActiveWalk {
265  public:
266  TreeWalk *tw;
267  Compute *c;
268  Opt *o;
269  State *s;
270 
271  ActiveWalk(TreeWalk *_tw, Compute *_c, Opt *_o, State *state) :
272  tw(_tw), c(_c), o(_o), s(state){}
273  ActiveWalk(){}
274 };
275 
278 
279  public:
280  virtual bool work(GenericTreeNode *node, int level) = 0;
281  virtual void doneChildren(GenericTreeNode *node, int level) {}
282 };
283 
287  TreePiece *tp;
288  bool requestNonLocalMoments;
289 
290  public:
291  RemoteTreeBuilder(TreePiece *owner, bool req) :
292  tp(owner),
293  requestNonLocalMoments(req)
294  {}
295 
296  bool work(GenericTreeNode *node, int level);
297  void doneChildren(GenericTreeNode *node, int level);
298 
299  private:
300  void registerNode(GenericTreeNode *node);
301 
302 };
303 
306  TreePiece *tp;
307 
308  public:
309  LocalTreeBuilder(TreePiece *owner) :
310  tp(owner)
311  {}
312 
313  bool work(GenericTreeNode *node, int level);
314  void doneChildren(GenericTreeNode *node, int level);
315 
316  private:
317  void registerNode(GenericTreeNode *node);
318 };
319 
324  int index;
325  std::ofstream file;
326  string description;
327 
328  void openFile();
329 
330  public:
331  LocalTreePrinter(string d, int idx) :
332  index(idx),
333  description(d)
334  {
335  openFile();
336  }
337 
338  ~LocalTreePrinter(){
339  file << "}" << std::endl;
340  file.close();
341  }
342 
343  bool work(GenericTreeNode *node, int level);
344  void doneChildren(GenericTreeNode *node, int level);
345 };
346 
347 #ifdef COOLING_MOLECULARH
348 class LocalLymanWernerDistributor : public TreeNodeWorker {
349  /*Defining a new class inherited from TreeNodeWorker to use while distributing LW over a depth-first walk */
350  TreePiece *tp; /*Defined in ParallelGravity.h. Fundamental structure that holds particle and tree data.*/
351 
352  public:
353  /*Constructor. Only argment is the TreePiece*/
354  LocalLymanWernerDistributor(TreePiece *owner) :
355  tp(owner)
356  {}
357 
358  bool work(GenericTreeNode *node, int level); /*virtually defined in TreeNodeWorker Class (Compute.h)*/
359  void doneChildren(GenericTreeNode *node, int level); /*virtually defined in TreeNodeWorker Class*/
360 
361  private:
362 };
363 #endif /*COOLING_MOLECULARH*/
364 
365 #endif
int openCriterion(TreePiece *ownerTP, GenericTreeNode *node, int reqID, State *state)
apply node opening criterion to this node.
Definition: Compute.cpp:955
Class to build the remote part of the tree. Fills in Boundary and NonLocal nodes. ...
Definition: Compute.h:286
Base clase for all tree based computations.
Definition: Compute.h:26
CkQ< OffsetNode > CheckList
Queue of nodes to check for interactions.
Definition: ParallelGravity.h:629
Class to compute gravity using a &quot;bucket walk&quot;.
Definition: Compute.h:105
Interface for work in LocalTreeTraversal.
Definition: Compute.h:277
void recvdParticles(ExternalGravityParticle *egp, int num, int chunk, int reqID, State *state, TreePiece *tp, Tree::NodeKey &remoteBucket)
Process received remote particles.
Definition: Compute.cpp:881
Compute for the remote node prefetch walk.
Definition: Compute.h:226
Computations for Stadel-style interaction list walk.
Definition: Compute.h:148
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:1221
Definition: Compute.h:264
virtual void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition: Compute.h:75
int computeParticleForces(TreePiece *owner, GenericTreeNode *node, ExternalGravityParticle *part, int reqID)
Calculate forces due to particles in a node.
Definition: Compute.cpp:586
virtual void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Allow book-keeping of a cache miss.
Definition: Compute.h:77
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:320
Base class for walking trees.
Definition: TreeWalk.h:11
void initState(State *state)
Clear lists.
Definition: Compute.cpp:178
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:402
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition: Compute.cpp:333
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:267
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
void freeDoubleWalkState(DoubleWalkState *state)
Free up all the lists.
Definition: Compute.cpp:83
void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Update state on a node miss.
Definition: Compute.cpp:242
Class to build the local part of the tree. Builds Internal nodes.
Definition: Compute.h:305
WalkIndices
distingish between the walks that could be running.
Definition: Compute.h:254
TreeNodeWorker implementation that just prints out the tree. This is just for diagnostics.
Definition: Compute.h:323
Base class for tree nodes.
Definition: GenericTreeNode.h:59
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
void stateReadyPar(TreePiece *tp, int start, int end, CkVec< OffsetNode > &clist, CkVec< RemotePartInfo > &rpilist, CkVec< LocalPartInfo > &lpilist)
CkLoop version of stateReady()
Definition: Compute.cpp:1893
Base class for maintaining the state of a tree walk.
Definition: State.h:6
virtual void startNodeProcessEvent(State *state)
Definition: Compute.h:73
Information needed to calculate gravity.
Definition: GravityParticle.h:33
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
Fundamental structure that holds particle and tree data.
Definition: ParallelGravity.h:730
Definition: Compute.h:244
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.
void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Update state upon receiving a remote node.
Definition: Compute.cpp:354
Hold state where both the targets and sources are tree walked.
Definition: State.h:117
int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Immediately stop the walk.
Definition: Compute.h:247
unsigned int bucketSize
Definition: ParallelGravity.cpp:125
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:621
State * getNewState()
Version that allocates a DoubleWalkState.
Definition: Compute.cpp:163
void freeState(State *state)
Version that frees a DoubleWalkState.
Definition: Compute.cpp:77
Base class for optimizing walk actions.
Definition: Opt.h:12
Fundamental type for a particle.
Definition: GravityParticle.h:316
void nodeMissedEvent(int reqID, int chunk, State *state, TreePiece *tp)
Allow book-keeping of a cache miss.
Definition: Compute.cpp:218
void reassoc(void *cE, int activeRung, Opt *o)
Reassociate the target node.
Definition: Compute.cpp:211
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:1511
virtual void nodeRecvdEvent(TreePiece *owner, int chunk, State *state, int bucket)
Allow book-keeping of a cache receive event.
Definition: Compute.h:79
void finishNodeProcessEvent(TreePiece *owner, State *state)
Allow book-keeping when finished with a node.
Definition: Compute.cpp:231
int doWork(GenericTreeNode *, TreeWalk *tw, State *state, int chunk, int reqID, bool isRoot, bool &didcomp, int awi)
Process a node.
Definition: Compute.cpp:686
void startNodeProcessEvent(State *state)
Definition: Compute.cpp:225