Examples of user-defined reduction functions for integer vector addition follow.
void int_sum (int *in, int *inout,
int *len, MPI_Datatype *type);
{
int i
for (i=0; i<*len; i++) {
inout[i] + = in[i];
}
}
SUBROUTINE INT_SUM(IN,INOUT,LEN,TYPE)
INTEGER IN(*),INOUT(*),LEN,TYPE,I
DO I = 1,LEN
INOUT(I) = IN(I) + INOUT(I)
ENDDO
END
User-supplied reduction operations have four arguments:
This argument is an input array to be reduced.
This argument is an input array to be reduced and the result of the reduction will be placed here.
Users may code their own reduction operations, with the restriction that the operations must be associative. Also, C programmers should note that the values of len and type will be passed as pointers. No communication calls are allowed in user-defined reduction operations. See Limitations in setting the thread stack size for thread stack size considerations when using the MPI threads library.