On 06/05/17 19:23, Tomasz Buchert wrote: > [...] Ok, I confirm that dlopen() is required to properly resolve some symbols later: I can only assume that openmpi does some magic there. Here are 2 solutions I came up with:
1. Just like in #741297: add another dlopen() call to the chain (see
attached simple-but-wrong.debdiff)
2. Figure out what is the libmpi to load. I attach a proof-of-concept that
uses dl_iterate_phdr
to find this out (see attached findlibmpi.debdiff).
I've tested both approaches and they work for me.
Btw, it would be good to add a smoke test to verify that loading from
R works, so that we can detect it just after build.
Let me know what you think.
Tomasz
only in patch2:
unchanged:
--- rmpi-0.6-6.orig/src/Rmpi.c
+++ rmpi-0.6-6/src/Rmpi.c
@@ -74,7 +74,8 @@
#ifndef __APPLE__
#ifdef OPENMPI
- if (!dlopen("libmpi.so.1", RTLD_GLOBAL | RTLD_LAZY)
+ if (!dlopen("libmpi.so.20", RTLD_GLOBAL | RTLD_LAZY)
+ && !dlopen("libmpi.so.1", RTLD_GLOBAL | RTLD_LAZY)
&& !dlopen("libmpi.so.0", RTLD_GLOBAL | RTLD_LAZY)
&& !dlopen("libmpi.so", RTLD_GLOBAL | RTLD_LAZY)) {
Rprintf("%s\n",dlerror());
only in patch2:
unchanged:
--- rmpi-0.6-6.orig/src/Rmpi.c
+++ rmpi-0.6-6/src/Rmpi.c
@@ -15,10 +15,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define _GNU_SOURCE
#include "Rmpi.h"
#ifdef OPENMPI
#include <dlfcn.h>
+#include <link.h>
+#include <string.h>
#endif
static MPI_Comm *comm;
@@ -57,6 +60,15 @@
return AsInt(i);
}
+static int
+dl_iter_cb(struct dl_phdr_info *info, size_t size, void *data)
+{
+ if (strstr(info->dlpi_name, "libmpi.so") != NULL) {
+ *((char**)data) = strdup(info->dlpi_name);
+ }
+ return 0;
+}
+
SEXP mpi_initialize(){
int i,flag;
MPI_Initialized(&flag);
@@ -74,12 +86,19 @@
#ifndef __APPLE__
#ifdef OPENMPI
- if (!dlopen("libmpi.so.1", RTLD_GLOBAL | RTLD_LAZY)
- && !dlopen("libmpi.so.0", RTLD_GLOBAL | RTLD_LAZY)
- && !dlopen("libmpi.so", RTLD_GLOBAL | RTLD_LAZY)) {
+ char* mpiso = NULL;
+ dl_iterate_phdr(dl_iter_cb, &mpiso);
+ if (mpiso == NULL) {
+ Rprintf("No openmpi linked.\n");
+ return AsInt(0);
+ }
+
+ if (!dlopen(mpiso, RTLD_GLOBAL | RTLD_LAZY)) {
+ free(mpiso);
Rprintf("%s\n",dlerror());
return AsInt(0);
}
+ free(mpiso);
#endif
#endif
signature.asc
Description: PGP signature

