00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _MAPTABLE_H_
00022 #define _MAPTABLE_H_
00023 #include "../../include/debug_flags.h"
00024
00025 class inttriple {
00026 private:
00027 int x, y, z;
00028 public:
00029 inttriple(){x=y=z=0;}
00030
00031 inttriple(int _x,int _y,int _z) : x(_x), y(_y), z(_z) {}
00032 void pup(PUP::er &p)
00033 {
00034 p|x;
00035 p|y;
00036 p|z;
00037 }
00038 inline int getx(){return x;};
00039 inline int gety(){return y;};
00040 inline int getz(){return z;};
00041
00042
00043 inline CkHashCode hash() const {
00044 return (CkHashCode)((x<<16)|(y<<8)|z);
00045 }
00046 static CkHashCode staticHash(const void *k,size_t){
00047 return ((inttriple *)k)->hash();
00048 }
00049 inline int compare(inttriple &t) const{
00050 return (t.getx() == x && t.gety() == y && t.getz() ==z);
00051 }
00052 static int staticCompare(const void *a,const void *b,size_t){
00053 return ((inttriple *)a)->compare((*(inttriple *)b));
00054 }
00055
00056 };
00057
00058 class intdual {
00059 private:
00060 int x, y;
00061 public:
00062 intdual(){x=y=0;}
00063
00064 intdual(int _x,int _y) : x(_x), y(_y){}
00065 void pup(PUP::er &p)
00066 {
00067 p|x;
00068 p|y;
00069 }
00070 inline int getx(){return x;};
00071 inline int gety(){return y;};
00072 inline CkHashCode hash() const {
00073 return (CkHashCode)((x<<10)|y);
00074 }
00075 static CkHashCode staticHash(const void *k,size_t){
00076 return ((intdual *)k)->hash();
00077 }
00078 inline int compare(intdual &t) const{
00079 return (t.getx() == x && t.gety() == y);
00080 }
00081 static int staticCompare(const void *a,const void *b,size_t){
00082 return ((intdual *)a)->compare((*(intdual *)b));
00083 }
00084
00085 };
00086
00087
00088 #ifndef USE_INT_MAP
00089
00090 typedef CkHashtableT <intdual, int > MapType4;
00091 typedef CkHashtableT <inttriple, int > MapType3;
00092 #else
00093 #endif
00094
00095
00096
00097
00098
00099
00100 class MapTable2
00101 {
00102 public:
00103 MapType2 *maptable;
00104 PeList *availprocs;
00105 void dump()
00106 {
00107 #ifndef USE_INT_MAP
00108 CkHashtableIterator *it=maptable->iterator();
00109 it->seekStart();
00110 CkPrintf("Map dump\n");
00111 intdual *key;
00112 while(it->hasNext())
00113 {
00114 it->next((void **) &key);
00115 int proc =maptable->get(key[0]);
00116 #ifdef _MAP_VERBOSE_
00117 CkPrintf("%d %d %d\n", key[0].getx(), key[0].gety(),proc);
00118 #endif
00119 }
00120 delete it;
00121 #else
00122 maptable->dump();
00123 #endif
00124 }
00125
00126 protected:
00127 CkVec <intdual> *reverseMap;
00128
00129 MapTable2()
00130 {
00131 availprocs=NULL;
00132 maptable=NULL;
00133 reverseMap=NULL;
00134 }
00135 ~MapTable2()
00136 {
00137 if(reverseMap!=NULL)
00138 delete [] reverseMap;
00139 }
00140 void makeReverseMap();
00141
00142
00143
00144
00145
00146 inline CkVec <intdual> ProcByArrIndex(int proc)
00147 {
00148 if(reverseMap==NULL)
00149 makeReverseMap();
00150 return(reverseMap[proc]);
00151 }
00152
00153
00154 int getCentroid(int torusMap);
00155
00156 };
00157
00158 class MapTable3
00159 {
00160 public:
00161 MapType3 *maptable;
00162 PeList *availprocs;
00163 void dump()
00164 {
00165 #ifndef USE_INT_MAP
00166 CkHashtableIterator *it=maptable->iterator();
00167 it->seekStart();
00168 CkPrintf("Map dump\n");
00169 inttriple *key;
00170 while(it->hasNext())
00171 {
00172 it->next((void **) &key);
00173 int proc =maptable->get(key[0]);
00174 #ifdef _MAP_VERBOSE_
00175 CkPrintf("%d %d %d %d\n", key[0].getx(), key[0].gety(), key[0].getz(),proc);
00176 #endif
00177 }
00178 delete it;
00179 #else
00180 maptable->dump();
00181 #endif
00182 }
00183
00184 protected:
00185 CkVec <inttriple> *reverseMap;
00186
00187 MapTable3()
00188 {
00189 availprocs=NULL;
00190 maptable=NULL;
00191 reverseMap=NULL;
00192 }
00193 ~MapTable3()
00194 {
00195 if(reverseMap!=NULL)
00196 delete [] reverseMap;
00197 }
00198 void makeReverseMap();
00199
00200
00201
00202
00203
00204 inline CkVec <inttriple> ProcByArrIndex(int proc)
00205 {
00206 if(reverseMap==NULL)
00207 makeReverseMap();
00208 return(reverseMap[proc]);
00209 }
00210
00211
00212 int getCentroid(int torusMap);
00213
00214 };
00215
00216
00217
00218
00219
00220
00221 class MapTable4
00222 {
00223 public:
00224 MapType4 *maptable;
00225 PeList *availprocs;
00226 void dump()
00227 {
00228 #ifndef USE_INT_MAP
00229 CkHashtableIterator *it=maptable->iterator();
00230 it->seekStart();
00231 CkPrintf("Map dump\n");
00232 intdual *key;
00233 while(it->hasNext())
00234 {
00235 it->next((void **) &key);
00236 int proc =maptable->get(key[0]);
00237 #ifdef _MAP_VERBOSE_
00238 CkPrintf("%d %d %d\n", key[0].getx(), key[0].gety(),proc);
00239 #endif
00240 }
00241 delete it;
00242 #else
00243 maptable->dump();
00244 #endif
00245 }
00246
00247 protected:
00248 CkVec <intdual> *reverseMap;
00249
00250 MapTable4()
00251 {
00252 availprocs=NULL;
00253 maptable=NULL;
00254 reverseMap=NULL;
00255 }
00256 ~MapTable4()
00257 {
00258 if(reverseMap!=NULL)
00259 delete [] reverseMap;
00260 }
00261 void makeReverseMap();
00262
00263
00264
00265
00266
00267 inline CkVec <intdual> ProcByArrIndex(int proc)
00268 {
00269 if(reverseMap==NULL)
00270 makeReverseMap();
00271 return(reverseMap[proc]);
00272 }
00273
00274
00275 };
00276
00277 PeList *subListPlane(int plane, int nstates, MapType2 *smap);
00278 PeList *subListState(int state, int nplanes, MapType2 *smap);
00279 PeList *subListState2(int state1, int state2, int nplanes, int numChunks, MapType4 *smap);
00280
00281
00282 class GSMapTable : public MapTable2
00283 {
00284 public:
00285
00286 int nchareG;
00287 int nstates;
00288 int Gstates_per_pe;
00289
00290 double state_load;
00291 int planes_per_pe;
00292
00293 GSMapTable(MapType2 *_map, PeList *_availprocs, int _nchareG,
00294 int _nstates, int _Gstates_per_pe, bool useCuboidMap);
00295
00296 GSMapTable()
00297 {
00298 }
00299
00300 };
00301
00302
00303 class SCalcMapTable : public MapTable4
00304 {
00305
00306 int max_states, nchareG, grainsize;
00307 CmiBool symmetric;
00308 int scalc_per_plane;
00309 int planes_per_pe;
00310 int numChunksAsym;
00311 int numChunksSym;
00312 double totalload;
00313
00314 public:
00315 SCalcMapTable(MapType4 *_map, PeList *_availprocs, int _nstates,
00316 int _nchareG, int gs, CmiBool _flag, int _scalc_per_plane,
00317 int _planes_per_pe, int _numChunksA, int _numChunksS, MapType2 *_gmap, bool useCuboidMap, bool useCentroid, int boxSize);
00318
00319 void dump()
00320 {
00321 #ifndef USE_INT_MAP
00322 CkHashtableIterator *it=maptable->iterator();
00323 it->seekStart();
00324 CkPrintf("Map dump\n");
00325 intdual *key;
00326 while(it->hasNext())
00327 {
00328 it->next((void **) &key);
00329 int proc =maptable->get(key[0]);
00330 short *four=(short*) key;
00331 #ifdef _MAP_VERBOSE_
00332 CkPrintf("%d %d %d %d %d\n", four[0], four[1], four[2], four[3],proc);
00333 #endif
00334 }
00335 delete it;
00336 #else
00337 maptable->dump();
00338 #endif
00339 }
00340 void sortByCentroid(PeList *avail, int plane, int stateX, int stateY, int grainsize, MapType2 *gsmap);
00341
00342 };
00343
00344 class RSMapTable : public MapTable2
00345 {
00346 public:
00347 int nstates;
00348 int sizeZ;
00349 int Rstates_per_pe;
00350 RSMapTable(MapType2 *_map, PeList *_availprocs,
00351 int _nstates, int _sizeZ, int _Rstates_per_pe, bool useCuboid, MapType2 *gsmap, int nchareG);
00352 RSMapTable(){}
00353 };
00354
00355
00356 class RPPMapTable : public MapTable2
00357 {
00358 public:
00359 int nstates;
00360 int sizeZNL;
00361 int Rstates_per_pe;
00362 RPPMapTable(MapType2 *_map, PeList *_availprocs,
00363 PeList *exclude, int _nstates, int _sizeZNL,
00364 int _Rstates_per_pe, int boxSize, bool useCuboidMap,
00365 int nchareG, MapType2 *ppmap) ;
00366 RPPMapTable(){}
00367 };
00368
00369
00370 class OrthoMapTable : public MapTable2
00371 {
00372 public:
00373 int nstates;
00374 int orthoGrainSize;
00375
00376 OrthoMapTable(MapType2 *_map, PeList *_availprocs, int _nstates, int _orthograinsize, MapType4 *scalcmap, int nplanes, int numChunks, int sGrainSize, PeList *);
00377 OrthoMapTable() { }
00378 void sortByCentroid(PeList *avail, int nplanes, int state1, int state2, int numChunks, MapType4 *smap);
00379 int minDistCentroid(PeList *avail, int nplanes, int state1, int state2, int numChunks, MapType4 *smap);
00380 };
00381
00382 class OrthoHelperMapTable : public MapTable2
00383 {
00384 public:
00385 int nstates;
00386 int orthoGrainSize;
00387
00388 OrthoHelperMapTable(MapType2 *_map, int _nstates, int _orthograinsize, MapType2 *omap, PeList*, PeList*);
00389 OrthoHelperMapTable() { }
00390 };
00391
00392 class RhoRSMapTable : public MapTable2
00393 {
00394 public:
00395 int nchareRhoR;
00396 int rhoRsubplanes;
00397 RhoRSMapTable(MapType2 *_map, PeList *_availprocs,
00398 int _nchareRhoR, int _rhoRsubplanes, int maxstates, bool useCentroid, MapType2 *rsmap, PeList *exclude);
00399 void sortByCentroid(PeList *avail, int plane, int nstates, MapType2 *rsmap);
00400 RhoRSMapTable(){}
00401 };
00402
00403
00404 class RhoRHartMapTable : public MapTable3
00405 {
00406 public:
00407 int nchareRhoRHart;
00408 RhoRHartMapTable(MapType3 *_map, PeList *_availprocs,
00409 int _nchareRhoRHart, int rhoRsubplanes, int _nchareHartAtmT,
00410 PeList *exclude);
00411 RhoRHartMapTable(){}
00412 };
00413
00414 class RhoGHartMapTable : public MapTable2
00415 {
00416 public:
00417 int nchareRhoGHart;
00418 RhoGHartMapTable(MapType2 *_map, PeList *_availprocs,
00419 int _nchareRhoGHart, int _nchareHartAtmT, int useCentroid,
00420 MapType3 *rhartmap, PeList *exclude);
00421 RhoGHartMapTable(){}
00422 };
00423
00424 class RhoGSMapTable : public MapTable2
00425 {
00426 public:
00427 int nchareRhoG;
00428 RhoGSMapTable(MapType2 *_map, PeList *_availprocs,
00429 int _nchareRhoG, bool useCentroid, MapType2 *rhorsmap, PeList *exclude);
00430 RhoGSMapTable(){}
00431 };
00432
00433
00434 #endif
00435