Python 调用使用 MPI 的 (fortran) 库

标签 python mpi

我想加载并调用一个使用 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/

相关文章:

c++ - MPI 运行时给出不正确的输出

c++ - 查找并行化 C/C++ 的第 n 个排列

c++ - MPI Allgatherv 函数出现问题

python - 有效语法的语法错误突出显示 - Python 3.6

python - 谷歌云函数 : How to get access tokens in cloud function for the required scope?

C++ 程序在不执行 catch block 的情况下终止

c++ - 如何使用一次广播在 MPI 中传输不同类型的 vector

python - 从浏览器运行 Python 应用程序

python - VS Code 中的请求出现错误,原因是 SSLError ("Can' t connect to HTTPS URL,因为 SSL 模块不可用。”)

用于捕获所有字符串的 Python 正则表达式 (\w\s)+