changa  3.5
 All Classes Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
TreeWalk.h
1 #ifndef __TREEWALK_H__
2 #define __TREEWALK_H__
3 
4 #include "codes.h"
5 
6 class State;
7 class Compute;
8 class TreePiece;
9 
11 class TreeWalk{
12  protected:
13  Compute *comp;
14  TreePiece *ownerTP;
15  WalkType type;
16 #ifdef BENCHMARK_TIME_WALK
17  double walkTime, keepTime, finishNodeTime, doWorkTime;
18 #endif
19 
20  TreeWalk(Compute *_comp, TreePiece *tp, WalkType _type): ownerTP(tp), comp(_comp), type(_type){
21 #ifdef BENCHMARK_TIME_WALK
22  walkTime = keepTime = finishNodeTime = doWorkTime = 0.0;
23 #endif
24  }
25  TreeWalk() : comp(NULL), ownerTP(NULL), type(InvalidWalk){
26 #ifdef BENCHMARK_TIME_WALK
27  walkTime = keepTime = finishNodeTime = doWorkTime = 0.0;
28 #endif
29  }
30  TreeWalk(WalkType t) : comp(NULL), ownerTP(NULL), type(t){
31 #ifdef BENCHMARK_TIME_WALK
32  walkTime = keepTime = finishNodeTime = doWorkTime = 0.0;
33 #endif
34  }
35 
36  public:
37  virtual ~TreeWalk() {
38 #ifdef BENCHMARK_TIME_WALK
39  CkPrintf("walk,keep,finishNode,doWork time: %lf %lf %lf %lf\n",walkTime,keepTime,finishNodeTime,doWorkTime);
40 #endif
41  }
42 
43  // must tell compute the ownerTP so it can perform its openCriterion() test
44  TreePiece *getOwnerTP(){return ownerTP;}
45  Compute *getCompute(){return comp;}
47  virtual void init(Compute *c, TreePiece *owner);
48  void reassoc(Compute *c);
49 
50  virtual void reset() {};
51  virtual void walk(GenericTreeNode *node, State *state, int chunk, int reqID, int activeWalkIndex) = 0;
52  // when resuming a walk after a missed node is received, use this function
53  virtual void resumeWalk(GenericTreeNode *node, State *state, int chunk, int reqID, int activeWalkIndex) {
54  walk(node, state, chunk, reqID, activeWalkIndex);
55  }
56  // beware of using default implementation - always returns 'false'
57  //virtual bool ancestorCheck(GenericTreeNode *node, int reqID) {return false;};
58  WalkType getSelfType() {return type;}
59 
60 };
61 
63 class TopDownTreeWalk : public TreeWalk{
64  private:
65 #ifndef CHANGA_REFACTOR_WALKCHECK
66  void dft(GenericTreeNode *node, State *state, int chunk, int reqID, bool isRoot, int awi);
67  void bft(GenericTreeNode *node, State *state, int chunk, int reqID, bool isRoot, int awi);
68 #else
69  void dft(GenericTreeNode *node, State *state, int chunk, int reqID, bool isRoot, int shift, bool doprint);
70 #endif
71  public:
72  TopDownTreeWalk(Compute *_comp, TreePiece *tp):TreeWalk(_comp,tp,TopDown){}
73  TopDownTreeWalk() : TreeWalk(TopDown) {}
74 
75  //bool ancestorCheck(GenericTreeNode *node, int reqID);
76  void walk(GenericTreeNode *node, State *state, int chunk, int reqID, int awi);
77 };
78 
81 
82 class BottomUpTreeWalk : public TreeWalk{
83  public:
84  BottomUpTreeWalk(Compute *_comp, TreePiece *tp):TreeWalk(_comp,tp,BottomUp){}
85  BottomUpTreeWalk() : TreeWalk(BottomUp) {}
86 
87  void walk(GenericTreeNode *node, State *state, int chunk, int reqID, int awi);
88 };
89 
90 
91 #if INTERLIST_VER > 0
92 class LocalTargetWalk : public TreeWalk {
103 
104  NodeKey targetKey;
105  private:
114  void dft(GenericTreeNode *localNode, State *state, int chunk, int reqID,
115  bool isRoot, int awi, int level);
118  bool processNode(
119  GenericTreeNode *glblNode,
120  State *state,
121  int chunk, int reqID,
122  bool isRoot, bool &didcomp,
123  int awi);
124  public:
125  LocalTargetWalk(Compute *_comp, TreePiece *tp):TreeWalk(_comp,tp,LocalTarget){}
126  LocalTargetWalk() : TreeWalk(LocalTarget) { targetKey = 0;}
127  void walk(GenericTreeNode *startAncestor, State *state, int chunk, int reqID, int awi);
128  void resumeWalk(GenericTreeNode *node, State *state, int chunk, int reqID, int activeWalkIndex);
129  NodeKey getTargetKey() {return targetKey;}
130 
131 };
132 #endif
133 
136 
137  public:
142  void dft(GenericTreeNode *node, TreeNodeWorker *worker, int level){
143  if(worker->work(node,level)){
144  for(int i = 0; i < node->numChildren(); i++){
145  dft(node->getChildren(i),worker,level+1);
146  }
147  if(node->numChildren() > 0) worker->doneChildren(node,level);
148  }
149  }
150 };
151 
152 #endif
Base clase for all tree based computations.
Definition: Compute.h:26
Interface for work in LocalTreeTraversal.
Definition: Compute.h:277
void walk(GenericTreeNode *startAncestor, State *state, int chunk, int reqID, int awi)
Definition: TreeWalk.cpp:297
Definition: TreeWalk.h:102
Base class for walking trees.
Definition: TreeWalk.h:11
virtual void init(Compute *c, TreePiece *owner)
Associate a compute object and a treepiece with this walk.
Definition: TreeWalk.cpp:15
Base class for maintaining the state of a tree walk.
Definition: State.h:6
Definition: TreeWalk.h:82
class to walk just the local treepiece.
Definition: TreeWalk.h:135
Fundamental structure that holds particle and tree data.
Definition: ParallelGravity.h:730
void walk(GenericTreeNode *node, State *state, int chunk, int reqID, int awi)
Definition: TreeWalk.cpp:216
Walk a tree starting with the root node.
Definition: TreeWalk.h:63
void dft(GenericTreeNode *node, TreeNodeWorker *worker, int level)
Definition: TreeWalk.h:142