![]() ![]() ![]() ![]() Next: Parameters Up: PUGHReduce Previous: Purpose Contents ExamplesThe following C example illustrates how the get the maximum value of a grid function.int vindex; /* grid variable index */ CCTK_REAL result; /* resulting reduction value */ int target_proc; /* processor to hold the result */ int reduction_handle; /* handle for reduction operator */ char *reduction_name; /* reduction operator to use */ /* want to get the maximum for the wavetoy grid function */ reduction_name = "maximum"; vindex = CCTK_VarIndex ("wavetoy::phi"); /* the reduction result will be obtained by processor 0 only */ target_proc = 0; /* get the handle for the given reduction operator */ reduction_handle = CCTK_ReductionHandle (reduction_name); if (reduction_handle >= 0) { /* now do the reduction using the flesh's generic reduction API (passing in one input, expecting one output value of REAL type) */ if (CCTK_Reduce (cctkGH, target_proc, reduction_handle, 1, CCTK_VARIABLE_REAL, &result, 1, vindex) == 0) { if (CCTK_MyProc (cctkGH) == target_proc) { printf ("%s reduction value is %f\n", reduction_name, result); } } else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "%s reduction failed", reduction_name); } } else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Invalid reduction operator '%s'", reduction_name); }
|