diff options
Diffstat (limited to 'src/Storage.c')
-rw-r--r-- | src/Storage.c | 579 |
1 files changed, 73 insertions, 506 deletions
diff --git a/src/Storage.c b/src/Storage.c index e702a08..d27e197 100644 --- a/src/Storage.c +++ b/src/Storage.c @@ -37,18 +37,10 @@ static int numberGF = 0; /* Number of GFs at max */ /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static int PUGH_EnableScalarGroupStorage (pGH *pughGH, - int first_var, - int n_variables, - int n_timelevels); static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, int first_var, int n_variables, int n_timelevels); -static void PUGH_InitializeMemory (const char *initialize_memory, - int vtype, - int bytes, - void *data); static int PUGHi_EnableGArrayGroupStorage (pGH *pughGH, @@ -57,25 +49,12 @@ static int PUGHi_EnableGArrayGroupStorage (pGH *pughGH, int max_timelevels, int n_timelevels); -static int PUGHi_EnableScalarGroupStorage (pGH *pughGH, - int first_var, - int n_variables, - int max_timelevels, - int n_timelevels); - static int PUGHi_DisableGArrayGroupStorage (pGH *pughGH, int first_var, int n_variables, int max_timelevels, int n_timelevels); -static int PUGHi_DisableScalarGroupStorage (pGH *pughGH, - int first_var, - int n_variables, - int max_timelevels, - int n_timelevels); - -static int PUGHi_NumTimeLevelsScalar(const pGH *pughGH, int var, int timelevels); static int PUGHi_NumTimeLevelsArray(const pGH *pughGH, int var, int timelevels); /******************************************************************** @@ -226,7 +205,6 @@ int PUGH_QueryGroupStorage (const cGH *GH, int group, const char *groupname) int first_var; int storage; int grouptype; - int vtypesize; int retval; pGH *pughGH; @@ -244,20 +222,7 @@ int PUGH_QueryGroupStorage (const cGH *GH, int group, const char *groupname) { pughGH = PUGH_pGH (GH); grouptype = CCTK_GroupTypeI (group); - if (grouptype == CCTK_SCALAR) - { - vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var)); - storage = ((char *) pughGH->variables[first_var][0])[vtypesize]; - } - else if (grouptype == CCTK_GF || grouptype == CCTK_ARRAY) - { - storage = ((pGA *) pughGH->variables[first_var][0])->storage; - } - else - { - storage = -1; - CCTK_WARN (1, "Unknown group type in PUGH_QueryGroupStorage"); - } + storage = ((pGA *) pughGH->variables[first_var][0])->storage; if (storage == PUGH_STORAGE) { @@ -302,7 +267,6 @@ int PUGH_QueryGroupStorage (const cGH *GH, int group, const char *groupname) @enddesc @calls CCTK_GroupIndex CCTK_GroupData - PUGH_EnableScalarGroupStorage PUGH_EnableGArrayGroupStorage @var GH @@ -318,8 +282,7 @@ int PUGH_QueryGroupStorage (const cGH *GH, int group, const char *groupname) @returntype int @returndesc - return code of @seeroutine PUGH_EnableScalarGroupStorage or - @seeroutine PUGH_EnableGArrayGroupStorage: <BR> + return code of @seeroutine PUGH_EnableGArrayGroupStorage: <BR> 1 if storage was already enabled, or <BR> 0 if storage was successfully enabled <BR> -1 if group type is not one of the above <BR> @@ -353,55 +316,39 @@ int PUGH_EnableGroupStorage (const cGH *GH, const char *groupname) /* get the group info from its index */ CCTK_GroupData (group, &pgroup); - if (pgroup.grouptype == CCTK_SCALAR) + retval = PUGH_EnableGArrayGroupStorage (pughGH, + first_var, + pgroup.numvars, + pgroup.numtimelevels); + if (!CCTK_Equals(storage_verbose,"no") && retval == 0) { - retval = PUGH_EnableScalarGroupStorage (pughGH, - first_var, - pgroup.numvars, - pgroup.numtimelevels); - } - else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY) - { - retval = PUGH_EnableGArrayGroupStorage (pughGH, - first_var, - pgroup.numvars, - pgroup.numtimelevels); - if (!CCTK_Equals(storage_verbose,"no") && retval == 0) + /* get GA pointer of first var in group */ + GA = (pGA *) pughGH->variables[first_var][0]; + if (pgroup.grouptype == CCTK_GF) { - /* get GA pointer of first var in group */ - GA = (pGA *) pughGH->variables[first_var][0]; - if (pgroup.grouptype == CCTK_GF) - { - totalnumberGF += pgroup.numvars * pgroup.numtimelevels; - } - else - { - totalnumberGA += pgroup.numvars * pgroup.numtimelevels; - } - totalstorage += (GA->extras->npoints * GA->varsize * - pgroup.numtimelevels * pgroup.numvars) / - (float) (1024*1024); - if (totalstorage > maxstorage) - { - numberGF = totalnumberGF; - numberGA = totalnumberGA; - maxstorage = totalstorage; - } - - /* Report on memory usage */ - if (CCTK_Equals(storage_verbose,"yes")) - { - CCTK_VInfo (CCTK_THORNSTRING, "Switched memory on for group '%s'" - " [GFs: %d GAs: %d Total Size: %6.2fMB]", - groupname, totalnumberGF, totalnumberGA, totalstorage); - } + totalnumberGF += pgroup.numvars * pgroup.numtimelevels; + } + else + { + totalnumberGA += pgroup.numvars * pgroup.numtimelevels; + } + totalstorage += (GA->extras->npoints * GA->varsize * + pgroup.numtimelevels * pgroup.numvars) / + (float) (1024*1024); + if (totalstorage > maxstorage) + { + numberGF = totalnumberGF; + numberGA = totalnumberGA; + maxstorage = totalstorage; } - } - else - { - CCTK_WARN (1, "PUGH_EnableGroupStorage: Unknown group type"); - retval = -1; + /* Report on memory usage */ + if (CCTK_Equals(storage_verbose,"yes")) + { + CCTK_VInfo (CCTK_THORNSTRING, "Switched memory on for group '%s'" + " [GFs: %d GAs: %d Total Size: %6.2fMB]", + groupname, totalnumberGF, totalnumberGA, totalstorage); + } } } @@ -461,11 +408,10 @@ int PUGH_DisableGroupStorage (const cGH *GH, const char *groupname) DECLARE_CCTK_PARAMETERS int group; /* group index */ cGroup pgroup; /* group information */ - int vtypesize, retval; + int retval; pGA ***variables; int first_var, var, level; int unchanged; /* count how many aren't toggled */ - char *temp; #ifdef DEBUG_PUGH @@ -485,40 +431,13 @@ int PUGH_DisableGroupStorage (const cGH *GH, const char *groupname) unchanged = 0; retval = 1; - if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY) - { - for (var = first_var; var < first_var+pgroup.numvars; var++) - { - for (level = 0; level < pgroup.numtimelevels; level++) - { - unchanged += PUGH_DisableGArrayDataStorage (variables[var][level]); - } - } - } - else if (pgroup.grouptype == CCTK_SCALAR) + for (var = first_var; var < first_var+pgroup.numvars; var++) { - vtypesize = CCTK_VarTypeSize (pgroup.vartype); - for (var = first_var; var < first_var+pgroup.numvars; var++) + for (level = 0; level < pgroup.numtimelevels; level++) { - for (level = 0; level < pgroup.numtimelevels; level++) - { - temp = (char *) variables[var][level]; - if (temp[vtypesize] == PUGH_STORAGE) - { - temp[vtypesize] = PUGH_NOSTORAGE; - } - else - { - unchanged++; - } - } + unchanged += PUGH_DisableGArrayDataStorage (variables[var][level]); } } - else - { - CCTK_WARN (1, "Unknown group type in PUGH_DisableGroupStorage"); - retval = -1; - } /* Report on memory usage */ if (!CCTK_Equals(storage_verbose,"no") && retval >= 0) @@ -531,7 +450,7 @@ int PUGH_DisableGroupStorage (const cGH *GH, const char *groupname) { totalnumberGF -= pgroup.numvars; } - else if (pgroup.grouptype == CCTK_ARRAY) + else { totalnumberGA -= pgroup.numvars; } @@ -607,86 +526,6 @@ float PUGH_ReturnMaxStorage(void) ********************************************************************/ /*@@ - @routine PUGH_EnableScalarGroupStorage - @author Thomas Radke - @date Thu 30 Aug 2001 - @desc - Enables storage for a group of CCTK_SCALAR variables - 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 pughGH - @vdesc Pointer to PUGH GH extensions - @vtype pGH * - @vio in - @endvar - @var first_var - @vdesc index of the first variable to enable storage for - @vtype int - @vio in - @endvar - @var n_variables - @vdesc total number of variables to enable storage for - @vtype int - @vio in - @endvar - @var n_timelevels - @vdesc total number of timelevels to enable storage for - @vtype int - @vio in - @endvar - - @returntype int - @returndesc - 1 if storage was already enabled before - 0 if storage was successfully enabled - @endreturndesc -@@*/ -static int PUGH_EnableScalarGroupStorage (pGH *pughGH, - int first_var, - int n_variables, - int n_timelevels) -{ - DECLARE_CCTK_PARAMETERS - int vtype, vtypesize, variable, level, retval; - void *temp; - - - vtype = CCTK_VarTypeI (first_var); - vtypesize = CCTK_VarTypeSize (vtype); - temp = pughGH->variables[first_var][0]; - retval = ((char *) temp)[vtypesize] == PUGH_STORAGE; - - /* don't assign storage if was already switched on */ - if (! retval) - { - for (variable = 0; variable < n_variables; variable++) - { - for (level = 0; level < n_timelevels; level++) - { - temp = pughGH->variables[variable+first_var][level]; - - /* 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); - } - } - } - } - - return (retval); -} - - - /*@@ @routine PUGH_EnableGArrayGroupStorage @author Tom Goodale @date 30 Mar 1999 @@ -897,9 +736,14 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, GA->extras->npoints * GA->varsize * GA->vector_size, &GA->padddata); } +#ifdef DEBUG_PUGH + printf (" PUGH_EnableGArrayDataStorage: new pointer is %p (%p)\n", + GA->padddata, GA->data); + fflush (stdout); +#endif /* Initialize the memory if desired. */ - if (GA->data && ! CCTK_Equals (initialize_memory, "none")) + if (GA->data) { PUGH_InitializeMemory (initialize_memory, GA->vtype, GA->extras->npoints * GA->varsize, GA->data); @@ -953,7 +797,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, { #ifdef DEBUG_PUGH - printf ("PUGH_DisableGArrayDataStorage: freeing storage for var '%s'\n", + printf (" PUGH_DisableGArrayDataStorage: freeing storage for var '%s'\n", GA->name); fflush (stdout); #endif @@ -966,6 +810,11 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, { if (GA->padddata) { +#ifdef DEBUG_PUGH + printf (" PUGH_DisableGArrayDataStorage: old pointer is %p (%p)\n", + GA->padddata, GA->data); + fflush (stdout); +#endif free (GA->padddata); } GA->padddata = NULL; @@ -988,7 +837,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, or NaNs (floating point types only) @enddesc - @var initialize_memory + @var do_initialize_memory @vdesc keyword describing how to initialize memory @vtype const char * @vio in @@ -1009,21 +858,22 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, @vio in @endvar @@*/ -static void PUGH_InitializeMemory (const char *initialize_memory, - int vtype, - int bytes, - void *data) +void PUGH_InitializeMemory (const char *do_initialize_memory, + int vtype, + int bytes, + void *data) { + DECLARE_CCTK_PARAMETERS; const char *vtypename; /* zero out variable */ - if (CCTK_Equals (initialize_memory, "zero")) + if (CCTK_Equals (do_initialize_memory, "zero")) { memset (data, 0, bytes); } /* set elements to Not-a-Number values (floating point variables only) */ - else if (CCTK_Equals (initialize_memory, "NaN")) + else if (CCTK_Equals (do_initialize_memory, "NaN")) { vtypename = CCTK_VarTypeName (vtype); if (strncmp (vtypename, "CCTK_VARIABLE_REAL", 18) == 0 || @@ -1032,11 +882,11 @@ static void PUGH_InitializeMemory (const char *initialize_memory, memset (data, -1, bytes); } } - else if (! CCTK_Equals (initialize_memory, "none")) + else if (! CCTK_Equals (do_initialize_memory, "none")) { CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, "InitializeMemory: Unknown value '%s' for " - "argument 'initialize_memory'", initialize_memory); + "argument 'do_initialize_memory'", do_initialize_memory); } } @@ -1071,8 +921,7 @@ void PUGHi_PrintStorageReport () not change the storage for that group. @enddesc - @calls PUGHi_EnableScalarGroupStorage - PUGHi_EnableGArrayGroupStorage + @calls PUGHi_EnableGArrayGroupStorage @var GH @vdesc Pointer to CCTK grid hierarchy @@ -1149,27 +998,11 @@ int PUGH_GroupStorageIncrease(const cGH *GH, int n_groups,const int *groups,cons tlevels = timelevels[group]; } - if (pgroup.grouptype == CCTK_SCALAR) - { - previous = PUGHi_EnableScalarGroupStorage (pughGH, - first_var, - pgroup.numvars, - pgroup.numtimelevels, - tlevels); - } - else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY) - { - previous = PUGHi_EnableGArrayGroupStorage (pughGH, - first_var, - pgroup.numvars, - pgroup.numtimelevels, - tlevels); - } - else - { - CCTK_WARN (1, "PUGH_GroupStorageIncrease: Unknown group type"); - previous = 0; - } + previous = PUGHi_EnableGArrayGroupStorage (pughGH, + first_var, + pgroup.numvars, + pgroup.numtimelevels, + tlevels); if(status) { @@ -1198,8 +1031,7 @@ int PUGH_GroupStorageIncrease(const cGH *GH, int n_groups,const int *groups,cons not change the storage for that group. @enddesc - @calls PUGHi_DisableScalarGroupStorage - PUGHi_DisableGArrayGroupStorage + @calls PUGHi_DisableGArrayGroupStorage @var GH @vdesc Pointer to CCTK grid hierarchy @@ -1276,27 +1108,11 @@ int PUGH_GroupStorageDecrease(const cGH *GH, int n_groups,const int *groups,cons tlevels = timelevels[group]; } - if (pgroup.grouptype == CCTK_SCALAR) - { - previous = PUGHi_DisableScalarGroupStorage (pughGH, - first_var, - pgroup.numvars, - pgroup.numtimelevels, - tlevels); - } - else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY) - { - previous = PUGHi_DisableGArrayGroupStorage (pughGH, - first_var, - pgroup.numvars, - pgroup.numtimelevels, - tlevels); - } - else - { - CCTK_WARN (1, "PUGH_GroupStorageIncrease: Unknown group type"); - previous = 0; - } + previous = PUGHi_DisableGArrayGroupStorage (pughGH, + first_var, + pgroup.numvars, + pgroup.numtimelevels, + tlevels); if(status) { @@ -1381,7 +1197,7 @@ static int PUGHi_EnableGArrayGroupStorage (pGH *pughGH, if(level < n_timelevels) { #ifdef DEBUG_PUGH - printf (" PUGH_EnableGArrayGroupStorage: request for var '%s' " + printf (" PUGHi_EnableGArrayGroupStorage: request for var '%s' " "timelevel %d\n", GA->name, level); fflush (stdout); #endif @@ -1512,193 +1328,13 @@ static int PUGHi_DisableGArrayGroupStorage (pGH *pughGH, } /*@@ - @routine PUGHi_EnableScalarGroupStorage - @author Thomas Radke - @date Thu 30 Aug 2001 - @desc - Enables storage for a group of CCTK_SCALAR variables - 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 pughGH - @vdesc Pointer to PUGH GH extensions - @vtype pGH * - @vio in - @endvar - @var first_var - @vdesc index of the first variable to enable storage for - @vtype int - @vio in - @endvar - @var n_variables - @vdesc total number of variables to enable storage for - @vtype int - @vio in - @endvar - @var max_timelevels - @vdesc total number of timelevels for this group - @vtype int - @vio in - @var n_timelevels - @vdesc number of timelevels to enable storage for - @vtype int - @vio in - @endvar - - @returntype int - @returndesc - The number of timelevels enabled previously - @endreturndesc -@@*/ -static int PUGHi_EnableScalarGroupStorage (pGH *pughGH, - int first_var, - int n_variables, - int max_timelevels, - int n_timelevels) -{ - DECLARE_CCTK_PARAMETERS - int vtype, vtypesize, variable, level, retval; - void *temp; - - retval = 0; - vtype = CCTK_VarTypeI (first_var); - vtypesize = CCTK_VarTypeSize (vtype); - - for (variable = 0; variable < n_variables; variable++) - { - for (level = 0; level < max_timelevels; level++) - { - temp = pughGH->variables[variable+first_var][level]; - - if(((char *) temp)[vtypesize] != PUGH_STORAGE) - { - if(level < n_timelevels) - { - /* 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 - { - if(variable == 0) - { - retval++; - } - } - - /* set the variable's data pointer in the cGH structure */ - ((cGH *) pughGH->callerid)->data[variable+first_var][level] = temp; - } - } - - return retval; -} - - - /*@@ - @routine PUGHi_DisableScalarGroupStorage - @author Thomas Radke - @date Thu 30 Aug 2001 - @desc - Disables storage for a group of CCTK_SCALAR variables - 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 pughGH - @vdesc Pointer to PUGH GH extensions - @vtype pGH * - @vio in - @endvar - @var first_var - @vdesc index of the first variable to disable storage for - @vtype int - @vio in - @endvar - @var n_variables - @vdesc total number of variables to disable storage for - @vtype int - @vio in - @endvar - @var max_timelevels - @vdesc total number of timelevels for this group - @vtype int - @vio in - @var n_timelevels - @vdesc number of timelevels to disable storage for - @vtype int - @vio in - @endvar - - @returntype int - @returndesc - The number of timelevels disabled previously - @endreturndesc -@@*/ -static int PUGHi_DisableScalarGroupStorage (pGH *pughGH, - int first_var, - int n_variables, - int max_timelevels, - int n_timelevels) -{ - int vtypesize, variable, level, retval; - void *temp; - DECLARE_CCTK_PARAMETERS - - retval = 0; - - vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var)); - - for (variable = 0; variable < n_variables; variable++) - { - for (level = 0; level < max_timelevels; level++) - { - temp = pughGH->variables[variable+first_var][level]; - - if(((char *) temp)[vtypesize] != PUGH_NOSTORAGE) - { - if(variable == 0) - { - retval++; - } - - if(level >= n_timelevels) - { - /* set the storage flag to no-storage*/ - ((char *) temp)[vtypesize] = PUGH_NOSTORAGE; - - /* set the variable's data pointer in the cGH structure */ - ((cGH *) pughGH->callerid)->data[variable+first_var][level] = NULL; - } - } - } - } - - return retval; -} - - /*@@ @routine PUGH_NumTimeLevels @date Tue Apr 16 19:03:30 2002 @author Tom Goodale @desc Work out the number of enabled timelevels for a variable. @enddesc - @calls PUGHi_NumTimeLevelsScalar - PUGHi_NumTimeLevelsArray + @calls PUGHi_NumTimeLevelsArray @var pughGH @vdesc a PUGH GH @@ -1722,76 +1358,7 @@ int PUGH_NumTimeLevels(const pGH *pughGH, int var) timelevels = CCTK_MaxTimeLevelsVI(var); - switch(CCTK_GroupTypeFromVarI(var)) - { - case CCTK_SCALAR: - retval = PUGHi_NumTimeLevelsScalar(pughGH, var, timelevels); - break; - case CCTK_GF: - /* Fall through. */ - case CCTK_ARRAY: - retval = PUGHi_NumTimeLevelsArray(pughGH, var, timelevels); - break; - default: - retval = -1; - } - - return retval; -} - - /*@@ - @routine PUGH_NumTimeLevelsScalar - @date Tue Apr 16 19:03:30 2002 - @author Tom Goodale - @desc - Work out the number of enabled timelevels for a scalar variable. - @enddesc - - @var pughGH - @vdesc a PUGH GH - @vtype const pGH * - @vio in - @var var - @vdesc The variable index to get the info for - @vtype int - @vio in - @var timelevels - @vdesc The maximum number of timelevels the variable can have - @vtype int - @vio in - - @returntype int - @returndesc - The number of timelevels enabled for this variable - @endreturndesc - @@*/ -static int PUGHi_NumTimeLevelsScalar(const pGH *pughGH, int var, int timelevels) -{ - int retval; - - int vtype; - int vtypesize; - int level; - void *temp; - - retval = 0; - - vtype = CCTK_VarTypeI (var); - vtypesize = CCTK_VarTypeSize (vtype); - - for (level = 0; level < timelevels; level++) - { - temp = pughGH->variables[var][level]; - - if(((char *) temp)[vtypesize] == PUGH_STORAGE) - { - retval++; - } - else - { - break; - } - } + retval = PUGHi_NumTimeLevelsArray(pughGH, var, timelevels); return retval; } |