IBM Books

MPI Programming Guide


Examples

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

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 stack size for thread stack size considerations when using the MPI threads library.


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