2

I work with OpenMPI. I want to run Hello.java and Ring.java from the examples here . I compile Hello.java with this line:

javac Hello.java

Then I can run it with mpirun.

But when I compile it, I get this error:

Hello.java:25: error: package mpi does not exist
import mpi.*;
^
Hello.java:28: error: cannot find symbol
    static public void main(String[] args) throws MPIException {
                                                  ^
  symbol:   class MPIException
  location: class Hello
Hello.java:31: error: cannot find symbol
    MPI.Init(args);
    ^
  symbol:   variable MPI
  location: class Hello
Hello.java:33: error: package MPI does not exist
    int myrank = MPI.COMM_WORLD.getRank();
                    ^
Hello.java:34: error: package MPI does not exist
    int size = MPI.COMM_WORLD.getSize() ;
                  ^
Hello.java:37: error: cannot find symbol
    MPI.Finalize();
    ^
  symbol:   variable MPI
  location: class Hello
6 errors

can anyone tell me where I can find MPI package? or how can I resolve this problem?

PS: I run the file hello_c.c with mpicc and mpic++ without any problem.

0

2 Answers 2

3

You should compile "Hello.java" with mpi classpath

javac -cp "path to mpi.jar" Hello.java

As I'm using "MAC OS" the "mpi.jar" is located in this path: "/usr/local/lib/mpi.jar"

So I compiled with this command:

javac -cp "/usr/local/lib/mpi.jar" Hello.java

You can also use "mpijavac":

mpijavac -cp "/usr/local/lib/mpi.jar" Hello.java

Then you can run your file with this command:

mpirun java Hello

If you are not able to find "mpi.jar" in your libs, maybe you didn't install open-mpi with java binding:

./configure --enable-mpi-java

For more information you can visit open-mpi with java

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe, you must install openMPI with java libary (example) and (or) add mpi.jar to project

1 Comment

But I cannot find mpi.jar in the directory. Where can I find it? or how can I install ist?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.