加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python调用使用MPI的(fortran)库

发布时间:2020-12-20 13:45:33 所属栏目:Python 来源:网络整理
导读:我想加载并调用一个使用MPI的库. 我想象每个等级加载自己的库版本,然后库将相互通信.我不想从库调用者进行任何通信或MPI处理. 无论我是否加载使用mpi的库或使用openmp的库,python代码都将保持不变.当我从C动态加载和调用库时,我设法使它工作.但是使用python
我想加载并调用一个使用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 "," 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

希望这对你有用!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读