diff options
author | tradke <tradke@d60812e6-3970-4df4-986e-c251b06effeb> | 2003-03-10 13:10:47 +0000 |
---|---|---|
committer | tradke <tradke@d60812e6-3970-4df4-986e-c251b06effeb> | 2003-03-10 13:10:47 +0000 |
commit | f69684d7aba78edce0e0465e8ba338ae19a1e4b7 (patch) | |
tree | a1dcfc5e5c9db511b4129a7b637a5c8d2f2a419d /src/Reduction.c | |
parent | 5a55318a46ef9e35ff93d0b36bd4053a1734c61a (diff) |
Almost forgot to commit this: added 'const' qualifiers to all the read-only
input arguments for the reduction API.
You also need an up-to-date flesh now in order to compile.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGHReduce/trunk@35 d60812e6-3970-4df4-986e-c251b06effeb
Diffstat (limited to 'src/Reduction.c')
-rw-r--r-- | src/Reduction.c | 169 |
1 files changed, 85 insertions, 84 deletions
diff --git a/src/Reduction.c b/src/Reduction.c index 388fdd6..a088414 100644 --- a/src/Reduction.c +++ b/src/Reduction.c @@ -2,9 +2,9 @@ @file Reduction.c @date Thu Apr 3 11:54:53 1997 @author Thomas Radke, Paul Walker - @desc - Various MPI reduction operators. - @enddesc + @desc + Various MPI reduction operators. + @enddesc @version $Id$ @@*/ @@ -20,15 +20,15 @@ CCTK_FILEVERSION(CactusPUGH_PUGHReduce_Reduction_c) ********************* Local Routine Prototypes ********************* ********************************************************************/ -static int PUGH_ReductionGA (cGH *GH, - int vindex, - int proc, - CCTK_REAL *outval, - reduction_fn_t reduction_fn); +static int ReductionGA (const cGH *GH, + int vindex, + int proc, + CCTK_REAL *outval, + reduction_fn_t reduction_fn); -static int PUGH_ReductionScalar (cGH *GH, int vindex, int proc, - CCTK_REAL *outval, - reduction_fn_t reduction_fn); +static int ReductionScalar (const cGH *GH, int vindex, int proc, + CCTK_REAL *outval, + reduction_fn_t reduction_fn); static int copy_real_to_outtype (int num_elems, CCTK_REAL inarray [/* num_elems */], @@ -44,16 +44,16 @@ static int copy_real_to_outtype (int num_elems, @routine PUGH_ReductionArrays @author Thomas Radke @date 19 Aug 1999 - @desc + @desc Wrapper to reduce a list of arrays. Just calls the appropriate reduction operator and does the type conversion of the results. @enddesc @calls copy_real_to_outtype - + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH * + @vtype const cGH * @vio in @endvar @var proc @@ -84,7 +84,7 @@ static int copy_real_to_outtype (int num_elems, @endvar @var inarrays @vdesc field of input arrays - @vtype void ** + @vtype const void *const * @vio in @endvar @var outtype @@ -115,13 +115,13 @@ static int copy_real_to_outtype (int num_elems, -2 if <num_outvals> is invalid @endreturndesc @@*/ -int PUGH_ReductionArrays (cGH *GH, +int PUGH_ReductionArrays (const cGH *GH, int proc, int num_dims, - int dims[/* num_dims */], + const int dims[/* num_dims */], int intype, int num_inarrays, - void *inarrays[/* num_inarrays */], + const void *const inarrays[/* num_inarrays */], int outtype, int num_outvals, void *outvals /* [num_outvals] */, @@ -167,35 +167,35 @@ int PUGH_ReductionArrays (cGH *GH, /* set the array types to intype */ /* FIXME: could allow to pass in arrays of different types now !!! */ - intypes = (int *) malloc (num_inarrays * sizeof (int)); + intypes = malloc (num_inarrays * sizeof (int)); for (i = 0; i < num_inarrays; i++) { intypes[i] = intype; } - buffer = (CCTK_REAL *) malloc (num_outvals * sizeof (CCTK_REAL)); + buffer = malloc (num_outvals * sizeof (CCTK_REAL)); /* do the reduction on the input arrays */ - retval = reduction_fn (GH, - proc, - num_dims, - from, - to, - iterator, + retval = reduction_fn (GH, + proc, + num_dims, + from, + to, + iterator, points_per_dim, - num_points, - num_inarrays, - intypes, + num_points, + num_inarrays, + intypes, inarrays, - num_outvals, + num_outvals, buffer); if (retval == 0 && (proc < 0 || proc == CCTK_MyProc (GH))) { /* type-cast the result to the requested datatype */ - retval = copy_real_to_outtype (num_inarrays * num_outvals, + retval = copy_real_to_outtype (num_inarrays * num_outvals, buffer, - outtype, + outtype, outvals); } @@ -210,20 +210,20 @@ int PUGH_ReductionArrays (cGH *GH, @routine PUGH_ReductionGVs @author Thomas Radke @date 19 Aug 1999 - @desc + @desc Wrapper to reduce a list of grid variables. Just calls the appropriate reduction operator and does the type conversion of the results. @enddesc @calls CCTK_VarTypeSize CCTK_GroupTypeFromVarI - PUGH_ReductionGA - PUGH_ReductionScalar + ReductionGA + ReductionScalar copy_real_to_outtype - + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH * + @vtype const cGH * @vio in @endvar @var proc @@ -237,9 +237,9 @@ int PUGH_ReductionArrays (cGH *GH, @vtype int @vio in @endvar - @var inarrays + @var invars @vdesc field of input arrays - @vtype void ** + @vtype const int * @vio in @endvar @var outtype @@ -268,10 +268,10 @@ int PUGH_ReductionArrays (cGH *GH, the return code of the reduction operator @endreturndesc @@*/ -int PUGH_ReductionGVs (cGH *GH, +int PUGH_ReductionGVs (const cGH *GH, int proc, int num_invars, - int invars[/* num_invars */], + const int invars[/* num_invars */], int outtype, int num_outvals, void *outvals /* [num_outvals] */, @@ -304,12 +304,12 @@ int PUGH_ReductionGVs (cGH *GH, { case CCTK_GF: case CCTK_ARRAY: - this_retval = PUGH_ReductionGA (GH, invars[i], proc, &result, + this_retval = ReductionGA (GH, invars[i], proc, &result, reduction_fn); break; case CCTK_SCALAR: - this_retval = PUGH_ReductionScalar (GH, invars[i], proc, &result, + this_retval = ReductionScalar (GH, invars[i], proc, &result, reduction_fn); break; @@ -337,69 +337,71 @@ int PUGH_ReductionGVs (cGH *GH, ********************************************************************/ /*@@ - @routine PUGH_ReductionGA + @routine ReductionGA @date Fri Jun 29 15:35:01 2001 @author Tom Goodale - @desc - Reduction of a grid array variable. - @enddesc - + @desc + Reduction of a grid array variable. + @enddesc + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH * + @vtype const cGH * @vio in - @endvar + @endvar @var vindex @vdesc The GV index @vtype int @vio in - @endvar + @endvar @var proc @vdesc The processor at which we desire the result @vtype int @vio in - @endvar + @endvar @var outval @vdesc buffer to store the reduction result in @vtype CCTK_REAL * @vio out - @endvar + @endvar @var reduction_fn @vdesc The function which does the actual reduction @vtype reduction_fn_t @vio in - @endvar + @endvar @returntype int @returndesc The return code of the reduction operator. @endreturndesc @@*/ -static int PUGH_ReductionGA (cGH *GH, int vindex, int proc, CCTK_REAL *outval, - reduction_fn_t reduction_fn) +static int ReductionGA (const 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; + const void *data; char *fullname; int *from, *to, *iterator, *points_per_dim; /* get the GA structure for the current timelevel */ GA = ((pGA ***) PUGH_pGH (GH)->variables)[vindex][0]; + data = GA->data; /* 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'", + "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)); + from = malloc (4 * GA->connectivity->dim * sizeof (int)); to = from + 1*GA->connectivity->dim; iterator = from + 2*GA->connectivity->dim; points_per_dim = from + 3*GA->connectivity->dim; @@ -439,7 +441,7 @@ static int PUGH_ReductionGA (cGH *GH, int vindex, int proc, CCTK_REAL *outval, /* now do the reduction */ retval = reduction_fn (GH, proc, GA->connectivity->dim, from, to, iterator, - points_per_dim, num_points, 1, &GA->vtype, &GA->data, + points_per_dim, num_points, 1, &GA->vtype, &data, 1, outval); /* free temporary vectors */ @@ -450,59 +452,58 @@ static int PUGH_ReductionGA (cGH *GH, int vindex, int proc, CCTK_REAL *outval, /*@@ - @routine PUGH_ReductionScalar + @routine ReductionScalar @date Fri Jun 29 15:35:01 2001 @author Tom Goodale - @desc - Reduction of a scalar GV. - Basically a copy of PUGH_ReductionGA cut down to the scalar case. - @enddesc - + @desc + Reduction of a scalar GV. + Basically a copy of ReductionGA cut down to the scalar case. + @enddesc + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH * + @vtype const cGH * @vio in - @endvar + @endvar @var vindex @vdesc The GV index @vtype int @vio in - @endvar + @endvar @var proc @vdesc The processor at which we desire the result @vtype int @vio in - @endvar + @endvar @var outval @vdesc buffer to store the reduction result in @vtype CCTK_REAL * @vio out - @endvar + @endvar @var reduction_fn @vdesc The function which does the actual reduction @vtype reduction_fn_t @vio in - @endvar + @endvar @returntype int @returndesc The return code of the reduction operator. @endreturndesc @@*/ -static int PUGH_ReductionScalar (cGH *GH, - int vindex, - int proc, - CCTK_REAL *outval, - reduction_fn_t reduction_fn) +static int ReductionScalar (const cGH *GH, + int vindex, + int proc, + CCTK_REAL *outval, + reduction_fn_t reduction_fn) { int retval; - int num_points, from, to, iterator, points_per_dim, type; - - void *data; + const void *data; + /* get the data for the current timelevel */ - data = ((void ***) PUGH_pGH (GH)->variables)[vindex][0]; + data = ((const void ***) PUGH_pGH (GH)->variables)[vindex][0]; from = 0; to = 1; @@ -525,16 +526,16 @@ static int PUGH_ReductionScalar (cGH *GH, @routine copy_real_to_outtype @author Thomas Radke @date 19 Aug 1999 - @desc + @desc Does the type conversion from CCTK_REAL into the requested datatype. @enddesc @calls CCTK_VarTypeSize CCTK_GroupTypeFromVarI - PUGH_ReductionGA - PUGH_ReductionScalar + ReductionGA + ReductionScalar copy_real_to_outtype - + @var num_elems @vdesc number of elements to convert @vtype int |