-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataManager.h
200 lines (150 loc) · 5.06 KB
/
DataManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifndef __DATA_MANAGER_H__
#define __DATA_MANAGER_H__
#include "Particle.h"
#include "OrientedBox.h"
#include "barnes.decl.h"
#include "Node.h"
#include "Descriptor.h"
#include "ActiveBinInfo.h"
#include "Traversal_decls.h"
#include "Request.h"
class TreePiece;
#include <map>
using namespace std;
class TreePieceCounter : public CkLocIterator {
public:
int count;
CkHashtableT<CkArrayIndex, int> registered;
TreePieceCounter() : count(0) { }
void addLocation(CkLocation &loc) {
registered.put(loc.getIndex()) = ++count;
}
void reset() {
count = 0;
registered.empty();
}
};
struct RequestedMomentsDescriptor {
Node<ForceData> *node;
int numOutstanding;
RequestedMomentsDescriptor() :
node(NULL), numOutstanding(-1)
{
}
RequestedMomentsDescriptor(Node<ForceData> *nd, int n) :
node(nd), numOutstanding(n)
{
}
};
struct CacheStats {
int outstandingRequests;
int outstandingDeliveries;
CacheStats() :
outstandingRequests(0),
outstandingDeliveries(0)
{
}
void incrRequests(){ outstandingRequests++; }
void decrRequests(int n=1){ outstandingRequests -= n; }
void incrDeliveries(){ outstandingDeliveries++; }
void decrDeliveries(int n=1){ outstandingDeliveries -= n; }
bool test(){ return (outstandingRequests==0) && (outstandingDeliveries==0); }
};
class DataManager : public CBase_DataManager {
int numRankBits;
double prevIterationStart;
CkVec<Particle> myParticles;
int myNumParticles;
bool firstSplitterRound;
Node<NodeDescriptor> *sortingRoot;
int numTreePieces;
int iteration;
int decompIterations;
ActiveBinInfo<NodeDescriptor> activeBins;
TreePieceCounter localTreePieces;
int numLocalTreePieces;
CkVec<TreePieceDescriptor> submittedParticles;
Node<ForceData> *root;
Key *keyRanges;
bool haveRanges;
RangeMsg *rangeMsg;
CkVec<Node<ForceData>*> myBuckets;
// I am done constructing the tree
// from particles present on this PE
bool doneTreeBuild;
//CkVec<RequestedMomentsDescriptor> requestedMoments;
map<Key,Node<ForceData>*> nodeTable;
map<Key,CkVec<int> > pendingMoments;
// I have processed the moment
// contributions from all other PEs, so that
// the tree on this PE is now ready for
// traversal
bool treeMomentsReady;
CkVec<RequestMsg *> bufferedNodeRequests;
CkVec<RequestMsg *> bufferedParticleRequests;
Traversal<NodeDescriptor> scaffoldTrav;
Traversal<ForceData> fillTrav;
map<Key,Request> nodeRequestTable;
map<Key,Request> particleRequestTable;
int numTreePiecesDoneTraversals;
CacheStats nodeReqs;
CacheStats partReqs;
Real savedEnergy;
#ifdef STATISTICS
CmiUInt8 numInteractions[3];
#endif
void kickDriftKick(OrientedBox<Real> &box, Real &energy);
void hashParticleCoordinates(const OrientedBox<Real> &universe);
void initHistogramParticles();
void sendHistogram();
void senseTreePieces();
void buildTree();
void printTree();
void flushParticles();
void processSubmittedParticles();
void makeMoments();
void flushMomentRequests();
void respondToMomentsRequest(Node<ForceData> *,CkVec<int>&);
Node<ForceData> *lookupNode(Key k);
void updateLeafMoments(Node<ForceData> *node, MomentsExchangeStruct &data);
void passMomentsUpward(Node<ForceData> *node);
void treeReady();
void startTraversal();
void flushBufferedRemoteDataRequests();
void freeCachedData();
void freeTree();
void finishIteration();
void findMinVByA(DtReductionStruct &);
void markNaNBuckets();
public:
DataManager();
void loadParticles(const CkCallback &cb);
void decompose(const BoundingBox &universe);
void receiveHistogram(CkReductionMsg *msg);
void receiveSplitters(SplitterMsg *msg);
void sendParticles(RangeMsg *msg);
void sendParticlesToTreePiece(Node<NodeDescriptor> *nd, int tp);
void receiveMoments(MomentsMsg *msg);
// called by tree pieces
void submitParticles(CkVec<ParticleMsg *> *vec, int numParticles, TreePiece *tp, Key smallestKey, Key largestKey);
void requestMoments(Key k, int replyTo);
void advance(CkReductionMsg *);
#ifdef STATISTICS
void traversalsDone(CmiUInt8 pnInter, CmiUInt8 ppInter, CmiUInt8 openCrit);
#else
void traversalsDone();
#endif
// called by tree piece that is making a request
void requestNode(Node<ForceData> *leaf, CutoffWorker<ForceData> *worker, State *state, Traversal<ForceData> *callbackTraversal);
void requestParticles(Node<ForceData> *leaf, CutoffWorker<ForceData> *worker, State *state, Traversal<ForceData> *callbackTraversal);
// called by tree piece that is forwarding a remote request
void requestNode(RequestMsg *msg);
void requestParticles(RequestMsg *msg);
void recvParticles(ParticleReplyMsg *msg);
void recvNode(NodeReplyMsg *msg);
void recvUnivBoundingBox(CkReductionMsg *msg);
void quiescence();
void addBucketNodeInteractions(Key k, CmiUInt8 pn);
void addBucketPartInteractions(Key k, CmiUInt8 pp);
};
#endif