Next: Irregular collective communications Up: A distributed array communication Previous: Regular collective communications   Contents

# Reductions

Reduction operations take one or more distributed arrays as input. They combine the elements to produce one or more scalar values, or arrays of lower rank. Adlib provides a large set of reduction operations, supporting the many kinds of reduction available in as ``intrinsic functions'' in Fortran. Here we mention only a few of the simplest reductions.

The maxval operation simply returns the maximum of all elements of an array. It has prototypes

```
`    `` maxval(`` [[]] a) ;`
`    `` maxval(`` [[,]] a) ;`
`    `` maxval(`` [[,,]] a) ;`
`    ...`
```
The result is broadcast to the active process group, and returned by the function. Other reduction operations with similar interfaces are minval, sum and product. Of these minval is minimum value, sum adds the elements of a in an unspecified order, and product multiplies them.

The function dotProduct used in some earlier examples is also logically a reduction, but it takes two one-dimensional arrays as arguments and returns their scalar product--the sum of pairwise products of elements. The situation with element types is complicated because the types of the two arguments needn't be identical. If they are different, standard Java binary numeric promotions are applied--for example if the dot product of an int array with a float array is a float value. Some of the prototypes are

```    int    dotProduct(int   [[]] a, int    [[]] b) ;
float  dotProduct(int   [[]] a, float  [[]] b) ;
double dotProduct(int   [[]] a, double [[]] b) ;
float  dotProduct(float [[]] a, int    [[]] b) ;
float  dotProduct(float [[]] a, float  [[]] b) ;
double dotProduct(float [[]] a, double [[]] b) ;
...
```
The arguments must have the same shape and must be aligned. As usual the result is broadcast to all members of the active process group.

The function broacast is not actually a reduction, but it has some features in common with other functions discussed in this section. The prototype is

```
`    `` broadcast(`` # s) ;`

```
It takes a scalar (rank-0 distributed array) as argument and broadcasts the element value to all processes of the active process group. Typically it is used in conjunction with a scalar section to broadcast an element of a general array, as in this fragment:
```    int [[,]] a = new int [[x, y]] ;