aboutsummaryrefslogtreecommitdiff
path: root/src/SetupPGV.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/SetupPGV.c')
-rw-r--r--src/SetupPGV.c204
1 files changed, 109 insertions, 95 deletions
diff --git a/src/SetupPGV.c b/src/SetupPGV.c
index 5536c26..a1554a8 100644
--- a/src/SetupPGV.c
+++ b/src/SetupPGV.c
@@ -126,8 +126,11 @@ void PUGH_DestroyPGExtras(pGExtras **PGExtras)
{
for(j = 0; j < 2; j++)
{
- free((*PGExtras)->ghosts[i][j][0]);
- free((*PGExtras)->overlap[i][j][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]);
@@ -416,7 +419,7 @@ int PUGH_GenerateNeighbours(int dim,
pos = (int *)malloc(dim*sizeof(int));
- if(pos)
+ if(dim == 0 || pos)
{
for(i = 0; i < total_procs; i++)
{
@@ -559,11 +562,11 @@ int PUGH_ComposeIJK(int dim,
* e.g. i+nx*(j+ny*k)
*/
- ijk = pos[dim-1];
- for(idim = dim-2; idim >=0; idim--)
+ ijk = 0;
+ for(idim = dim-1; idim >=0; idim--)
{
ijk = pos[idim] + nprocs[idim]*ijk;
- };
+ }
return ijk;
}
@@ -618,59 +621,62 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->ub &&
this->rnsize &&
this->rnpoints &&
- this->nghostzones &&
- this->nsize &&
- this->lnsize &&
- this->bbox &&
- this->iterator &&
- this->hyper_volume)
+ (dim == 0 || this->nghostzones ) &&
+ (dim == 0 || this->nsize ) &&
+ (dim == 0 || this->lnsize ) &&
+ (dim == 0 || this->bbox ) &&
+ (dim == 0 || this->iterator ) &&
+ (dim == 0 || this->hyper_volume))
{
this->lb[0] = (int *)malloc(total_procs *dim*sizeof(int));
this->ub[0] = (int *)malloc(total_procs *dim*sizeof(int));
this->rnsize[0] = (int *)malloc(total_procs*2*dim*sizeof(int));
- if(this->lb[0] &&
- this->ub[0] &&
- this->rnsize[0])
+ if (dim > 0)
{
- for (i = 1; i < total_procs; i++)
+ if(this->lb[0] &&
+ this->ub[0] &&
+ this->rnsize[0])
{
- this->lb[i] = this->lb[0] + i*dim;
- this->ub[i] = this->ub[0] + i*dim;
- this->rnsize[i] = this->rnsize[0] + i*2*dim;
+ for (i = 1; i < total_procs; i++)
+ {
+ this->lb[i] = this->lb[0] + i*dim;
+ this->ub[i] = this->ub[0] + i*dim;
+ this->rnsize[i] = this->rnsize[0] + i*2*dim;
+ }
+ }
+ else
+ {
+ /* Free inner arrays */
+ free(this->lb[0]);
+ this->lb[0] = NULL;
+ free(this->ub[0]);
+ this->ub[0] = NULL;
+ free(this->rnsize[0]);
+ this->rnsize[0] = NULL;
+
+ /* Free toplevel arrays */
+ free(this->lb);
+ this->lb = NULL;
+ free(this->ub);
+ this->ub = NULL;
+ free(this->rnsize);
+ this->rnsize = NULL;
+ free(this->rnpoints);
+ this->rnpoints = NULL;
+ free(this->nghostzones);
+ this->nghostzones = NULL;
+ free(this->nsize);
+ this->nsize = NULL;
+ free(this->lnsize);
+ this->lnsize = NULL;
+ free(this->bbox);
+ this->bbox = NULL;
+ free(this->iterator);
+ this->iterator = NULL;
+ free(this->hyper_volume);
+ this->hyper_volume = NULL;
}
- }
- else
- {
- /* Free inner arrays */
- free(this->lb[0]);
- this->lb[0] = NULL;
- free(this->ub[0]);
- this->ub[0] = NULL;
- free(this->rnsize[0]);
- this->rnsize[0] = NULL;
-
- /* Free toplevel arrays */
- free(this->lb);
- this->lb = NULL;
- free(this->ub);
- this->ub = NULL;
- free(this->rnsize);
- this->rnsize = NULL;
- free(this->rnpoints);
- this->rnpoints = NULL;
- free(this->nghostzones);
- this->nghostzones = NULL;
- free(this->nsize);
- this->nsize = NULL;
- free(this->lnsize);
- this->lnsize = NULL;
- free(this->bbox);
- this->bbox = NULL;
- free(this->iterator);
- this->iterator = NULL;
- free(this->hyper_volume);
- this->hyper_volume = NULL;
}
}
else
@@ -697,18 +703,17 @@ int PUGH_SetupPGExtrasMemory(int dim,
free(this->hyper_volume);
this->hyper_volume = NULL;
}
-
-
+
if(this->lb &&
this->ub &&
this->rnsize &&
this->rnpoints &&
- this->nghostzones &&
- this->nsize &&
- this->lnsize &&
- this->bbox &&
- this->iterator &&
- this->hyper_volume)
+ (dim == 0 || this->nghostzones ) &&
+ (dim == 0 || this->nsize ) &&
+ (dim == 0 || this->lnsize ) &&
+ (dim == 0 || this->bbox ) &&
+ (dim == 0 || this->iterator ) &&
+ (dim == 0 || this->hyper_volume))
{
retcode = 0;
for (i = 0 ; i < PUGH_NSTAGGER; i++)
@@ -718,44 +723,46 @@ int PUGH_SetupPGExtrasMemory(int dim,
this->ownership[i][j] = (int *) malloc(dim*sizeof(int));
this->ghosts[i][j] = (int **)malloc(2*dim*sizeof(int *));
this->overlap[i][j] = (int **)malloc(2*dim*sizeof(int *));
- if(this->ghosts[i][j] &&
- this->overlap[i][j])
+ if(dim > 0)
{
- this->ghosts[i][j][0] = (int *)malloc(2*dim*dim*sizeof(int));
- this->overlap[i][j][0] = (int *)malloc(2*dim*dim*sizeof(int));
- for (k=1; k < 2*dim; k++)
+ if(this->ghosts[i][j] &&
+ this->overlap[i][j])
{
- 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[i][j][0] = (int *)malloc(2*dim*dim*sizeof(int));
+ this->overlap[i][j][0] = (int *)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;
+ }
+ }
+ else
+ {
+ free(this->ownership[i][j]);
+ this->ownership[i][j] = NULL;
+
+ free(this->ghosts[i][j]);
+ this->ghosts[i][j] = NULL;
+
+ free(this->overlap[i][j]);
+ this->overlap[i][j] = NULL;
+ retcode = 1;
+ break;
}
- }
- else
- {
- free(this->ownership[i][j]);
- this->ownership[i][j] = NULL;
-
- free(this->ghosts[i][j]);
- this->ghosts[i][j] = NULL;
-
- free(this->overlap[i][j]);
- this->overlap[i][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->ghosts[i][j]);
- this->ghosts[i][j] = NULL;
+ free(this->ownership[i][j]);
+ this->ownership[i][j] = NULL;
- free(this->overlap[i][j]);
- this->overlap[i][j] = NULL;
+ free(this->ghosts[i][j]);
+ this->ghosts[i][j] = NULL;
+ free(this->overlap[i][j]);
+ this->overlap[i][j] = NULL;
}
break;
}
@@ -767,8 +774,11 @@ int PUGH_SetupPGExtrasMemory(int dim,
{
for(j=1; j >=0 ; j--)
{
- free(this->ghosts[i][j][0]);
- free(this->overlap[i][j][0]);
+ if(dim > 0)
+ {
+ free(this->ghosts[i][j][0]);
+ free(this->overlap[i][j][0]);
+ }
free(this->ownership[i][j]);
this->ownership[i][j] = NULL;
@@ -813,9 +823,9 @@ int PUGH_SetupPGExtrasMemory(int dim,
free(this->iterator);
this->iterator = NULL;
free(this->hyper_volume);
- this->hyper_volume = NULL;
- }
- }
+ this->hyper_volume = NULL;
+ }
+ }
}
else
{
@@ -1169,7 +1179,7 @@ int PUGH_SetupBoundingBox(int dim,
bounds = (int **)malloc(dim*sizeof(int*));
pos = (int *)malloc(dim*sizeof(int));
- if(bounds && pos)
+ if(dim > 0 && bounds && pos)
{
/* Work out the bounds in each direction - either from parameters
file or default*/
@@ -1252,6 +1262,7 @@ int PUGH_SetupBoundingBox(int dim,
@endhistory
@@*/
+
int PUGH_SetupRemoteSizes(int dim,
int *perme,
int stagger,
@@ -1397,10 +1408,13 @@ pComm *PUGH_SetupGArrayGroupComm(pGH *pughGH,
*/
if(this)
{
- extras->hyper_volume[0] = 1;
- for (i = 1; i < extras->dim; i++)
+ if (extras->dim > 0)
{
- extras->hyper_volume[i] = extras->hyper_volume[i-1] * extras->lnsize[i-1];
+ extras->hyper_volume[0] = 1;
+ for (i = 1; i < extras->dim; i++)
+ {
+ extras->hyper_volume[i] = extras->hyper_volume[i-1] * extras->lnsize[i-1];
+ }
}
}