19 extern TopoManager *topoMgr;
23 int MapType1::getCentroid(
int torusMap) {
31 for(
int i=0;i<getXmax();i++)
34 topoMgr->rankToCoordinates(
get(i), X, Y, Z, T);
43 bestPe=topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
48 for(
int i=0;i<getXmax();i++)
59 int MapType2::getCentroid(
int torusMap) {
67 for(
int i=0;i<getXmax();i++)
68 for(
int j=0;j<getYmax();j++) {
69 CkAssert(
get(i,j)>=0);
70 topoMgr->rankToCoordinates(
get(i, j), X, Y, Z, T);
79 bestPe=topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
84 for(
int i=0;i<getXmax();i++)
85 for(
int j=0;j<getYmax();j++) {
86 CkAssert(
get(i,j)>=0);
95 int MapType3::getCentroid(
int torusMap) {
103 for(
int i=0;i<getXmax();i++)
104 for(
int j=0;j<getYmax();j++) {
105 for(
int k=0;k<getZmax();k++) {
106 CkAssert(
get(i,j,k)>=0);
107 topoMgr->rankToCoordinates(
get(i, j, k), X, Y, Z, T);
114 int avgX=sumX/points;
115 int avgY=sumY/points;
116 int avgZ=sumZ/points;
117 bestPe=topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
122 for(
int i=0;i<getXmax();i++)
123 for(
int j=0;j<getYmax();j++){
124 for(
int k=0;k<getZmax();k++){
125 CkAssert(
get(i,j,k)>=0);
135 void IntMap1::translate(
IntMap1 *fromMap,
int offsetX,
int offsetY,
int offsetZ,
bool torus )
138 keyXmax=fromMap->keyXmax;
140 Map=
new int[keyXmax];
143 int x, y, z, t, destpe;
144 for(
int xind=0; xind<keyXmax; xind++)
146 topoMgr->rankToCoordinates(fromMap->get(xind), x, y, z, t);
147 int newx=(x+offsetX)%topoMgr->getDimNX();
148 int newy=(y+offsetY)%topoMgr->getDimNY();
149 int newz=(z+offsetZ)%topoMgr->getDimNZ();
150 destpe = topoMgr->coordinatesToRank(newx, newy, newz, t);
156 for(
int xind=0; xind<keyXmax; xind++)
157 set(xind,fromMap->get(xind)+offsetX);
162 void IntMap2on2::translate(
IntMap2on2 *fromMap,
int offsetX,
int offsetY,
int offsetZ,
bool torus )
164 keyXmax=fromMap->keyXmax;
165 keyYmax=fromMap->keyYmax;
168 CkAssert(keyXmax<10000000);
169 CkAssert(keyYmax<10000000);
170 Map=
new int*[keyXmax];
172 int *mapbuf=
new int[keyXmax*keyYmax];
173 for(
int x=0;x<keyXmax;x++)
175 Map[x] = mapbuf + keyYmax * x;
176 memset(Map[x],-1,keyYmax*
sizeof(
int));
181 int x, y, z, t, destpe;
182 for(
int xind=0; xind<keyXmax; xind++)
183 for(
int yind=0; yind<keyYmax; yind++) {
184 topoMgr->rankToCoordinates(fromMap->get(xind, yind), x, y, z, t);
185 int newx=(x+offsetX)%topoMgr->getDimNX();
186 int newy=(y+offsetY)%topoMgr->getDimNY();
187 int newz=(z+offsetZ)%topoMgr->getDimNZ();
188 destpe = topoMgr->coordinatesToRank(newx, newy, newz, t);
189 set(xind, yind, destpe);
194 for(
int xind=0; xind<keyXmax; xind++)
195 for(
int yind=0; yind<keyYmax; yind++) {
196 set(xind, yind,fromMap->get(xind, yind)+offsetX);
201 void IntMap3::translate(
IntMap3 *fromMap,
int offsetX,
int offsetY,
int offsetZ,
bool torus )
204 keyXmax=fromMap->keyXmax;
205 keyYmax=fromMap->keyYmax;
206 keyZmax=fromMap->keyZmax;
210 Map=
new int**[keyXmax];
211 int **mappointbuf =
new int*[keyXmax*keyYmax];
212 int *mapbuf=
new int[keyXmax*keyYmax*keyZmax];
213 for(
int x=0;x<keyXmax;x++)
215 Map[x]= mappointbuf + (x*keyYmax);
216 for(
int y=0;y<keyYmax;y++)
218 Map[x][y]= mapbuf + (x*keyYmax+y)*keyZmax;
219 memset(Map[x][y],-1,keyZmax*
sizeof(
int));
224 int x, y, z, t, destpe;
225 for(
int xind=0; xind<keyXmax; xind++)
226 for(
int yind=0; yind<keyYmax; yind++) {
227 for(
int zind=0; zind<keyZmax; zind++) {
228 topoMgr->rankToCoordinates(fromMap->get(xind, yind,zind), x, y, z, t);
229 int newx=(x+offsetX)%topoMgr->getDimNX();
230 int newy=(y+offsetY)%topoMgr->getDimNY();
231 int newz=(z+offsetZ)%topoMgr->getDimNZ();
232 destpe = topoMgr->coordinatesToRank(newx, newy, newz, t);
233 set(xind, yind, zind, destpe);
239 for(
int xind=0; xind<keyXmax; xind++)
240 for(
int yind=0; yind<keyYmax; yind++) {
241 for(
int zind=0; zind<keyZmax; zind++) {
242 set(xind, yind, zind, fromMap->get(xind, yind,zind)+offsetX);
247 void IntMap4::translate(
IntMap4 *fromMap,
int offsetX,
int offsetY,
int offsetZ,
bool torus )
249 keyWmax=fromMap->keyWmax;
250 keyXmax=fromMap->keyXmax;
251 keyYmax=fromMap->keyYmax;
252 keyZmax=fromMap->keyZmax;
253 keyStep=fromMap->keyStep;
259 Map=
new int***[keyWmax];
260 int ***mappointpointbuf =
new int**[keyWmax*keyXmax];
261 int **mappointbuf =
new int*[keyWmax*keyXmax*keyYmax];
262 int *mapbuf=
new int[keyWmax*keyXmax*keyYmax*keyZmax];
263 for(
int w=0;w<keyWmax;w++)
265 Map[w]= mappointpointbuf + (w*keyXmax);
266 for(
int x=0;x<keyXmax;x++)
268 Map[w][x]= mappointbuf + (w*keyXmax+x)*keyYmax;
269 for(
int y=0;y<keyYmax;y++)
270 Map[w][x][y]= mapbuf + ((w*keyXmax+x)*keyYmax+y)*keyZmax;
275 int x, y, z, t, destpe;
276 for(
int wind=0; wind<keyWmax; wind++)
277 for(
int xind=0; xind<keyXmax; xind++){
278 for(
int yind=0; yind<keyYmax; yind++) {
279 for(
int zind=0; zind<keyZmax; zind++) {
280 topoMgr->rankToCoordinates(fromMap->get(wind,xind*keyStep, yind*keyStep,zind), x, y, z, t);
281 int newx=(x+offsetX)%topoMgr->getDimNX();
282 int newy=(y+offsetY)%topoMgr->getDimNY();
283 int newz=(z+offsetZ)%topoMgr->getDimNZ();
284 destpe = topoMgr->coordinatesToRank(newx, newy, newz, t);
285 set(wind, xind*keyStep, yind*keyStep, zind, destpe);
292 for(
int wind=0; wind<keyWmax; wind++)
293 for(
int xind=0; xind<keyXmax; xind++){
294 for(
int yind=0; yind<keyYmax; yind++) {
295 for(
int zind=0; zind<keyZmax; zind++) {
296 set(wind, xind*keyStep, yind*keyStep, zind, fromMap->get(wind, xind*keyStep, yind*keyStep,zind)+offsetX);
302 if (keyXmax > 0 && keyStep > 0)
304 if (stepTable)
delete [] stepTable;
305 stepTable=
new int [keyXmax*keyStep];
306 for(
int s=0; s<keyXmax*keyStep; s++)
307 stepTable[s] = s/keyStep;
312 AtomMapTable::AtomMapTable(
MapType1 *_tomap,
PeList *availprocs,
int numInst,
313 int _nchareAtoms): nchareAtoms(_nchareAtoms)
318 for(
int element=0; element<nchareAtoms; element++)
320 if(availprocs->count()==0)
322 maptable->set(element,availprocs->findNext());
327 CkAbort(
"this should only called on the first instance");
333 int _nchareG,
int _nstates,
int _Gstates_per_pe,
bool useCuboidMap,
int numInst,
334 int offsetX,
int offsetY,
int offsetZ):
335 nchareG(_nchareG), nstates(_nstates), Gstates_per_pe(_Gstates_per_pe)
339 availprocs = _availprocs;
346 int l, m, pl, pm, srem, rem, i=0;
372 while(pow(2.0, (
double)i) < pl)
375 pl = (int) pow(2.0, (
double)(i-1));
378 pm = availprocs->count() / pl;
380 if(!useCuboidMap && pm == 0) {
381 CkPrintf(
"Choose a larger Gstates_per_pe than %d such that { no. of processors [%d] / (no. of states [%d] / Gstates_per_pe [%d]) } is > 0 \n",
382 l, availprocs->count(), nstates, l);
383 CkAssert(availprocs->count() / (nstates/l) > 0);
400 int *Pecount=
new int[config.numPesPerInstance];
401 bzero(Pecount, config.numPesPerInstance *
sizeof(
int));
402 PeList *exclusionList = NULL;
405 if(config.numPesPerInstance % nchareG != 0)
407 CkPrintf(
"To use CuboidMap nchareG %d should be set as a factor of numprocs %d using gExpandFact\n", nchareG, config.numPesPerInstance);
410 int procsPerPlane = config.numPesPerInstance/nchareG;
411 int cubeGstates_per_pe = nstates/procsPerPlane;
412 int charesperpe = nchareG*nstates/config.numPesPerInstance;
413 int cubesrem = nstates%procsPerPlane;
415 cubeGstates_per_pe++;
419 CkPrintf(
"procsPerPlane %d Gstates_per_pe %d remainder %d\n", procsPerPlane, cubeGstates_per_pe, cubesrem);
420 for(
int plane=0; plane<nchareG; plane++)
423 PeList *planeProcs=
new PeList(availprocs, plane*procsPerPlane, procsPerPlane);
424 if(planeProcs->count()==0)
426 int destpe=planeProcs->findNext();
427 int workingGsPerPe=cubeGstates_per_pe;
428 bool unallocateRem= (cubesrem) ?
true:
false;
430 for(
int state=0;state<nstates;state+=workingGsPerPe)
442 for(
int stateperpe=0;(stateperpe<workingGsPerPe)&&((state+stateperpe)<nstates);stateperpe++)
445 maptable->set(state+stateperpe, plane, destpe);
447 maptable->put(
intdual(state+stateperpe, plane))=destpe;
452 if(Pecount[destpe]>=charesperpe)
454 if(exclusionList==NULL)
456 exclusionList=
new PeList(1);
457 exclusionList->TheList[0]=destpe;
458 exclusionList->sortIdx[0]=0;
462 exclusionList->mergeOne(destpe);
464 one.TheList[0]=destpe;
466 planeProcs->reindex();
470 if(((stateperpe+1<workingGsPerPe)&&((state+stateperpe+1)<nstates)) || state+workingGsPerPe<nstates)
473 destpe=planeProcs->findNext();
474 if(planeProcs->count()==0)
477 if(planeProcs->count()==0)
478 CkPrintf(
"GSMap exceeding count on plane %d state %d after pe %d workingGsPerPe %d cubesrem %d\n",state,plane,destpe, workingGsPerPe, cubesrem);
485 if(planeProcs->count()==0)
487 destpe=planeProcs->findNext();
501 if(exclusionList!=NULL)
502 delete exclusionList;
506 int destpe=availprocs->findNext();
515 for(
int ychunk=0; ychunk<nchareG; ychunk=ychunk+m)
517 if(ychunk==(pm-rem)*m)
519 for(
int xchunk=0; xchunk<nstates; xchunk=xchunk+l)
521 if(xchunk==(pl-srem)*l)
523 for(
int state=xchunk; state<xchunk+l && state<nstates; state++)
525 for(
int plane=ychunk; plane<ychunk+m && plane<nchareG; plane++)
528 maptable->set(state, plane,destpe);
530 maptable->put(
intdual(state, plane))=destpe;
535 if(availprocs->count()==0)
537 destpe=availprocs->findNext();
542 CkPrintf(
"GSMap created on processor %d\n", CkMyPe());
544 int size[2] = {128, 12};
545 MapFile *mf =
new MapFile(
"GSMap", 2, size, config.numPes,
"TXYZ", 2, 1, 1, 1);
546 mf->dumpMap(maptable);
551 int x, y, z, t, destpe;
552 CkPrintf(
"{%d} GS using offsets X=%d Y=%d Z=%d\n",numInst, offsetX, offsetY, offsetZ);
553 for(
int state=0; state<nstates; state++)
554 for(
int plane=0; plane<nchareG; plane++) {
555 topoMgr->rankToCoordinates(_frommap->get(state, plane), x, y, z, t);
556 int newx=(x+offsetX)%topoMgr->getDimNX();
557 int newy=(y+offsetY)%topoMgr->getDimNY();
558 int newz=(z+offsetZ)%topoMgr->getDimNZ();
559 destpe = topoMgr->coordinatesToRank(newx, newy, newz, t);
560 maptable->set(state, plane, destpe);
565 CkPrintf(
"WARNING: using co-mapping for instances because I'm too lazy to partition the processors in the non topo case\n");
566 for(
int state=0; state<nstates; state++)
567 for(
int plane=0; plane<nchareG; plane++) {
568 maptable->set(state,plane,_frommap->get(state, plane));
575 int _nstates,
int _nchareG,
int _grainsize,
576 bool _flag,
int _scalc_per_plane,
581 bool useCentroid,
int boxSize):
583 max_states(_nstates), nchareG(_nchareG),
584 grainsize(_grainsize), symmetric(_flag),
585 scalc_per_plane(_scalc_per_plane), planes_per_pe(_planes_per_pe),
586 numChunksAsym(_numChunksA), numChunksSym(_numChunksS)
589 int scobjs_per_pe, rem;
590 int count=0, procno=0;
592 int lesser_scalc = 0;
595 availprocs=_availprocs;
597 int maxstateindex=max_states/grainsize*grainsize;
598 if(planes_per_pe == 0)
599 CkAbort(
"Choose a larger nChareG to avoid this crash\n");
602 for(
int i=1; i<=max_states/grainsize; i++)
604 scobjs_per_pe = lesser_scalc*nchareG*numChunksSym/availprocs->count();
605 rem = lesser_scalc*nchareG*numChunksSym % availprocs->count();
609 CkPrintf(
" lesser_scalc %d *nchareG %d *numChunksSym %d %% availprocs->count() %d = rem %d and scobjs_per_pe is %d\n", lesser_scalc,scalc_per_plane,nchareG,numChunksAsym , availprocs->count(),rem, scobjs_per_pe);
612 int srcpe=0,destpe=availprocs->findNext();
613 if(availprocs->count()==0)
617 if(useCuboidMap|| useCentroid)
619 for(
int plane=0; plane<nchareG; plane++)
626 thisPlaneBox= subListPlane(plane, max_states, gsmap);
627 thisPlaneBox->reset();
633 thisPlaneBox=
new PeList(availprocs, plane*boxSize, boxSize);
640 destpe=thisPlaneBox->findNext();
641 if(thisPlaneBox->count()==0)
642 thisPlaneBox->reset();
645 for(
int xchunk=0; xchunk<maxstateindex; xchunk=xchunk+grainsize)
646 for(
int ychunk=xchunk; ychunk<maxstateindex; ychunk=ychunk+grainsize)
650 thisPlaneBox->trimUsed();
653 sortByCentroid(thisPlaneBox, plane, xchunk, ychunk, grainsize, gsmap);
656 destpe=thisPlaneBox->findNext();
657 if(thisPlaneBox->count()==0)
658 thisPlaneBox->reset();
661 for(
int newdim=0; newdim<numChunksSym; newdim++)
663 if(count<scobjs_per_pe)
670 if(thisPlaneBox->count()==0)
671 thisPlaneBox->reset();
673 destpe=thisPlaneBox->findNext();
674 if(thisPlaneBox->count()==0)
675 thisPlaneBox->reset();
684 CkAssert(destpe<config.numPes);
686 maptable->set(plane, xchunk, ychunk, newdim,destpe);
688 CkArrayIndex4D idx4d(plane, xchunk, ychunk, newdim);
689 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
690 maptable->put(
intdual(intidx[0], intidx[1]))=destpe;
703 for(
int pchunk=0; pchunk<nchareG; pchunk=pchunk+planes_per_pe)
704 for(
int newdim=0; newdim<numChunksSym; newdim++)
705 for(
int xchunk=0; xchunk<maxstateindex; xchunk=xchunk+grainsize)
706 for(
int ychunk=xchunk; ychunk<maxstateindex; ychunk=ychunk+grainsize)
708 for(
int plane=pchunk; plane<pchunk+planes_per_pe && plane<nchareG; plane++)
710 CkArrayIndex4D idx4d(plane, xchunk, ychunk, newdim);
711 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
713 if(count<scobjs_per_pe)
716 CkAssert(destpe<config.numPes);
718 maptable->set(plane, xchunk, ychunk, newdim,destpe);
720 maptable->put(
intdual(intidx[0], intidx[1]))=destpe;
730 if(availprocs->count()==0)
733 destpe=availprocs->findNext();
734 if(availprocs->count()==0)
737 if(rem!=0 &&scobjs_per_pe>1)
740 CkAssert(destpe<config.numPes);
742 maptable->set(plane, xchunk, ychunk, newdim,destpe);
744 maptable->put(
intdual(intidx[0], intidx[1]))=destpe;
752 CkPrintf(
"Symmetric SCalcMap created on processor %d\n", CkMyPe());
759 scobjs_per_pe = scalc_per_plane*nchareG*numChunksAsym/availprocs->count();
760 rem = scalc_per_plane*nchareG*numChunksAsym % availprocs->count();
766 CkPrintf(
" scalc_per_plane %d *nchareG %d *numChunksAsym %d availprocs->count() %d = rem %d and scobjs_per_pe is %d boxSize %d\n", scalc_per_plane,nchareG,numChunksAsym , availprocs->count(),rem, scobjs_per_pe, boxSize);
769 int srcpe=0,destpe=0;
770 if(!useCentroid && !useCuboidMap)
771 destpe=availprocs->findNext();
772 if(availprocs->count()==0)
774 if(useCuboidMap|| useCentroid)
776 for(
int plane=0; plane<nchareG; plane++)
783 thisPlaneBox= subListPlane(plane, max_states, gsmap);
790 thisPlaneBox=
new PeList(availprocs, plane*boxSize, boxSize);
797 destpe=thisPlaneBox->findNext();
798 if(thisPlaneBox->count()==0)
799 thisPlaneBox->reset();
802 for(
int xchunk=0; xchunk<maxstateindex; xchunk=xchunk+grainsize)
803 for(
int ychunk=0; ychunk<maxstateindex; ychunk=ychunk+grainsize)
807 thisPlaneBox->trimUsed();
810 sortByCentroid(thisPlaneBox, plane, xchunk, ychunk, grainsize, gsmap);
813 destpe=thisPlaneBox->findNext();
814 if(thisPlaneBox->count()==0)
815 thisPlaneBox->reset();
818 for(
int newdim=0; newdim<numChunksAsym; newdim++)
821 if(count<scobjs_per_pe)
828 destpe=thisPlaneBox->findNext();
829 if(thisPlaneBox->count()==0)
830 thisPlaneBox->reset();
832 if(rem!=0&& scobjs_per_pe>1)
840 maptable->set(plane, xchunk, ychunk, newdim,destpe);
842 CkArrayIndex4D idx4d(plane, xchunk, ychunk, newdim);
843 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
844 maptable->put(
intdual(intidx[0], intidx[1]))=destpe;
857 for(
int pchunk=0; pchunk<nchareG; pchunk=pchunk+planes_per_pe)
858 for(
int newdim=0; newdim<numChunksAsym; newdim++)
859 for(
int xchunk=0; xchunk<maxstateindex; xchunk=xchunk+grainsize)
860 for(
int ychunk=0; ychunk<maxstateindex; ychunk=ychunk+grainsize)
861 for(
int plane=pchunk; plane<pchunk+planes_per_pe && plane<nchareG; plane++)
863 CkArrayIndex4D idx4d(plane, xchunk, ychunk, newdim);
864 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
866 if(count<scobjs_per_pe)
870 maptable->set(plane, xchunk, ychunk, newdim, destpe);
872 maptable->put(
intdual(intidx[0], intidx[1]))=destpe;
880 if(availprocs->count()==0)
883 destpe=availprocs->findNext();
884 if(availprocs->count()==0)
891 maptable->set(plane, xchunk, ychunk, newdim,destpe);
893 maptable->put(
intdual(intidx[0], intidx[1]))=destpe;
903 CkPrintf(
"Asymmetric SCalcMap created on processor %d\n", CkMyPe());
914 PeList *exclusionList=NULL;
915 for(
int exc=0; exc<config.numPesPerInstance; exc++)
917 if(Pecount[exc]>=rsobjs_per_pe)
919 if(exclusionList==NULL)
921 exclusionList=
new PeList(1);
922 exclusionList->TheList[0]=exc;
923 exclusionList->sortIdx[0]=0;
927 exclusionList->mergeOne(exc);
931 return(exclusionList);
936 int _nstates,
int _sizeZ,
int _Rstates_per_pe,
bool useCuboidMap,
MapType2 *gsmap,
937 int nchareG,
int numInst,
int offsetX,
int offsetY,
int offsetZ):
938 nstates(_nstates), sizeZ(_sizeZ),
939 Rstates_per_pe(_Rstates_per_pe)
943 availprocs = _availprocs;
947 int l, m, pl, pm, srem, rem, i=0, rsobjs_per_pe;
948 int *Pecount=
new int [config.numPes];
950 bzero(Pecount, config.numPes*
sizeof(
int));
952 rsobjs_per_pe = nstates*sizeZ/config.numPesPerInstance;
953 if(config.useStrictCuboid)
961 while(pow(2.0, (
double)i) < pl)
963 pl = (int) pow(2.0, (
double)(i-1));
966 pm = availprocs->count() / pl;
969 CkPrintf(
"Choose a larger Rstates_per_pe than %d such that { no. of processors [%d] / (no. of states [%d] / Rstates_per_pe [%d]) } is > 0 \n",
970 l, availprocs->count(), nstates, l);
971 CkAssert(availprocs->count() / (nstates/l) > 0);
981 int destpe=availprocs->findNext();
983 if(availprocs->count()==0)
987 int srem = (nstates*sizeZ) % config.numPesPerInstance;
1001 PeList *exclusionList = NULL;
1002 for(
int state=0; state < nstates; state++)
1005 int srsobjs_per_pe=rsobjs_per_pe;
1006 PeList *thisStateBox = subListState(state, nchareG, gsmap);
1007 int samplePe=thisStateBox->TheList[0];
1010 bool useExclude=
true;
1011 if(exclusionList!=NULL && useExclude)
1013 *thisStateBox - *exclusionList;
1014 thisStateBox->reindex();
1015 thisStateBox->reset();
1020 if(thisStateBox->count()<=0)
1022 if(config.useStrictCuboid)
1025 while(thisStateBox->count()<=0 && srsobjs_per_pe<=sizeZ*nstates)
1027 CkPrintf(
"State %d Ran out of procs in RS centroid map increasing rs objects per proc to %d\n",state,srsobjs_per_pe);
1029 if(exclusionList!=NULL)
1030 delete exclusionList;
1032 delete thisStateBox;
1033 thisStateBox = subListState(state, nchareG, gsmap);
1034 if(exclusionList!=NULL){
1035 *thisStateBox - *exclusionList;
1036 thisStateBox->reindex();
1037 thisStateBox->reset();
1045 CkPrintf(
"State %d Ran out of procs in RS centroid map scheme, spilling over to master list\n",state,srsobjs_per_pe);
1047 delete thisStateBox;
1048 thisStateBox=
new PeList(*myavail);
1049 thisStateBox->reindex();
1050 thisStateBox->reset();
1051 thisStateBox->sortSource(samplePe);
1054 if(thisStateBox->count()==0)
1057 CkPrintf(
"RS state %d excluded to nil, ignoring exclusions\n",state);
1058 delete thisStateBox;
1059 thisStateBox = subListState(state, nchareG, gsmap);
1064 for(
int plane=0; plane < sizeZ; plane++)
1066 if(thisStateBox->count()==0)
1067 thisStateBox->reset();
1068 if(thisStateBox->count()<=0)
1070 if(config.useStrictCuboid)
1072 while(thisStateBox->count()<=0 && srsobjs_per_pe<=sizeZ*nstates)
1075 CkPrintf(
"State %d Plane %d Ran out of procs in RS centroid map increasing rs objects per proc to %d\n",state,plane,srsobjs_per_pe);
1076 if(exclusionList!=NULL)
1077 delete exclusionList;
1079 delete thisStateBox;
1080 thisStateBox = subListState(state, nchareG, gsmap);
1081 if(exclusionList!=NULL && useExclude)
1083 *thisStateBox - *exclusionList;
1084 thisStateBox->reset();
1085 thisStateBox->reindex();
1091 CkPrintf(
"State %d Ran out of procs in RS centroid map scheme, spilling over to master list\n",state,srsobjs_per_pe);
1092 if(myavail->count()<=0)
1095 CkPrintf(
"State %d Ran out of procs in master, bumping srsobjs_per_pe\n",state,srsobjs_per_pe);
1096 delete thisStateBox;
1098 myavail=
new PeList(*availprocs);
1099 if(exclusionList!=NULL)
1100 delete exclusionList;
1103 if(exclusionList!=NULL)
1105 *myavail - *exclusionList;
1107 thisStateBox =
new PeList(*myavail);
1111 delete thisStateBox;
1112 thisStateBox=
new PeList(*myavail);
1114 thisStateBox->reindex();
1115 thisStateBox->reset();
1116 thisStateBox->sortSource(samplePe);
1119 if(useExclude && thisStateBox->count()<=0)
1122 delete thisStateBox;
1123 CkAbort(
"RS cuboid map hopeless please examine configuration\n");
1127 destpe = thisStateBox->findNext();
1130 maptable->set(state, plane, destpe);
1132 maptable->put(
intdual(state, plane))= destpe;
1137 if(Pecount[destpe]>=srsobjs_per_pe)
1139 if(exclusionList==NULL)
1141 exclusionList=
new PeList(1);
1142 exclusionList->TheList[0]=destpe;
1143 exclusionList->sortIdx[0]=0;
1147 exclusionList->mergeOne(destpe);
1149 one.TheList[0]=destpe;
1150 *thisStateBox - one;
1152 thisStateBox->reindex();
1153 thisStateBox->reset();
1158 delete thisStateBox;
1160 if(exclusionList!=NULL)
1161 delete exclusionList;
1171 for(
int ychunk=0; ychunk<sizeZ-rem; ychunk=ychunk+m)
1175 for(
int xchunk=0; xchunk<nstates; xchunk=xchunk+l)
1177 if(xchunk==(pl-srem)*l)
1179 for(
int state=xchunk; state<xchunk+l && state<nstates; state++)
1181 for(
int plane=ychunk; plane<ychunk+m && plane<sizeZ; plane++)
1184 maptable->set(state, plane, destpe);
1186 maptable->put(
intdual(state, plane))= destpe;
1190 destpe=availprocs->findNext();
1191 if(availprocs->count()==0)
1192 availprocs->reset();
1197 for(
int state=0; state<nstates; state++)
1199 for(
int plane=sizeZ-rem; plane<sizeZ; plane++)
1201 if(availprocs->count()==0)
1202 availprocs->reset();
1203 destpe=availprocs->findNext();
1205 maptable->set(state, plane, destpe);
1207 maptable->put(
intdual(state, plane)) = destpe;
1215 CkPrintf(
"RSMap created on processor %d\n", CkMyPe());
1219 if(config.torusMap==1)
1221 int x, y, z, t, destpe;
1222 CkPrintf(
"{%d} RS using offsets X=%d Y=%d Z=%d\n",numInst, offsetX, offsetY, offsetZ);
1223 for(
int state=0; state<nstates; state++)
1224 for(
int plane=0; plane<sizeZ; plane++) {
1225 topoMgr->rankToCoordinates(_frommap->get(state, plane), x, y, z, t);
1226 int newx=(x+offsetX)%topoMgr->getDimNX();
1227 int newy=(y+offsetY)%topoMgr->getDimNY();
1228 int newz=(z+offsetZ)%topoMgr->getDimNZ();
1229 destpe = topoMgr->coordinatesToRank(newx, newy, newz, t);
1230 maptable->set(state, plane, destpe);
1235 CkPrintf(
"WARNING: using co-mapping for instances because I'm too lazy to partition the processors in the non topo case\n");
1236 for(
int state=0; state<nstates; state++)
1237 for(
int plane=0; plane<sizeZ; plane++) {
1238 maptable->set(state,plane,_frommap->get(state, plane));
1245 RPPMapTable::RPPMapTable(
MapType2 *_map,
1247 int _nstates,
int _sizeZNL,
int _Rstates_per_pe,
1248 int boxSize,
bool usePPmap,
int nchareG,
1250 nstates(_nstates), sizeZNL(_sizeZNL),
1251 Rstates_per_pe(_Rstates_per_pe)
1253 int states_per_pe=Rstates_per_pe;
1254 int totalChares=nstates*sizeZNL;
1257 availprocs=_availprocs;
1263 bool useExclusion=
true;
1264 PeList *RPPlist=availprocs;
1265 int chares_per_pe=totalChares/config.numPesPerInstance;
1267 CkPrintf(
"CharesPerPe %d states_per_pe %d\n",chares_per_pe, states_per_pe);
1268 if(exclusion==NULL || exclusion->count()==0 || config.numPesPerInstance <=exclusion->count() )
1270 int afterExclusion=availprocs->count();
1272 afterExclusion=availprocs->count() - exclusion->count();
1275 if(useExclusion && afterExclusion > chares_per_pe*sizeZNL)
1277 CkPrintf(
"RPP using density exclusion to avoid %d processors\n",exclusion->count());
1278 *RPPlist-*exclusion;
1283 if(useExclusion && afterExclusion > (sizeZNL+nstates)*2)
1286 states_per_pe=(int) ((
float) (totalChares/afterExclusion))*0.75;
1287 CkPrintf(
"RPP adjusting states per pe from %d to %d to use density exclusion to stay within %d processors\n",Rstates_per_pe, states_per_pe, exclusion->count());
1288 *RPPlist-*exclusion;
1294 CkPrintf(
"RPP with %d chares ignoring density exclusion which left %d out of %d processors\n",totalChares, exclusion->count(), availprocs->count());
1298 chares_per_pe=totalChares/RPPlist->count();
1308 bool neednewexc=
false;
1314 int maxcharesperpe=states_per_pe;
1315 int *usedPes=
new int[config.numPes];
1316 bool *useExclude=
new bool[nstates];
1317 bzero(usedPes, config.numPes *
sizeof(
int));
1318 for(
int state=0; state < nstates ; state++)
1324 PeList *state_map=subListState( state, nchareG, pp_map);
1325 CkAssert(state_map->count()>0);
1328 *state_map-*exclusion;
1329 state_map->reindex();
1330 if(state_map->count()==0 || sizeZNL/state_map->count() > states_per_pe)
1333 state_map=subListState( state, nchareG, pp_map);
1334 useExclude[state]=
false;
1338 useExclude[state]=
true;
1343 useExclude[state]=
false;
1345 int thischaresperpe=sizeZNL/state_map->count() + 1;
1349 maxcharesperpe=(thischaresperpe>maxcharesperpe) ? thischaresperpe : maxcharesperpe;
1355 int totcharesperpe=sizeZNL*nstates/config.numPesPerInstance+1;
1356 maxcharesperpe=(maxcharesperpe>totcharesperpe) ? maxcharesperpe : totcharesperpe;
1359 CkPrintf(
"RPP maxcharesperpe is %d\n",maxcharesperpe);
1360 int origmaxcharesperpe=maxcharesperpe;
1361 PeList *excludedBigmap=NULL;
1362 for(
int state=0; state < nstates ; state++)
1364 PeList *state_map=subListState( state, nchareG, pp_map);
1365 if(useExclude[state])
1367 *state_map-*exclusion;
1368 state_map->reindex();
1370 while(state_map->count()<=0 && maxcharesperpe<=sizeZNL*nstates)
1372 if(config.useStrictCuboid)
1374 CkPrintf(
"State %d Ran out of procs in RPP centroid map increasing rpp objects per proc to %d\n",state,maxcharesperpe);
1380 state_map = subListState(state, nchareG, pp_map);
1381 if(usedbyRPP!=NULL){
1382 *state_map - *usedbyRPP;
1383 state_map->reindex();
1391 CkPrintf(
"State %d Ran out of procs in RPP centroid using full RPPlist\n",state);
1393 if(!neednewexc && excludedBigmap!=NULL)
1395 state_map=
new PeList(*excludedBigmap);
1399 state_map =
new PeList(*RPPlist);
1400 if(usedbyRPP!=NULL){
1401 *state_map - *usedbyRPP;
1402 state_map->reindex();
1404 if(excludedBigmap!=NULL)
1405 delete excludedBigmap;
1406 excludedBigmap=
new PeList(*state_map);
1409 if(state_map->count()<=0)
1412 CkPrintf(
"plane %d Ran out of procs in RPP centroid using full RPPlist and bumping maxcharesperpe to %d\n",state, maxcharesperpe);
1417 state_map =
new PeList(*RPPlist);
1418 if(usedbyRPP!=NULL && usedbyRPP->count()>0){
1419 *state_map - *usedbyRPP;
1420 state_map->reindex();
1423 if(excludedBigmap!=NULL)
1424 delete excludedBigmap;
1425 excludedBigmap=
new PeList(*state_map);
1430 state_map->sortSource(pp_map->get(state,0));
1432 for(
int plane=0; plane < sizeZNL; plane++)
1434 if(state_map->count()==0)
1436 while(state_map->count()<=0 && maxcharesperpe<=sizeZNL*nstates)
1438 if(config.useStrictCuboid)
1440 while(state_map->count()<=0 && maxcharesperpe<=sizeZNL*nstates)
1442 CkPrintf(
"State %d Ran out of procs in RPP centroid map increasing rpp objects per proc to %d\n",state,maxcharesperpe);
1448 state_map = subListState(state, nchareG, pp_map);
1449 if(usedbyRPP!=NULL){
1450 *state_map - *usedbyRPP;
1451 state_map->reindex();
1460 CkPrintf(
"State %d Ran out of procs in RPP centroid using full RPPlist\n",state);
1462 if(!neednewexc && excludedBigmap!=NULL&& excludedBigmap->count()>0)
1464 state_map=
new PeList(*excludedBigmap);
1468 state_map =
new PeList(*RPPlist);
1469 if(usedbyRPP!=NULL){
1470 *state_map - *usedbyRPP;
1471 state_map->reindex();
1473 if(excludedBigmap!=NULL)
1474 delete excludedBigmap;
1475 if(state_map->count()==0)
1478 excludedBigmap=NULL;
1482 excludedBigmap=
new PeList(*state_map);
1487 if(state_map->count()<=0)
1490 CkPrintf(
"plane %d Ran out of procs in RPP centroid using full RPPlist and bumping maxcharesperpe to %d\n",state, maxcharesperpe);
1496 state_map =
new PeList(*RPPlist);
1499 *state_map - *usedbyRPP;
1500 state_map->reindex();
1503 if(state_map->count()==0)
1506 CkPrintf(
"plane %d Ran out of procs in RPP centroid using full RPPlist after bumping maxcharesperpe to %d, clearing used list, resetting maxcharesperpe to %d\n",state, maxcharesperpe, origmaxcharesperpe);
1509 maxcharesperpe=origmaxcharesperpe;
1510 bzero(usedPes, config.numPes *
sizeof(
int));
1515 state_map =
new PeList(*RPPlist);
1518 *state_map - *usedbyRPP;
1519 state_map->reindex();
1524 if(excludedBigmap!=NULL)
1525 delete excludedBigmap;
1526 excludedBigmap=
new PeList(*state_map);
1530 state_map->sortSource(pp_map->get(state,0));
1533 int destpe=state_map->findNext();
1535 maptable->set(state, plane, destpe);
1537 maptable->put(
intdual(state, plane))=destpe;
1540 if(usedPes[destpe]>maxcharesperpe)
1545 usedbyRPP=
new PeList(1);
1546 usedbyRPP->TheList[0]=destpe;
1549 usedbyRPP->mergeOne(destpe);
1550 usedbyRPP->reindex();
1551 exclusion->mergeOne(destpe);
1552 exclusion->reindex();
1554 thisOne.TheList[0]=destpe;
1555 if(excludedBigmap!=NULL)
1558 *excludedBigmap-thisOne;
1560 *state_map - thisOne;
1561 state_map->reindex();
1569 delete [] useExclude;
1570 if(excludedBigmap!=NULL)
1571 delete excludedBigmap;
1575 int destpe=RPPlist->findNext();
1577 int charesOnThisPe=0;
1578 int rem = totalChares % chares_per_pe;
1579 int starting_cpp=chares_per_pe;
1581 CkPrintf(
"chares_per_pe %d rem %d\n",chares_per_pe, rem);
1582 for(
int state=0; state < nstates; state++)
1584 for(
int plane=0; plane < sizeZNL; plane++)
1588 maptable->set(state, plane, destpe);
1590 maptable->put(
intdual(state, plane))=destpe;
1592 if(++charesOnThisPe==chares_per_pe)
1594 destpe=RPPlist->findNext();
1596 if(RPPlist->count()==0)
1600 if(rem && RPPlist->count()<2*nstates)
1602 chares_per_pe=starting_cpp+1;
1609 CkPrintf(
"RPPMap created on processor %d\n", CkMyPe());
1615 OrthoMapTable::OrthoMapTable(
MapType2 *_map,
PeList *_availprocs,
int _nstates,
int _orthograinsize,
MapType4 *scalcmap,
int nplanes,
int numChunks,
int sGrainSize,
PeList *exclusionList): nstates(_nstates), orthoGrainSize(_orthograinsize)
1618 availprocs = _availprocs;
1620 int srcpe = 0, destpe;
1621 bool useSublist=
true;
1622 bool useExclude=
true;
1623 int maxorthoindex=(nstates/orthoGrainSize-1);
1624 int northo=(maxorthoindex+1)*(maxorthoindex+1);
1625 oobjs_per_pe = northo/(config.numPesPerInstance);
1626 int *Pecount=
new int [config.numPesPerInstance];
1627 bzero(Pecount, config.numPesPerInstance*
sizeof(
int));
1629 int maxpcstateindex=(nstates/sGrainSize-1)*sGrainSize;
1630 int maxorthostateindex=(nstates/orthoGrainSize-1)*orthoGrainSize;
1631 for(
int state1 = 0; state1 <= maxorthostateindex; state1 += orthoGrainSize)
1632 for(
int state2 = 0; state2 <= maxorthostateindex; state2 += orthoGrainSize)
1634 s1 = (state1/sGrainSize);
1635 s1 = s1 * sGrainSize;
1636 s1 = (s1>maxpcstateindex) ? maxpcstateindex :s1;
1637 s2 = (state2/sGrainSize);
1638 s2 = s2 * sGrainSize;
1639 s2 = (s2>maxpcstateindex) ? maxpcstateindex :s2;
1640 PeList *thisStateBox=NULL;
1643 thisStateBox = subListState2(s1, s2, nplanes, numChunks, scalcmap);
1645 *thisStateBox - *exclusionList;
1646 thisStateBox->reindex();
1647 thisStateBox->reset();
1651 thisStateBox=availprocs;
1653 if(thisStateBox->count() == 0)
1655 CkPrintf(
"Ortho %d %d ignoring SubList\n", state1, state2);
1656 if(thisStateBox!=availprocs)
1657 delete thisStateBox;
1658 thisStateBox = availprocs;
1664 if(thisStateBox->count() == 0)
1666 CkPrintf(
"Ortho %d %d ignoring exclusion\n", state1, state2);
1667 if(thisStateBox!=availprocs)
1668 delete thisStateBox;
1669 thisStateBox = subListState2(s1, s2, nplanes, numChunks, scalcmap);
1679 destpe=minDistCentroid(thisStateBox, nplanes, s1, s2, numChunks, scalcmap);
1680 int os1 = (state1/orthoGrainSize);
1681 os1 = (os1>maxorthoindex) ? maxorthoindex :os1;
1682 int os2=(state2/orthoGrainSize);
1683 os2 = (os2>maxorthoindex) ? maxorthoindex :os2;
1685 maptable->set(os1, os2, destpe);
1687 maptable->put(
intdual(os1, os2))=destpe;
1690 if(Pecount[destpe]>=oobjs_per_pe)
1692 exclusionList->mergeOne(destpe);
1696 one.TheList[0]=destpe;
1698 availprocs->reindex();
1699 availprocs->reset();
1702 if(thisStateBox!=availprocs)
1703 delete thisStateBox;
1708 OrthoHelperMapTable::OrthoHelperMapTable(
MapType2 *_map,
int _nstates,
int _orthograinsize,
MapType2 *omap,
PeList *_avail,
PeList *exclude): nstates(_nstates), orthoGrainSize(_orthograinsize)
1713 availprocs=
new PeList(*_avail);
1714 *availprocs-*exclude;
1717 bool useExclude=
true;
1718 if(availprocs->count() < ((nstates/orthoGrainSize)*(nstates/orthoGrainSize)))
1720 CkPrintf(
"There aren't enough processors to effectively parallelize orthoHelpers, you should disable orthoHelpers!!!\n");
1722 availprocs=
new PeList(*_avail);
1723 availprocs->reset();
1726 int maxorthoindex=(nstates/orthoGrainSize-1);
1727 for(
int state1 = 0; state1 <= maxorthoindex; state1++)
1728 for(
int state2 = 0; state2 <= maxorthoindex; state2++)
1732 destpe=availprocs->
minDist(omap->get(state1, state2));
1733 maptable->set(state1, state2, destpe);
1736 maptable->put(
intdual(state1, state2))=destpe;
1742 one.TheList[0]=destpe;
1744 availprocs->reindex();
1751 RhoRSMapTable::RhoRSMapTable(
MapType2 *_map,
PeList *_availprocs,
int _nchareRhoR,
int _rhoRsubplanes,
int max_states,
bool useCentroid,
MapType2 *rsmap,
PeList *exclude): nchareRhoR(_nchareRhoR), rhoRsubplanes(_rhoRsubplanes)
1755 availprocs=_availprocs;
1756 int rrsobjs_per_pe, rem;
1758 int numChares=nchareRhoR*rhoRsubplanes;
1760 if(availprocs->count()==1)
1762 rrsobjs_per_pe= numChares;
1767 rrsobjs_per_pe= numChares/(availprocs->count());
1768 rem = numChares % (availprocs->count());
1769 if(numChares<availprocs->count())
1775 rrsobjs_per_pe += 1;
1778 if(availprocs->count()==0)
1779 availprocs->reset();
1781 int *Pecount =
new int [config.numPes];
1782 bzero(Pecount, config.numPes*
sizeof(
int));
1787 PeList *exclusionList = NULL;
1790 for(
int chunk=0; chunk<nchareRhoR; chunk++)
1792 PeList *thisPlaneBox = subListPlane(chunk, max_states, rsmap);
1793 bool useExclude=
true;
1794 if(exclusionList!=NULL) {
1795 *thisPlaneBox - *exclusionList;
1796 thisPlaneBox->reindex();
1799 if(thisPlaneBox->count()==0)
1801 CkPrintf(
"Rho RS %d ignoring plane sublist\n",chunk);
1802 thisPlaneBox =
new PeList(*availprocs);
1803 if(exclusionList!=NULL) {
1804 *thisPlaneBox - *exclusionList;
1805 thisPlaneBox->reindex();
1807 if(thisPlaneBox->count()==0)
1809 CkPrintf(
"Rho RS %d ignoring plane sublist and exclusion\n",chunk);
1810 thisPlaneBox =
new PeList(*availprocs);
1813 sortByCentroid(thisPlaneBox, chunk, max_states, rsmap);
1816 destpe=thisPlaneBox->findNext();
1817 if(thisPlaneBox->count()==0)
1818 thisPlaneBox->reset();
1819 for(
int subplane=0 ; subplane<rhoRsubplanes ; subplane++)
1822 maptable->set(chunk, subplane, destpe);
1824 maptable->put(
intdual(chunk, subplane))=destpe;
1827 if(Pecount[destpe]>=rrsobjs_per_pe)
1829 if(exclusionList==NULL)
1831 exclusionList=
new PeList(1);
1832 exclusionList->TheList[0]=destpe;
1835 exclusionList->mergeOne(destpe);
1836 if(useExclude && thisPlaneBox->size>1)
1838 *thisPlaneBox - *exclusionList;
1839 thisPlaneBox->reindex();
1841 sortByCentroid(thisPlaneBox, chunk, max_states, rsmap);
1843 destpe=thisPlaneBox->findNext();
1844 if(thisPlaneBox->count()==0)
1845 thisPlaneBox->reset();
1847 delete thisPlaneBox;
1850 for(
int i=0; i<config.numPesPerInstance;i++)
1855 if(Pecount[i] <rrsobjs_per_pe)
1857 if(exclusionList==NULL)
1859 exclusionList=
new PeList(1);
1860 exclusionList->TheList[0]=i;
1863 exclusionList->mergeOne(i);
1866 exclusionList->reindex();
1868 if(exclusionList!=NULL)
1870 exclude->append(*exclusionList);
1871 delete exclusionList;
1876 int nprocs=0, objs=0;
1877 destpe=availprocs->findNext();
1878 if(availprocs->count()==0)
1879 availprocs->reset();
1880 for(
int chunk=0; chunk<nchareRhoR; chunk++)
1882 for(
int subplane=0; subplane<rhoRsubplanes; subplane++)
1886 rrsobjs_per_pe -= 1;
1888 maptable->set(chunk, subplane, destpe);
1890 maptable->put(
intdual(chunk, subplane))=destpe;
1893 if(objs==rrsobjs_per_pe)
1895 destpe=availprocs->findNext();
1896 if(availprocs->count()==0)
1897 availprocs->reset();
1905 CkPrintf(
"Built RhoRS Map [%d, %d] on %d processors\n",nchareRhoR,rhoRsubplanes, pesused );
1907 CkPrintf(
"RhoRSMap created on processor %d\n", CkMyPe());
1926 availprocs=_availprocs;
1927 int rgsobjs_per_pe, rem;
1929 if(availprocs->count()==0)
1930 availprocs->reset();
1937 availprocs->sortSource(rhorsmap->getCentroid(config.torusMap));
1938 availprocs->reset();
1942 if(avail->count()>nchareRhoG)
1945 CkPrintf(
"RhoG excluding %d from avail %d\n",exclude->count(), availprocs->count());
1946 *availprocs-*exclude;
1947 availprocs->reindex();
1952 CkPrintf(
"cannot use exclusion in rhog\n");
1953 availprocs->reset();
1957 if(availprocs->count()==1)
1959 rgsobjs_per_pe= nchareRhoG;
1964 rgsobjs_per_pe= nchareRhoG/(availprocs->count());
1965 rem = nchareRhoG % (availprocs->count());
1966 if(nchareRhoG<availprocs->count())
1972 rgsobjs_per_pe += 1;
1975 int destpe=availprocs->findNext();
1976 if(availprocs->count()==0)
1977 availprocs->reset();
1979 for(
int chunk=0; chunk<nchareRhoG; chunk+=rgsobjs_per_pe)
1982 if(chunk==rem*rgsobjs_per_pe)
1983 rgsobjs_per_pe -= 1;
1984 for(
int i=chunk;((i<chunk+rgsobjs_per_pe)&&(i<nchareRhoG));i++)
1987 maptable->set(i, 0, destpe);
1989 maptable->put(
intdual(i, 0))=destpe;
1992 exclude->mergeOne(destpe);
1993 if(chunk+1<nchareRhoG)
1994 destpe=availprocs->findNext();
1995 if(availprocs->count()==0)
1996 availprocs->reset();
1999 CkPrintf(
"RhoGSMap created on processor %d\n", CkMyPe());
2005 RhoRHartMapTable::RhoRHartMapTable(
MapType3 *_map,
PeList *_availprocs,
int _nchareRhoRHart,
int rhoRsubplanes,
int nchareHartAtmT,
PeList *exclude ): nchareRhoRHart(_nchareRhoRHart)
2009 availprocs=_availprocs;
2010 int rrsobjs_per_pe, rem;
2012 int numChares=nchareRhoRHart*rhoRsubplanes*nchareHartAtmT;
2013 if(availprocs->count()==0)
2014 availprocs->reset();
2017 if(avail->count()>numChares)
2020 CkPrintf(
"RhoRHart excluding %d from avail %d\n",exclude->count(), availprocs->count());
2021 *availprocs-*exclude;
2022 availprocs->reindex();
2028 availprocs->reset();
2032 if(availprocs->count()==1)
2034 rrsobjs_per_pe= numChares;
2039 rrsobjs_per_pe= numChares/(availprocs->count());
2040 rem = numChares % (availprocs->count());
2041 if(numChares<availprocs->count())
2047 rrsobjs_per_pe += 1;
2050 int destpe=availprocs->findNext();
2052 if(availprocs->count()==0)
2053 availprocs->reset();
2057 int nprocs=0, objs=0;
2058 destpe=availprocs->findNext();
2059 if(availprocs->count()==0)
2060 availprocs->reset();
2062 for(
int atmtype=0; atmtype< nchareHartAtmT;atmtype++)
2064 for(
int chunk=0; chunk<nchareRhoRHart; chunk++)
2066 for(
int subplane=0; subplane<rhoRsubplanes; subplane++)
2070 rrsobjs_per_pe -= 1;
2072 maptable->set(chunk, subplane, atmtype,destpe);
2074 maptable->put(
inttriple(chunk, subplane, atmtype))=destpe;
2077 exclude->mergeOne(destpe);
2078 if(objs>=rrsobjs_per_pe)
2081 destpe=availprocs->findNext();
2082 if(availprocs->count()==0)
2083 availprocs->reset();
2091 CkPrintf(
"RhoRHartMap created on processor %d\n", CkMyPe());
2097 RhoGHartMapTable::RhoGHartMapTable(
MapType2 *_map,
PeList *_availprocs,
int _nchareRhoGHart,
int nchareHartAtmT,
int useCentroid,
MapType3 *rhartmap,
PeList *exclude): nchareRhoGHart(_nchareRhoGHart)
2102 PeList *availprocs=_availprocs;
2107 int numchares=nchareRhoGHart*nchareHartAtmT;
2109 if(avail->count()>numchares)
2112 CkPrintf(
"RhoGHart excluding %d from avail %d\n",exclude->count(), availprocs->count());
2113 *availprocs-*exclude;
2114 availprocs->reindex();
2119 CkPrintf(
"cannot use exclusion in rhoghart\n");
2120 availprocs->reset();
2123 if(availprocs->count()==0)
2124 availprocs->reset();
2125 npes=availprocs->count();
2126 int rghobjs_per_pe, rem;
2128 if(availprocs->count()==1)
2130 rghobjs_per_pe= numchares;
2135 rghobjs_per_pe= numchares/npes;
2136 rem = numchares % npes;
2137 if(numchares < npes)
2143 rghobjs_per_pe += 1;
2145 if(useCentroid && excluded && rhartmap!=NULL)
2148 availprocs->reset();
2149 availprocs->sortSource(rhartmap->getCentroid(config.torusMap));
2150 availprocs->reset();
2152 int destpe=availprocs->findNext();
2153 if(availprocs->count()==0)
2154 availprocs->reset();
2155 for(
int atmtype=0; atmtype< nchareHartAtmT;atmtype++)
2157 for(
int chunk=0; chunk<nchareRhoGHart; chunk+=rghobjs_per_pe)
2160 if(rem>1 && rghobjs_per_pe>1)
2161 if(chunk==rem*rghobjs_per_pe)
2162 rghobjs_per_pe -= 1;
2163 for(
int i=chunk;((i<chunk+rghobjs_per_pe)&&(i<nchareRhoGHart));i++)
2166 maptable->set(i, atmtype, destpe);
2168 maptable->put(
intdual(i, atmtype))=destpe;
2171 exclude->mergeOne(destpe);
2173 if(chunk+1<nchareRhoGHart)
2174 destpe=availprocs->findNext();
2176 chunk=nchareRhoGHart;
2177 if(availprocs->count()==0)
2178 availprocs->reset();
2183 CkPrintf(
"RhoGHartMap created on processor %d\n", CkMyPe());
2194 VdWRSMapTable::VdWRSMapTable(
MapType3 *_map,
PeList *_availprocs,
int _nchareRhoR,
int _rhoRsubplanes,
int _nchareVdW,
int max_states,
PeList *exclude): nchareRhoR(_nchareRhoR), rhoRsubplanes(_rhoRsubplanes)
2195 ,nchareVdW(_nchareVdW) {
2198 availprocs=_availprocs;
2199 int rvdwobjs_per_pe, rem;
2201 int numChares=nchareRhoR*rhoRsubplanes* nchareVdW;
2203 if(availprocs->count()==1)
2205 rvdwobjs_per_pe= numChares;
2210 rvdwobjs_per_pe= numChares/(availprocs->count());
2211 rem = numChares % (availprocs->count());
2212 if(numChares<availprocs->count())
2218 rvdwobjs_per_pe += 1;
2221 if(availprocs->count()==0)
2222 availprocs->reset();
2224 int nprocs=0, objs=0;
2225 destpe=availprocs->findNext();
2226 if(availprocs->count()==0)
2227 availprocs->reset();
2228 for(
int chunk=0; chunk<nchareRhoR; chunk++)
2230 for(
int subplane=0; subplane<rhoRsubplanes; subplane++)
2232 for(
int vdw=0; vdw<nchareVdW; vdw++)
2236 rvdwobjs_per_pe -= 1;
2238 maptable->set(chunk, subplane, vdw, destpe);
2240 maptable->put(
inttriple(chunk, subplane,vdw))=destpe;
2243 if(objs==rvdwobjs_per_pe)
2245 destpe=availprocs->findNext();
2246 if(availprocs->count()==0)
2247 availprocs->reset();
2254 CkPrintf(
"Built VdWRS Map [%d, %d, %d]\n",nchareRhoR,rhoRsubplanes, nchareVdW);
2256 CkPrintf(
"VdWRSMap created on processor %d\n", CkMyPe());
2277 availprocs=_availprocs;
2278 int rgsobjs_per_pe, rem;
2280 if(availprocs->count()==0)
2281 availprocs->reset();
2284 int numVdWObjs=nchareRhoG*nchareVdW;
2285 if(avail->count()>numVdWObjs)
2288 CkPrintf(
"RhoG excluding %d from avail %d\n",exclude->count(), availprocs->count());
2289 *availprocs-*exclude;
2290 availprocs->reindex();
2295 CkPrintf(
"cannot use exclusion in rhog\n");
2296 availprocs->reset();
2300 if(availprocs->count()==1)
2302 rgsobjs_per_pe= numVdWObjs;
2307 rgsobjs_per_pe= numVdWObjs/(availprocs->count());
2308 rem = numVdWObjs % (availprocs->count());
2309 if(numVdWObjs<availprocs->count())
2315 rgsobjs_per_pe += 1;
2318 int destpe=availprocs->findNext();
2319 if(availprocs->count()==0)
2320 availprocs->reset();
2323 for(
int i=0; i<nchareRhoG; i++)
2325 for(
int j=0; j<nchareVdW; j++)
2329 maptable->set(i, j, destpe);
2331 maptable->put(
intdual(i, j))=destpe;
2334 if(thischunk>rgsobjs_per_pe)
2336 exclude->mergeOne(destpe);
2337 destpe=availprocs->findNext();
2338 if(availprocs->count()==0)
2339 availprocs->reset();
2344 CkPrintf(
"VdWGSMap created on processor %d\n", CkMyPe());
2351 void MapTable2::makeReverseMap()
2354 CkHashtableIterator *it=maptable->iterator();
2357 reverseMap=
new CkVec <intdual> [config.numPesPerInstance];
2358 while(it->hasNext())
2360 it->next((
void **) &key);
2361 int proc =maptable->get(key[0]);
2362 reverseMap[proc].push_back(key[0]);
2374 thisPlane->TheList[0]=smap->get(0,plane);
2375 for(
int state=1; state<nstates; state++)
2377 thisPlane->mergeOne(smap->get(state,plane));
2380 thisPlane->reindex();
2388 thisState->TheList[0]=smap->get(state,0);
2389 thisState->sortIdx[0]=0;
2390 for(
int plane=1; plane < nplanes; plane++)
2392 int pe=smap->get(state, plane);
2393 thisState->mergeOne(pe);
2395 thisState->reindex();
2400 PeList *subListState2(
int state1,
int state2,
int nplanes,
int numChunks,
MapType4 *smap)
2403 thisState->TheList[0]=smap->get(0, state1, state2, 0);
2404 thisState->sortIdx[0]=0;
2405 for(
int plane=0; plane<nplanes; plane++)
2406 for(
int chunk=0; chunk<numChunks; chunk++)
2408 int pe = smap->get(plane, state1, state2, chunk);
2409 thisState->mergeOne(pe);
2411 thisState->reindex();
2418 void RhoRSMapTable::sortByCentroid(
PeList *avail,
int plane,
int nstates,
MapType2 *rsmap)
2420 int points=0, bestPe;
2421 if(config.torusMap==1) {
2422 int sumX=0, sumY=0, sumZ=0;
2423 for(
int state=0;state<nstates;state++)
2426 topoMgr->rankToCoordinates(rsmap->get(state, plane), X, Y, Z, T);
2432 int avgX=sumX/points;
2433 int avgY=sumY/points;
2434 int avgZ=sumZ/points;
2435 bestPe=topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
2436 avail->sortSource(bestPe);
2441 for(
int state=0;state<nstates;state++)
2443 sumPe+=rsmap->get(state,plane);
2446 bestPe=sumPe/points;
2447 avail->sortSource(bestPe);
2453 void SCalcMapTable::sortByCentroid(
PeList *avail,
int plane,
int stateX,
int stateY,
int grainsize,
MapType2 *gsmap)
2455 int points=0, bestPe;
2457 if(config.torusMap==1) {
2458 int sumX=0, sumY=0, sumZ=0;
2459 for(
int state=stateX;(state<stateX+grainsize)&&(state<config.nstates);state++)
2462 topoMgr->rankToCoordinates(gsmap->get(state, plane), X, Y, Z, T);
2468 for(
int state=stateY;(state<stateY+grainsize)&&(state<config.nstates);state++)
2471 topoMgr->rankToCoordinates(gsmap->get(state, plane), X, Y, Z, T);
2477 int avgX=sumX/points;
2478 int avgY=sumY/points;
2479 int avgZ=sumZ/points;
2480 bestPe=topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
2484 for(
int state=stateX;(state<stateX+grainsize)&&(state<config.nstates);state++)
2486 sumPe+=gsmap->get(state,plane);
2489 for(
int state=stateY;(state<stateY+grainsize)&&(state<config.nstates);state++)
2491 sumPe+=gsmap->get(state,plane);
2494 bestPe=sumPe/points;
2496 avail->sortSource(bestPe);
2502 void OrthoMapTable::sortByCentroid(
PeList *avail,
int nplanes,
int state1,
int state2,
int numChunks,
MapType4 *smap)
2504 int points=0, bestPe;
2505 if(config.torusMap==1) {
2506 int sumX = 0, sumY = 0, sumZ = 0;
2508 for(
int plane=0; plane<nplanes; plane++)
2509 for(
int chunk=0; chunk<numChunks; chunk++)
2512 topoMgr->rankToCoordinates(smap->get(plane, state1, state2, chunk), X, Y, Z, T);
2518 int avgX = sumX/points;
2519 int avgY = sumY/points;
2520 int avgZ = sumZ/points;
2521 bestPe = topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
2522 avail->sortSource(bestPe);
2527 for(
int plane=0; plane<nplanes; plane++)
2528 for(
int chunk=0; chunk<numChunks; chunk++)
2530 sumPe += smap->get(plane, state1, state2, chunk);
2533 bestPe = sumPe/points;
2534 avail->sortSource(bestPe);
2539 int OrthoMapTable::minDistCentroid(
PeList *avail,
int nplanes,
int state1,
int state2,
int numChunks,
MapType4 *smap)
2541 int points=0, bestPe;
2542 if(config.torusMap==1) {
2543 int sumX = 0, sumY = 0, sumZ = 0;
2545 for(
int plane=0; plane<nplanes; plane++)
2546 for(
int chunk=0; chunk<numChunks; chunk++)
2549 topoMgr->rankToCoordinates(smap->get(plane, state1, state2, chunk), X, Y, Z, T);
2555 int avgX = sumX/points;
2556 int avgY = sumY/points;
2557 int avgZ = sumZ/points;
2558 bestPe = topoMgr->coordinatesToRank(avgX, avgY, avgZ, 0);
2559 return(avail->
minDist(bestPe));
2563 for(
int plane=0; plane<nplanes; plane++)
2564 for(
int chunk=0; chunk<numChunks; chunk++)
2566 sumPe += smap->get(plane, state1, state2, chunk);
2569 bestPe = sumPe/points;
2570 return(avail->
minDist(bestPe));
PeList * rebuildExclusion(int *Pecount, int rsobjs_per_pe)
helper function
Author: Abhinav S Bhatele Date Created: December 28th, 2006.
GSMapTable(MapType2 *_frommap, MapType2 *_tomap, PeList *_availprocs, int _nchareG, int _nstates, int _Gstates_per_pe, bool useCuboidMap, int numInst, int offsetX, int offsetY, int offsetZ)
Author: Eric J Bohm Date Created: June 4th, 2006.
int minDist(int source)
return a processor at minumum distance from source
VdWGSMapTable(MapType2 *_map, PeList *_availprocs, int _nchareRhoG, int _nchareVdW, PeList *exclude)
VdWG and VdWR are mutually all to all.
Author: Eric J Bohm Date Created: June 4th, 2006.
RhoGSMapTable(MapType2 *_map, PeList *_availprocs, int _nchareRhoG, bool useCentroid, MapType2 *rhorsmap, PeList *exclude)
RhoG and RhoR are mutually all to all.
Author: Eric J Bohm Date Created: May 31, 2006.