3

I am totally new to MPJ which is an API for developing MPI based programs in Java. I wrote a simple code as follows:

import mpi.MPI;
import mpi.Status;

public class Send {
    public static void main(String[] args) throws Exception
    {
        MPI.Init(args);

        int rank = MPI.COMM_WORLD.Rank();
        int size = MPI.COMM_WORLD.Size();
        int peer;

        int buffer[] = new int[10];
        int len = 1;
        int dataToBeSent = 99;
        int tag = 100;

        if(rank == 0)
        {
            buffer[0] = dataToBeSent;
            peer = 1;
            MPI.COMM_WORLD.Send(buffer, 0, len, MPI.INT, peer, tag);
            System.out.println("process <"+rank+"> sent a msg to process <"+peer+">");             
        }
        else if(rank == 1)
        {
             peer = 0 ; 
             Status status = MPI.COMM_WORLD.Recv(buffer, 0, buffer.length, MPI.INT, peer, tag);
             System.out.println("process <"+rank+"> recv'ed a msg\n"+ "\tdata <"+buffer[0]+"> \n"+"\tsource <"+status.source+"> \n"+"\ttag<"+status.tag+"> \n"+"\tcount  <"+status.count +">");             
        }
        MPI.Finalize();
    }
}

When I compile, I get the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: mpi/MPI : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at Send.main(Send.java:7)
Java Result: 1

To resolve this issue, I came to know that both my JDK and JRE versions must be the same. After executing the following commands, I found that they are same and not different:

C:\Users\Dev>javac -version
javac 1.6.0

C:\Users\Dev>java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

In Ubuntu Java 8, I get the following Exception:

Exception in thread "main" mpi.MPIException: Usage: java MPI <myrank> <conf_file> <device_name> conf_file can be, ../conf/xdev.conf <Local>OR http://holly.dsg.port.ac.uk:15000/xdev.conf <Remote>
    at mpi.MPI.Init(MPI.java:233)
    at mpi.MPI.Init(MPI.java:233)   at mpi.MPI.Init(MPI.java:233)
    at Send.main(Send.java:7)
Java Result: 1

How do I resolve this issue and get MPI running on my system in Java?

Java Enthusiast
  • 1,161
  • 2
  • 15
  • 30
  • Are you sure that MPI is Java 6 compatible? – Ria Apr 02 '15 at 17:02
  • I tried in Java 8 in Ubuntu but it didn't work as well. I got a different exception there – Java Enthusiast Apr 02 '15 at 17:07
  • Normally this error shows up if the compilance level does not match the runtime. If MPI was compiled with 7 and you run it on 6 it would explain the message. Which error do you get with java 8? – Ria Apr 02 '15 at 17:50
  • 1
    @JavaEnthusiast try recompiling MPJ Express with Java version you have installed on your system and see if this solves your issue. You can recompile MPJ Express using **ant**. – Aleem Apr 03 '15 at 15:16
  • Seems to me that your first error was because of the Java version. The error your are getting with java 8 says that the program can be run, but a runtime error occurs. Are you passing any arguments to the `main` method (variable ´args`)? – Ria Apr 04 '15 at 08:13
  • @Ria no. I am not passing any args – Java Enthusiast Apr 04 '15 at 09:03
  • I found the source code and they seem to expect 3 arguments but I am not sure if it is the same version you are using. May it helps asking this as a new question. Sorry for not being able so solve it completely. – Ria Apr 06 '15 at 09:32

1 Answers1

0

This is an old question but I think I can summarize what happened here, having used this library myself.

The compilation error that you obtained, "Unsupported major.minor version 51.0" indicates that the version of java you are using to run your program is too old. Most likely some parts of your program were compiled with a newer version of Java. Probably the MPJ library you downloaded?

When you tried to run your program with Java 8, you actually solved this problem on your own! However, as you correctly identified in the second half of your question, you still have a problem with the arguments of your program. The MPJ-express main expects some specific arguments to know how many processes are being launched. In the absence of these arguments, you get the error Exception in thread "main" mpi.MPIException: Usage: java MPI <myrank> <conf_file> <device_name>

Basically, the MPJ-Express library comes with a number of small scripts that will arrange the MPI specific arguments for you. Depending on the mode (multicore / cluster) that you want to use, the script and the procedure will be different. All the details are explained in the guides available on this page: http://mpj-express.org/guides.html. If that's what you are using, you can also launch programs from within the Eclipse IDE.

Patrick
  • 1,458
  • 13
  • 27