Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #866 from ggouaillardet/topic/v1.10/java_full_libm…
Browse files Browse the repository at this point in the history
…pi_path

java: try do dlopen libmpi with the full path
  • Loading branch information
rhc54 committed Dec 23, 2015
2 parents f28bf4e + 1037c4b commit ad281e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/ompi_setup_java.m4
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ AC_DEFUN([OMPI_SETUP_JAVA_BINDINGS],[
# header file needs this file, so we need to check for
# it/include it in our sources when compiling on Mac).
AC_CHECK_HEADERS([TargetConditionals.h])

# dladdr and Dl_info are required to build the full path to libmpi on OS X 10.11 aka El Capitan
AC_CHECK_TYPES([Dl_info], [], [], [[#include <dlfcn.h>]])
else
AC_MSG_RESULT([no])
WANT_MPI_JAVA_SUPPORT=0
Expand Down
6 changes: 4 additions & 2 deletions ompi/mpi/java/c/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- makefile -*-
#
# Copyright (c) 2011-2013 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
Expand Down Expand Up @@ -41,7 +43,7 @@ libmpi_java_la_SOURCES = \
mpi_Status.c \
mpi_Win.c

libmpi_java_la_LIBADD = $(top_builddir)/ompi/libmpi.la
libmpi_java_la_LIBADD = -ldl $(top_builddir)/ompi/libmpi.la
libmpi_java_la_LDFLAGS = -version-info $(libmpi_java_so_version)

endif
29 changes: 28 additions & 1 deletion ompi/mpi/java/c/mpi_MPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -66,8 +68,13 @@
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#include <poll.h>
#ifdef HAVE_LIBGEN_H
#include <libgen.h>
#endif

#include "opal/util/output.h"
#include "opal/datatype/opal_convertor.h"
Expand Down Expand Up @@ -130,7 +137,27 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
libmpi = dlopen("libmpi." OPAL_DYN_LIB_SUFFIX, RTLD_NOW | RTLD_GLOBAL);

if(libmpi == NULL)
#if defined(HAVE_DL_INFO) && defined(HAVE_LIBGEN_H)
/*
* OS X El Capitan does not propagate DYLD_LIBRARY_PATH to children any more
* so if previous dlopen failed, try to open libmpi in the same directory
* than the current libmpi_java
*/
if(NULL == libmpi) {
Dl_info info;
if(0 != dladdr((void *)JNI_OnLoad, &info)) {
char libmpipath[OPAL_PATH_MAX];
char *libmpijavapath = strdup(info.dli_fname);
if (NULL != libmpijavapath) {
snprintf(libmpipath, OPAL_PATH_MAX-1, "%s/libmpi." OPAL_DYN_LIB_SUFFIX, dirname(libmpijavapath));
free(libmpijavapath);
libmpi = dlopen(libmpipath, RTLD_NOW | RTLD_GLOBAL);
}
}
}
#endif

if(NULL == libmpi)
{
fprintf(stderr, "Java bindings failed to load libmpi: %s\n",dlerror());
exit(1);
Expand Down

0 comments on commit ad281e0

Please sign in to comment.