MPI Using Java PDF
MPI Using Java PDF
Assignment no. 02
Computer Lab IX
MPI: The Message Passing Interface
● MPI is the HPC Message Passing Interface standardized in the early 1990s
by the MPI Forum.
● It is an API for communication between nodes of a distributed memory
parallel computer (typically, now, a workstation cluster).
● The original standard defines bindings to C and Fortran (later C++).
● MPI is a technology from the HPC world, which various people have worked
on importing into Java.
MPI: The Message Passing Interface
MPJ
○ An API specification by the “Message-passing Working Group” of the Java Grande Forum.
Published 2000.
MPJ - Setup Environment
The MPI class has a few static methods for administrative things, and
numerous static fields holding global constants
MPJ - Setup Environment
You should forward the arguments parameter of the main() method to the
Init() method
Call MPI.Finalize() to shut down MPI before the main() method Terminates.
You don’t want these distinct “activities” to interfere with one another.
Each process in a group has a unique rank within the group, an int value
between 0 and Size() – 1. This value is returned by the Rank() method.
The World Communicator
void Send(Object buf, int offset, int count, Datatype type, int dst, int tag) ;
Status Recv(Object buf, int offset, int count, Datatype type, int src, int tag) ;
The arguments buf, offset, count, type describe the data buffer—the storage
of the data that is sent or received.
Simple send and receive
In the actual arguments passed to these methods, buf must be an array (or a
run-time exception will occur).
count is the number of items to send. type describes the type of these items.
ANY_SOURCE and ANY_TAG
A recv() operation can explicitly specify which process within the communicator group
it wants to accept a message from, through the src parameter.
It can also explicitly specify what message tag the message should have been sent
with, through the tag parameter.
The recv() operation will block until a message meeting both these criteria arrives.
If you want the recv() operation to accept a message from any source, or with any tag,
you may specify the values MPI.ANY_SOURCE or MPI.ANY_TAG for the respective
arguments.
Status values
This object provides access to several useful pieces about the message that
arrived.
int field status.source holds the rank of the process that sent the message
(particularly useful if the message was received with MPI.ANY_SOURCE).
int field status.tag holds the message tag specified by the sender of the
message (particularly useful if the message was received with MPI.ANY_TAG).
Status values
This is supposed to report the error status of a failed method, closely following
the failure modes documented in the MPI standard.
Collective Communications
All processes in the communicator group must engage in a collective operation “at the
same time”
– i.e. all processes must invoke collective operations in the same sequence, all passing
consistent arguments.
Can argue that collective communications (and other similar collective functions built on
them) are a defining feature of the SPMD programming model.
Example Collective Operations
Object recvbuf, int recvoffset, int recvcount, Datatype recvtype, int root)
» Each process sends the contents of its send buffer to the root process.
void Scatter(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object
recvbuf, int recvoffset, int recvcount, Datatype recvtype, int root)
This is very natural in Java, and it allows various things to be done conveniently.
● Write the program to sum 100 numbers using Send and Recv
www.thelearningsolutions.com