/*@@ @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" #define ABS(x) ((x) < 0 ? -(x) : (x)) #define SMALL_NUMBER 0 #ifdef __cplusplus extern "C" { #endif #define ITERATE_ON_ARRAY(i,cctk_type, in_data, out_type, out_num, weight_on, weight, input_array_offset, indices, sum_indices, max_iter, iter, flag, actual_indices,input_array_strides, input_array_min_subscripts,input_array_dims,product) \ { \ const cctk_type * typed_vdata = (const cctk_type *)(in_data); \ CCTK_ATTRIBUTE_UNUSED out_type inval; \ out_type * outval = (out_type *) out_num; \ iter = 0; \ sum_indices = 0; \ num_points = 1; \ REDUCTION_INITIAL(inval) \ REDUCTION_INITIAL( * outval) \ \ if ( N_dims == 0 ) \ { \ REDUCTION_PREOP_CAST(inval, typed_vdata,sum_indices, out_type); \ REDUCTION_OPERATION(*outval,inval); \ } \ else \ { \ if ( weight_on == 1) \ { \ if ( input_array_offset == 0) \ { \ while (iter < max_iter) \ { \ sum_indices = actual_indices[0]; \ for (k=N_dims-1;k>0;k--) \ { \ product = 1; \ for (j=k-1;j>=0;j--) \ { \ product *= input_array_dims[j]; \ } \ sum_indices += actual_indices[k]*product; \ } \ weight_value = ((const CCTK_REAL *) weight)[sum_indices]; \ \ REDUCTION_PREOP_CAST(inval, typed_vdata,sum_indices, out_type); \ WEIGHTED_REDUCTION_OPERATION(*outval,inval,weight_value); \ num_points++; \ weight_sum += weight_value; \ 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; \ } \ /* prevent offset from giving segfaults */ \ if (sum_indices >= max_iter) \ { \ CCTK_WARN(1,"offsets and strides access unallocated memory"); \ return -1; \ } \ REDUCTION_PREOP_CAST(inval, typed_vdata,sum_indices, out_type); \ WEIGHTED_REDUCTION_OPERATION(*outval,inval,weight_value); \ num_points++; \ iter++; \ flag = 0; \ for (k=0;k0;k--) \ { \ product = 1; \ for (j=k-1;j>=0;j--) \ { \ product *= input_array_dims[j]; \ } \ sum_indices += actual_indices[k]*product; \ } \ REDUCTION_PREOP_CAST(inval, typed_vdata,sum_indices, out_type); \ REDUCTION_OPERATION(*outval,inval); \ num_points++; \ weight_sum += weight_value; \ 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; \ } \ /* prevent offset from giving segfaults */ \ if (sum_indices >= max_iter) \ { \ CCTK_WARN(1,"offsets and strides access unallocated memory"); \ return -1; \ } \ REDUCTION_PREOP_CAST(inval, typed_vdata,sum_indices, out_type); \ REDUCTION_OPERATION(*outval,inval); \ num_points++; \ iter++; \ flag = 0; \ for (k=0;k