OpenAtom  Version1.5a
MapTable.h
Go to the documentation of this file.
1 /** \file MapTable.h
2  * Author: Eric J Bohm
3  * Date Created: June 4th, 2006
4  *
5  * Given all necessary inputs, the MapTable creates a ckhashtable
6  * or an int array which maps ckarrayindices to processors.
7  *
8  * Subclasses are made for each ckarray which needs different input
9  * in its partitioning scheme.
10  *
11  * Maptables are sequential objects which can be used in a readonly
12  * global or local context. Essentially just a factory for creating
13  * CkHashtable <intdual, int> maps for use by CkArrayMap::procnum
14  * functions.
15  */
16 
17 /** \defgroup mapping Mapping Framework
18  *
19  * \brief All array objects in OpenAtom are mapped onto the physical processor grid based on heuristics about their interaction patterns, each array has its own CkArrayMap, generally based on MapTable array indexed by the CkArray indices to map each index onto the preferred processor element.
20  */
21 //@{
22 
23 #include "load_balance/IntMap.h"
24 
25 #ifndef _MAPTABLE_H_
26 #define _MAPTABLE_H_
27 #include "debug_flags.h"
28 
29 class PeList;
30 
31 class inttriple {
32  private:
33  int x, y, z;
34  public:
35  inttriple(){x=y=z=0;}
36 
37  inttriple(int _x,int _y,int _z) : x(_x), y(_y), z(_z) {}
38  void pup(PUP::er &p)
39  {
40  p|x;
41  p|y;
42  p|z;
43  }
44  inline int getx() const {return x;};
45  inline int gety() const {return y;};
46  inline int getz() const {return z;};
47  // silenty assumes that X is the heavy hitter in keyspace
48  // safe for our purposes
49  inline CkHashCode hash() const {
50  return (CkHashCode)((x<<16)|(y<<8)|z);
51  }
52  static CkHashCode staticHash(const void *k,size_t){
53  return ((inttriple *)k)->hash();
54  }
55  inline int compare(inttriple &t) const{
56  return (t.getx() == x && t.gety() == y && t.getz() ==z);
57  }
58  static int staticCompare(const void *a,const void *b,size_t){
59  return ((inttriple *)a)->compare((*(inttriple *)b));
60  }
61 
62 };
63 
64 class intdual {
65  private:
66  int x, y;
67  public:
68  intdual(){x=y=0;}
69 
70  intdual(int _x,int _y) : x(_x), y(_y){}
71  void pup(PUP::er &p)
72  {
73  p|x;
74  p|y;
75  }
76  inline int getx(){return x;};
77  inline int gety(){return y;};
78  inline CkHashCode hash() const {
79  return (CkHashCode)((x<<10)|y);
80  }
81  static CkHashCode staticHash(const void *k,size_t){
82  return ((intdual *)k)->hash();
83  }
84  inline int compare(intdual &t) const{
85  return (t.getx() == x && t.gety() == y);
86  }
87  static int staticCompare(const void *a,const void *b,size_t){
88  return ((intdual *)a)->compare((*(intdual *)b));
89  }
90 
91 };
92 
93 /**
94  * Abstract base class.
95  *
96  */
97 class MapTable1
98 {
99  public:
100  MapType1 *maptable;
101  PeList *availprocs;
102  void dump()
103  {
104  maptable->dump();
105  }
106  protected:
107  CkVec <int> *reverseMap;
108 
109  MapTable1()
110  {
111  availprocs=NULL;
112  maptable=NULL;
113  reverseMap=NULL;
114  }
115  ~MapTable1()
116  {
117  if(reverseMap!=NULL)
118  delete [] reverseMap;
119  }
120  void makeReverseMap();
121 
122  /**
123  * return ckvec containing the reverse map of all elements on
124  * given proc
125  */
126  inline CkVec <int> ProcByArrIndex(int proc)
127  {
128  if(reverseMap==NULL)
129  makeReverseMap();
130  return(reverseMap[proc]);
131  }
132 
133  //! return processor at topological center of this list
134  int getCentroid(int torusMap);
135 
136 };
137 
138 
139 /**
140  * Abstract base class.
141  *
142  */
143 class MapTable2
144 {
145  public:
146  MapType2 *maptable;
147  PeList *availprocs;
148  void dump()
149  {
150  maptable->dump();
151  }
152  protected:
153  CkVec <intdual> *reverseMap;
154 
155  MapTable2()
156  {
157  availprocs=NULL;
158  maptable=NULL;
159  reverseMap=NULL;
160  }
161  ~MapTable2()
162  {
163  if(reverseMap!=NULL)
164  delete [] reverseMap;
165  }
166  void makeReverseMap();
167 
168  /**
169  * return ckvec containing the reverse map of all elements on
170  * given proc
171  */
172  inline CkVec <intdual> ProcByArrIndex(int proc)
173  {
174  if(reverseMap==NULL)
175  makeReverseMap();
176  return(reverseMap[proc]);
177  }
178 
179  //! return processor at topological center of this list
180  int getCentroid(int torusMap);
181 
182 };
183 
185 {
186  public:
187  MapType3 *maptable;
188  PeList *availprocs;
189  void dump()
190  {
191  maptable->dump();
192  }
193  protected:
194  CkVec <inttriple> *reverseMap;
195 
196  MapTable3()
197  {
198  availprocs=NULL;
199  maptable=NULL;
200  reverseMap=NULL;
201  }
202  ~MapTable3()
203  {
204  if(reverseMap!=NULL)
205  delete [] reverseMap;
206  }
207  void makeReverseMap();
208 
209  /**
210  * return ckvec containing the reverse map of all elements on
211  * given proc
212  */
213  inline CkVec <inttriple> ProcByArrIndex(int proc)
214  {
215  if(reverseMap==NULL)
216  makeReverseMap();
217  return(reverseMap[proc]);
218  }
219 
220  //! return processor at topological center of this list
221  int getCentroid(int torusMap);
222 
223 };
224 
225 
226 /**
227  * Abstract base class.
228  *
229  */
230 class MapTable4
231 {
232  public:
233  MapType4 *maptable;
234  PeList *availprocs;
235  void dump()
236  {
237  maptable->dump();
238  }
239 
240  protected:
241  CkVec <intdual> *reverseMap;
242 
243  MapTable4()
244  {
245  availprocs=NULL;
246  maptable=NULL;
247  reverseMap=NULL;
248  }
249  ~MapTable4()
250  {
251  if(reverseMap!=NULL)
252  delete [] reverseMap;
253  }
254  void makeReverseMap();
255 
256  /**
257  * return ckvec containing the reverse map of all elements on
258  * given proc
259  */
260  inline CkVec <intdual> ProcByArrIndex(int proc)
261  {
262  if(reverseMap==NULL)
263  makeReverseMap();
264  return(reverseMap[proc]);
265  }
266 
267 
268 };
269 
270 PeList *subListPlane(int plane, int nstates, MapType2 *smap);
271 PeList *subListState(int state, int nplanes, MapType2 *smap);
272 PeList *subListState2(int state1, int state2, int nplanes, int numChunks, MapType4 *smap);
273 
274 class AtomMapTable : public MapTable1
275 {
276  public:
277  int nchareAtoms;
278  AtomMapTable( MapType1 *_tomap, PeList *_availprocs,
279  int numInst,
280  int _nchareAtoms);
281  AtomMapTable()
282  {
283  }
284 
285 };
286 
287 class GSMapTable : public MapTable2
288 {
289  public:
290 
291  int nchareG;
292  int nstates;
293  int Gstates_per_pe;
294 
295  double state_load;
296  int planes_per_pe;
297 
298  GSMapTable(MapType2 *_frommap, MapType2 *_tomap, PeList *_availprocs,
299  int _nchareG, int _nstates, int _Gstates_per_pe, bool useCuboidMap, int numInst,
300  int offsetX, int offsetY, int offsetZ);
301 
302  GSMapTable()
303  {
304  }
305 
306 };
307 
308 
309 class SCalcMapTable : public MapTable4
310 {
311 
312  int max_states, nchareG, grainsize;
313  bool symmetric;
314  int scalc_per_plane;
315  int planes_per_pe;
316  int numChunksAsym;
317  int numChunksSym;
318  double totalload;
319 
320  public:
321  SCalcMapTable(MapType4 *_map, PeList *_availprocs, int _nstates,
322  int _nchareG, int gs, bool _flag, int _scalc_per_plane,
323  int _planes_per_pe, int _numChunksA, int _numChunksS, MapType2 *_gmap, bool useCuboidMap, bool useCentroid, int boxSize);
324 
325  void dump()
326  {
327  maptable->dump();
328  }
329  void sortByCentroid(PeList *avail, int plane, int stateX, int stateY, int grainsize, MapType2 *gsmap);
330 
331 };
332 
333 class RSMapTable : public MapTable2
334 {
335  public:
336  int nstates;
337  int sizeZ;
338  int Rstates_per_pe;
339  RSMapTable(MapType2 *_frommap, MapType2 *_tomap, PeList *_availprocs,
340  int _nstates, int _sizeZ, int _Rstates_per_pe, bool useCuboidMap, MapType2 *gsmap,
341  int nchareG, int numInst, int offsetX, int offsetY, int offsetZ);
342 
343  RSMapTable(){}
344 };
345 
346 
347 class RPPMapTable : public MapTable2
348 {
349  public:
350  int nstates;
351  int sizeZNL;
352  int Rstates_per_pe;
353  RPPMapTable(MapType2 *_map, PeList *_availprocs,
354  PeList *exclude, int _nstates, int _sizeZNL,
355  int _Rstates_per_pe, int boxSize, bool useCuboidMap,
356  int nchareG, MapType2 *ppmap) ;
357  RPPMapTable(){}
358 };
359 
360 
361 class OrthoMapTable : public MapTable2
362 {
363  public:
364  int nstates;
365  int orthoGrainSize;
366 
367  OrthoMapTable(MapType2 *_map, PeList *_availprocs, int _nstates, int _orthograinsize, MapType4 *scalcmap, int nplanes, int numChunks, int sGrainSize, PeList *);
368  OrthoMapTable() { }
369  void sortByCentroid(PeList *avail, int nplanes, int state1, int state2, int numChunks, MapType4 *smap);
370  int minDistCentroid(PeList *avail, int nplanes, int state1, int state2, int numChunks, MapType4 *smap);
371 };
372 
374 {
375  public:
376  int nstates;
377  int orthoGrainSize;
378 
379  OrthoHelperMapTable(MapType2 *_map, int _nstates, int _orthograinsize, MapType2 *omap, PeList*, PeList*);
380  OrthoHelperMapTable() { }
381 };
382 
383 class RhoRSMapTable : public MapTable2
384 {
385  public:
386  int nchareRhoR;
387  int rhoRsubplanes;
388  RhoRSMapTable(MapType2 *_map, PeList *_availprocs,
389  int _nchareRhoR, int _rhoRsubplanes, int maxstates, bool useCentroid, MapType2 *rsmap, PeList *exclude);
390  void sortByCentroid(PeList *avail, int plane, int nstates, MapType2 *rsmap);
391  RhoRSMapTable(){}
392 };
393 
394 class VdWRSMapTable : public MapTable3
395 {
396  public:
397  int nchareRhoR;
398  int rhoRsubplanes;
399  int nchareVdW;
400  VdWRSMapTable(MapType3 *_map, PeList *_availprocs,
401  int _nchareRhoR, int _rhoRsubplanes, int _nchareVdW, int maxstates, PeList *exclude);
402  VdWRSMapTable(){}
403 };
404 
405 class VdWGSMapTable : public MapTable2
406 {
407  public:
408  int nchareRhoG;
409  int nchareVdW;
410  VdWGSMapTable(MapType2 *_map, PeList *_availprocs,
411  int _nchareRhoG, int _nchareVdW, PeList *exclude);
412  VdWGSMapTable(){}
413 };
414 
415 
416 
418 {
419  public:
420  int nchareRhoRHart;
421  RhoRHartMapTable(MapType3 *_map, PeList *_availprocs,
422  int _nchareRhoRHart, int rhoRsubplanes, int _nchareHartAtmT,
423  PeList *exclude);
424  RhoRHartMapTable(){}
425 };
426 
428 {
429  public:
430  int nchareRhoGHart;
431  RhoGHartMapTable(MapType2 *_map, PeList *_availprocs,
432  int _nchareRhoGHart, int _nchareHartAtmT, int useCentroid,
433  MapType3 *rhartmap, PeList *exclude);
434  RhoGHartMapTable(){}
435 };
436 
437 class RhoGSMapTable : public MapTable2
438 {
439  public:
440  int nchareRhoG;
441  RhoGSMapTable(MapType2 *_map, PeList *_availprocs,
442  int _nchareRhoG, bool useCentroid, MapType2 *rhorsmap, PeList *exclude);
443  RhoGSMapTable(){}
444 };
445 
446 //@}
447 #endif
CkVec< intdual > ProcByArrIndex(int proc)
return ckvec containing the reverse map of all elements on given proc
Definition: MapTable.h:260
Abstract base class.
Definition: MapTable.h:97
Definition: PeList.h:33
CkVec< intdual > ProcByArrIndex(int proc)
return ckvec containing the reverse map of all elements on given proc
Definition: MapTable.h:172
Abstract base class.
Definition: MapTable.h:230
Abstract base class.
Definition: MapTable.h:143
Author: Eric J Bohm Date Created: June 4th, 2006.
int getCentroid(int torusMap)
return processor at topological center of this list
Definition: IntMap.h:26
CkVec< inttriple > ProcByArrIndex(int proc)
return ckvec containing the reverse map of all elements on given proc
Definition: MapTable.h:213
int getCentroid(int torusMap)
return processor at topological center of this list
int getCentroid(int torusMap)
return processor at topological center of this list
Useful debugging flags.
CkVec< int > ProcByArrIndex(int proc)
return ckvec containing the reverse map of all elements on given proc
Definition: MapTable.h:126