diff options
author | tradke <tradke@d60812e6-3970-4df4-986e-c251b06effeb> | 2002-04-08 15:36:58 +0000 |
---|---|---|
committer | tradke <tradke@d60812e6-3970-4df4-986e-c251b06effeb> | 2002-04-08 15:36:58 +0000 |
commit | 06020a849697583712c75ff1e8d262b015d2618c (patch) | |
tree | 28a83f506d519c826502fda21133dabe2756b8f9 | |
parent | 5c54e5f80ad1006b60d5c5ed00fccf3578c511e0 (diff) |
Check for zero-sized arrays and return an error in case.
This closes PR CactusPUGH/961.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGHReduce/trunk@25 d60812e6-3970-4df4-986e-c251b06effeb
-rw-r--r-- | src/Reduction.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/Reduction.c b/src/Reduction.c index 8ac7dfd..388fdd6 100644 --- a/src/Reduction.c +++ b/src/Reduction.c @@ -21,12 +21,12 @@ CCTK_FILEVERSION(CactusPUGH_PUGHReduce_Reduction_c) ********************************************************************/ static int PUGH_ReductionGA (cGH *GH, - int index, + int vindex, int proc, CCTK_REAL *outval, reduction_fn_t reduction_fn); -static int PUGH_ReductionScalar (cGH *GH, int index, int proc, +static int PUGH_ReductionScalar (cGH *GH, int vindex, int proc, CCTK_REAL *outval, reduction_fn_t reduction_fn); @@ -110,7 +110,9 @@ static int copy_real_to_outtype (int num_elems, @returntype int @returndesc - the return code of the reduction operator + the return code of the reduction operator, or<BR> + -1 if array size is zero<BR> + -2 if <num_outvals> is invalid @endreturndesc @@*/ int PUGH_ReductionArrays (cGH *GH, @@ -135,11 +137,19 @@ int PUGH_ReductionArrays (cGH *GH, from[0] = 0; to[0] = dims[0]; + /* get the total number of array elements */ for (i = 1; i < num_dims; i++) { to[0] *= dims[i]; } + /* check for zero-sized arrays */ + if (to[0] <= 0) + { + CCTK_WARN (2, "PUGH_ReductionArrays: Cannot reduce zero-sized arrays"); + return (-1); + } + if (num_outvals != 1) { if (num_outvals != to[0]) @@ -149,7 +159,7 @@ int PUGH_ReductionArrays (cGH *GH, "a %d-dimensional array with %d elements " "to an output array of %d elements", num_dims, to[0], num_outvals); - return (-1); + return (-2); } to[0] = 1; } @@ -339,7 +349,7 @@ int PUGH_ReductionGVs (cGH *GH, @vtype cGH * @vio in @endvar - @var index + @var vindex @vdesc The GV index @vtype int @vio in @@ -365,16 +375,28 @@ int PUGH_ReductionGVs (cGH *GH, The return code of the reduction operator. @endreturndesc @@*/ -static int PUGH_ReductionGA (cGH *GH, int index, int proc, CCTK_REAL *outval, +static int PUGH_ReductionGA (cGH *GH, int vindex, int proc, CCTK_REAL *outval, reduction_fn_t reduction_fn) { int i, stagger_index, num_points, dir_points, retval; pGA *GA; + char *fullname; int *from, *to, *iterator, *points_per_dim; /* get the GA structure for the current timelevel */ - GA = ((pGA ***) PUGH_pGH (GH)->variables)[index][0]; + GA = ((pGA ***) PUGH_pGH (GH)->variables)[vindex][0]; + + /* check for zero-sized arrays */ + if (GA->extras->npoints <= 0) + { + fullname = CCTK_FullName (vindex); + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "PUGH_ReductionGA: Cannot reduce zero-sized grid array '%s'", + fullname); + free (fullname); + return (-1); + } /* allocate temporary vectors */ from = (int *) malloc (4 * GA->connectivity->dim * sizeof (int)); @@ -441,7 +463,7 @@ static int PUGH_ReductionGA (cGH *GH, int index, int proc, CCTK_REAL *outval, @vtype cGH * @vio in @endvar - @var index + @var vindex @vdesc The GV index @vtype int @vio in @@ -468,7 +490,7 @@ static int PUGH_ReductionGA (cGH *GH, int index, int proc, CCTK_REAL *outval, @endreturndesc @@*/ static int PUGH_ReductionScalar (cGH *GH, - int index, + int vindex, int proc, CCTK_REAL *outval, reduction_fn_t reduction_fn) @@ -480,13 +502,13 @@ static int PUGH_ReductionScalar (cGH *GH, void *data; /* get the data for the current timelevel */ - data = ((void ***) PUGH_pGH (GH)->variables)[index][0]; + data = ((void ***) PUGH_pGH (GH)->variables)[vindex][0]; from = 0; to = 1; iterator = 1; points_per_dim = 1; - type = CCTK_VarTypeI (index); + type = CCTK_VarTypeI (vindex); num_points = 1; |