35 #include "main/groups.h"
37 #include "cp_state_plane/CP_State_Plane.h"
57 if( (idx < 0) || (idx >= nchareG) ){
58 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
59 CkPrintf(
"GSpace plane index %d out of range: 0 < idx > %d\n",idx,nchareG);
60 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
64 line_load[0] = lines_per_chareG[idx];
65 pt_load[0] = pts_per_chareG[idx];
79 if( (idx < 0) || (idx >= nchareG) ){
80 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
81 CkPrintf(
"GSpace plane index %d out of range: 0 < idx > %d\n",idx,nchareG);
82 CkPrintf(
"@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
86 line_load[0] = lines_per_chareG[idx];
87 pt_load[0] = pts_per_chareG[idx];
102 int basicMap(CkArrayIndex2D &idx2d,
int numPlanes) {
104 int pes_per_state = config.RpesPerState;
105 int np = CkNumPes()/pes_per_state;
110 int partition_nstates = config.nstates / np;
111 if(config.nstates % np != 0)
112 partition_nstates ++;
114 double total_planes = config.nstates * numPlanes;
115 double numPerProc = total_planes / CkNumPes();
118 int s = idx2d.index[0]%partition_nstates;
120 int pe = (int) floor((idx2d.index[1]*partition_nstates + s)/numPerProc);
122 pe = pe % pes_per_state;
123 pe += pes_per_state * (idx2d.index[0]/partition_nstates);
126 pe = pe % CkNumPes();
142 void GSMap::makemap(){
145 if(config.doublePack)
148 CkAbort(
"not doublepack broken!");
150 for(
int state = 0; state < config.nstates; state++){
151 for (
int plane = 0; plane < numChareG; plane++) {
152 CkArrayIndex2D idx2d(state,plane);
167 CkArrayIndex2D idx2d = *(CkArrayIndex2D *) &idx;
172 if(config.doublePack) {
175 CkAbort(
"not doublepack broken\n");
178 if(state_load <= 0.0 ) {
179 for(
int x = 0; x < numChareG; x++) {
180 double curload = 0.0;
185 state_load += curload;
189 int pes_per_state = config.GpesPerState;
190 int np = CkNumPes()/pes_per_state;
194 int partition_nstates = config.nstates / np;
195 if(config.nstates % np != 0){partition_nstates ++;}
197 int start_pe = (idx2d.index[0]/partition_nstates) * pes_per_state;
198 int start_state = (idx2d.index[0]/partition_nstates) * partition_nstates;
200 double cum_load = 0.0;
201 double average_load = state_load * config.nstates / CkNumPes();
203 for(
int x = 0; x < numChareG; x++) {
204 for(
int s = 0; s < partition_nstates; s++) {
205 double curload = 0.0;
212 if((idx2d.index[0] == s + start_state) && idx2d.index[1] == x) {
214 dpe = cum_load / average_load;
217 pe = pe % pes_per_state;
220 return (pe % CkNumPes());
224 return (idx2d.index[0]*1037+idx2d.index[1])%CkNumPes();
235 CkArrayIndex2D idx2d = *(CkArrayIndex2D *) &idx;
242 double total_planes = config.nstates * numPlanes;
243 double planes_per_proc = total_planes / CkNumPes();
254 inline double scalc_load(
int x,
int numplanes,
double *load) {
255 *load = numplanes * numplanes - x*x;
269 CkArrayIndex4D &idx4d = *(CkArrayIndex4D *)&idx;
271 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
273 int calcchunks=max_states/gs;
274 maptable=
new CkHashtableT<intdual,int> (nchareG*calcchunks*calcchunks);
278 return maptable->get(
intdual(intidx[0], intidx[1]));
285 void SCalcMap::makemap(){
289 for(
int numX = 0; numX < nchareG; numX++){
290 for (
int s1 = 0; s1 < max_states; s1 += gs) {
291 for (
int s2 = s1; s2 < max_states; s2 += gs) {
292 CkArrayIndex4D idx4d(numX,s1,s2,0);
294 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
295 maptable->put(
intdual(intidx[0],intidx[1]))=slowprocNum(0,idx4d);
302 for(
int numX = 0; numX < nchareG; numX++){
303 for (
int s1 = 0; s1 < max_states; s1 += gs) {
304 for (
int s2 = 0; s2 < max_states; s2 += gs) {
305 CkArrayIndex4D idx4d(numX,s1,s2,0);
307 CmiMemcpy(intidx,idx4d.index,2*
sizeof(
int));
308 maptable->put(
intdual(intidx[0],intidx[1]))=slowprocNum(0,idx4d);
319 int SCalcMap::slowprocNum2(
int hdl,
const CkArrayIndex4D &idx4d){
320 short *idx =
reinterpret_cast<short*
> ( idx4d.data() );
322 return cheesyhackgsprocNum(CPcharmParaInfo::get();, idx[2] + idx[3]/gs, idx[0]);
329 int SCalcMap::slowprocNum(int hdl, const CkArrayIndex4D &idx4d){
335 #if CMK_TRACE_ENABLED
336 double StartTime=CmiWallTimer();
338 //Here maxY is the max number of planes;
339 int planeid = idx4d.index[0];
342 if(config.doublePack){
343 numChareG = config.nchareG;
345 numChareG = max_planes/2;
349 double *load = new double[CkNumPes()];
350 memset(load, 0, CkNumPes() * sizeof(double));
354 if(totalload <= 0.0) {
355 for(w = 0; w < numChareG; w ++)
356 for(x = 0; x < max_states; x += gs) {
363 for(; y < max_states; y += gs) {
365 double curload = 0.0;
368 //scalc_load(w, numChareG, &curload);
369 GSpacePlaneLoad(w, &gload, &curload);
371 totalload += curload;
378 for(w = 0; w < numChareG; w ++) {
379 for(x = 0; x < max_states; x += gs){
386 for(; y < max_states; y += gs) {
387 double curload = 0.0;
390 //scalc_load(w, numChareG, &curload);
391 GSpacePlaneLoad(w, &gload, &curload);
393 curload /= totalload;
395 if(load[pe] + curload > 0.3/CkNumPes()){pe ++;}
397 if(pe >= CkNumPes()){pe = 0;}
401 if((w == idx4d.index[0]) && (x == idx4d.index[1]) &&
402 (y == idx4d.index[2])) {
403 #if CMK_TRACE_ENABLED
404 traceUserBracketEvent(Scalcmap_, StartTime, CmiWallTimer());
414 #if CMK_TRACE_ENABLED
415 traceUserBracketEvent(Scalcmap_, StartTime, CmiWallTimer());
419 return (idx4d.index[0]*197+idx4d.index[1]*23+idx4d.index[2]*7
420 +idx4d.index[3])%CkNumPes();
427 int SCalcMap::slowprocNum(
int hdl,
const CkArrayIndex4D &idx4d)
429 short *idx =
reinterpret_cast<short*
> ( idx4d.data() );
432 int planeid = idx[0];
436 if(config.doublePack){
437 numChareG = config.nchareG;
439 numChareG = max_planes/2;
443 double *load =
new double[CkNumPes()];
444 memset(load, 0, CkNumPes() *
sizeof(
double));
448 if(totalload <= 0.0) {
449 for(w = 0; w < numChareG; w ++)
450 for(x = 0; x < max_states; x += gs) {
456 for(; y < max_states; y += gs) {
458 double curload = 0.0;
464 totalload += curload;
471 for(w = 0; w < numChareG; w ++)
472 for(x = 0; x < max_states; x += gs) {
478 for(; y < max_states; y += gs) {
479 double curload = 0.0;
485 curload /= totalload;
487 if(load[pe] + curload > 0.3/CkNumPes())
495 if((w == idx[0]) && (x == idx[1]) && (y == idx[2])) {
507 return (idx[0]*197+idx[1]*23+idx[2]*7+idx[3])%CkNumPes();
int procNum(int, const CkArrayIndex &iIndex)
this one uses a lookup table built by calling the slow version
Add type declarations for simulationConstants class (readonly vars) and once class for each type of o...
int procNum(int, const CkArrayIndex &iIndex)
int GSMap::slowprocNum(int arrayHdl, const CkArrayIndex2D &idx2d)
Some basic data structures and the array map classes are defined here.
int procNum(int, const CkArrayIndex &iIndex)
Function for RealSpace objects.
void GSpacePlaneLoad(int, double *, double *)
void hackGSpacePlaneLoad(CPcharmParaInfo *sim,int idx, double *line_load, double *pt_load); ...
int basicMap(CkArrayIndex2D &idx2d, int numPlanes)
Void allocate each state to more than one processor.