我想加载并调用一个使用 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
生成文件
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
希望对你有用!
关于Python 调用使用 MPI 的 (fortran) 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26739644/