/*@@ @header local_reductions.h @date @author Tom Goodale, Yaakoub Y El Khamra @desc Prototypes for local reduction operators @enddesc @version $Header$ @@*/ #ifndef _LOCAL_REDUCTIONS_H_ #define _LOCAL_REDUCTIONS_H_ #include "cctk.h" #include "util_Table.h" #include "cctk_Reduction.h" #ifdef __cplusplus extern "C" { #endif #define ITERATE_ON_ARRAY(i,cctk_type, in_data, out_type, out_num, mask_on,input_array_offset, indices, sum_indices, max_iter, iter, flag, actual_indices,input_array_strides, input_array_min_subscripts,product) \ { \ iter = 0; \ sum_indices = 0; \ num_points = 1; \ const cctk_type * typed_vdata = (const cctk_type *)(in_data); \ out_type inval; \ out_type * outval = (out_type *) out_num; \ REDUCTION_INITIAL( * outval) \ if ( mask_on == 1) \ { \ if ( input_array_offset == 0) \ { \ while (iter < max_iter) \ { \ inval = (out_type) typed_vdata[sum_indices]; \ REDUCTION_OPERATION(*outval,inval); \ num_points++; \ iter++; \ flag = 0; \ for (k=0;k0;k--) \ { \ product = 1; \ for (j=k-1;j>=0;j--) \ { \ product *= actual_iters_per_dim[j]; \ } \ sum_indices += actual_indices[k]*product; \ } \ } \ } \ else \ { \ while (iter < max_iter) \ { \ /* prevent offset from giving segfaults */ \ if (sum_indices >= max_iter) \ { \ CCTK_WARN(1,"offsets and strides access unallocated memory"); \ return -1; \ } \ inval = (out_type) typed_vdata[sum_indices]; \ REDUCTION_OPERATION(*outval,inval); \ num_points++; \ iter++; \ flag = 0; \ for (k=0;k0;k--) \ { \ product = 1; \ for (j=k-1;j>=0;j--) \ { \ product *= actual_iters_per_dim[j]; \ } \ sum_indices += actual_indices[k]*product; \ } \ } \ } \ } \ else if (mask_on == 0) \ { \ if ( input_array_offset == 0) \ { \ while (iter < max_iter) \ { \ inval = (out_type) typed_vdata[sum_indices]; \ REDUCTION_OPERATION(*outval,inval); \ num_points++; \ iter++; \ flag = 0; \ for (k=0;k0;k--) \ { \ product = 1; \ for (j=k-1;j>=0;j--) \ { \ product *= actual_iters_per_dim[j]; \ } \ sum_indices += actual_indices[k]*product; \ } \ } \ } \ else \ { \ while (iter < max_iter) \ { \ /* prevent offset from giving segfaults */ \ if (sum_indices >= max_iter) \ { \ CCTK_WARN(1,"offsets and strides access unallocated memory"); \ return -1; \ } \ inval = (out_type) typed_vdata[sum_indices]; \ REDUCTION_OPERATION(*outval,inval); \ num_points++; \ iter++; \ flag = 0; \ for (k=0;k0;k--) \ { \ product = 1; \ for (j=k-1;j>=0;j--) \ { \ product *= actual_iters_per_dim[j]; \ } \ sum_indices += actual_indices[k]*product; \ } \ } \ } \ } \ else \ { \ CCTK_WARN(1, "mask_on is not set to a valid value"); \ } \ EXTRA_STEP(*outval, (out_type)num_points) \ } int LocalReduce_Mean (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_Count (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_Max (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_Min (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_L1 (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_L2 (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_L3 (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_L4 (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_LInf (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); int LocalReduce_Sum (REDUCTION_LOCAL_ARRAY_OPERATOR_REGISTER_ARGLIST); typedef int (*reduction_fn_t) (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[]); int LocalReduce_Reduce (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[],reduction_fn_t reduction_fn); #ifdef __cplusplus } #endif #endif