next up previous contents
Next: Language Binding Up: mpiJava: An Object-Oriented Java Previous: Motivation   Contents

Introduction to the mpiJava API

The MPI standard is explicitly object-based. The C and Fortran bindings rely on ``opaque objects'' that can be manipulated only by acquiring object handles from constructor functions, and passing the handles to suitable functions in the library. The C++ binding specified in the MPI 2 standard collects these objects into suitable class hierarchies and defines most of the library functions as class member functions. The mpiJava API follows this model, lifting the structure of its class hierarchy directly from the C++ binding. The major classes of mpiJava are illustrated in Figure 4.1.

Figure 4.1: Principal classes of mpiJava

The class MPI only has static members. It acts as a module containing global services, such as initialization of MPI, and many global constants including the default communicator COMM_WORLD.

The most important class in the package is the communicator class Comm. All communication functions in mpiJava are members of Comm or its subclasses. As usual in MPI, a communicator stands for a ``collective object'' logically shared by a group of processors. The processes communicate, typically by addressing messages to their peers through the common communicator.

Another class that is important for the discussion below is the Datatype class. This describes the type of the elements in the message buffers passed to send, receive, and all other communication functions. Various basic datatypes are predefined in the package. These mainly correspond to the primitive types of Java, shown in Table 4.1. The MPI.OBJECT is a new predefined datatype for derived data types.

Table 4.1: Basic datatypes of mpiJava
MPI datatype Java datatype

The standard send and receive operations of MPI are members of Comm with interfaces:

public void Send(Object buf, int offset, int count, Datatype
                 datatype, int dest, int tag)

public Status Recv(Object buf, int offset, int count, Datatype
                   datatype, int source, int tag)

In both cases the actual argument corresponding to buf must be a Java array. In the current implementation they must be arrays with elements of primitive type. By implication they must be one-dimensional arrays, because Java ``multidimensional arrays'' are really arrays of arrays. In these and all other mpiJava calls, the buffer array argument is followed by an offset that specifies the element of in array where the message actually starts.

Figure 4.2: Minimal mpiJava program (run in two processes)

next up previous contents
Next: Language Binding Up: mpiJava: An Object-Oriented Java Previous: Motivation   Contents
Bryan Carpenter 2004-06-09