aboutsummaryrefslogtreecommitdiff
path: root/src/Storage.c
diff options
context:
space:
mode:
authortradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-04-19 17:27:02 +0000
committertradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364>2001-04-19 17:27:02 +0000
commit4123693e65e3a7203f7d6075cccce46025d04b80 (patch)
tree48287eaf2f3dc8c0f51eef003cd9061ad79a4778 /src/Storage.c
parent0e12453d9c666cd8a5b2d3f7e0b99df7461dfe06 (diff)
Fixed a bug in PUGH_ArrayGroupSize().
Fixed compiler warnings, completed grdoc. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@316 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/Storage.c')
-rw-r--r--src/Storage.c788
1 files changed, 462 insertions, 326 deletions
diff --git a/src/Storage.c b/src/Storage.c
index 8918c5a..3c06d3a 100644
--- a/src/Storage.c
+++ b/src/Storage.c
@@ -2,431 +2,515 @@
@file Storage.c
@date Tue Jun 13 2000
@author Thomas Radke
- @desc
+ @desc
Pugh storage functions
- @enddesc
- @version $Header$
+ @enddesc
+ @version $Id$
@@*/
-/*#define DEBUG_PUGH*/
-
#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include "cctk.h"
#include "cctk_Parameters.h"
#include "pugh.h"
#include "pughi.h"
+#include "pugh_Comm.h"
static char *rcsid="$Header$";
-
CCTK_FILEVERSION(CactusPUGH_PUGH_Storage_c)
+/*#define DEBUG_PUGH*/
+
+
+/********************************************************************
+ ******************** Static Variables *************************
+ ********************************************************************/
static float totalstorage = 0; /* Storage for GAs in Bytes */
-static int totalnumber = 0; /* Number of stored GAs */
-
-
-/*@@
- @routine PUGH_ArrayGroupSize
- @author Gabrielle Allen
- @date 11 Apr 1999
- @desc
- Returns size of arrays in a group, in a given direction
- @enddesc
- @calls
- @history
+static int totalnumber = 0; /* Number of stored GAs */
+
+
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
+static int PUGH_EnableGArrayGroupStorage (pGH *pughGH,
+ int first_var,
+ int n_variables,
+ int n_timelevels);
+
+
+ /*@@
+ @routine PUGH_ArrayGroupSize
+ @author Gabrielle Allen
+ @date 11 Apr 1999
+ @desc
+ Returns size of arrays in a group, in a given direction.
+ Either group index or its name must be given,
+ the name takes precedence.
+ @enddesc
+ @calls CCTK_GroupIndex
+ CCTK_FirstVarIndexI
+
- @endhistory
- @var GH
- @vdesc Pointer to CCTK grid hierarchy
- @vtype cGH
- @vio in
- @endvar
- @var groupname
- @vdesc name of the group to be synchronized
- @vtype const char *
- @vio in
- @vcomment either index or groupname must be present
- @endvar
- @var group
- @vdesc index of group
- @vtype int
- @vio in
- @vcomment either index or groupname must be given
- @endvar
- @var dir
- @vdesc direction
- @vtype int
- @vio in
- @@*/
-
-const int *PUGH_ArrayGroupSize(cGH *GH, int dir, int group, const char *groupname)
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+ @var dir
+ @vdesc direction to return size of
+ @vtype int
+ @vio in
+ @endvar
+ @var group
+ @vdesc index of group
+ @vtype int
+ @vio in
+ @endvar
+ @var groupname
+ @vdesc name of group
+ @vtype const char *
+ @vio in
+ @endvar
+
+ @returntype const int *
+ @returndesc
+ pointer to the size variable for the given direction, or
+ NULL if given direction or group index/name are invalid
+ @endreturndesc
+@@*/
+const int *PUGH_ArrayGroupSize (cGH *GH,
+ int dir,
+ int group,
+ const char *groupname)
{
- int *sizep;
+ int first_var;
pGA *GA;
+ const int *retval;
+
if (groupname)
{
- group = CCTK_GroupIndex(groupname);
-
- if (group >= 0)
- {
+ group = CCTK_GroupIndex (groupname);
+ }
- /* get pointer to pGA for a timelevel of first variable in this group */
- GA = (pGA *) PUGH_pGH(GH)->variables[CCTK_FirstVarIndexI(group)][0];
+ first_var = CCTK_FirstVarIndexI (group);
+ if (first_var >= 0)
+ {
+ /* get pointer to pGA for a timelevel of first variable in this group */
+ GA = (pGA *) PUGH_pGH (GH)->variables[first_var][0];
- if (GA->storage == PUGH_STORAGE)
+ if (GA->storage == PUGH_STORAGE)
+ {
+ if (dir >= 0 && dir < GA->extras->dim)
{
- if (dir >= 0 && dir < GA->extras->dim)
- {
- sizep = &GA->extras->lnsize[dir];
- }
- else
- {
- sizep = NULL;
- CCTK_WARN(1, "Wrong value for dir");
- }
+ retval = &GA->extras->lnsize[dir];
}
else
{
- sizep = &_cctk_one;
+ CCTK_WARN (1, "Wrong value for dir");
+ retval = NULL;
}
}
+ else
+ {
+ retval = &_cctk_one;
+ }
+ }
+ else
+ {
+ if (groupname)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid group name '%s' in PUGH_ArrayGroupSize",
+ groupname);
+ }
+ else
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid group ID %d in PUGH_ArrayGroupSize",
+ group);
+ }
+
+ retval = NULL;
}
- return (sizep);
+ return (retval);
}
-/*@@
- @routine PUGH_QueryGroupStorage
- @author Gabrielle Allen
- @date 13 Apr 1999
- @desc
- Returns true if group has storage assigned, false otherwise
- @enddesc
- @calls CCTK_DecomposeName
- @history
+ /*@@
+ @routine PUGH_QueryGroupStorage
+ @author Gabrielle Allen
+ @date 13 Apr 1999
+ @desc
+ Checks if group has storage assigned.
+ Either group index or its name must be given,
+ the name takes precedence.
+ @enddesc
+ @calls CCTK_GroupIndex
+ CCTK_FirstVarIndexI
+ CCTK_GroupTypeI
+
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+ @var group
+ @vdesc index of group
+ @vtype int
+ @vio in
+ @endvar
+ @var groupname
+ @vdesc name of the group to be queried
+ @vtype const char *
+ @vio in
+ @endvar
- @endhistory
- @var GH
- @vdesc Pointer to CCTK grid hierarchy
- @vtype cGH
- @vio in
- @endvar
- @var groupname
- @vdesc name of the group to be queried
- @vtype const char *
- @vio in
- @vcomment either index or groupname must be present
- @endvar
- @var group
- @vdesc index of group
- @vtype int
- @vio in
- @vcomment either index or groupname must be given
- @endvar
- @@*/
-
-int PUGH_QueryGroupStorage(cGH *GH, int group, const char *groupname)
+ @returntype int
+ @returndesc
+ 1 if storage for this group is assigned
+ 0 if storage for this group is not assigned
+ -1 if given group index/name is invalid
+ @endreturndesc
+@@*/
+int PUGH_QueryGroupStorage (cGH *GH, int group, const char *groupname)
{
-
- int first;
- int storage=PUGH_UNDEFINEDSTORAGE;
- int retval=0;
+ int first_var;
+ int storage;
int grouptype;
+ int retval;
+
+
+ retval = -1;
if (groupname)
{
- group = CCTK_GroupIndex(groupname);
+ group = CCTK_GroupIndex (groupname);
}
/* get first variable in group */
- first = CCTK_FirstVarIndexI(group);
- if (first < 0)
- {
- CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Invalid group ID %d for %s in PUGH_QueryGroupStorage",
- group, groupname);
- }
- else
+ first_var = CCTK_FirstVarIndexI (group);
+ if (first_var >= 0)
{
- grouptype = CCTK_GroupTypeI(group);
-
+ grouptype = CCTK_GroupTypeI (group);
if (grouptype == CCTK_SCALAR)
{
- storage = PUGH_STORAGE;
retval = 1;
}
else if (grouptype == CCTK_GF || grouptype == CCTK_ARRAY)
{
- storage = ((pGA *) PUGH_pGH(GH)->variables[first][0])->storage;
+ storage = ((pGA *) PUGH_pGH (GH)->variables[first_var][0])->storage;
if (storage == PUGH_STORAGE)
{
- retval = 1;
+ retval = 1;
}
else if (storage == PUGH_NOSTORAGE)
{
- retval = 0;
+ retval = 0;
}
else
{
- CCTK_WARN(1,"Inconsistency in PUGH_QueryGroupStorage");
+ CCTK_WARN (1, "Inconsistency in PUGH_QueryGroupStorage");
}
}
else
{
- CCTK_WARN(1,"Unknown group type in PUGH_QueryGroupStorage");
+ CCTK_WARN (1, "Unknown group type in PUGH_QueryGroupStorage");
+ }
+ }
+ else
+ {
+ if (groupname)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid group name '%s' in PUGH_ArrayGroupSize",
+ groupname);
+ }
+ else
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Invalid group ID %d in PUGH_ArrayGroupSize",
+ group);
}
-
}
return (retval);
}
-/*@@
- @routine PUGH_EnableGroupStorage
- @author Tom Goodale
- @date 30 Mar 1999
- @desc
- Enables storage for all variables in the group indicated by groupname.
- @enddesc
- @calls CCTK_DecomposeName CCTK_GroupIndex CCTK_GroupData CCTK_WARN
- PUGH_EnableGArrayGroupStorage
- @history
+ /*@@
+ @routine PUGH_EnableGroupStorage
+ @author Tom Goodale
+ @date 30 Mar 1999
+ @desc
+ Enables storage for all variables in the group
+ indicated by groupname.
+ @enddesc
+ @calls CCTK_GroupIndex
+ CCTK_GroupData
+ PUGH_EnableGArrayGroupStorage
- @endhistory
- @var GH
- @vdesc Pointer to CCTK grid hierarchy
- @vtype cGH
- @vio in
- @endvar
- @var groupname
- @vdesc name of the group to be synchronized
- @vtype const char *
- @vio in
- @endvar
- @@*/
-
-int PUGH_EnableGroupStorage(cGH *GH, const char *groupname)
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+ @var groupname
+ @vdesc name of the group to enable storage for
+ @vtype const char *
+ @vio in
+ @endvar
+
+ @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>
+ -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
+ @endreturndesc
+@@*/
+int PUGH_EnableGroupStorage (cGH *GH, const char *groupname)
{
-
DECLARE_CCTK_PARAMETERS
-
int group; /* group index */
int first_var; /* first variable's index */
cGroup pgroup; /* group information */
- int rc; /* return code */
+ int retval;
pGA *GA;
pGH *pughGH;
+
#ifdef DEBUG_PUGH
- printf(" PUGH_EnableGroupStorage: request for group '%s'\n", groupname);
- fflush(stdout);
+ printf (" PUGH_EnableGroupStorage: request for group '%s'\n", groupname);
+ fflush (stdout);
#endif
- pughGH = PUGH_pGH(GH);
- group = CCTK_GroupIndex(groupname);
+ pughGH = PUGH_pGH (GH);
+ group = CCTK_GroupIndex (groupname);
- if (group > -1 && pughGH)
+ if (pughGH && group >= 0)
{
- first_var = CCTK_FirstVarIndexI(group);
+ first_var = CCTK_FirstVarIndexI (group);
/* get the group info from its index */
- CCTK_GroupData(group, &pgroup);
+ CCTK_GroupData (group, &pgroup);
/* SCALAR types have always switched on memory */
if (pgroup.grouptype == CCTK_SCALAR)
{
- rc = 1;
+ retval = 1;
}
else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
{
- rc = PUGH_EnableGArrayGroupStorage(pughGH,
- first_var,
- pgroup.numvars,
- pgroup.numtimelevels);
+ retval = PUGH_EnableGArrayGroupStorage (pughGH,
+ first_var,
+ pgroup.numvars,
+ pgroup.numtimelevels);
}
else
{
- CCTK_WARN(1, "Unknown group type in PUGH_EnableGroupStorage");
- rc = -1;
+ CCTK_WARN (1, "Unknown group type in PUGH_EnableGroupStorage");
+ retval = -1;
}
- if (rc == 0)
+ if (retval == 0)
{
/* get GA pointer of first var in group */
GA = (pGA *) pughGH->variables[first_var][0];
- totalnumber += pgroup.numvars*pgroup.numtimelevels;
- totalstorage += ((float)(GA->extras->npoints * GA->varsize *
- pgroup.numtimelevels * pgroup.numvars))/(1024*1024);
+ 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)
+ if (storage_verbose && retval >= 0)
{
- if (rc == 0)
- {
- /* Memory toggled */
- printf("Switched memory on for %s \n "
- " [Num Arrays: %d Total Size: %6.2fMB]\n",
+ printf ("%s for group '%s'\n"
+ " [Num Arrays: %d Total Size: %6.2fMB]\n",
+ retval ? "Memory already on" : "Switched memory on",
groupname, totalnumber, totalstorage);
- }
- else if (rc == 1)
- {
- /* Memory already on */
- printf("Memory already on for %s\n "
- " [Num Arrays: %d Total Size: %6.2fMB]\n",
- groupname, totalnumber, totalstorage);
- }
}
}
else
{
-
- if (!pughGH)
+ if (! pughGH)
{
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,
- "PUGH_EnableGroupStorage: Error with cctkGH pointer "
- "for group %s",groupname);
- rc = -2;
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "PUGH_EnableGroupStorage: Error with cctkGH pointer "
+ "for group %s", groupname);
+ retval = -2;
}
else
{
- CCTK_VWarn(1,__LINE__,__FILE__,CCTK_THORNSTRING,
- "PUGH_EnableGroupStorage: Invalid group %s",groupname);
- rc = -3;
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "PUGH_EnableGroupStorage: Invalid group %s", groupname);
+ retval = -3;
}
-
}
- return (rc);
-
+ return (retval);
}
-/*@@
- @routine PUGH_DisableGroupStorage
- @author Tom Goodale
- @date 30 Mar 1999
- @desc
- Disables storage for all variables in the group indicated by groupname.
- @enddesc
- @calls CCTK_DecomposeName CCTK_GroupIndex CCTK_GroupData CCTK_WARN
- @history
+ /*@@
+ @routine PUGH_DisableGroupStorage
+ @author Tom Goodale
+ @date 30 Mar 1999
+ @desc
+ Disables storage for all variables in the group
+ indicated by groupname.
+ @enddesc
+ @calls CCTK_GroupIndex
+ CCTK_GroupData
+ CCTK_FirstVarIndexI
+ PUGH_DisableGArrayGroupStorage
- @endhistory
- @var GH
- @vdesc Pointer to CCTK grid hierarchy
- @vtype cGH
- @vio in
- @endvar
- @var groupname
- @vdesc name of the group to be synchronized
- @vtype const char *
- @vio in
- @endvar
- @@*/
-
-int PUGH_DisableGroupStorage(cGH *GH, const char *groupname)
-{
+ @var GH
+ @vdesc Pointer to CCTK grid hierarchy
+ @vtype cGH *
+ @vio in
+ @endvar
+ @var groupname
+ @vdesc name of the group to enable storage for
+ @vtype const char *
+ @vio in
+ @endvar
+
+ @returntype int
+ @returndesc
+ 1 if storage for given group was disabled
+ -1 if group type is invalid
+ @endreturndesc
+@@*/
+int PUGH_DisableGroupStorage (cGH *GH, const char *groupname)
+ {
DECLARE_CCTK_PARAMETERS
-
int group; /* group index */
cGroup pgroup; /* group information */
- int rc; /* return code */
- pGH *pughGH; /* PUGH extension reference */
+ int retval;
+ pGA ***variables;
pGA *GA;
int level;
- int first_var,var;
+ int first_var, var;
int unchanged; /* count how many aren't toggled */
- /* get PUGH extension handle */
- pughGH = PUGH_pGH(GH);
-
+
#ifdef DEBUG_PUGH
- printf(" PUGH_DisableGroupStorage: request for group '%s'\n", groupname);
- fflush(stdout);
+ printf (" PUGH_DisableGroupStorage: request for group '%s'\n", groupname);
+ fflush (stdout);
#endif
- /* get the group info from its index */
- group = CCTK_GroupIndex(groupname);
- CCTK_GroupData(group, &pgroup);
+ group = CCTK_GroupIndex (groupname);
+ CCTK_GroupData (group, &pgroup);
/* get global index of first variable in group */
- first_var = CCTK_FirstVarIndexI(group);
+ first_var = CCTK_FirstVarIndexI (group);
+
+ variables = (pGA ***) PUGH_pGH (GH)->variables;
+ /* get the group info from its index */
unchanged = 0;
- if (pgroup.grouptype == CCTK_SCALAR)
- {
- rc = 1;
- }
- else if (pgroup.grouptype == CCTK_GF || pgroup.grouptype == CCTK_ARRAY)
+ 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 = unchanged +
- PUGH_DisableGArrayDataStorage((pGA *)(pughGH->variables[var][level]));
+ unchanged += PUGH_DisableGArrayDataStorage (variables[var][level]);
}
}
-
- rc = 1;
}
- else
+ else if (pgroup.grouptype != CCTK_SCALAR)
{
- CCTK_WARN(1, "Unknown group type in PUGH_DisableGroupStorage");
- rc = 0;
+ CCTK_WARN (1, "Unknown group type in PUGH_DisableGroupStorage");
+ retval = -1;
}
/* Report on memory usage */
- if (storage_verbose)
+ if (storage_verbose && retval >= 0)
{
if (unchanged == 0)
{
- GA = (pGA *) pughGH->variables[first_var][0];
+ GA = variables[first_var][0];
/* Memory toggled */
totalnumber -= pgroup.numvars;
- totalstorage -= (float) (GA->extras->npoints * GA->varsize *
- pgroup.numtimelevels * pgroup.numvars) / (1024 * 1024);
- printf("Switched memory off for %s \n"
- " [Num Arrays: %d Total Size: %6.2fMB]\n",
- groupname, totalnumber, totalstorage);
+ totalstorage -= (variables[first_var][0]->extras->npoints *
+ variables[first_var][0]->varsize *
+ pgroup.numtimelevels * pgroup.numvars) /
+ (float) (1024 * 1024);
+ printf ("Switched memory off for group '%s'\n"
+ " [Num Arrays: %d Total Size: %6.2fMB]\n",
+ groupname, totalnumber, totalstorage);
}
else if (unchanged == pgroup.numvars)
{
/* Memory already off */
- printf("Memory already off for %s\n",groupname);
+ printf ("Memory already off for group '%s'\n", groupname);
}
else
{
- CCTK_WARN(1,"Inconsistency in group memory assignment");
+ CCTK_WARN (1, "Inconsistency in group memory assignment");
}
}
- return (rc);
+ return (retval);
}
-/*****************************************************************************/
-/* local functions */
-/*****************************************************************************/
+/********************************************************************
+ ******************** Internal Routines ************************
+ ********************************************************************/
-int PUGH_EnableGArrayGroupStorage(pGH *pughGH,
- int first_var,
- int n_variables,
- int n_timelevels)
+ /*@@
+ @routine PUGH_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 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 enabled (for at least one variable)
+ -1 if there was an inconsistency in storage allocation
+ @endreturndesc
+@@*/
+static int PUGH_EnableGArrayGroupStorage (pGH *pughGH,
+ int first_var,
+ int n_variables,
+ int n_timelevels)
{
DECLARE_CCTK_PARAMETERS
int nstorage; /* Number of Arrays for which storage was set */
@@ -436,8 +520,8 @@ int PUGH_EnableGArrayGroupStorage(pGH *pughGH,
pGA *GA;
int level;
- nstorage = 0;
- nnostorage = 0;
+
+ nstorage = nnostorage = 0;
for (var = first_var; var < first_var + n_variables; var++)
{
@@ -448,17 +532,17 @@ int PUGH_EnableGArrayGroupStorage(pGH *pughGH,
if (! GA->storage)
{
#ifdef DEBUG_PUGH
- printf(" PUGH_EnableGArrayGroupStorage: request for var '%s' "
- "timelevel %d\n", GA->name, level);
- fflush(stdout);
+ printf (" PUGH_EnableGArrayGroupStorage: request for var '%s' "
+ "timelevel %d\n", GA->name, level);
+ fflush (stdout);
#endif
- PUGH_EnableGArrayDataStorage(GA,
- pughGH->myproc,
- zero_memory,
- padding_active,
- padding_cacheline_bits,
- padding_size,
- padding_address_spacing);
+ PUGH_EnableGArrayDataStorage (GA,
+ pughGH->myproc,
+ zero_memory,
+ padding_active,
+ padding_cacheline_bits,
+ padding_size,
+ padding_address_spacing);
((cGH *) pughGH->callerid)->data[var][level] = GA->data;
@@ -474,124 +558,176 @@ int PUGH_EnableGArrayGroupStorage(pGH *pughGH,
if (nstorage > 0 && nnostorage > 0)
{
- CCTK_WARN(0, "Group storage violation in PUGH_EnableGArrayGroupStorage");
+ CCTK_WARN (0, "Group storage violation in PUGH_EnableGArrayGroupStorage");
retval = -1;
}
- else if (nstorage > 0)
- {
- retval = 1;
- }
- else if (nnostorage > 0)
- {
- retval = 0;
- }
else
{
- CCTK_WARN(0, "Problem in PUGH_EnableGArrayGroupStorage");
- retval = -1;
+ retval = nstorage > 0 ? 1 : 0;
}
- return retval;
-
+ return (retval);
}
-int PUGH_EnableGArrayDataStorage(pGA *GA,
- int this_proc,
- int zero_memory,
- int padding_active,
- int padding_cacheline_bits,
- int padding_size,
- int padding_address_spacing)
+ /*@@
+ @routine PUGH_EnableGArrayDataStorage
+ @author Tom Goodale
+ @date 30 Mar 1999
+ @desc
+ Allocates storage for a single variable.
+ For now this routine cannot be made static because it's used
+ in BAM :-(
+ @enddesc
+ @calls Util_CacheMalloc
+
+ @var GA
+ @vdesc Pointer to the variable's info structure
+ @vtype pGA *
+ @vio in
+ @endvar
+ @var this_proc
+ @vdesc the processor ID
+ @vtype int
+ @vio unused
+ @endvar
+ @var zero_memory
+ @vdesc flag indicating whether allocated memory should be zeroed or not
+ @vtype int
+ @vio in
+ @endvar
+ @var padding_active, padding_cacheline_bits, padding_size,
+ padding_address_spacing
+ @vdesc padding information
+ @vtype int
+ @vio unused
+ @endvar
+
+ @returntype int
+ @returndesc
+ 0 if storage was enabled
+ -1 if memory allocation failed
+ @endreturndesc
+@@*/
+/* static */ int PUGH_EnableGArrayDataStorage (pGA *GA,
+ int this_proc,
+ int zero_memory,
+ int padding_active,
+ int padding_cacheline_bits,
+ int padding_size,
+ int padding_address_spacing)
{
-
- if(GA->storage == PUGH_NOSTORAGE)
+ /* avoid compiler warnings about unused parameters */
+ this_proc = this_proc;
+ padding_active = padding_active;
+ padding_cacheline_bits = padding_cacheline_bits;
+ padding_size = padding_size;
+ padding_address_spacing = padding_address_spacing;
+
+ if (GA->storage == PUGH_NOSTORAGE)
{
+
#ifdef DEBUG_PUGH
- printf(" PUGH_EnableGArrayDataStorage: allocating storage "
- "for var '%s'\n", GA->name);
- fflush(stdout);
+ printf (" PUGH_EnableGArrayDataStorage: allocating storage "
+ "for var '%s'\n", GA->name);
+ fflush (stdout);
#endif
/* Now assign memory for the variable itself */
- if(GA->padddata)
+ if (GA->padddata)
{
- free(GA->padddata);
+ free (GA->padddata);
}
- if(!padding_active)
+ if (! padding_active)
{
/* Easy case. */
- if(zero_memory)
+ if (zero_memory)
{
- GA->padddata = calloc(GA->extras->npoints, GA->varsize);
+ GA->padddata = calloc (GA->extras->npoints, GA->varsize);
}
else
{
- GA->padddata = malloc(GA->extras->npoints * GA->varsize);
+ GA->padddata = malloc (GA->extras->npoints * GA->varsize);
}
GA->data = GA->padddata;
}
else
{
-
/* Use the Cactus Cache alignment function */
- GA->data = Util_CacheMalloc(GA->arrayid,
- GA->extras->npoints * GA->varsize,
- &(GA->padddata));
+ GA->data = Util_CacheMalloc (GA->arrayid,
+ GA->extras->npoints * GA->varsize,
+ &GA->padddata);
/* Zero the memory if desired. */
- if(GA->data && zero_memory)
+ if (GA->data && zero_memory)
{
- memset(GA->data, 0, GA->extras->npoints * GA->varsize);
+ memset (GA->data, 0, GA->extras->npoints * GA->varsize);
}
}
}
- if (!GA->padddata)
+ if (! GA->padddata)
{
CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
- "FATAL ERROR: Cannot allocate data for %s [%d]\n",
+ "FATAL ERROR: Cannot allocate data for '%s' [%d]\n",
GA->name, GA->id);
}
GA->storage = PUGH_STORAGE;
- return 0;
-
+ return (GA->padddata ? 0 : -1);
}
-int PUGH_DisableGArrayDataStorage(pGA *GA)
+ /*@@
+ @routine PUGH_DisableGArrayDataStorage
+ @author Tom Goodale
+ @date 30 Mar 1999
+ @desc
+ Frees allocated storage for a variable
+ 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 *
+ @vio in
+ @endvar
+
+ @returntype int
+ @returndesc
+ 1 if storage was already disabled
+ 0 if storage was freed
+ @endreturndesc
+@@*/
+/* static */ int PUGH_DisableGArrayDataStorage (pGA *GA)
{
int retval;
+
+ retval = GA->storage != PUGH_STORAGE;
+
if (GA->storage == PUGH_STORAGE)
{
+
#ifdef DEBUG_PUGH
- printf(" PUGH_DisableGArrayDataStorage: freeing storage for var '%s'\n",
- GA->name);
- fflush(stdout);
+ printf ("PUGH_DisableGArrayDataStorage: freeing storage for var '%s'\n",
+ GA->name);
+ fflush (stdout);
#endif
+
if (GA->padddata)
{
- free(GA->padddata);
- GA->padddata = NULL;
- GA->data = NULL;
+ free (GA->padddata);
}
-
- GA->padddata = calloc(1, GA->varsize);
+ GA->padddata = calloc (1, GA->varsize);
GA->data = GA->padddata;
-
GA->storage = PUGH_NOSTORAGE;
- retval = 0;
- }
- else
- {
- retval = 1;
}
- return retval;
+ return (retval);
}