简体   繁体   中英

openmpi + java, could not find or load main class

I am recently trying out the java binding of the openmpi library :

I have succesfully compiled the lib with the following configurations:

$/configure --prefix "/home/yuechuan/Application/.openmpi" --enable-mpi-java --with-jdk-dir="/usr/lib/jvm/java-8-oracle/" --with-jdk-header="/usr/lib/jvm/java-8-oracle/include/"

$sudo make install

I am able to compile a simple java program with : $mpijavac src/com/cyc115/pa2/Main.java

currently $echo $CLASSPATH gives /home/yuechuan/Github/parallel_pa2/src/com/cyc115/pa2/

However I am having trouble to get the class file to run. Here are some alternatives I have tried so far:

$java -Djava.library.path=/home/yuechuan/Application/.openmpi/lib/mpi.jar -cp .:/home/yuechuan/Application/.openmpi/lib/mpi.jar Main

which returns Error: Could not find or load main class Main error.

the pure and simple $java Main command returns NoClassDefFoundError

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: mpi/MPIException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: mpi.MPIException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

Here's the java file if anyone needs :

package com.cyc115.pa2;

import mpi.MPI;
import mpi.MPIException;

public class Main {

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

        int rank = MPI.COMM_WORLD.getRank();
        int size = MPI.COMM_WORLD.getSize();

        System.out.print("hello world");
        MPI.Finalize();
    }
}

Any ideas on how I can get the .class to run?

Since the package is :

package com.cyc115.pa2;

You need to put the file Main.java in a sub-directory named com/cyc115/pa2 The java library path should be a path to the directory containing libmpi_java.so rather than the path to mpi.jar.

To compile:

javac -cp /home/yuechuan/Application/.openmpi/lib/mpi.jar com/cyc115/pa2/Main.java 

To run:

java -Djava.library.path=/home/yuechuan/Application/.openmpi/lib/ -cp .:/home/yuechuan/Application/.openmpi/lib/mpi.jar com.cyc115.pa2.Main

The following is not the problem, just an FYI:

It should be --with-jdk-headers with an s rather than --with-jdk-header however you do not have to specify it at all if you are already specifying --with-jdk-dir .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM