Introduction to MPJ Express

Published on
4,906 Points
2 Endorsements
Last Modified:

The advent of distributed computing technologies has afforded programmers the much appreciated opportunity to crunch data on a massive scale. The multithreading paradigm that realized speedups on a single machine via work load scheduling on separate CPU cores has been extended to distribution on an arbitrary number of machines often referred to as Nodes. Nodes can have any number of CPUs,  varying amounts of RAM and Storage, and may or may not be housed in the same facility.

With this new paradigm came the need for a way for nodes to communicate with one another both synchronously and asynchronously to coordinate efforts and to send and receive data to one another. One solution that has gained notable support in recent years came in the form of the Message Passing Interface, a standard created by academic researchers and industry experts which detailed standards for a framework that allowed inter-nodal communcation (Figure 1).

There have been a number of implementations of the MPI standard, most notably Open-MPI, that materialize the MPI standard in several languages including C and Fortran. There was also an implementation in Java that has been lightly maintained by the Open-MPI community but receives no official support from the consortium that maintains the Open-MPI project. In order to fill the Java MPI implementation void, academic researchers created MPJ-Express that offers a Java API wrapper over MPI functionality.

Basic Setup

MPJ-Express exposes an API that binds Java objects and methods to an implementation of MPI built on top of various networking frameworks that can easily be swapped in and out using a convenient command line argument. In order to get MPJ-Express running a user should first set up the software on all computer nodes using the startup guide for their platform (ie. Windows or Unix/Linux) available on the following website http://mpj-express.org/guides.html. This process essentially involves creating an environment variable in your operating system that binds to an absolute folder path containing the MPJ-Express binaries.

SSH is also required for passwordless login so that the MPJ Dameon on your primary node (the machine that you will call the MPJ boot sequence on) can boot the daemon on other nodes. Passwordless login setup is detailed in many guides on Experts Exchange and in other locations.

Finally, create a file called "machines" in your mpj-user directory and enter a machine name per line for each machine in your cluster. For example, on a local network where virtual machine names follow the convention "networkmachine###" your "machines" file might contain the following
DO include the machine that you are logged into and will be running the application from.

Up and Running

Once initial setup is complete, a basic program can be created to demonstrate passing messages between nodes. Very little is required to do this, but it is important to be knowledgable about a few MPI nomenclatures before you begin:
  1. Each node is uniquely identified by its rank. For example, if you have a 3 machine cluster, the primary node (the one which you called mpjrun on to start your application) will be rank 0, another node will be 1 and another will be 2. You can reference these rankings in your java code using the MPI.COMM_WORLD.Rank().
  2. Nodes can be logically gathered into different workgroups which can be used to communicate certain messages to certain channels. For example, COMM_WORLD above is a supergroup that contains all nodes by default (Figure 2).

    comm-group600pix.gifFigure 2: MPI Comm Group Visualization

    Source: https://computing.llnl.gov/tutorials/mpi/#Getting_Started
  3. Every node must call MPI.Init() before it can use any of the MPJ functiones. This initializes all MPI datastructures required for intranodal communication.
Now you should know enough to be able to run and understand a basic MPJ application:
import mpi.*;
public class HelloWorld {

   public static void main(String args[]) throws Exception {
      int me = MPI.COMM_WORLD.Rank();
      int size = MPI.COMM_WORLD.Size();
      System.out.println("Hi from <"+me+">");

Open in new window

Compile and save the previous code snippet as HelloWorld.class and run it using MPJ-Express:
mpjrun.sh -np 2 HelloWorld

Open in new window

Here we are running the HelloWorld program using 2 nodes (np 2) which should be enumerated in the Machines file. In the background, MPJ will run the java code on each machine which will find its rank and print "Hi from Node#".  


Anything you want to learn about MPJ functionality can be learned via an equivalent tutorial on MPI since MPJ simply exposes MPI functions using java wrappers. There are many amazing things that can be done with MPI including the utilization of multiple cores on individual nodes, message mass broadcasting, maps and reduces, and more. For more information on MPI see https://computing.llnl.gov/tutorials/mpi/#Getting_Started. For MPJ-Express specific information, including different cluster configuration setups, check out http://mpj-express.org/.

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Join & Write a Comment

Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month