diff options
Diffstat (limited to 'src/Reduction.c')
-rw-r--r-- | src/Reduction.c | 72 |
1 files changed, 9 insertions, 63 deletions
diff --git a/src/Reduction.c b/src/Reduction.c index 91d3bc6..118e74d 100644 --- a/src/Reduction.c +++ b/src/Reduction.c @@ -23,7 +23,7 @@ CCTK_FILEVERSION(CCTDevelopment_LocalReduce_Reduction_c); static int copy_real_to_outtype (int num_elems, CCTK_REAL inarray [/* num_elems */], int outtype, - void *outarray /* [num_elems] */); + void *const outarray /* [num_elems] */); /******************************************************************** @@ -99,71 +99,16 @@ int LocalReduce_Reduce (int N_dims, int operator_handle, const void *const input_arrays[], int M_output_numbers, const CCTK_INT output_number_type_codes[], - void *const output_numbers[], + void * const output_numbers[], reduction_fn_t reduction_fn) { - int i, num_points, retval; - int from[1], to[1], iterator[1], points_per_dim[1]; - int *intypes; - CCTK_REAL *buffer; - - - points_per_dim[0] = 1; - from[0] = 0; - to[0] = input_array_dims[0]; - - /* get the total number of array elements */ - for (i = 1; i < N_dims; i++) - { - to[0] *= input_array_dims[i]; - } - - /* check for zero-sized arrays */ - if (to[0] <= 0) - { - CCTK_WARN (2, "LocalReduce_Reduce: Cannot reduce zero-sized arrays"); - return (-1); - } - - if (M_output_numbers != 1) - { - if (M_output_numbers != to[0]) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "LocalLocalReduce_Reduce: Don't know how to reduce " - "a %d-dimensional array with %d elements " - "to an output array of %d elements", - N_dims, to[0], M_output_numbers); - return (-2); - } - to[0] = 1; - } - num_points = to[0]; - - /* set the array types to intype */ - /* FIXME: could allow to pass in arrays of different types now !!! */ - intypes = malloc (N_input_arrays * sizeof (int)); - for (i = 0; i < N_input_arrays; i++) - { - intypes[i] = input_array_type_codes[i]; - } - - buffer = malloc (M_output_numbers * sizeof (CCTK_REAL)); - + int retval; /* do the reduction on the input arrays */ - retval = reduction_fn (N_dims, from, to, iterator, points_per_dim, - num_points, 1, N_input_arrays, intypes, input_arrays, - M_output_numbers, buffer); - - if (retval == 0 ) - { - /* type-cast the result to the requested datatype */ -/* retval = copy_real_to_outtype (N_input_arrays * M_output_numbers, - buffer, output_number_type_codes, output_numbers);*/ - } - - free (intypes); - free (buffer); + retval = reduction_fn (N_dims, operator_handle, + param_table_handle, N_input_arrays, + input_array_dims, input_array_type_codes, + input_arrays, M_output_numbers, + output_number_type_codes, output_numbers); return (retval); } @@ -178,6 +123,7 @@ int LocalReduce_Reduce (int N_dims, int operator_handle, @enddesc @calls CCTK_VarTypeSize CCTK_GroupTypeFromVarI + ReductionGA ReductionScalar copy_real_to_outtype |