【发布时间】:2014-12-31 14:36:32
【问题描述】:
我想加载和调用一个使用 MPI 的库。 我想每个等级都会加载它自己版本的库,然后这些库会相互通信。我不想从库调用者做任何通信或 MPI 处理。 例如,无论我加载使用 mpi 的库还是使用 openmp 的库,python 代码都将保持不变。当我从 C 动态加载和调用库时,我设法使它工作。但是使用 python 它失败了:
mca: base: component_find: 无法打开 /usr/lib/openmpi/lib/openmpi/mca_paffinity_hwloc:可能缺少 符号,还是为不同版本的 Open MPI 编译? (忽略)
[..]
看起来 opal_init 由于某种原因失败了;
[..]
opal_shmem_base_select 失败 --> 返回值 -1 而不是 OPAL_SUCCESS ompi_mpi_init: orte_init failed --> 返回“错误”(-1)而不是“成功”(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*
【问题讨论】: