From e2e1eed3fae6ba2d1bf7304e3c33c7710a9602d4 Mon Sep 17 00:00:00 2001 From: goodale Date: Fri, 29 Jun 2001 14:02:02 +0000 Subject: Reduction for Grid Scalars. Weakly tested. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGH/PUGHReduce/trunk@16 d60812e6-3970-4df4-986e-c251b06effeb --- src/Reduction.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Reduction.c b/src/Reduction.c index 6316a22..035b126 100644 --- a/src/Reduction.c +++ b/src/Reduction.c @@ -26,6 +26,9 @@ static int PUGH_ReductionGA (cGH *GH, CCTK_REAL *outval, reduction_fn_t reduction_fn); +static int PUGH_ReductionScalar (cGH *GH, int index, int proc, CCTK_REAL *outval, + reduction_fn_t reduction_fn); + static int copy_real_to_outtype (int num_elems, CCTK_REAL inarray [/* num_elems */], int outtype, @@ -208,8 +211,8 @@ int PUGH_ReductionGVs (cGH *GH, break; case CCTK_SCALAR: - CCTK_WARN (1, "PUGH_ReductionGVs: Reducing scalars doesn't make sense"); - this_retval = -1; + this_retval = PUGH_ReductionScalar (GH, invars[i], proc, &result, + reduction_fn); break; default: @@ -311,6 +314,84 @@ static int PUGH_ReductionGA (cGH *GH, int index, int proc, CCTK_REAL *outval, return (retval); } + /*@@ + @routine PUGH_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 + @calls + @calledby + @history + + @endhistory + @var GH + @vdesc A CCTK GH + @vtype cGH * + @vio in + @vcomment + + @endvar + @var index + @vdesc The GV index + @vtype int + @vio in + @vcomment + + @endvar + @var proc + @vdesc The processor at which we desire the result + @vtype int + @vio in + @vcomment + + @endvar + @var reduction_fn + @vdesc The function which does the actual reduction + @vtype reduction_fn_t + @vio in + @vcomment + + @endvar + + @returntype int + @returndesc + The return code of the reduction operator. + @endreturndesc +@@*/ +static int PUGH_ReductionScalar (cGH *GH, + int index, + int proc, + CCTK_REAL *outval, + reduction_fn_t reduction_fn) +{ + int retval; + + int num_points, from, to, iterator, points_per_dim, type; + + void *data; + + /* get the data for the current timelevel */ + data = ((void ***) PUGH_pGH (GH)->variables)[index][0]; + + from = 0; + to = 1; + iterator = 1; + points_per_dim = 1; + type = CCTK_VarTypeI (index); + + num_points = 1; + + /* now do the reduction */ + retval = reduction_fn (GH, proc, 1, &from, &to, &iterator, + &points_per_dim, num_points, 1, &type, &data, + 1, outval); + + return retval; +} + /*@@ @routine copy_real_to_outtype -- cgit v1.2.3