IBM Books

MPI Programming and Subroutine Reference


Appendix D. Reduction Operations


Predefined Reduction Operations

The following is a list of the predefined operations for use with MPI_REDUCE, MPI_ALLREDUCE, MPI_REDUCE_SCATTER and MPI_SCAN. To invoke a predefined operation, place any of the following in op.
Reduction Operation Description
MPI_MAX maximum
MPI_MIN minimum
MPI_SUM sum
MPI_PROD product
MPI_LAND logical AND
MPI_BAND bitwise AND
MPI_LOR logical OR
MPI_BOR bitwise OR
MPI_LXOR logical XOR
MPI_BXOR bitwise XOR
MPI_MAXLOC max value and location
MPI_MINLOC min value and location

Reduction Operations - Valid Datatype Arguments Operations

The reduction operations have the following basic datatype arguments.
Type Valid Datatype Arguments
C integer
MPI_INT
MPI_LONG
MPI_LONG_LONG_INT
MPI_SHORT
MPI_UNSIGNED
MPI_UNSIGNED_LONG
MPI_UNSIGNED_LONG_LONG
MPI_UNSIGNED_SHORT

FORTRAN integer
MPI_INTEGER
MPI_INTEGER8

Floating point
MPI_DOUBLE
MPI_DOUBLE_PRECISION
MPI_FLOAT
MPI_LONG_DOUBLE
MPI_REAL

Logical MPI_LOGICAL
Complex MPI_COMPLEX
Byte MPI_BYTE
C Pair
MPI_DOUBLE_INT
MPI_FLOAT_INT
MPI_LONG_INT
MPI_LONG_DOUBLE_INT
MPI_SHORT_INT
MPI_2INT

FORTRAN Pair
MPI_2DOUBLE_PRECISION
MPI_2INTEGER
MPI_2REAL

op Option - Valid Datatypes

The following are the valid datatypes for each op option.
Type Valid Datatypes For op Option
C integer
MPI_BAND
MPI_BOR
MPI_BXOR
MPI_LAND
MPI_LOR
MPI_LXOR
MPI_MAX
MPI_MIN
MPI_SUM
MPI_PROD

FORTRAN integer
MPI_BAND
MPI_BOR
MPI_BXOR
MPI_MAX
MPI_MIN
MPI_PROD
MPI_SUM

Floating point
MPI_MAX
MPI_MIN
MPI_PROD
MPI_SUM

Logical
MPI_LAND
MPI_LOR
MPI_LXOR

Complex
MPI_PROD
MPI_SUM

Byte
MPI_BAND
MPI_BOR
MPI_BXOR

C Pair
MPI_MAXLOC
MPI_MINLOC

FORTRAN Pair
MPI_MAXLOC
MPI_MINLOC


Examples

Examples of user-defined reduction functions for integer vector addition.

C Example

void int_sum (int *in, int *inout,
     int *len, MPI_Datatype *type);
 
{
   int i
   for (i=0; i<*len; i++)  {
      inout[i] + = in[i];
   }
}

FORTRAN Example

      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:

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 Stacksize" in Appendix G. "Programming Considerations for User Applications in POE" for thread stacksize considerations when using the threaded MPI library.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]