diff options
author | tradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2001-10-03 23:28:01 +0000 |
---|---|---|
committer | tradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2001-10-03 23:28:01 +0000 |
commit | 21374b8c6a67f5d8ddf11a14a2353b7ee11c0054 (patch) | |
tree | c8f1aa49edbf8e5810fda9f3d8311bfe27a8b7d7 | |
parent | 5d7a705040cba7785c22ef037d0de4a8bf4589fe (diff) |
Bugfix for setting up ghostsizes for variables of dimensions greater than 3.
Completed grdoc.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@350 b61c5cb5-eaca-4651-9a7a-d64986f99364
-rw-r--r-- | src/GHExtension.c | 551 |
1 files changed, 294 insertions, 257 deletions
diff --git a/src/GHExtension.c b/src/GHExtension.c index 27e4a01..e427de2 100644 --- a/src/GHExtension.c +++ b/src/GHExtension.c @@ -3,14 +3,13 @@ @date Thu Feb 4 10:47:14 1999 @author Tom Goodale @desc - Pugh GH extension stuff. + Pugh GH extension stuff. @enddesc - @version $Header$ + @version $Id$ @@*/ -/*#define DEBUG_PUGH*/ +/* #define DEBUG_PUGH 1 */ -#include <stdio.h> #include <stdlib.h> #include "cctk.h" @@ -21,7 +20,6 @@ #include "pugh_extension.h" - static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusPUGH_pugh_GHExtension_c) @@ -36,80 +34,89 @@ int PUGH_PrintTimingInfo (cGH *GH); @date Wed Feb 3 23:10:19 1999 @author Tom Goodale @desc - + Sets up a new PUGH GH extension structure. @enddesc - @calls - @calledby - @history - - @endhistory - + @calls PUGH_GFSize + PUGH_GFGhostsize + PUGH_GFPeriodic + PUGH_SetupPGH + CCTK_GroupData + CCTK_GroupSizesI + CCTK_GroupGhostsizesI + PUGH_SetupGroup + @var config + @vdesc pointer to flesh configuration structure + @vtype tFleshConfig * + @vio not used + @endvar + @var convergence_level + @vdesc convergence level of this GH + @vtype int + @vio not used + @endvar + @var GH + @vdesc pointer to CCTK grid hierarchy + @vtype cGH * + @vio out + @endvar + + @returntype void * + @returndesc + pointer to new PUGH GH extension, or NULL in case of errors. + @endreturndesc @@*/ -void *PUGH_SetupGH(tFleshConfig *config, - int convergence_level, - cGH *GH) +void *PUGH_SetupGH (tFleshConfig *config, + int convergence_level, + cGH *GH) { - DECLARE_CCTK_PARAMETERS - - int group; - int dim; - int *nsize; - int *ghostsize; - int *perme; - int *groupghostsize; - int *groupsize; + int i, group, maxdim; + pGH *newGH; cGroup pgroup; - pGH *newGH; + CCTK_INT **size; + int *nsize, *ghostsize, *perme, *groupghostsize, *groupsize; + DECLARE_CCTK_PARAMETERS - /* shut up compiler warning about unused parameters */ + /* avoid compiler warnings about unused parameters */ config = config; convergence_level = convergence_level; /* Set up the GH */ - dim = CCTK_MaxDim(); - - nsize = (int *)malloc(dim*sizeof(int)); - PUGH_GFSize(dim,nsize); + maxdim = CCTK_MaxDim (); - ghostsize = (int *)malloc(dim*sizeof(int)); - PUGH_GFGhostsize(dim,ghostsize); + nsize = (int *) malloc (5 * maxdim * sizeof (int)); + ghostsize = nsize + 1*maxdim; + perme = nsize + 2*maxdim; - perme = (int *)malloc(dim*sizeof(int)); - PUGH_GFPeriodic(dim,perme); + PUGH_GFSize (maxdim, nsize); + PUGH_GFGhostsize (maxdim, ghostsize); + PUGH_GFPeriodic (maxdim, perme); - newGH = PUGH_SetupPGH(GH, - dim, - nsize, - ghostsize, - CCTK_StaggerVars() ? PUGH_STAGGER : PUGH_NO_STAGGER, - perme); - if (!newGH) + newGH = PUGH_SetupPGH (GH, maxdim, nsize, ghostsize, + CCTK_StaggerVars() ? PUGH_STAGGER : PUGH_NO_STAGGER, + perme); + if (!newGH) { - CCTK_WARN(0,"Failed to allocate memory for a pGH"); + CCTK_WARN (0, "Failed to allocate memory for a pGH"); } /* Set the identity for this pGH. For now this is an empty string. */ newGH->identity_string = (char *) calloc (1, sizeof (char)); /* Set up groups on the GH */ - - for (group = 0; group < CCTK_NumGroups(); group++) + for (group = 0; group < CCTK_NumGroups (); group++) { - CCTK_INT **size; - int i; - - CCTK_GroupData(group,&pgroup); + CCTK_GroupData (group, &pgroup); + groupsize = nsize + 3*maxdim; + groupghostsize = nsize + 4*maxdim; /* Set the global size of the variables in the group */ - size=CCTK_GroupSizesI(group); - + size = CCTK_GroupSizesI (group); if (size) { - groupsize = (int *)malloc(pgroup.dim*sizeof(int)); - for (i=0;i<pgroup.dim;i++) + for (i = 0; i < pgroup.dim; i++) { - groupsize[i]=*size[i]; + groupsize[i] = *size[i]; /* Check distribution type */ if (pgroup.disttype == CCTK_DISTRIB_CONSTANT) { @@ -123,50 +130,32 @@ void *PUGH_SetupGH(tFleshConfig *config, } /* Set the ghostzone size of the variables in the group */ - size=CCTK_GroupGhostsizesI(group); - + size = CCTK_GroupGhostsizesI (group); if (size) { - groupghostsize = (int *)malloc(pgroup.dim*sizeof(int)); - for (i=0;i<pgroup.dim;i++) + for (i = 0; i < pgroup.dim; i++) { - groupghostsize[i]=*size[i]; + groupghostsize[i] = *size[i]; } } else if (pgroup.grouptype == CCTK_ARRAY) { - groupghostsize = (int *)malloc(pgroup.dim*sizeof(int)); - for (i=0;i<pgroup.dim;i++) - { - groupghostsize[i]=0; - } + memset (groupghostsize, 0, pgroup.dim * sizeof (int)); } else { groupghostsize = NULL; } - PUGH_SetupGroup(newGH, - groupsize, - groupghostsize, - pgroup.grouptype, - pgroup.vartype, - pgroup.dim, - pgroup.numvars, - pgroup.stagtype, - pgroup.numtimelevels); - - if (groupsize) free(groupsize); - if (groupghostsize) free(groupghostsize); - + PUGH_SetupGroup (newGH, groupsize, groupghostsize, pgroup.grouptype, + pgroup.vartype, pgroup.dim, pgroup.numvars, + pgroup.stagtype, pgroup.numtimelevels); } - free(nsize); - free(ghostsize); - free(perme); - - return newGH; + /* clean up */ + free (nsize); + return (newGH); } @@ -175,47 +164,52 @@ void *PUGH_SetupGH(tFleshConfig *config, @date Thu May 11 2000 @author Thomas Radke @desc - Initializes the basic fields of a cGH structure + Initializes the basic fields of a cGH structure. @enddesc - @calls - @calledby - @history - - @endhistory - + @var GH + @vdesc pointer to CCTK grid hierarchy + @vtype cGH * + @vio out + @endvar @@*/ static void PUGH_InitGHBasics (cGH *GH) { - int idir; - int istag; + int dim, stagger; pGH *mypGH; pGExtras *GFExtras; - mypGH = PUGH_pGH(GH); - if(GH->cctk_dim > 0) + mypGH = PUGH_pGH (GH); + + if (GH->cctk_dim > 0) + { + GFExtras = mypGH->GFExtras[GH->cctk_dim - 1]; + } + else { - GFExtras = mypGH->GFExtras[GH->cctk_dim-1]; + GFExtras = NULL; } GH->cctk_convlevel = 0; - for (idir=0;idir<GH->cctk_dim;idir++) + for (dim = 0; dim < GH->cctk_dim; dim++) { - GH->cctk_levfac[idir] = 1; - GH->cctk_nghostzones[idir] = GFExtras->nghostzones[idir]; - GH->cctk_lsh[idir] = GFExtras->lnsize[idir]; - GH->cctk_gsh[idir] = GFExtras->nsize[idir]; - GH->cctk_bbox[2*idir] = GFExtras->bbox[2*idir]; - GH->cctk_bbox[2*idir+1] = GFExtras->bbox[2*idir+1]; - GH->cctk_lbnd[idir] = GFExtras->lb[mypGH->myproc][idir]; - GH->cctk_ubnd[idir] = GFExtras->ub[mypGH->myproc][idir]; + GH->cctk_levfac[dim] = 1; + GH->cctk_nghostzones[dim] = GFExtras->nghostzones[dim]; + GH->cctk_lsh[dim] = GFExtras->lnsize[dim]; + GH->cctk_gsh[dim] = GFExtras->nsize[dim]; + GH->cctk_bbox[2*dim] = GFExtras->bbox[2*dim]; + GH->cctk_bbox[2*dim+1] = GFExtras->bbox[2*dim+1]; + GH->cctk_lbnd[dim] = GFExtras->lb[mypGH->myproc][dim]; + GH->cctk_ubnd[dim] = GFExtras->ub[mypGH->myproc][dim]; - for (istag=0;istag<CCTK_NSTAGGER;istag++) + for (stagger = 0; stagger < CCTK_NSTAGGER; stagger++) { - GH->cctk_lssh[CCTK_LSSH_IDX(istag,idir)] = GH->cctk_lsh[idir]; - if ((GH->cctk_bbox[2*idir+1]==1) && (istag>0)) - GH->cctk_lssh[CCTK_LSSH_IDX(istag,idir)]--; + GH->cctk_lssh[CCTK_LSSH_IDX (stagger, dim)] = GH->cctk_lsh[dim]; + if (GH->cctk_bbox[2*dim + 1] == 1 && stagger > 0) + { + GH->cctk_lssh[CCTK_LSSH_IDX (stagger, dim)]--; + } } } } @@ -226,82 +220,87 @@ static void PUGH_InitGHBasics (cGH *GH) @date Thu May 11 2000 @author Thomas Radke @desc - Initializes the variables of a cGH structure + Initializes the variables of a cGH structure. @enddesc - @calls - @calledby - @history - - @endhistory - + @calls CCTK_GroupTypeFromVarI + CCTK_NumTimeLevelsFromVarI + @var GH + @vdesc pointer to CCTK grid hierarchy + @vtype cGH * + @vio out + @endvar @@*/ static void PUGH_InitGHVariables (cGH *GH) { - int var; - int gtype; - int ntimelevels; - int level; + int var, gtype, level, ntimelevels; pGH *mypGH; - mypGH = PUGH_pGH(GH); + mypGH = PUGH_pGH (GH); - for(var = 0; var < mypGH->nvariables; var++) + for (var = 0; var < mypGH->nvariables; var++) { - gtype = CCTK_GroupTypeFromVarI(var); - ntimelevels = CCTK_NumTimeLevelsFromVarI(var); + gtype = CCTK_GroupTypeFromVarI (var); + ntimelevels = CCTK_NumTimeLevelsFromVarI (var); - for(level = 0; level < ntimelevels; level++) + for (level = 0; level < ntimelevels; level++) { - switch(gtype) + switch (gtype) { - case CCTK_SCALAR : + case CCTK_SCALAR: GH->data[var][level] = mypGH->variables[var][level]; break; - case CCTK_GF : - case CCTK_ARRAY : - GH->data[var][level] = - ((pGA ***)(mypGH->variables))[var][level]->data; + case CCTK_GF: + case CCTK_ARRAY: + GH->data[var][level] = ((pGA *) mypGH->variables[var][level])->data; break; default: - CCTK_WARN(1,"PUGH_InitGHVariables: Unknown group type in PUGH_InitGHVariables"); + CCTK_WARN (1, "PUGH_InitGHVariables: Unknown group type"); } } } } + /*@@ @routine PUGH_InitGH @date Wed Feb 3 23:10:19 1999 @author Tom Goodale @desc - + Initialization routine for a given GH structure. @enddesc - @calls - @calledby - @history - - @endhistory - + @calls CCTK_NumGroups + CCTK_GroupName + CCTK_EnableGroupStorage + @var GH + @vdesc pointer to CCTK grid hierarchy + @vtype cGH * + @vio out + @endvar + + @returntype void * + @returndesc + always returns 0 + @endreturndesc @@*/ -int PUGH_InitGH(cGH *GH) +int PUGH_InitGH (cGH *GH) { + int i; DECLARE_CCTK_PARAMETERS - int i; PUGH_InitGHBasics (GH); /* Enable storage for all variables if required */ if (enable_all_storage) { - for (i=0;i<CCTK_NumGroups();i++) - { - CCTK_EnableGroupStorage(GH,CCTK_GroupName(i)); + for (i = 0; i < CCTK_NumGroups (); i++) + { + CCTK_EnableGroupStorage (GH, CCTK_GroupName (i)); } } - return 0; + return (0); } @@ -310,167 +309,205 @@ int PUGH_InitGH(cGH *GH) @date Thu Jan 27 15:14:09 2000 @author Tom Goodale @desc - Fills out the cGH and then calls schedule traverse. + Fills out the cGH and then calls schedule traverse. @enddesc @calls - @calledby @history - @hdate Thu Jan 27 15:15:35 2000 @hauthor Tom Goodale - @hdesc Was originally PUGH_rfrTraverse - @hdate Thu May 11 2000 @hauthor Thomas Radke - @hdesc Splitted pGH setup into PUGH_InitGHBasics() and PUGH_InitGHVariables() + @hdate Thu Jan 27 15:15:35 2000 + @hauthor Tom Goodale + @hdesc Was originally PUGH_rfrTraverse + @hdate Thu May 11 2000 + @hauthor Thomas Radke + @hdesc Splitted pGH setup into PUGH_InitGHBasics() and + PUGH_InitGHVariables() @endhistory + @var GH + @vdesc pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar + @var where + @vdesc name of this scheduling bin + @vtype const char * + @vio in + @endvar + + @returntype void * + @returndesc + return code of @seeroutine CCTK_ScheduleTraverse + @endreturndesc @@*/ -int PUGH_ScheduleTraverseGH(cGH *GH, - const char *where) +int PUGH_ScheduleTraverseGH (cGH *GH, + const char *where) { - if (strcmp ("CCTK_SHUTDOWN", where) != 0) + int retval; + + + if (strcmp ("CCTK_SHUTDOWN", where)) { PUGH_InitGHBasics (GH); PUGH_InitGHVariables (GH); } - return CCTK_ScheduleTraverse(where, GH, NULL); + retval = CCTK_ScheduleTraverse (where, GH, NULL); + + return (retval); } -int PUGH_GFSize(int dim, int *nsize) + + /*@@ + @routine PUGH_GFSize + @date Wed Feb 3 23:10:19 1999 + @author Tom Goodale + @desc + Gets the size of a grid function of a given dimension. + FIXME: This cannot be made static' because it is used by + thorn BAM_Elliptic. + @enddesc + @var dim + @vdesc dimension of the grid function + @vtype int + @vio in + @endvar + @var nsize + @vdesc size in every direction + @vtype int * + @vio out + @endvar +@@*/ +/* static */ void PUGH_GFSize (int dim, int *nsize) { + int dir, size; DECLARE_CCTK_PARAMETERS - int dir; - if (global_nsize > 0) + if (global_nsize > 0 || local_nsize > 0) { - for (dir=0;dir<dim;dir++) + size = global_nsize > 0 ? global_nsize : -local_nsize; + for (dir = 0; dir < dim; dir++) { - nsize[dir] = global_nsize; + nsize[dir] = size; } } else { - if (local_nsize > 0) - { - for (dir=0;dir<dim;dir++) - { - nsize[dir] = -local_nsize; - } - } - else + switch (dim) { - if (dim>0) - { - if (local_nx > 0) - { - nsize[0] = -local_nx; - } - else - { - nsize[0] = global_nx; - } - } - - if (dim>1) - { - if (local_ny > 0) - { - nsize[1] = -local_ny; - } - else - { - nsize[1] = global_ny; - } - } - - if (dim>2) - { - if (local_nz > 0) - { - nsize[2] = -local_nz; - } - else - { - nsize[2] = global_nz; - } - } + case 3: nsize[2] = local_nz > 0 ? -local_nz : global_nz; + case 2: nsize[1] = local_ny > 0 ? -local_ny : global_ny; + case 1: nsize[0] = local_nx > 0 ? -local_nx : global_nx; } } - - return 0; } -int PUGH_GFGhostsize(int dim, int *ghostsize) -{ + /*@@ + @routine PUGH_GFGhostsize + @date Wed Feb 3 23:10:19 1999 + @author Tom Goodale + @desc + Gets the ghostsize of a grid function of a given dimension. + FIXME: This cannot be made static' because it is used by + thorn BAM_Elliptic. + @enddesc + @var dim + @vdesc dimension of the grid function + @vtype int + @vio in + @endvar + @var ghostsize + @vdesc ghostsize in every direction + @vtype int * + @vio out + @endvar +@@*/ +/* static */ void PUGH_GFGhostsize (int dim, int *ghostsize) +{ + int dir; DECLARE_CCTK_PARAMETERS - int dir; - if (ghost_size>-1) + if (ghost_size >= 0) { - for (dir=0;dir<dim;dir++) + for (dir = 0; dir < dim; dir++) { ghostsize[dir] = ghost_size; } } else { - switch(dim) + memset (ghostsize, 0, dim); + switch (dim) { - case 3: - ghostsize[2] = ghost_size_z; - case 2: - ghostsize[1] = ghost_size_y; - case 1: - ghostsize[0] = ghost_size_x; - default: - ; + case 3: ghostsize[2] = ghost_size_z; + case 2: ghostsize[1] = ghost_size_y; + case 1: ghostsize[0] = ghost_size_x; } } - - return 0; } -int PUGH_GFPeriodic(int dim, int *perme) + /*@@ + @routine PUGH_GFPeriodic + @date Wed Feb 3 23:10:19 1999 + @author Tom Goodale + @desc + Gets the periodic BC of a grid function of a given dimension. + FIXME: This cannot be made static' because it is used by + thorn BAM_Elliptic. + @enddesc + @var dim + @vdesc dimension of the grid function + @vtype int + @vio in + @endvar + @var perme + @vdesc periodicity in every direction + @vtype int * + @vio out + @endvar +@@*/ +/* static */ void PUGH_GFPeriodic (int dim, int *perme) { - DECLARE_CCTK_PARAMETERS + if (periodic) { - switch(dim) + switch (dim) { - case 3: - perme[2] = periodic_z; - case 2: - perme[1] = periodic_y; - case 1: - perme[0] = periodic_x; - default: - ; + case 3: perme[2] = periodic_z; + case 2: perme[1] = periodic_y; + case 1: perme[0] = periodic_x; } } else { - switch(dim) - { - case 3: - perme[2] = 0; - case 2: - perme[1] = 0; - case 1: - perme[0] = 0; - default: - ; - } + memset (perme, 0, dim * sizeof (int)); } - - return 0; } -int PUGH_PrintTimingInfo(cGH *GH) + /*@@ + @routine PUGH_PrintTimingInfo + @date Wed Feb 3 23:10:19 1999 + @author Tom Goodale + @desc + Prints the info from PUGH communication timers to stdout. + @enddesc + @var GH + @vdesc pointer to CCTK grid hierarchy + @vtype cGH * + @vio out + @endvar + + @returntype int + @returndesc + always returns 0 + @endreturndesc +@@*/ +int PUGH_PrintTimingInfo (cGH *GH) { int i; cTimerData *info; @@ -482,43 +519,43 @@ int PUGH_PrintTimingInfo(cGH *GH) return 0; } - info = CCTK_TimerCreateData(); + info = CCTK_TimerCreateData (); if (info) { - CCTK_INFO("Elapsed time spent in communication:"); - CCTK_TimerI(pughGH->comm_time, info); + CCTK_INFO ("Elapsed time spent in communication:"); + CCTK_TimerI (pughGH->comm_time, info); for (i = 0; i < info->n_vals; i++) { switch (info->vals[i].type) { case val_int: - CCTK_VInfo(CCTK_THORNSTRING, " %s: %d %s", info->vals[i].heading, - info->vals[i].val.i, info->vals[i].units); + CCTK_VInfo (CCTK_THORNSTRING, " %s: %d %s", info->vals[i].heading, + info->vals[i].val.i, info->vals[i].units); break; case val_long: - CCTK_VInfo(CCTK_THORNSTRING, " %s: %d %s", info->vals[i].heading, - (int) info->vals[i].val.l, info->vals[i].units); + CCTK_VInfo (CCTK_THORNSTRING, " %s: %d %s", info->vals[i].heading, + (int) info->vals[i].val.l, info->vals[i].units); break; case val_double: - CCTK_VInfo(CCTK_THORNSTRING, " %s: %.3f %s", info->vals[i].heading, - info->vals[i].val.d, info->vals[i].units); + CCTK_VInfo (CCTK_THORNSTRING, " %s: %.3f %s", info->vals[i].heading, + info->vals[i].val.d, info->vals[i].units); break; default: - CCTK_WARN(1, "Unknown data type for timer info"); + CCTK_WARN (1, "Unknown data type for timer info"); break; } } - CCTK_TimerDestroyData(info); + CCTK_TimerDestroyData (info); } else { - CCTK_WARN(1, "Couldn't create timer info structure ! " - "No timing output available."); + CCTK_WARN (1, "Couldn't create timer info structure ! " + "No timing output available."); } - return 0; + return (0); } |