I am trying to run a simple native mpi code from java which I need later for my project. I am using Ubuntu. I have:
HelloJNI.java
public class HelloJNI {
static {
System.loadLibrary("hello");
}
private native void sayHello();
public static void main(String[] args) {
new HelloJNI().sayHello(); // invoke the native method
}
}
The header file:
JNIEXPORT void JNICALL Java_HelloJNI_sayHello (JNIEnv *, jobject);
The C source file:
JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
printf("Hello World- MPI from C!\n");
MPI_Init(NULL, NULL);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
printf("Hello world from processor %s, rank %d"
" out of %d processors\n",
processor_name, world_rank, world_size);
MPI_Finalize();
}
I have followed this tutorial: https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html
I am able to create the shared library through the make file which is:
INCLUDE1 = /usr/lib/java/jdk1.8.0_45/include
INCLUDE2 = /usr/lib/java/jdk1.8.0_45/include/linux
MPI_INCLUDE = /home/openmpi-1.8.5/ompi/include
JAVAHPATH = /usr/lib/java/jdk1.8.0_45/bin
MPICC = /home/openmpi-1.8.5/bin/mpicc
# Define a variable for classpath
CLASS_PATH = ../bin
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : libhello.so
# $@ matches the target, $< matches the first dependancy
libhello.so : HelloJNI.o
${MPICC} $< -L/home/openmpi-1.8.5/lib -lmpi -shared -fpic -o $@ -Wl,- rpath=/home/openmpi-1.8.5/lib
# $@ matches the target, $< matches the first dependancy
HelloJNI.o : HelloJNI.c HelloJNI.h
${MPICC} -fpic -I$(INCLUDE1) -I$(INCLUDE2) -I$(MPI_INCLUDE) -c $< -o $@
# $* matches the target filename without the extension
HelloJNI.h : HelloJNI.class
$(JAVAHPATH)/javah -classpath $(CLASS_PATH) $*
clean :
rm HelloJNI.h HelloJNI.o libhello.so
The problem is when I try to run it I am having these MPI errors:
"mca: base: component_find: unable to open /home/openmpi-1.8.5/lib/openmpi/mca_shmem_sysv: /home/openmpi-1.8.5/lib/openmpi/mca_shmem_sysv.so: undefined symbol: opal_show_help (ignored)
mca: base: component_find: unable to open /home/openmpi-1.8.5/lib/openmpi/mca_shmem_mmap: /home/openmpi-1.8.5/lib/openmpi/mca_shmem_mmap.so: undefined symbol: opal_show_help (ignored)
mca: base: component_find: unable to open /home/openmpi-1.8.5/lib/openmpi/mca_shmem_posix: /home/openmpi-1.8.5/lib/openmpi/mca_shmem_posix.so: undefined symbol: opal_shmem_base_framework (ignored)
It looks like opal_init failed .....orte_init failed ..... mpi_init failed"
I have tried various things so far both from command line and using eclipse which are: Using Eclipse:
- Added the shared library path via -Djava.library.path in the VM Argument in the run configuration
- Also through LD_LIBRARY_PATH as in Environment and also in bashrc
- In the makefile I have tried to compile the shared library using mpicc
- I have added the mpi.jar to the project as well
Using command line:
- javac -cp /home/s3050004/Downloads/openmpi-1.8.5/lib/mpi.jar HelloJNI.java
- java -Djava.library.path=/home/workspace/HelloJNI/jni:/home/openmpi-1.8.5/lib -cp /home/openmpi-1.8.5/lib/mpi.jar:/home/workspace/HelloJNI/src HelloJNI
In the command line I am trying to do the same as in eclipse which is specifying path to the shared library and the mpi lib also specfying the mpi.jar and the trying to run the HelloJNI but I get the same errors. I am not sure why I am getting these errors and I want to understand why I am getting them. I will really appreciate any suggestions or ideas towards this.