## PUGHReduce

Date

### Abstract

Reductions operations which are performed using the PUGH driver

### 1 Purpose

This thorn registers a number of reduction operators with the flesh. The reductions are performed using internals of the PUGH driver, so that this thorn can only be used when CactusPUGH/PUGH is active.

The reduction operations this thorn registers are

 Reduction Operator Calculates By average${}^{\ast }$, mean${}^{\ast }$ the average/mean of a grid variable $\sum GV∕N$ count the number of grid points in a grid variable $N$ maximum${}^{\ast }$ the maximum of a grid variable $\mathrm{max}GV$ minimum${}^{\ast }$ the minimum of a grid variable $\mathrm{min}GV$ norm1, L1Norm the L1 norm of a grid variable $\left(\mathrm{\Sigma }|GV|\right)∕N$ norm2, L2Norm the L2 norm of a grid variable $\sqrt[2]{\left(\mathrm{\Sigma }|GV{|}^{2}\right)∕N}$ norm3, L3Norm the L3 norm of a grid variable $\sqrt[3]{\left(\mathrm{\Sigma }|GV{|}^{3}\right)∕N}$ norm4, L4Norm the L4 norm of a grid variable $\sqrt[4]{\left(\mathrm{\Sigma }|GV{|}^{4}\right)∕N}$ norm_inf, LinfNorm the Infinitity norm of a grid variable $\mathrm{max}|GV|$ sum${}^{\ast }$ the sum of the elements of a grid variable $\sum GV$

Reduction operators with multiple names are just synonyms for the same kind of reduction operation. In the formulas $GV$ is the grid variable to be reduced, and $N$ denotes the number of its elements. Reduction operators marked with ${}^{\ast }$ cannot be applied to grid variables of complex datatype.

### 2 Examples

The 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);
}


Implements:

reduce

### 5 Schedule

This section lists all the variables which are assigned storage by thorn CactusPUGH/PUGHReduce. Storage can either last for the duration of the run (Always means that if this thorn is activated storage will be assigned, Conditional means that if this thorn is activated storage will be assigned for the duration of the run if some condition is met), or can be turned on for the duration of a schedule function.

NONE

#### Scheduled Functions

CCTK_STARTUP

pughreduce_startup

startup routine

 Language: c Type: function