diff options
author | tradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2001-05-07 21:14:56 +0000 |
---|---|---|
committer | tradke <tradke@b61c5cb5-eaca-4651-9a7a-d64986f99364> | 2001-05-07 21:14:56 +0000 |
commit | d03733b0bfa1b7ea2bb09b84c820c19ade5efc36 (patch) | |
tree | 18dd74faf4ed31f9dc7a6bcc174131ae5ab2fa7e /src/Storage.c | |
parent | b2b5ce55a0f055069670fc48cd883ba2365081c6 (diff) |
Initialize memory for allocated CCTK variables according to the setting of
"PUGH::initialize_memory".
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGH/trunk@322 b61c5cb5-eaca-4651-9a7a-d64986f99364
Diffstat (limited to 'src/Storage.c')
-rw-r--r-- | src/Storage.c | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/src/Storage.c b/src/Storage.c index 3c06d3a..382d1da 100644 --- a/src/Storage.c +++ b/src/Storage.c @@ -395,7 +395,6 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname) cGroup pgroup; /* group information */ int retval; pGA ***variables; - pGA *GA; int level; int first_var, var; int unchanged; /* count how many aren't toggled */ @@ -439,8 +438,6 @@ int PUGH_DisableGroupStorage (cGH *GH, const char *groupname) { if (unchanged == 0) { - GA = variables[first_var][0]; - /* Memory toggled */ totalnumber -= pgroup.numvars; totalstorage -= (variables[first_var][0]->extras->npoints * @@ -538,7 +535,7 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, #endif PUGH_EnableGArrayDataStorage (GA, pughGH->myproc, - zero_memory, + initialize_memory, padding_active, padding_cacheline_bits, padding_size, @@ -591,9 +588,9 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, @vtype int @vio unused @endvar - @var zero_memory - @vdesc flag indicating whether allocated memory should be zeroed or not - @vtype int + @var initialize_memory + @vdesc how to initialize allocated memory + @vtype const char * @vio in @endvar @var padding_active, padding_cacheline_bits, padding_size, @@ -611,12 +608,15 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, @@*/ /* static */ int PUGH_EnableGArrayDataStorage (pGA *GA, int this_proc, - int zero_memory, + const char *initialize_memory, int padding_active, int padding_cacheline_bits, int padding_size, int padding_address_spacing) { + const char *vtypename; + + /* avoid compiler warnings about unused parameters */ this_proc = this_proc; padding_active = padding_active; @@ -628,30 +628,30 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, { #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) { free (GA->padddata); + GA->padddata = NULL; } - if (! padding_active) + if (GA->extras->npoints * GA->varsize <= 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "PUGH_EnableGArrayDataStorage: Tried to allocate storage " + "for zero-sized variable '%s'", GA->name); + GA->data = GA->padddata = NULL; + } + else if (! padding_active) { /* Easy case. */ - if (zero_memory) - { - GA->padddata = calloc (GA->extras->npoints, GA->varsize); - } - else - { - GA->padddata = malloc (GA->extras->npoints * GA->varsize); - } - - GA->data = GA->padddata; + GA->data = malloc (GA->extras->npoints * GA->varsize); + GA->padddata = GA->data; } else { @@ -659,13 +659,32 @@ static int PUGH_EnableGArrayGroupStorage (pGH *pughGH, GA->data = Util_CacheMalloc (GA->arrayid, GA->extras->npoints * GA->varsize, &GA->padddata); + } - /* Zero the memory if desired. */ - if (GA->data && zero_memory) + /* 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); + } } } |