next up previous contents
Next: Reduce-Scatter Up: Collective Communication Previous: All-to-All Scatter/Gather   Contents

Global Reduction Operations

void Intracomm.Reduce(Object sendbuf, int sendoffset,
                      Object recvbuf, int recvoffset,
                      int count, Datatype datatype,
                      Op op, int root)
Java binding of the MPI operation MPI_REDUCE. The value sendoffset is a subscript in sendbuf, defining the position of the first item input data. The value recvoffset is a subscript in recvbuf, defining the position into which the first item of result data be copied.

The predefined operations are available in Java as MPI.MAX, MPI.MIN, MPI.SUM, MPI.PROD, MPI.LAND, MPI.BAND, MPI.LOR, MPI.BOR, MPI.LXOR, MPI.BXOR, MPI.MINLOC and MPI.MAXLOC.

The handling of MINLOC and MAXLOC is modelled on the Fortran binding. The extra predefined types MPI.SHORT2, MPI.INT2, MPI.LONG2, MPI.FLOAT2, MPI.DOUBLE2 describe pairs of Java numeric primitive types.

Op.Op(User_function function, boolean commute)
Java binding of the MPI operation MPI_OP_CREATE.

The abstract base class User_function is defined by

  class User_function {
    public abstract void call(Object invec, Object outvec,
                              Datatype datatype) ;
  }
There is an implementation problem here: how does the C code inside the wrapper persuade the MPI reduction operation to invoke the Java method, call? Some C MPI_User_function must dispatch the call method of a Java object of type User_function. The difficulty is creating a C function at runtime that will do this. A generic C function can reference a Java object through a handle held in some static variable. But if more than one user defined operation is needed, how does a particular invocation find the proper Java function object? One possibility is to assume a fixed bound, $N$, on the number of allowed user-defined operations, and define $N$ different MPI_User_function functions, invoking call methods through $N$ different static variables. These MPI_User_function/static-variable pairs are managed as a pool. Calling the Op constructor involves copying a handle to its function object argument into one of the static variables in the pool and passing the corresponding MPI_User_function to MPI_OP_CREATE.

void Op.finalize()
The Op destructor will invoke the MPI operation MPI_OP_FREE.

void Intracomm.Allreduce(Object sendbuf, int sendoffset,
                         Object recvbuf, int recvoffset,
                         int count, Datatype datatype,
                         Op op)
Java binding of the MPI operation MPI_ALLREDUCE. Arguments as for Reduce, except for the omission of root.


next up previous contents
Next: Reduce-Scatter Up: Collective Communication Previous: All-to-All Scatter/Gather   Contents
Bryan Carpenter 2002-07-12