aboutsummaryrefslogtreecommitdiff
path: root/src/Storage.c
diff options
context:
space:
mode:
authorgoodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364>2002-04-16 17:26:55 +0000
committergoodale <goodale@b61c5cb5-eaca-4651-9a7a-d64986f99364>2002-04-16 17:26:55 +0000
commit1e49bf834044cdb29fd064b93ac8035319d6d1c4 (patch)
tree463deda9692975015c22a63ba90683313eaaebde /src/Storage.c
parenteca53bf94c5659485aa8bcfeecc37549c516e515 (diff)
Changing so that the number of timelevels enabled isn't necessarily
the maximum. Now overloads the CCTK_GroupStorageIncrease/Decrease functions and only rotates the levels with storage. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@375 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/Storage.c')
-rw-r--r--src/Storage.c832
1 files changed, 832 insertions, 0 deletions
diff --git a/src/Storage.c b/src/Storage.c
index e3d4aa9..76e2fa9 100644
--- a/src/Storage.c
+++ b/src/Storage.c
@@ -50,6 +50,34 @@ static void PUGH_InitializeMemory (const char *initialize_memory,
int bytes,
void *data);
+
+static int PUGHi_EnableGArrayGroupStorage (pGH *pughGH,
+ int first_var,
+ int n_variables,
+ 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);
+
/********************************************************************
******************** External Routines ************************
********************************************************************/
@@ -1018,3 +1046,807 @@ void PUGHi_PrintStorageReport ()
CCTK_VInfo(CCTK_THORNSTRING, " Maximum storage: %6.2fMB",maxstorage);
CCTK_VInfo(CCTK_THORNSTRING, " [%d Grid Functions, %d Grid Arrays]",numberGF,numberGA);
}
+
+
+ /*@@
+ @routine PUGH_GroupStorageIncrease
+ @date Tue Apr 16 16:01:22 2002
+ @author Tom Goodale
+ @desc
+ The increase group storage routine should increase the allocated memory
+ to the specified number of timelevels of each listed group, returning the
+ previous number of timelevels enable for that group in the status array,
+ if that is not NULL. It should never decrease the number of timelevels enabled,
+ i.e. if it is asked to enable less timelevels than are already enable it should
+ not change the storage for that group.
+
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio inout
+ @vcomment
+ A driver should replace the appropriate GV pointers on this
+ structure when they change the storage state of a GV.
+ @endvar
+ @var n_groups
+ @vdesc Number of groups in group array
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var groups
+ @vdesc Groups to allocate storage for
+ @vtype const int *
+ @vio in
+ @vcomment
+ This should be a list of group indices. -1 is treated as a flag to ignore this entry.
+ @endvar
+ @var timelevels
+ @vdesc Number of timelevels to allocate storage for for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ This array should have n_groups elements.
+ @endvar
+ @var status
+ @vdesc Optional return array to contain previous state of storage for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ If this array is not NULL, it will, on return, contain the number of timelevels which
+ were previously allocated storage for each group.
+ @endvar
+
+ @returntype int
+ @returndesc
+ The total number of timelevels with storage enabled for all groups queried or
+ modified.
+ @endreturndesc
+ @@*/
+int PUGH_GroupStorageIncrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status)
+{
+ int retval;
+ int group;
+ pGH *pughGH;
+
+ retval = 0;
+ pughGH = PUGH_pGH (GH);
+
+ for(group = 0; group < n_groups; group++)
+ {
+ if(groups[group] > -1)
+ {
+ int previous;
+ int first_var;
+ int tlevels;
+ cGroup pgroup;
+
+ /* get the group info from its index */
+ CCTK_GroupData (groups[group], &pgroup);
+
+ first_var = CCTK_FirstVarIndexI (groups[group]);
+
+ /* Enable all timelevels or just some */
+ if(timelevels[group] == -1)
+ {
+ tlevels = pgroup.numtimelevels;
+ }
+ else
+ {
+ 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;
+ }
+
+ if(status)
+ {
+ status[group] = previous;
+ }
+
+ retval += previous;
+ }
+ }
+
+
+ /* FIXME: need to add stuff to record how juch storage is in use. */
+ return retval;
+}
+
+ /*@@
+ @routine PUGH_GroupStorageDecrease
+ @date Tue Apr 16 16:01:22 2002
+ @author Tom Goodale
+ @desc
+ The decrease group storage routine should decrease the memory allocated
+ to the specified number of timelevels for each listed group, returning the
+ previous number of timelevels enable for that group in the status array,
+ if that is not NULL. It should never increase the number of timelevels enabled,
+ i.e. if it is asked to reduce to more timelevels than are enable it should
+ not change the storage for that group.
+
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio inout
+ @vcomment
+ A driver should replace the appropriate GV pointers on this
+ structure when they change the storage state of a GV.
+ @endvar
+ @var n_groups
+ @vdesc Number of groups in group array
+ @vtype int
+ @vio in
+ @vcomment
+
+ @endvar
+ @var groups
+ @vdesc Groups to reduce storage for
+ @vtype const int *
+ @vio in
+ @vcomment
+ This should be a list of group indices. -1 is treated as a flag to ignore this entry.
+ @endvar
+ @var timelevels
+ @vdesc Number of timelevels to reduce storage for for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ This array should have n_groups elements.
+ @endvar
+ @var status
+ @vdesc Optional return array to contain previous state of storage for each group.
+ @vtype const int *
+ @vio in
+ @vcomment
+ If this array is not NULL, it will, on return, contain the number of timelevels which
+ were previously allocated storage for each group.
+ @endvar
+
+ @returntype int
+ @returndesc
+ The total number of timelevels with storage enabled for all groups queried or
+ modified.
+ @endreturndesc
+ @@*/
+int PUGH_GroupStorageDecrease(cGH *GH, int n_groups,const int *groups,const int *timelevels, int *status)
+{
+ int retval;
+ int group;
+ pGH *pughGH;
+
+ retval = 0;
+ pughGH = PUGH_pGH (GH);
+
+ for(group = 0; group < n_groups; group++)
+ {
+ if(groups[group] > -1)
+ {
+ int previous;
+ int first_var;
+ int tlevels;
+ cGroup pgroup;
+
+ /* get the group info from its index */
+ CCTK_GroupData (groups[group], &pgroup);
+
+ first_var = CCTK_FirstVarIndexI (groups[group]);
+
+ /* Disable all timelevels or just some */
+ if(timelevels[group] == -1)
+ {
+ tlevels = 0;
+ }
+ else
+ {
+ 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;
+ }
+
+ if(status)
+ {
+ status[group] = previous;
+ }
+
+ retval += previous;
+ }
+ }
+
+
+ /* FIXME: need to add stuff to record how juch storage is in use. */
+ return retval;
+}
+
+ /*@@
+ @routine PUGHi_EnableGArrayGroupStorage
+ @author Tom Goodale
+ @date 30 Mar 1999
+ @desc
+ Enables storage for a set of variables
+ @enddesc
+ @calls PUGH_EnableGArrayDataStorage
+
+ @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 previously allocated
+ @endreturndesc
+@@*/
+static int PUGHi_EnableGArrayGroupStorage (pGH *pughGH,
+ int first_var,
+ int n_variables,
+ int max_timelevels,
+ int n_timelevels)
+{
+ DECLARE_CCTK_PARAMETERS
+ int nstorage; /* Number of Arrays for which storage was set */
+ int nnostorage; /* Number of Arrays for which no storage was set */
+ int retval;
+ int var;
+ pGA *GA;
+ int level;
+
+ retval = 0;
+ nstorage = 0;
+ nnostorage = 0;
+
+ for (var = first_var; var < first_var + n_variables; var++)
+ {
+ for (level = 0; level < max_timelevels; level++)
+ {
+ GA = (pGA *) pughGH->variables[var][level];
+
+ if (! GA->storage)
+ {
+
+ if(level < n_timelevels)
+ {
+#ifdef DEBUG_PUGH
+ printf (" PUGH_EnableGArrayGroupStorage: request for var '%s' "
+ "timelevel %d\n", GA->name, level);
+ fflush (stdout);
+#endif
+ PUGH_EnableGArrayDataStorage (GA,
+ pughGH->myproc,
+ initialize_memory,
+ padding_active,
+ padding_cacheline_bits,
+ padding_size,
+ padding_address_spacing);
+ }
+
+ ((cGH *) pughGH->callerid)->data[var][level] = GA->data;
+
+ nnostorage++;
+ }
+ else
+ {
+ ((cGH *) pughGH->callerid)->data[var][level] = GA->data;
+ nstorage++;
+
+ /* Count the number of timelevels which were previously allocated. */
+ if(var == first_var)
+ {
+ retval++;
+ }
+ }
+ }
+ }
+
+ if (nstorage > 0 && nnostorage > 0)
+ {
+ CCTK_WARN (0, "Group storage violation in PUGHi_EnableGArrayGroupStorage");
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine PUGHi_DisableGArrayGroupStorage
+ @author Tom Goodale
+ @date 30 Mar 1999
+ @desc
+ Disables storage for a set of variables
+ @enddesc
+ @calls PUGH_DisableGArrayDataStorage
+
+ @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 maximum number of timelevels for this group
+ @vtype int
+ @vio in
+ @endvar
+ @var n_timelevels
+ @vdesc number of timelevels to leave storage for
+ @vtype int
+ @vio in
+ @endvar
+
+ @returntype int
+ @returndesc
+ The number of timelevels previously allocated
+ @endreturndesc
+@@*/
+static int PUGHi_DisableGArrayGroupStorage (pGH *pughGH,
+ int first_var,
+ int n_variables,
+ int max_timelevels,
+ int n_timelevels)
+{
+ DECLARE_CCTK_PARAMETERS
+ int nstorage; /* Number of Arrays for which storage was set */
+ int nnostorage; /* Number of Arrays for which no storage was set */
+ int retval;
+ int var;
+ pGA *GA;
+ int level;
+
+ retval = 0;
+ nstorage = 0;
+ nnostorage = 0;
+
+ for (var = first_var; var < first_var + n_variables; var++)
+ {
+ for (level = max_timelevels-1; level >= 0; level--)
+ {
+ GA = (pGA *) pughGH->variables[var][level];
+
+ if (GA->storage)
+ {
+ /* Count the number of timelevels which were previously allocated. */
+ if(var == first_var)
+ {
+ retval++;
+ }
+
+ if(level >= n_timelevels)
+ {
+#ifdef DEBUG_PUGH
+ printf (" PUGHi_DisableGArrayGroupStorage: request for var '%s' "
+ "timelevel %d\n", GA->name, level);
+ fflush (stdout);
+#endif
+ PUGH_DisableGArrayDataStorage (GA);
+ }
+
+ ((cGH *) pughGH->callerid)->data[var][level] = GA->data;
+ nstorage++;
+ }
+ else
+ {
+ ((cGH *) pughGH->callerid)->data[var][level] = GA->data;
+ nnostorage++;
+ }
+ }
+ }
+
+ if (nstorage > 0 && nnostorage > 0)
+ {
+ CCTK_WARN (0, "Group storage violation in PUGHi_DisableGArrayGroupStorage");
+ }
+
+ return retval;
+}
+
+ /*@@
+ @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++;
+ }
+ }
+ }
+ }
+
+ 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)
+{
+ 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 = max_timelevels-1; level >= 0; 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;
+ }
+ }
+ }
+ }
+
+ 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
+ @calledby
+ @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
+
+ @returntype int
+ @returndesc
+ The number of timelevels enabled for this variable
+ @endreturndesc
+ @@*/
+int PUGH_NumTimeLevels(const pGH *pughGH, int var)
+{
+ int retval;
+
+ int timelevels;
+
+ timelevels = CCTK_NumTimeLevelsFromVarI(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
+ @calls
+ @calledby
+ @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;
+ }
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine PUGH_NumTimeLevelsArray
+ @date Tue Apr 16 19:03:30 2002
+ @author Tom Goodale
+ @desc
+ Work out the number of enabled timelevels for an array variable.
+ @enddesc
+ @calls
+ @calledby
+ @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_NumTimeLevelsArray(const pGH *pughGH, int var, int timelevels)
+{
+ int retval;
+ int level;
+ pGA *GA;
+
+ retval = 0;
+
+ for (level = 0; level < timelevels; level++)
+ {
+ GA = (pGA *) pughGH->variables[var][level];
+
+ if (GA->storage)
+ {
+ retval++;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return retval;
+}