Sample user function


Up: Collective Communications in MPI Next: Defining groups Previous: Defining Your Own Collective Operations

For example, to create an operation that has the same effect as MPI_SUM on Fortran double precision values, use

subroutine myfunc( invec, inoutvec, len, datatype ) 
   integer len, datatype 
   double precision invec(len), inoutvec(len) 
   integer i 
   do 10 i=1,len 
10   inoutvec(i) = invec(i) + inoutvec(i) 
   return 
   end 
To use, just
integer myop 
call MPI_Op_create( myfunc, .true., myop, ierr ) 
call MPI_Reduce( a, b, 1, MPI_DOUBLE_PRECISON, myop, ... ) 
The routine MPI_Op_free destroys user-functions when they are no longer needed.



Up: Collective Communications in MPI Next: Defining groups Previous: Defining Your Own Collective Operations