-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorker.h
179 lines (148 loc) · 3.65 KB
/
Worker.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
#ifndef __WORKER_H__
#define __WORKER_H__
#include "Node.h"
#include "util.h"
#include "MultipoleMoments.h"
#include "Descriptor.h"
#include <map>
using namespace std;
// worker abstract class
template<typename T>
class CutoffWorker {
public:
virtual int work(Node<T> *) = 0;
virtual void work(ExternalParticle *) {}
virtual void bucketDone(Key k) {}
virtual void *getContext() {return NULL;}
virtual void setContext(void *context) {}
virtual void done() {}
};
class DataManager;
class ParticleFlushWorker : public CutoffWorker<NodeDescriptor> {
int leafCnt;
DataManager *dataManager;
public:
ParticleFlushWorker(DataManager *dm) :
dataManager(dm),
leafCnt(0)
{
}
int work(Node<NodeDescriptor> *node);
int getNumLeaves(){
return leafCnt;
}
};
class MomentsWorker : public CutoffWorker<ForceData> {
// tree pieces on this PE, in sorted order
// this allows us to mark the nodes that are
// internal to each PE. The last PE in this list
// is a dummy value, and is equal to the number of
// useful treepieces+1
CkVec<TreePieceDescriptor> &peTreePieces;
map<Key,Node<ForceData>*> &nodeTable;
CkVec<Node<ForceData>*> &buckets;
int curTP;
public:
MomentsWorker(CkVec<TreePieceDescriptor> &petps,
map<Key,Node<ForceData>*> &tab,
CkVec<Node<ForceData>*> &bucks
) :
peTreePieces(petps),
nodeTable(tab),
buckets(bucks),
curTP(0)
{
}
int work(Node<ForceData> *node);
void setLeafType(Node<ForceData> *leaf);
void setTypeFromChildren(Node<ForceData> *node);
};
class State;
class TraversalWorker : public CutoffWorker<ForceData> {
protected:
TreePiece *ownerTreePiece;
State *state;
Node<ForceData> *currentBucket;
TraversalWorker() :
ownerTreePiece(NULL),
currentBucket(NULL)
{
}
public:
void reset(TreePiece *owner, State *s, Node<ForceData> *bucket){
ownerTreePiece = owner;
state = s;
currentBucket = bucket;
}
Node<ForceData> *getCurrentBucket(){
return currentBucket;
}
void *getContext(){
return (void *) currentBucket;
}
void setContext(void *context){
currentBucket = (Node<ForceData> *) context;
}
int work(Node<ForceData> *node);
void work(ExternalParticle *particle);
void bucketDone(Key k);
virtual void done() {}
virtual bool getKeep(NodeType type) = 0;
};
class LocalTraversalWorker : public TraversalWorker {
static const bool keep[];
public:
LocalTraversalWorker() : TraversalWorker() {}
bool getKeep(NodeType type);
};
class RemoteTraversalWorker : public TraversalWorker {
static const bool keep[];
public:
RemoteTraversalWorker() : TraversalWorker() {}
void done();
bool getKeep(NodeType type);
};
class TreeSizeWorker : public CutoffWorker<ForceData> {
int numNodes;
int cutoffDepth;
public:
TreeSizeWorker(int d) :
cutoffDepth(d),
numNodes(0)
{
}
int work(Node<ForceData> *node);
int getNumNodes(){
return numNodes;
}
};
template<typename T>
class FreeTreeWorker : public CutoffWorker<T> {
public:
int work(Node<T> *node){
if(node->getNumChildren() > 0){
/*
CkPrintf("(%d) deleting %d children of %lu ptr %lx\n",
CkMyPe(),
node->getNumChildren(),
node->getKey(),
node->getChildren()
);
*/
delete[] node->getChildren();
}
return 1;
}
};
class TreeChecker : public CutoffWorker<ForceData> {
ostream &os;
public:
TreeChecker(ostream &o) : os(o) {}
int work(Node<ForceData> *node);
};
class InteractionChecker : public CutoffWorker<ForceData> {
public:
InteractionChecker() {}
int work(Node<ForceData> *node);
};
#endif