Python调用使用MPI的(fortran)库

我想加载并调用一个使用MPI的库.
我想象每个等级加载自己的库版本,然后库将相互通信.我不想从库调用者进行任何通信或MPI处理.
无论我是否加载使用mpi的库或使用openmp的库,python代码都将保持不变.当我从C动态加载和调用库时,我设法使它工作.但是使用python它失败了:

mca: base: component_find: unable to open
/usr/lib/openmpi/lib/openmpi/mca_paffinity_hwloc: perhaps a missing
symbol, or compiled for a different version of Open MPI? (ignored)

[..]

It looks like opal_init 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)

[..]

我想知道我要为python做些什么.像openmpi重新编译python的东西?

我举一个例子如下:

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*

解决方法:

我有类似的问题,有一个解决方法:
当您运行configure以编译openmpi时,请使用以下标志:

./configure –disable-dlopen

希望这对你有用!

上一篇:并行计算学习之用MPI实现梯形积分法


下一篇:c – MPI_Finalize()未完成