changa  3.5
 All Classes Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
DataManager.h
Go to the documentation of this file.
1 
7 #ifndef DATAMANAGER_H
8 #define DATAMANAGER_H
9 
10 #include <vector>
11 #include <map>
12 #include <string>
13 #include "GenericTreeNode.h"
14 #include "ParallelGravity.decl.h"
15 
16 #if CHARM_VERSION > 60401 && CMK_BALANCED_INJECTION_API
17 #include "ckBIconfig.h"
18 #endif
19 
20 
23  TreePiece *treePiece;
25 
27  TreePieceDescriptor(TreePiece *tp_, GenericTreeNode *r){
28  treePiece = tp_;
29  root = r;
30  }
31 };
32 
33 #ifdef CUDA
34 
35 struct UpdateParticlesStruct{
36  CkCallback *cb;
37  DataManager *dm;
38  VariablePartData *buf;
39  int size;
40 };
41 
42 
43 // store pointers to flattened buffers if !gpuFree
44 struct PendingBuffers {
45  CkVec<CudaMultipoleMoments> *moments;
46  CkVec<CompactPartData> *particles;
47  int chunk;
49  CkCallback *cb;
50 };
51 
52 #endif
53 
60 class DataManager : public CBase_DataManager {
61  friend class TreePiece;
62  friend class OctTreeBuildPhaseIWorker;
63 
65  CProxy_TreePiece treePieces;
66 
67 protected:
68 
70  std::vector<SFC::Key> boundaryKeys;
71 
73  std::vector<int> responsibleIndex;
74 
76  std::vector<int> particleCounts;
77 
79  // holds chare array indices of registered treepieces
80  CkVec<TreePieceDescriptor> registeredTreePieces;
81 #ifdef CUDA
82  //CkVec<int> registeredTreePieceIndices;
85  int cumNumReplicatedNodes;
86  int treePiecesDone;
87  int savedChunk;
88  int treePiecesDonePrefetch;
89  int treePiecesDoneLocalComputation;
90  // XXX - assumes that only one chunk can be on the gpu
91  // at a given time
92  int treePiecesDoneRemoteChunkComputation;
93  int treePiecesWantParticlesBack;
96  int treePiecesParticlesUpdated;
97  int savedNumTotalParticles;
98  int savedNumTotalNodes;
99  // keeps track of buckets of particles that were
100  // received during the prefetch and which were subsequently
101  // shipped off to the gpu - XXX
102  // not including cached particles in postfrefetch entities shipped to gpu
103  // since it is hard to count their number given just the pointer to the cache entry
104  // * either do not concern yourself with cached particles
105  // * or for each entry, get key, find bucket node in CM, DM or TPs and get number
106  // for now, the former
107 
108  std::map<NodeKey, int> cachedPartsOnGpu;
109  // local particles that have been copied to the gpu
110  //std::map<NodeKey, int> localPartsOnGpu;
111 
112  // can the gpu accept a chunk of remote particles/nodes?
113  bool gpuFree;
114 
115  // This var will indicate if particle data has been loaded to the GPU
116  bool gputransfer;
118  CkCallback *localTransferCallback;
119 
120  PendingBuffers *currentChunkBuffers;
121  // queue that stores all pending chunk transfers
122  CkQ<PendingBuffers *> pendingChunkTransferQ;
123 
124  // last remote chunk's size in moments and particles
125  int lastChunkMoments;
126  int lastChunkParticles;
128  CudaMultipoleMoments *bufRemoteMoments;
130  CompactPartData *bufRemoteParts;
131 
133  CudaMultipoleMoments *bufLocalMoments;
135  CompactPartData *bufLocalParts;
137  VariablePartData *bufLocalVars;
138 
139 #ifdef HAPI_INSTRUMENT_WRS
140  int activeRung;
141  int treePiecesDoneInitInstrumentation;
142 #endif
143 #endif
148  CkVec<GenericTreeNode *> nodeTable;
149 
153  Tree::NodeKey *chunkRoots;
155  Tree::NodeLookupType chunkRootTable;
156 
157 public:
158 
159  /*
160  ** Cooling
161  */
162  COOL *Cool;
169  CmiNodeLock lockStarLog;
170 
171  DataManager(const CkArrayID& treePieceID);
172  DataManager(CkMigrateMessage *);
173 
174  void startLocalWalk();
175  void resumeRemoteChunk();
176 #ifdef CUDA
177  void donePrefetch(int chunk); // serialize remote chunk wrapper
178  void serializeLocalTree();
179 
180 #ifdef GPU_LOCAL_TREE_WALK
181  void transformLocalTreeRecursive(GenericTreeNode *node, CkVec<CudaMultipoleMoments>& localMoments);
182 #endif //GPU_LOCAL_TREE_WALK
183 
184  // actual serialization methods
185  PendingBuffers *serializeRemoteChunk(GenericTreeNode *);
186  void serializeLocal(GenericTreeNode *);
187  void freeLocalTreeMemory();
188  void freeRemoteChunkMemory(int chunk);
189  void transferParticleVarsBack();
190  void updateParticles(UpdateParticlesStruct *data);
191  void updateParticlesFreeMemory(UpdateParticlesStruct *data);
192  void initiateNextChunkTransfer();
193 #ifdef HAPI_INSTRUMENT_WRS
194  int initInstrumentation();
195 #endif
196  DataManager(){}
197 #endif
198  void clearInstrument(CkCallback const& cb);
199 
200 private:
201  void init();
202 
203 public:
204 
205  ~DataManager() {
206  for (unsigned int i = 0; i < nodeTable.length(); i++) {
207  delete nodeTable[i];
208  }
209  nodeTable.clear();
210 
211  CoolFinalize(Cool);
212  delete starLog;
213  CmiDestroyLock(lockStarLog);
214  }
215 
218  void acceptResponsibleIndex(const int* responsible, const int n,
219  const CkCallback& cb);
228  void acceptFinalKeys(const SFC::Key* keys, const int* responsible, uint64_t* bins, const int n, const CkCallback& cb);
229  void pup(PUP::er& p);
230 
231 #ifdef CUDA
232  /*
233  std::map<NodeKey, int> &getLocalPartsOnGpuTable(){
234  return localPartsOnGpu;
235  }
236  */
237  std::map<NodeKey, int> &getCachedPartsOnGpuTable(){
238  return cachedPartsOnGpu;
239  }
240 #endif
241  // Functions used to create a tree inside the DataManager comprising
242  // all the trees in the TreePieces in the local node
243 private:
244  Tree::GenericTreeNode *buildProcessorTree(int n, Tree::GenericTreeNode **gtn);
245  int createLookupRoots(Tree::GenericTreeNode *node, Tree::NodeKey *keys);
246 public:
247 
253  void clearRegisteredPieces(const CkCallback& cb);
254  void combineLocalTrees(CkReductionMsg *msg);
255  void getChunks(int &num, Tree::NodeKey *&roots);
256  inline Tree::GenericTreeNode *chunkRootToNode(const Tree::NodeKey k) {
257  NodeLookupType::iterator iter = chunkRootTable.find(k);
258  if (iter != chunkRootTable.end()) return iter->second;
259  else return NULL;
260  }
261  inline Tree::GenericTreeNode *getRoot() { return root; }
262  void initCooling(double dGmPerCcUnit, double dComovingGmPerCcUnit,
263  double dErgPerGmUnit, double dSecUnit, double dKpcUnit,
264  COOLPARAM inParam, const CkCallback& cb);
265  void initStarLog(std::string _fileName, const CkCallback &cb);
266  void dmCoolTableRead(double *dTableData, int nData, const CkCallback& cb);
267  void CoolingSetTime(double z, // redshift
268  double dTime, // Time
269  const CkCallback& cb);
270  void SetStarCM(double dCenterOfMass[4], const CkCallback& cb);
271  void memoryStats(const CkCallback& cb);
272  void resetReadOnly(Parameters param, const CkCallback &cb);
273 
274  public:
275  static Tree::GenericTreeNode *pickNodeFromMergeList(int n, GenericTreeNode **gtn, int &nUnresolved, int &pickedIndex);
276 };
277 
278 inline static void setBIconfig()
279 {
280 #if CHARM_VERSION > 60401 && CMK_BALANCED_INJECTION_API
281  if (CkMyRank()==0) {
282 #define GNI_BI_DEFAULT 64
283  uint16_t cur_bi = ck_get_GNI_BIConfig();
284  if (cur_bi > GNI_BI_DEFAULT) {
285  ck_set_GNI_BIConfig(GNI_BI_DEFAULT);
286  }
287  }
288  if (CkMyPe() == 0)
289  CkPrintf("Balanced injection is set to %d.\n", ck_get_GNI_BIConfig());
290 #endif
291 }
292 
298 class ProjectionsControl : public CBase_ProjectionsControl {
299  public:
301  setBIconfig();
302  LBTurnCommOff();
303 #ifndef LB_MANAGER_VERSION
304  // Older Charm++ requires this to avoid excessive delays between successive LBs even
305  // when using AtSync mode
306  LBSetPeriod(0.0);
307 #endif
308  }
309  ProjectionsControl(CkMigrateMessage *m) : CBase_ProjectionsControl(m) {
310  setBIconfig();
311  LBTurnCommOff();
312 #ifndef LB_MANAGER_VERSION
313  // Older Charm++ requires this to avoid excessive delays between successive LBs even
314  // when using AtSync mode
315  LBSetPeriod(0.0);
316 #endif
317  }
318 
319  void on(CkCallback cb) {
320  if(CkMyPe() == 0){
321  CkPrintf("\n\n**** PROJECTIONS ON *****\n\n");
322  }
323  traceBegin();
324  contribute(cb);
325  }
326 
327  void off(CkCallback cb) {
328  if(CkMyPe() == 0){
329  CkPrintf("\n\n**** PROJECTIONS OFF *****\n\n");
330  }
331  traceEnd();
332  contribute(cb);
333  }
334 
335  void pup(PUP::er &p){
336  CBase_ProjectionsControl::pup(p);
337  }
338 };
339 
340 #endif //DATAMANAGER_H
std::vector< int > particleCounts
An array with how many particles are held by each TreePiece when sorted.
Definition: DataManager.h:76
CkVec< GenericTreeNode * > nodeTable
Definition: DataManager.h:148
void SetStarCM(double dCenterOfMass[4], const CkCallback &cb)
DataManager::SetStarCM saves the total mass and center of mass of the star(s) to the COOL struct Cool...
Definition: Sph.cpp:281
void getChunks(int &num, Tree::NodeKey *&roots)
return the number of chunks and the roots of the remote walk subtrees.
Definition: DataManager.cpp:421
Information about TreePieces on an SMP node.
Definition: DataManager.h:22
Input parameters for cooling.
Definition: cooling_boley.h:56
void clearRegisteredPieces(const CkCallback &cb)
Clear registeredTreePieces on this node.
Definition: DataManager.cpp:162
void acceptResponsibleIndex(const int *responsible, const int n, const CkCallback &cb)
Definition: DataManager.cpp:66
static Tree::GenericTreeNode * pickNodeFromMergeList(int n, GenericTreeNode **gtn, int &nUnresolved, int &pickedIndex)
Pick a node out of equivalent nodes on different TreePieces. If one of the nodes is internal to a Tre...
Definition: DataManager.cpp:269
Hold parameters of the run.
Definition: parameters.h:14
void combineLocalTrees(CkReductionMsg *msg)
Build a local tree inside the node.
Definition: DataManager.cpp:175
Version of MultipoleMoments using cudatype.
Definition: cuda_typedef.h:95
CkVec< TreePieceDescriptor > registeredTreePieces
A list of roots of the TreePieces in this node.
Definition: DataManager.h:80
StarLog * starLog
log of star formation events.
Definition: DataManager.h:167
Definition: DataManager.h:60
int oldNumChunks
Number of chunks in which the tree was splitted during last combine operation.
Definition: DataManager.h:151
std::vector< SFC::Key > boundaryKeys
The array of splitter keys for the sort.
Definition: DataManager.h:70
Particle data that gets calculated by the GPU.
Definition: cuda_typedef.h:259
Base class for tree nodes.
Definition: GenericTreeNode.h:59
void initCooling(double dGmPerCcUnit, double dComovingGmPerCcUnit, double dErgPerGmUnit, double dSecUnit, double dKpcUnit, COOLPARAM inParam, const CkCallback &cb)
Definition: Sph.cpp:136
Particle data needed on the GPU to calculate gravity.
Definition: cuda_typedef.h:231
Fundamental structure that holds particle and tree data.
Definition: ParallelGravity.h:730
void acceptFinalKeys(const SFC::Key *keys, const int *responsible, uint64_t *bins, const int n, const CkCallback &cb)
Definition: DataManager.cpp:73
Heating/Cooling context: parameters and tables.
Definition: cooling_boley.h:83
std::vector< int > responsibleIndex
An array identifying which chare is responsible for each interval of keys.
Definition: DataManager.h:73
Tree::GenericTreeNode * root
The root of the combined trees.
Definition: DataManager.h:145
Tree::NodeLookupType chunkRootTable
Lookup table for the chunkRoots.
Definition: DataManager.h:155
Tree::NodeKey * chunkRoots
Nodes currently used as roots for remote computation.
Definition: DataManager.h:153
void notifyPresence(Tree::GenericTreeNode *root, TreePiece *treePiece)
Collect roots of treepieces on this node.
Definition: DataManager.cpp:148
Log of star formation events to be written out to a file.
Definition: starform.h:129
Control recording of Charm++ projections logs.
Definition: DataManager.h:298
CmiNodeLock lockStarLog
Lock for accessing starlog from TreePieces.
Definition: DataManager.h:169