aboutsummaryrefslogtreecommitdiff
path: root/src/Storage.c
diff options
context:
space:
mode:
authortradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-08-30 14:09:35 +0000
committertradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-08-30 14:09:35 +0000
commit6ca9d86c3032ba54c1e935d00c6331699e27d896 (patch)
tree94a37669709435265ef9382194138034cae0b0c4 /src/Storage.c
parenta7bf798652ee626d91d7364bd5a9c4d5e024827e (diff)
Enable/disable storage for CCTK_SCALAR variables. Although memory for those
types is allocated only once (in the first call to CCTK_EnableGroupStorage()) the current state of allocation is kept in a flag for every group. This is returned by CCTK_QueryGroupStorage() then. Main purpose of this is to make the NaNChecker working for CCTK_SCALARs also. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@342 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/Storage.c')
-rw-r--r--src/Storage.c291
1 files changed, 234 insertions, 57 deletions
diff --git a/src/Storage.c b/src/Storage.c
index e8e09ee..a8c8e3f 100644
--- a/src/Storage.c
+++ b/src/Storage.c
@@ -34,10 +34,18 @@ static int totalnumber = 0; /* Number of stored GAs */
/********************************************************************
******************** 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);
/*@@
@@ -181,7 +189,9 @@ int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname)
int first_var;
int storage;
int grouptype;
+ int vtypesize;
int retval;
+ pGH *pughGH;
retval = -1;
@@ -195,31 +205,42 @@ int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname)
first_var = CCTK_FirstVarIndexI (group);
if (first_var >= 0)
{
+ pughGH = PUGH_pGH (GH);
grouptype = CCTK_GroupTypeI (group);
if (grouptype == CCTK_SCALAR)
{
- retval = 1;
- }
- else if (grouptype == CCTK_GF || grouptype == CCTK_ARRAY)
- {
- storage = ((pGA *) PUGH_pGH (GH)->variables[first_var][0])->storage;
- if (storage == PUGH_STORAGE)
- {
- retval = 1;
- }
- else if (storage == PUGH_NOSTORAGE)
+ if (pughGH->variables[first_var][0])
{
- retval = 0;
+ vtypesize = CCTK_VarTypeSize (CCTK_VarTypeI (first_var));
+ storage = ((char *) pughGH->variables[first_var][0])[vtypesize];
}
else
{
- CCTK_WARN (1, "Inconsistency in PUGH_QueryGroupStorage");
+ storage = -1;
}
}
+ 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");
}
+
+ if (storage == PUGH_STORAGE)
+ {
+ retval = 1;
+ }
+ else if (storage == PUGH_NOSTORAGE)
+ {
+ retval = 0;
+ }
+ else
+ {
+ CCTK_WARN (1, "Inconsistency in PUGH_QueryGroupStorage");
+ }
}
else
{
@@ -251,6 +272,7 @@ int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname)
@enddesc
@calls CCTK_GroupIndex
CCTK_GroupData
+ PUGH_EnableScalarGroupStorage
PUGH_EnableGArrayGroupStorage
@var GH
@@ -266,9 +288,10 @@ int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname)
@returntype int
@returndesc
- 1 if storage is always assigned (for CCTK_SCALAR groups), <BR>
- return code of @seeroutine PUGH_EnableGArrayGroupStorage
- (for CCTK_ARRAY and CCTK_GF groups), or <BR>
+ return code of @seeroutine PUGH_EnableScalarGroupStorage or
+ @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>
-2 if an invalid GH pointer was given <BR>
-3 if invalid groupname was given
@@ -300,10 +323,12 @@ int PUGH_EnableGroupStorage (cGH *GH, const char *groupname)
/* get the group info from its index */
CCTK_GroupData (group, &pgroup);
- /* SCALAR types have always switched on memory */
if (pgroup.grouptype == CCTK_SCALAR)
{
- retval = 1;
+ retval = PUGH_EnableScalarGroupStorage (pughGH,
+ first_var,
+ pgroup.numvars,
+ pgroup.numtimelevels);
}
else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
{
@@ -311,6 +336,15 @@ int PUGH_EnableGroupStorage (cGH *GH, const char *groupname)
first_var,
pgroup.numvars,
pgroup.numtimelevels);
+ if (retval == 0)
+ {
+ /* get GA pointer of first var in group */
+ GA = (pGA *) pughGH->variables[first_var][0];
+ totalnumber += pgroup.numvars * pgroup.numtimelevels;
+ totalstorage += (GA->extras->npoints * GA->varsize *
+ pgroup.numtimelevels * pgroup.numvars) /
+ (float) (1024*1024);
+ }
}
else
{
@@ -318,23 +352,12 @@ int PUGH_EnableGroupStorage (cGH *GH, const char *groupname)
retval = -1;
}
- if (retval == 0)
- {
- /* get GA pointer of first var in group */
- GA = (pGA *) pughGH->variables[first_var][0];
- totalnumber += pgroup.numvars * pgroup.numtimelevels;
- totalstorage += (GA->extras->npoints * GA->varsize *
- pgroup.numtimelevels * pgroup.numvars) /
- (float) (1024*1024);
- }
-
/* Report on memory usage */
- if (storage_verbose && retval >= 0)
+ if (storage_verbose && retval == 0)
{
- printf ("%s for group '%s'\n"
+ printf ("Switched memory on for group '%s'\n"
" [Num Arrays: %d Total Size: %6.2fMB]\n",
- retval ? "Memory already on" : "Switched memory on",
- groupname, totalnumber, totalstorage);
+ groupname, totalnumber, totalstorage);
}
}
else
@@ -393,11 +416,11 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname)
DECLARE_CCTK_PARAMETERS
int group; /* group index */
cGroup pgroup; /* group information */
- int retval;
+ int vtypesize, retval;
pGA ***variables;
- int level;
- int first_var, var;
+ int first_var, var, level;
int unchanged; /* count how many aren't toggled */
+ char *temp;
#ifdef DEBUG_PUGH
@@ -427,7 +450,26 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname)
}
}
}
- else if (pgroup.grouptype != CCTK_SCALAR)
+ else if (pgroup.grouptype == CCTK_SCALAR)
+ {
+ vtypesize = CCTK_VarTypeSize (pgroup.vartype);
+ for (var = first_var; var < first_var+pgroup.numvars; var++)
+ {
+ for (level = 0; level < pgroup.numtimelevels; level++)
+ {
+ temp = (char *) variables[var][level];
+ if (temp && temp[vtypesize] == PUGH_STORAGE)
+ {
+ temp[vtypesize] = PUGH_NOSTORAGE;
+ }
+ else
+ {
+ unchanged++;
+ }
+ }
+ }
+ }
+ else
{
CCTK_WARN (1, "Unknown group type in PUGH_DisableGroupStorage");
retval = -1;
@@ -468,6 +510,99 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname)
********************************************************************/
/*@@
+ @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 at the first call to PUGH_EnableScalarGroupStorage().
+ The state of current 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
+ 0 if storage was successfully enabled
+ -1 if there was an inconsistency in storage allocation
+ @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;
+
+
+ temp = pughGH->variables[first_var][0];
+ vtype = CCTK_VarTypeI (first_var);
+ vtypesize = CCTK_VarTypeSize (vtype);
+ retval = temp ? ((char *) temp)[vtypesize] == PUGH_STORAGE : 0;
+
+ for (variable = 0; variable < n_variables && retval >= 0; 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;
+ }
+
+ 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
+ {
+ pughGH->variables[first_var][0] = NULL;
+ retval = PUGH_ERRORMEMORY;
+ break;
+ }
+ }
+ }
+
+ return (retval);
+}
+
+
+ /*@@
@routine PUGH_EnableGArrayGroupStorage
@author Tom Goodale
@date 30 Mar 1999
@@ -615,7 +750,6 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH,
int padding_address_spacing)
{
int retval;
- const char *vtypename;
/* avoid compiler warnings about unused parameters */
@@ -665,27 +799,8 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH,
/* Initialize the memory if desired. */
if (GA->data && ! CCTK_Equals (initialize_memory, "none"))
{
- /* zero out variable */
- if (CCTK_Equals (initialize_memory, "zero"))
- {
- memset (GA->data, 0, GA->extras->npoints * GA->varsize);
- }
- /* set elements to Not-a-Number values (floating point variables only) */
- else if (CCTK_Equals (initialize_memory, "NaN"))
- {
- vtypename = CCTK_VarTypeName (GA->vtype);
- if (strncmp (vtypename, "CCTK_VARIABLE_REAL", 18) == 0 ||
- strncmp (vtypename, "CCTK_VARIABLE_COMPLEX", 22) == 0)
- {
- memset (GA->data, -1, GA->extras->npoints * GA->varsize);
- }
- }
- else
- {
- CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
- "PUGH_EnableGArrayDataStorage: Unknown keyword '%s' for "
- "parameter 'initialize_memory'", initialize_memory);
- }
+ PUGH_InitializeMemory (initialize_memory, GA->vtype,
+ GA->extras->npoints * GA->varsize, GA->data);
}
}
@@ -753,3 +868,65 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH,
return (retval);
}
+
+
+ /*@@
+ @routine PUGH_InitializeMemory
+ @author Thomas Radke
+ @date Thu 30 Aug 2001
+ @desc
+ 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 *
+ @vio in
+ @endvar
+ @var vtype
+ @vdesc CCTK variable type of the variable to initialize
+ @vtype int
+ @vio in
+ @endvar
+ @var bytes
+ @vdesc total number of bytes to initialize
+ @vtype int
+ @vio in
+ @endvar
+ @var data
+ @vdesc pointer to data to initialize
+ @vtype void *
+ @vio in
+ @endvar
+@@*/
+static void PUGH_InitializeMemory (const char *initialize_memory,
+ int vtype,
+ int bytes,
+ void *data)
+{
+ const char *vtypename;
+
+
+ /* zero out variable */
+ if (CCTK_Equals (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"))
+ {
+ vtypename = CCTK_VarTypeName (vtype);
+ if (strncmp (vtypename, "CCTK_VARIABLE_REAL", 18) == 0 ||
+ strncmp (vtypename, "CCTK_VARIABLE_COMPLEX", 22) == 0)
+ {
+ memset (data, -1, bytes);
+ }
+ }
+ else if (! CCTK_Equals (initialize_memory, "none"))
+ {
+ CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "InitializeMemory: Unknown keyword '%s' for "
+ "parameter 'initialize_memory'", initialize_memory);
+ }
+}