diff options
Diffstat (limited to 'src/SetupPGV.c')
-rw-r--r-- | src/SetupPGV.c | 227 |
1 files changed, 70 insertions, 157 deletions
diff --git a/src/SetupPGV.c b/src/SetupPGV.c index 2375f2d..0828aa7 100644 --- a/src/SetupPGV.c +++ b/src/SetupPGV.c @@ -8,7 +8,7 @@ @version $Header$ @@*/ -/*#define DEBUG_PUGH*/ +/* #define DEBUG_PUGH 1 */ #include <stdio.h> #include <stdlib.h> @@ -43,10 +43,8 @@ static int PUGH_SetupPGExtrasOwnership(int dim, int nprocs, int **neighbours, pGExtras *this); -static int PUGH_SetupPGExtrasStaggering(int dim, int this_proc, pGExtras *this); static int PUGH_SetupBoundingBox(int is_gf, int dim, - int stagger, int *nghosts, int total_procs, int *nprocs, @@ -54,7 +52,6 @@ static int PUGH_SetupBoundingBox(int is_gf, static int PUGH_SetupRemoteSizes(int dim, int total_procs, pGExtras *this); static int PUGH_SetupPGExtrasSizes(int is_gf, int dim, - int stagger, int *sh, int *nghosts, int total_procs, @@ -87,7 +84,6 @@ static int PUGH_DecomposeIJK(int dim, int ijk, int *nprocs, int *pos); pGExtras *PUGH_SetupPGExtras(int is_gf, int dim, int *perme, - int stagger, int *sh, int *nghosts, int total_procs, @@ -106,11 +102,10 @@ pGExtras *PUGH_SetupPGExtras(int is_gf, { this->dim = dim; - PUGH_SetupPGExtrasSizes(is_gf, dim, stagger, sh, nghosts, + PUGH_SetupPGExtrasSizes(is_gf, dim, sh, nghosts, total_procs, nprocs, this_proc,this); PUGH_SetupPGExtrasOwnership(dim, perme, this_proc, total_procs, neighbours, this); - PUGH_SetupPGExtrasStaggering(dim, this_proc, this); } } @@ -129,21 +124,18 @@ void PUGH_DestroyPGExtras(pGExtras **PGExtras) { if(PGExtras && *PGExtras) { - int i, j; + int j; - for(i = 0 ; i < PUGH_NSTAGGER; i++) + for(j = 0; j < 2; j++) { - for(j = 0; j < 2; j++) + if((*PGExtras)->dim > 0) { - if((*PGExtras)->dim > 0) - { - free((*PGExtras)->ghosts[i][j][0]); - free((*PGExtras)->overlap[i][j][0]); - } - free((*PGExtras)->ownership[i][j]); - free((*PGExtras)->ghosts[i][j]); - free((*PGExtras)->overlap[i][j]); + free((*PGExtras)->ghosts[j][0]); + free((*PGExtras)->overlap[j][0]); } + free((*PGExtras)->ownership[j]); + free((*PGExtras)->ghosts[j]); + free((*PGExtras)->overlap[j]); } free((*PGExtras)->lb[0]); free((*PGExtras)->ub[0]); @@ -457,7 +449,7 @@ static int PUGH_ComposeIJK(int dim, int *nprocs, int *pos) static int PUGH_SetupPGExtrasMemory(int dim, int total_procs, pGExtras *this) { int retcode; - int i,j,k; + int j,k; retcode = 0; @@ -503,6 +495,7 @@ static int PUGH_SetupPGExtrasMemory(int dim, int total_procs, pGExtras *this) this->ub[0] && this->rnsize[0]) { + int i; for (i = 1; i < total_procs; i++) { this->lb[i] = this->lb[0] + i*dim; @@ -581,53 +574,50 @@ static int PUGH_SetupPGExtrasMemory(int dim, int total_procs, pGExtras *this) (dim == 0 || this->hyper_volume)) { retcode = 0; - for (i = 0 ; i < PUGH_NSTAGGER; i++) + for (j = 0; j < 2; j++) { - for (j = 0; j < 2; j++) + this->ownership[j] = malloc(dim*sizeof(int)); + this->ghosts[j] = malloc(2*dim*sizeof(int *)); + this->overlap[j] = malloc(2*dim*sizeof(int *)); + if(dim > 0) { - this->ownership[i][j] = malloc(dim*sizeof(int)); - this->ghosts[i][j] = malloc(2*dim*sizeof(int *)); - this->overlap[i][j] = malloc(2*dim*sizeof(int *)); - if(dim > 0) + if(this->ghosts[j] && + this->overlap[j]) { - if(this->ghosts[i][j] && - this->overlap[i][j]) + this->ghosts[j][0] = malloc(2*dim*dim*sizeof(int)); + this->overlap[j][0] = malloc(2*dim*dim*sizeof(int)); + for (k=1; k < 2*dim; k++) { - this->ghosts[i][j][0] = malloc(2*dim*dim*sizeof(int)); - this->overlap[i][j][0] = malloc(2*dim*dim*sizeof(int)); - for (k=1; k < 2*dim; k++) - { - this->ghosts[i][j][k] = this->ghosts[i][j][0] + k*dim; - this->overlap[i][j][k] = this->overlap[i][j][0] + k*dim; - } + this->ghosts[j][k] = this->ghosts[j][0] + k*dim; + this->overlap[j][k] = this->overlap[j][0] + k*dim; } - else - { - free(this->ownership[i][j]); - this->ownership[i][j] = NULL; + } + else + { + free(this->ownership[j]); + this->ownership[j] = NULL; - free(this->ghosts[i][j]); - this->ghosts[i][j] = NULL; + free(this->ghosts[j]); + this->ghosts[j] = NULL; - free(this->overlap[i][j]); - this->overlap[i][j] = NULL; - retcode = 1; - break; - } + free(this->overlap[j]); + this->overlap[j] = NULL; + retcode = 1; + break; } } if(retcode) { for(j=1; j >=0 ; j--) { - free(this->ownership[i][j]); - this->ownership[i][j] = NULL; + free(this->ownership[j]); + this->ownership[j] = NULL; - free(this->ghosts[i][j]); - this->ghosts[i][j] = NULL; + free(this->ghosts[j]); + this->ghosts[j] = NULL; - free(this->overlap[i][j]); - this->overlap[i][j] = NULL; + free(this->overlap[j]); + this->overlap[j] = NULL; } break; } @@ -635,31 +625,28 @@ static int PUGH_SetupPGExtrasMemory(int dim, int total_procs, pGExtras *this) if(retcode) { /* Loop back through the arrays freeing things */ - for(i--; i >=0; i--) + for(j=1; j >=0 ; j--) { - for(j=1; j >=0 ; j--) + if(dim > 0) { - if(dim > 0) - { - free(this->ghosts[i][j][0]); - free(this->overlap[i][j][0]); - } + free(this->ghosts[j][0]); + free(this->overlap[j][0]); + } - free(this->ownership[i][j]); - this->ownership[i][j] = NULL; + free(this->ownership[j]); + this->ownership[j] = NULL; - free(this->ghosts[i][j]); - this->ghosts[i][j] = NULL; + free(this->ghosts[j]); + this->ghosts[j] = NULL; - free(this->overlap[i][j]); - this->overlap[i][j] = NULL; - } - - free(this->ownership[i]); - free(this->ghosts[i]); - free(this->overlap[i]); + free(this->overlap[j]); + this->overlap[j] = NULL; } + free(this->ownership); + free(this->ghosts); + free(this->overlap); + /* Free the stuff originally allocated */ free(this->lb[0]); @@ -711,7 +698,6 @@ static int PUGH_SetupPGExtrasMemory(int dim, int total_procs, pGExtras *this) @@*/ static int PUGH_SetupPGExtrasSizes(int is_gf, int dim, - int stagger, int *sh, int *nghosts, int total_procs, @@ -739,11 +725,6 @@ static int PUGH_SetupPGExtrasSizes(int is_gf, { this->nsize[dir] = nprocs[dir] * (-sh[dir]); } - - if (stagger == PUGH_STAGGER) - { - this->nsize[dir] -= nprocs[dir]-1; - } } else { @@ -758,7 +739,7 @@ static int PUGH_SetupPGExtrasSizes(int is_gf, } /* Setup the bounding box stuff */ - PUGH_SetupBoundingBox(is_gf, dim, stagger, nghosts, total_procs, nprocs,this); + PUGH_SetupBoundingBox(is_gf, dim, nghosts, total_procs, nprocs,this); /* Set the remote sizes */ PUGH_SetupRemoteSizes(dim, total_procs, this); @@ -818,25 +799,24 @@ static int PUGH_SetupPGExtrasOwnership(int dim, /* Ownership is pretty easy. Remember ownership is indexed as - [stagger][ijk][min/max]. See pGF_Reduction for a use of this, + [ijk][min/max]. See pGF_Reduction for a use of this, among others. - Note: Ownership is same for staggered and non-staggered grids */ for (dir = 0 ; dir < dim; dir++) { /* Setup ownership and bbox using neighbours. */ if (neighbours[this_proc][2*dir] == -1 || neighbours[this_proc][2*dir+1] == -1) { - this->ownership[PUGH_VERTEXCTR][0][dir] = + this->ownership[0][dir] = (this->lb[this_proc][dir] == 0 ? 0 : this->nghostzones[dir]); - this->ownership[PUGH_VERTEXCTR][1][dir] = + this->ownership[1][dir] = (this->ub[this_proc][dir] == this->nsize[dir]-1 ? this->lnsize[dir] : this->lnsize[dir] - this->nghostzones[dir]); this->bbox[2*dir+0] = this->lb[this_proc][dir] == 0; this->bbox[2*dir+1] = this->ub[this_proc][dir] == this->nsize[dir]-1; } else { - this->ownership[PUGH_VERTEXCTR][0][dir] = this->nghostzones[dir]; - this->ownership[PUGH_VERTEXCTR][1][dir] = + this->ownership[0][dir] = this->nghostzones[dir]; + this->ownership[1][dir] = this->lnsize[dir] - this->nghostzones[dir]; this->bbox[2*dir+0] = 0; this->bbox[2*dir+1] = 0; @@ -849,8 +829,8 @@ static int PUGH_SetupPGExtrasOwnership(int dim, = (this->lb[this_proc][dir] == 0 && this->ub[this_proc][dir] == this->nsize[dir]-1); if (! is_single_proc_in_dim - && this->ownership[PUGH_VERTEXCTR][1][dir] - - this->ownership[PUGH_VERTEXCTR][0][dir] < this->nghostzones[dir]) + && this->ownership[1][dir] - + this->ownership[0][dir] < this->nghostzones[dir]) { CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, "Not enough interior grid points in dimension %d ! " @@ -869,8 +849,8 @@ static int PUGH_SetupPGExtrasOwnership(int dim, { if (this->nsize[dir] == 1) { - this->ownership[PUGH_VERTEXCTR][0][dir] = 0; - this->ownership[PUGH_VERTEXCTR][1][dir] = 1; + this->ownership[0][dir] = 0; + this->ownership[1][dir] = 1; } } @@ -904,8 +884,8 @@ static int PUGH_SetupPGExtrasOwnership(int dim, iend = tmp - this->nghostzones[idir]; } - this->overlap[PUGH_VERTEXCTR][0][dir][idir] = istart; - this->overlap[PUGH_VERTEXCTR][1][dir][idir] = iend; + this->overlap[0][dir][idir] = istart; + this->overlap[1][dir][idir] = iend; } } @@ -938,69 +918,14 @@ static int PUGH_SetupPGExtrasOwnership(int dim, iend = tmp; } - this->ghosts[PUGH_VERTEXCTR][0][dir][idir] = istart; - this->ghosts[PUGH_VERTEXCTR][1][dir][idir] = iend; + this->ghosts[0][dir][idir] = istart; + this->ghosts[1][dir][idir] = iend; } } return 0; } -static int PUGH_SetupPGExtrasStaggering(int dim, int this_proc, pGExtras *this) -{ - int s,d,k,dir; - int *upperbnd; - - upperbnd = malloc(dim*sizeof(int)); - - for (d=0;d<dim;d++) - { - upperbnd[d] = (this->ub[this_proc][d] == this->nsize[d]-1) ? 1 : 0; - } - - /* copy ownership/ghost/overlap from the default PUGH_VERTEXCTR */ - for(s=1;s<PUGH_NSTAGGER;s++) - { - for(d=0;d<dim;d++) - { - for(k=0;k<2;k++) - { - this->ownership[s][k][d] = this->ownership[0][k][d]; - for (dir=0;dir<2*dim;dir++) - { - this->overlap[s][k][dir][d] = this->overlap[0][k][dir][d]; - this->ghosts [s][k][dir][d] = this->ghosts [0][k][dir][d]; - } - } - - /* decrease ownership at upper bound */ - if(upperbnd[d]) - { - this->ownership[s][1][d] --; - } - } - - /* correct overlaps */ - for(dir=0;dir<2*dim;dir++) - { - for (d=0;d<dim;d++) - { - /* if we are at a upper physical bnd && at a upperface (1,3,5) - && we are in the dir direction decrease by one */ - if((upperbnd[d])&&((dir+1)%2==0)&&(dir==2*d+1)) - { - this->overlap[s][0][dir][d]--; - this->overlap[s][1][dir][d]--; - } - } - } - } - - free(upperbnd); - - return(0); -} - /*@@ @routine PUGH_SetupBoundingBox @date Mon Nov 8 09:03:40 1999 @@ -1011,7 +936,6 @@ static int PUGH_SetupPGExtrasStaggering(int dim, int this_proc, pGExtras *this) @@*/ static int PUGH_SetupBoundingBox(int is_gf, int dim, - int stagger, int *nghosts, int total_procs, int *nprocs, @@ -1051,10 +975,6 @@ static int PUGH_SetupBoundingBox(int is_gf, else { this->lb[pnum][dir] = bounds[dir][pos[dir]] +1 - nghosts[dir]; - if(stagger == PUGH_STAGGER) - { - this->lb[pnum][dir] --; - } } if (pos[dir] == nprocs[dir]-1) @@ -1300,12 +1220,10 @@ pGA *PUGH_SetupGArray(void *parent, int arrayid, int varsize, int vtype, - int staggercode, int vector_size, int vector_entry, pGA *vector_base) { - int dim; pGA *this; @@ -1319,11 +1237,6 @@ pGA *PUGH_SetupGArray(void *parent, this->parent = parent; this->varsize = varsize; this->vtype = vtype; - this->stagger = calloc (this->extras->dim, sizeof (int)); - for (dim = 0; dim < this->extras->dim; dim++) - { - this->stagger[dim] = CCTK_StaggerDirIndex (dim, staggercode); - } this->id = id; this->arrayid = arrayid; this->storage = PUGH_NOSTORAGE; |