Python calling a library (fortran) that uses MPI

I would like to load and call a library using MPI. I would assume that each rank loads its own version of the library and then the libraries will communicate with each other. I don't want to do the linking or MPI processing from the caller of the library. The python code would remain the same whether I download a library using mpi or a library using openmp for example. I manage to get it to work when I dynamically load and call the library from C. But with python it fails:

mca: base: component_find: Unable to open / usr / lib / openmpi / lib / openmpi / mca _paffinity_hwloc: symbol may be missing or compiled for another version of Open MPI? (Ignored)

[..]

It looks like opal_init has failed for some reason;

[..]

opal_shmem_base_select failed → Returned value -1 instead of OPAL_SUCCESS ompi_mpi_init: orte_init failed → Returned "Error" (-1) instead of "Success" (0)

[..]

I wonder what should I do for it with python. Something like recompiling python with openmpi?

Below is an example:

testMPI.py

#!/usr/bin/env python
from ctypes import *
# Loading library
raw = cdll.LoadLibrary('./libtest.so.1.0')
print "hello world "
raw.test()

      

test.f90

subroutine test() bind(c,name='test')
    use MPI
    implicit none
    integer :: nprocs =-1 !< total number of process 
    integer :: rank=0    !< rank in comm world
    integer :: ierr =-1  !< 
    call MPI_init(ierr)
    call MPI_comm_size(MPI_comm_world, nprocs, ierr)
    call MPI_comm_rank(MPI_comm_world, rank, ierr)
    write(*,*)"hello world from ",rank," of ",nprocs
    call MPI_finalize(ierr)
end subroutine

      

Makefile

FC=mpif90.openmpi
FFLAGS=-free -fPIC -g -Wall 
all: obj test
test:
    mpirun.openmpi -n 4 ./testMPI.py
obj:
    $(FC) $(FFLAGS) -c test.f90
    $(FC) $(FFLAGS) -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0 test.o
clean:
    rm *.o libtest*

      

+3


source to share


1 answer


I had a similar problem, there is a workaround for this: when running configure to compile openmpi use the following flag:

./configure --disable-dlopen



Hope it works for you!

+1


source







All Articles