diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/SetupGroup.c | 114 | ||||
-rw-r--r-- | src/Storage.c | 76 |
2 files changed, 96 insertions, 94 deletions
diff --git a/src/SetupGroup.c b/src/SetupGroup.c index 3cf4d57..e3fffc3 100644 --- a/src/SetupGroup.c +++ b/src/SetupGroup.c @@ -2,9 +2,9 @@ @file SetupGroup.c @date Mon Feb 8 19:31:45 1999 @author Tom Goodale - @desc + @desc Subroutines for setting up a group on a pGH. - @enddesc + @enddesc @version $Id$ @@*/ @@ -19,22 +19,22 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION (CactusPUGH_PUGH_SetupGroup_c) - + /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static int PUGH_SetupScalarGroup (pGH *newGH, +static int PUGH_SetupScalarGroup (pGH *newGH, int vtype, int n_variables, int n_timelevels); -static int PUGH_SetupGAGroup (pGH *newGH, - int *nsize, +static int PUGH_SetupGAGroup (pGH *newGH, + int *nsize, int *ghostsize, - int gtype, - int vtype, - int dim, - int n_variables, - int staggercode, + int gtype, + int vtype, + int dim, + int n_variables, + int staggercode, int n_timelevels); @@ -42,9 +42,14 @@ static int PUGH_SetupGAGroup (pGH *newGH, @routine PUGH_SetupScalarGroup @date Wed Feb 17 04:45:49 1999 @author Tom Goodale - @desc + @desc Set up a group of scalar variables on a pGH. - @enddesc + For efficiency reasons, PUGH allocates storage for scalars + only once when the group is created. + The current state of storage allocation (which is toggled by + Enable/DisableGroupStorage) is stored in a byte-sized flag + immediately after the scalar data. + @enddesc @var newGH @vdesc Pointer to PUGH grid hierarchy @@ -73,13 +78,13 @@ static int PUGH_SetupGAGroup (pGH *newGH, PUGH_ERRORMEMORY (negative) if memory allocation failed @endreturndesc @@*/ -static int PUGH_SetupScalarGroup (pGH *newGH, +static int PUGH_SetupScalarGroup (pGH *newGH, int vtype, int n_variables, int n_timelevels) { DECLARE_CCTK_PARAMETERS - int variable, retval; + int variable, level, vtypesize, retval; void *temp; @@ -90,18 +95,35 @@ static int PUGH_SetupScalarGroup (pGH *newGH, if (temp) { newGH->variables = (void ***) temp; + vtypesize = CCTK_VarTypeSize (vtype); - for (variable = 0; variable < n_variables; variable++) + for (variable = 0; variable < n_variables && retval == 0; variable++) { - temp = (void **) calloc (n_timelevels, sizeof (void *)); + temp = malloc (n_timelevels * sizeof (void *)); if (temp) { - newGH->variables[newGH->nvariables++] = (void **) temp; + newGH->variables[newGH->nvariables + variable] = (void **) temp; + for (level = 0; level < n_timelevels; level++) + { + /* allocate one more byte for the query_storage flag */ + temp = malloc (vtypesize + 1); + if (temp) + { + newGH->variables[newGH->nvariables + variable][level] = temp; + + /* reset the query_storage flag */ + ((char *) temp)[vtypesize] = PUGH_NOSTORAGE; + } + else + { + retval = PUGH_ERRORMEMORY; + break; + } + } } else { retval = PUGH_ERRORMEMORY; - break; } } } @@ -110,7 +132,11 @@ static int PUGH_SetupScalarGroup (pGH *newGH, retval = PUGH_ERRORMEMORY; } - if (retval) + if (! retval) + { + newGH->nvariables += n_variables; + } + else { CCTK_WARN (1, "Memory allocation error in PUGH_SetupScalarGroup"); } @@ -123,10 +149,10 @@ static int PUGH_SetupScalarGroup (pGH *newGH, @routine PUGH_SetupGAGroup @date January 19 2000 @author Gabrielle Allen - @desc + @desc Set up a group of grid array variables (CCTK_GF or CCTK_ARRAY types) on a pGH. - @enddesc + @enddesc @calls CCTK_VarTypeSize PUGH_SetupConnectivity PUGH_SetupPGExtras @@ -185,14 +211,14 @@ static int PUGH_SetupScalarGroup (pGH *newGH, PUGH_ERRORMEMORY (negative) if memory allocation failed @endreturndesc @@*/ -static int PUGH_SetupGAGroup (pGH *newGH, - int *nsize, +static int PUGH_SetupGAGroup (pGH *newGH, + int *nsize, int *ghostsize, - int gtype, - int vtype, - int dim, - int n_variables, - int staggercode, + int gtype, + int vtype, + int dim, + int n_variables, + int staggercode, int n_timelevels) { int i; @@ -235,7 +261,7 @@ static int PUGH_SetupGAGroup (pGH *newGH, connectivity = PUGH_SetupConnectivity (dim, newGH->nprocs, nprocs, perme); - extras = PUGH_SetupPGExtras (dim, + extras = PUGH_SetupPGExtras (dim, perme, staggercode, nsize, @@ -287,12 +313,12 @@ static int PUGH_SetupGAGroup (pGH *newGH, { for (level = 0; level < n_timelevels; level++) { - newGH->variables[newGH->nvariables][level] = + newGH->variables[newGH->nvariables][level] = PUGH_SetupGArray (newGH, extras, connectivity, groupcomm, - CCTK_VarName (newGH->nvariables), + CCTK_VarName (newGH->nvariables), newGH->nvariables, newGH->narrays, var_size, @@ -313,7 +339,7 @@ static int PUGH_SetupGAGroup (pGH *newGH, { retval = PUGH_ERRORMEMORY; } - + if (retval) { CCTK_WARN (1, "Memory allocation error in PUGH_SetupGAGroup"); @@ -327,9 +353,9 @@ static int PUGH_SetupGAGroup (pGH *newGH, @routine PUGH_SetupGroup @date Mon Feb 8 19:37:55 1999 @author Tom Goodale - @desc + @desc Sets up a group on a pGH - @enddesc + @enddesc @calls PUGH_SetupScalarGroup PUGH_SetupGAGroup @@ -386,14 +412,14 @@ static int PUGH_SetupGAGroup (pGH *newGH, PUGH_ERROR if invalid group type was passed in @endreturndesc @@*/ -int PUGH_SetupGroup (pGH *newGH, - int *nsize, +int PUGH_SetupGroup (pGH *newGH, + int *nsize, int *nghostsize, - int gtype, - int vtype, - int dim, - int n_variables, - int staggercode, + int gtype, + int vtype, + int dim, + int n_variables, + int staggercode, int n_timelevels) { int retval; @@ -401,12 +427,12 @@ int PUGH_SetupGroup (pGH *newGH, if (gtype == CCTK_SCALAR) { - retval = PUGH_SetupScalarGroup (newGH, vtype, n_variables, n_timelevels); + retval = PUGH_SetupScalarGroup (newGH, vtype, n_variables, n_timelevels); } else if (gtype == CCTK_ARRAY || gtype == CCTK_GF) { retval = PUGH_SetupGAGroup (newGH, nsize, nghostsize, gtype, vtype, dim, - n_variables, staggercode, n_timelevels); + n_variables, staggercode, n_timelevels); } else { diff --git a/src/Storage.c b/src/Storage.c index a8c8e3f..b6d312d 100644 --- a/src/Storage.c +++ b/src/Storage.c @@ -21,7 +21,7 @@ static const char *rcsid="$Header$"; CCTK_FILEVERSION(CactusPUGH_PUGH_Storage_c) -/*#define DEBUG_PUGH*/ +/* #define DEBUG_PUGH 1 */ /******************************************************************** @@ -60,7 +60,7 @@ static void PUGH_InitializeMemory (const char *initialize_memory, @calls CCTK_GroupIndex CCTK_FirstVarIndexI - + @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH * @@ -81,7 +81,7 @@ static void PUGH_InitializeMemory (const char *initialize_memory, @vtype const char * @vio in @endvar - + @returntype const int * @returndesc pointer to the size variable for the given direction, or @@ -160,7 +160,7 @@ const int *PUGH_ArrayGroupSize (cGH *GH, @calls CCTK_GroupIndex CCTK_FirstVarIndexI CCTK_GroupTypeI - + @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH * @@ -176,7 +176,7 @@ const int *PUGH_ArrayGroupSize (cGH *GH, @vtype const char * @vio in @endvar - + @returntype int @returndesc 1 if storage for this group is assigned @@ -209,15 +209,8 @@ int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname) grouptype = CCTK_GroupTypeI (group); if (grouptype == CCTK_SCALAR) { - if (pughGH->variables[first_var][0]) - { - vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var)); - storage = ((char *) pughGH->variables[first_var][0])[vtypesize]; - } - else - { - storage = -1; - } + vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var)); + storage = ((char *) pughGH->variables[first_var][0])[vtypesize]; } else if (grouptype == CCTK_GF || grouptype == CCTK_ARRAY) { @@ -274,7 +267,7 @@ int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname) CCTK_GroupData PUGH_EnableScalarGroupStorage PUGH_EnableGArrayGroupStorage - + @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH * @@ -393,7 +386,7 @@ int PUGH_EnableGroupStorage (cGH *GH, const char *groupname) CCTK_GroupData CCTK_FirstVarIndexI PUGH_DisableGArrayGroupStorage - + @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH * @@ -458,7 +451,7 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname) for (level = 0; level < pgroup.numtimelevels; level++) { temp = (char *) variables[var][level]; - if (temp && temp[vtypesize] == PUGH_STORAGE) + if (temp[vtypesize] == PUGH_STORAGE) { temp[vtypesize] = PUGH_NOSTORAGE; } @@ -516,12 +509,12 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname) @desc Enables storage for a group of CCTK_SCALAR variables For efficiency reasons, PUGH allocates storage for scalars - only once at the first call to PUGH_EnableScalarGroupStorage(). - The state of current storage allocation (which is toggled by + only once when the group is created. + The current state of storage allocation (which is toggled by Enable/DisableGroupStorage) is stored in a byte-sized flag immediately after the scalar data. @enddesc - + @var pughGH @vdesc Pointer to PUGH GH extensions @vtype pGH * @@ -545,9 +538,8 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname) @returntype int @returndesc - 1 if storage was already enabled + 1 if storage was already enabled before 0 if storage was successfully enabled - -1 if there was an inconsistency in storage allocation @endreturndesc @@*/ static int PUGH_EnableScalarGroupStorage (pGH *pughGH, @@ -560,40 +552,24 @@ static int PUGH_EnableScalarGroupStorage (pGH *pughGH, void *temp; - temp = pughGH->variables[first_var][0]; vtype = CCTK_VarTypeI (first_var); vtypesize = CCTK_VarTypeSize (vtype); - retval = temp ? ((char *) temp)[vtypesize] == PUGH_STORAGE : 0; + temp = pughGH->variables[first_var][0]; + retval = ((char *) temp)[vtypesize] == PUGH_STORAGE; - for (variable = 0; variable < n_variables && retval >= 0; variable++) + for (variable = 0; variable < n_variables; variable++) { for (level = 0; level < n_timelevels; level++) { temp = pughGH->variables[variable+first_var][level]; - if (! temp) - { - /* allocate one more byte for the query_storage flag */ - temp = malloc (vtypesize + 1); - pughGH->variables[variable+first_var][level] = temp; - } + /* raise the query_storage flag */ + ((char *) temp)[vtypesize] = PUGH_STORAGE; - if (temp) - { - /* raise the query_storage flag */ - ((char *) temp)[vtypesize] = PUGH_STORAGE; - - /* initialize memory if desired */ - if (! CCTK_Equals (initialize_memory, "none")) - { - PUGH_InitializeMemory (initialize_memory, vtype, vtypesize, temp); - } - } - else + /* initialize memory if desired */ + if (! CCTK_Equals (initialize_memory, "none")) { - pughGH->variables[first_var][0] = NULL; - retval = PUGH_ERRORMEMORY; - break; + PUGH_InitializeMemory (initialize_memory, vtype, vtypesize, temp); } } } @@ -610,7 +586,7 @@ static int PUGH_EnableScalarGroupStorage (pGH *pughGH, Enables storage for a set of variables @enddesc @calls PUGH_EnableGArrayDataStorage - + @var pughGH @vdesc Pointer to PUGH GH extensions @vtype pGH * @@ -712,7 +688,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, in BAM :-( @enddesc @calls Util_CacheMalloc - + @var GA @vdesc Pointer to the variable's info structure @vtype pGA * @@ -828,7 +804,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, For now this routine cannot be made static because it's used in BAM :-( @enddesc - + @var GA @vdesc Pointer to the variable's info structure @vtype pGA * @@ -878,7 +854,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, Initializes allocated memory to all zeros (all variable types) or NaNs (floating point types only) @enddesc - + @var initialize_memory @vdesc keyword describing how to initialize memory @vtype const char * |