Skip to content
/ ezmpj Public
forked from mesocentrefc/ezmpj

A set of helper classes to enable Asynchronous Message Receiving (Event Driven) with Open MPI Java Binding

Notifications You must be signed in to change notification settings

kma/ezmpj

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EZMPJ

A set of helper classes to enable Asynchronous Message Receiving (Event Driven) with Open MPI Java Binding.

The goal is to provide a simple interface on top of MPI (Java binding) to program applications using events for receiving messages. For example:

  • Master worker paradigm
  • Message driven architecture
  • Asynchronous communication

How it works?

Each MPI process:

  • creates and spawns a Java thread for receiving messages using MPI functions Iprobe() and Recv()
  • Adds a listener to receive asynchronous messages using onMessage() method
  • Uses a new Method to send Serialized objects send(object, dest, tag)
  • Uses Java Serialization (or custom serialization APIs) for Data exchange.

Notice:

  1. EZMPJ finalize depends on your application, use waitFinalizeThreads() and shutdownReceiverThread() to properly stop your application. waitFinalizeThreads() is used to synchronize the master thread with receiver thread (wait the end of the receiver thread). shutdownReceiverThread() is used to force the receiver threads to stop (call this method when you're sure that there is no more message to consum).
  2. On can still use global communication functions since they not rely on tag
  3. Open MPI uses aggressive busy wait to receive messages. This keep one processor pegged at 100% for each process that is waiting. We are using iProbe() in a loop with a sleep call before calling a blocking receive. The default value of sleep is 10ms, this value can be changed by the environment variable: EZMPJ_BUSY_SLEEP

Example

// initialize threads
EZMPJ.initThreads(args);
        
// Start receiver threads with listener interface
EZMPJ.startReceiverThread(this);

// We could use MPI.COMM_WORLD.getRank()
if (EZMPJ.getRank() == 0) {

String message = new String("Hello World !");
// send to  process 1
EZMPJ.send(message, 1, tag);
 
//Stop receiving threads in proc 0 since it will not receive msg
EZMPJ.shutdownReceiverThread();
}

// Wait for all receiver threads
EZMPJ.waitFinalizeThreads();

//receiver listener
/*
 This method is called when a message is received
*/
@Override
public void onMessage(EZStatus ezStatus) throws MPIException {

System.out.println("processor#" + EZMPJ.getRank() + " Received message from: " + ezStatus.getSender()
                + ", tag=" + ezStatus.getTag() + ", data=" + ezStatus.getDataObject());

//stop receiving
EZMPJ.shutdownReceiverThread();
 
}

Compile your application

First we need to generate a jar file:

  • make sure that mpi.jar is in your CLASSPATH
  • generate ezmpj.jar with ant

To compile your application:

mpijavac -cp .:/path/to/ezmpj.jar  examples/HelloWorld.java

To run your application:

mpirun -np 4 java  -cp .:/path/to/ezmpj.jar  examples.HelloWorld

Limitations

  • Combine onMessage() with standard MPI sending methods (Send, Isend,...) will cause a conflict in receiving messages. Use only EZMPJ.Send() method to send objects.
  • Standard Java serialization is slow. On can use 3rd party APIs like Java Fast Serialization (https://ruedigermoeller.github.io/fast-serialization/). You need to write a class that implements EZMessageCodecInterface and than call setMessageCodec() method.

Requirements

About

A set of helper classes to enable Asynchronous Message Receiving (Event Driven) with Open MPI Java Binding

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%