/*@@ @file ReductionMax.c @date @author Tom Goodale, Yaakoub Y El Khamra @desc Defines the reduction operator to get the average of an arbitrary array. @enddesc @version $Id$ @@*/ #include #include #include "local_reductions.h" #include "Max_Functions.h" static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusBase_LocalReduce_ReductionMax_c); /* Define the reduction operations */ /* local function prototypes */ static int ReductionMax (int N_dims, int operator_handle, int param_table_handle, int N_input_arrays, const CCTK_INT input_array_dims[], const CCTK_INT input_array_type_codes[], const void *const input_arrays[], int M_output_numbers, const CCTK_INT output_number_type_codes[], void * const output_numbers[]); /*@@ @routine LocalReduce_Max @author Tom Goodale, Yaakoub Y El Khamra @date @desc @enddesc @history @endhistory @var N_dims @vdesc number of dimensions in the *reduction* @vtype int @vio in @endvar @var operator_handle @vdesc operator handle specificies the type of reduction we will perform @vtype int @vio in @endvar @var param_table_handle @vdesc handle to "parameter table", a key-value table @vtype int @vio in @endvar @var N_input_arrays @vdesc number of input arrays @vtype int @vio in @endvar @var input_array_dims @vdesc array of input array dimensions (common to all input arrays) @vtype const CCTK_INT @vio in @endvar @var input_array_type_codes @vdesc array of CCTK_VARIABLE_* codes giving data types of input arrays @vtype const CCTK_INT @vio in @endvar @var input_arrays @vdesc array of pointers to input arrays @vtype const void *const @vio in @endvar @var M_output_numbers @vdesc @vtype int @vio in @endvar @var output_number_type_codes @vdesc array of CCTK_VARIABLE_* codes giving data types of output numbers @vtype const CCTK_INT @vio in @endvar @var output_numbers @vdesc array[M_output_numbers] of pointers to output numbers[M_reduce_numbers] @vtype void *const @vio in @endvar @@*/ int LocalReduce_Max (int N_dims, int operator_handle, int param_table_handle, int N_input_arrays, const CCTK_INT input_array_dims[], const CCTK_INT input_array_type_codes[], const void *const input_arrays[], int M_output_numbers, const CCTK_INT output_number_type_codes[], void * const output_numbers[]) { return (LocalReduce_Reduce (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, ReductionMax)); } /*****************************************************************************/ /* local functions */ /*****************************************************************************/ /*@@ @routine ReductionMax @date @author Tom Goodale, Yaakoub Y El Khamra @desc Returns the average of a distributed array with 'num_points' elements. Global reduction is done element-wise (num_outvals == 1) or on the results of the local reductions. @enddesc @@*/ static int ReductionMax (int N_dims, int operator_handle, int param_table_handle, int N_input_arrays, const CCTK_INT input_array_dims[], const CCTK_INT input_array_type_codes[], const void *const input_arrays[], int M_output_numbers, const CCTK_INT output_number_type_codes[], void * const output_numbers[]) { /* utility variables */ int i, j, num_points; int * iters_per_dim; int global_calling = 0; /* indices to hold the temp indices of size N_dims and iteration indices*/ int * indices; int * actual_indices; int * actual_iters_per_dim; int max_iter = 0; int max_index = 1; /* data pointer offset and strides declared here */ CCTK_INT * input_array_offsets; CCTK_INT * input_array_strides; CCTK_INT * input_array_min_subscripts; CCTK_INT * input_array_max_subscripts; /* weight variables declared here */ int weight_on = 0; /* weight is by default off=0 */ void const * weight; /* pointer to the weight variable */ /* prevent warnings for unused vars */ (void)(operator_handle + 0); /* set the number of points */ num_points = 0; /* allocate memory for iters_per_dim */ iters_per_dim = (int *)malloc(N_dims * sizeof(int)); /* allocate then initialize the values of the strides and subscripts */ indices = (int *)malloc (N_dims * sizeof(int)); actual_indices = (int *)malloc (N_dims * sizeof(int)); actual_iters_per_dim = (int *)malloc (N_dims * sizeof(int)); /* allocate then initialize the values of the strides and subscripts */ input_array_offsets = (CCTK_INT *)malloc (N_input_arrays * sizeof(CCTK_INT)); input_array_strides = (CCTK_INT *) malloc (N_dims * sizeof(CCTK_INT)); input_array_min_subscripts = (CCTK_INT *) malloc (N_dims * sizeof(CCTK_INT)); input_array_max_subscripts = (CCTK_INT *) malloc (N_dims * sizeof(CCTK_INT)); for (i = 0; i