We have produced a Java interface to an existing MPI implementation [25] using Java native methods
The interface has been tested on a cluster of UltraSparc workstations running Solaris. Our interface is modelled on the proposed C++ bindings of MPI. For example, many of the most basic functions of the library are members of the communicator class, Comm:
public class Comm { public int Size(); public int Rank(); void Send(Object buf, int offset, int count, Datatype datatype, int dest, int tag) ; Status Recv(Object buf, int offset, int count, Datatype datatype, int dest, int tag) ; ... }
Figure 3: Simple MPI Life program.
Figure 3 is a straightforward transcription of the socket-based program in the last section. Our MPI inteface uses a slightly different model for accessing global resources--static members on an MPI class:
class MPI { static Init() ; static Finalize() ; public static Comm WORLD ; public static Datatype BYTE ; public static Datatype INT ; ... }
rather than dynamic members of a jpi class--but this difference is not particularly significant (yet another approach will be taken in the example of section 4.1). Otherwise the correspondence between this code and the socket code is direct. In the next section we illustrate some of the added value that an MPI interface brings.
We have broken with the usual MPI convention of returning an error status from every function. This practice is inconvenient in Java because arguments cannot be passed by reference and directly modified. This makes the return value precious, and using it up on an error value that everybody ignores is a waste. Java has a well established exception mechanism for ignoring error information.