Java Enthusiast
Java Enthusiast

Reputation: 1191

Unable to compile MPI programs in Java - UnsupportedClassVersionError

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?

Upvotes: 3

Views: 853

Answers (1)

Patrick
Patrick

Reputation: 1567

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.

Upvotes: 0

Related Questions