changa  3.5
 All Classes Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
Sorter.h
Go to the documentation of this file.
1 
7 #ifndef SORTER_H
8 #define SORTER_H
9 
10 #include <list>
11 #include <vector>
12 #include <set>
13 #include <numeric>
14 
15 #include "ParallelGravity.h"
16 
20 struct OctDecompNode {
21  static int maxNumChildren;
22  static int lgMaxNumChildren;
23 
24  OctDecompNode() : children(NULL), nchildren(0), nparticles(0)
25  {
26  }
27 
28  NodeKey key;
29 
30  OctDecompNode *children;
31  int nchildren;
32 
33  int64_t nparticles;
34 
35  void makeSubTree(int refineLevel, CkVec<OctDecompNode*> *active);
36  int64_t buildCounts();
37  void deleteBeneath();
38  void combine(int thresh, vector<NodeKey> &finalKeys, vector<uint64_t> &counts);
39  void getLeafNodes(CkVec<OctDecompNode*> *activeNodes);
40 };
41 
64 class Sorter : public CBase_Sorter {
65 
66  double decompTime;
68  int64_t numKeys;
70  int numChares;
72  std::vector<int> chareIDs;
74  std::vector<int> availableChares;
75  // Total size of the keys allocated (allows a margin to increase)
76  //int keysSize;
77 
79  double tolerance;
81  int closeEnough;
83  int numIterations;
85  bool sorted;
86 
87  std::vector<NodeKey> nodeKeys;
89  std::vector<uint64_t> binCounts;
90  std::vector<unsigned int> binCountsGas;
91  std::vector<unsigned int> binCountsStar;
93  int numCounts;
95  std::vector<SFC::Key> keyBoundaries;
96  std::vector<uint64_t> accumulatedBinCounts;
98  std::vector<SFC::Key> splitters;
99 
100  CkBitVector binsToSplit;
102  int64_t *goals;
103  int numGoalsPending;
104 
106  CProxy_DataManager dm;
108  CkCallback sortingCallback;
109 
111  int joinThreshold, splitThreshold;
114  int refineLevel;
115 
116  // root of the full tree of node keys for decomposition
117  OctDecompNode *root;
118  // node keys for the initial bins
119  OctDecompNode *decompRoots;
120  int numDecompRoots;
121  CkVec<OctDecompNode*> *activeNodes;
122  CkVec<OctDecompNode*> *tmpActiveNodes;
123 
125  typedef struct DivData{
126  OrientedBox<float> boundingBox;
127  double curLow;
128  double curHigh;
129  double curDivision;
130  char curDim;
131  } ORBData;
132 
136  std::list<ORBData> orbData;
137 
138 
140  CkVec<int> zeros;
142  CkVec<NodeKey> nodesOpened;
143 
144  void adjustSplitters();
145  bool refineOctSplitting(int n, int64_t *count);
146 
147 public:
148 
149  Sorter() {
150  root = NULL;
151  decompRoots = NULL;
152  numDecompRoots = 0;
153  joinThreshold = 0;
154 
155  activeNodes = new CkVec<OctDecompNode*>;
156  tmpActiveNodes = new CkVec<OctDecompNode*>;
157 
158  chareIDs.resize(numTreePieces, 1);
159  chareIDs[0] = 0;
160  partial_sum(chareIDs.begin(), chareIDs.end(), chareIDs.begin());
161  };
162  Sorter(CkMigrateMessage* m) : CBase_Sorter(m) {
163  root = NULL;
164  decompRoots = NULL;
165  numDecompRoots = 0;
166  joinThreshold = 0;
167 
168  chareIDs.resize(numTreePieces, 1);
169  chareIDs[0] = 0;
170  partial_sum(chareIDs.begin(), chareIDs.end(), chareIDs.begin());
171  };
172 
183  void startSorting(const CkGroupID& dataManagerID, const double toler, const CkCallback& cb, bool decompose);
185  SFC::Key * convertNodesToSplittersRefine(int num, NodeKey* keys);
186  //void convertNodesToSplittersNoZeros(int num, NodeKey* nodeKeys, CkVec<int> &zero);
188  void collectEvaluations(CkReductionMsg* m);
189  void collectEvaluationsSFC(CkReductionMsg* m);
190  void collectEvaluationsOct(CkReductionMsg* m);
191 
192  //ORB Decomposition
193  void doORBDecomposition(CkReductionMsg* m);
194  void finishPhase(CkReductionMsg *m);
195  void collectORBCounts(CkReductionMsg* m);
196  void readytoSendORB(CkReductionMsg* m);
197  //void sendBoundingBoxes(CkReductionMsg* m);
198 };
199 
200 #endif //SORTER_H
void doORBDecomposition(CkReductionMsg *m)
Start ORB decomposition.
Definition: Sorter.cpp:28
void collectEvaluationsSFC(CkReductionMsg *m)
Collect evaluations for the SFC domain decomposion.
Definition: Sorter.cpp:803
Domain decomposition of particles via a parallel sort.
Definition: Sorter.h:64
void collectORBCounts(CkReductionMsg *m)
Collect particle counts from treepieces and send out new splits.
Definition: Sorter.cpp:194
unsigned int numTreePieces
Number of pieces into which to divide the tree.
Definition: ParallelGravity.cpp:115
void makeSubTree(int refineLevel, CkVec< OctDecompNode * > *active)
Make a balanced subtree of OctDecompNode.
Definition: Sorter.cpp:686
void convertNodesToSplitters()
Definition: Sorter.cpp:403
Class to hold the Oct decomposition tree.
Definition: Sorter.h:20
void collectEvaluations(CkReductionMsg *m)
Collect the counts of particles in each domain.
Definition: Sorter.cpp:466
void startSorting(const CkGroupID &dataManagerID, const double toler, const CkCallback &cb, bool decompose)
Overall start of domain decomposition.
Definition: Sorter.cpp:265
void finishPhase(CkReductionMsg *m)
Definition: Sorter.cpp:81
void collectEvaluationsOct(CkReductionMsg *m)
Definition: Sorter.cpp:493
SFC::Key * convertNodesToSplittersRefine(int num, NodeKey *keys)
Definition: Sorter.cpp:433
CkGroupID dataManagerID
The group ID of your DataManager. You must set this!
Definition: ParallelGravity.cpp:157