【问题标题】:Python calling a (fortran) library that uses MPIPython 调用使用 MPI 的(fortran)库
【发布时间】: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*

【问题讨论】:

    标签: python mpi


    【解决方案1】:

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

    ./configure --disable-dlopen

    希望它对你有用!

    【讨论】:

    • 您可以考虑添加一些formatting 您的答案以提高其质量。
    • 我有点忙,但我会尽快回来接受它。谢谢!
    猜你喜欢
    • 2020-03-26
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    • 2019-08-29
    • 2015-04-14
    • 2021-02-05
    • 2017-01-16
    相关资源
    最近更新 更多