【发布时间】:2020-03-26 16:11:06
【问题描述】:
我尝试从 python 调用 Fortran 的 MPI。
在 helloworld.f90 中,我写道:
subroutine sayhello(comm)
use mpi
!include 'mpif.h'
implicit none
integer :: comm, rank, size, ierr
call MPI_Comm_size(comm, size, ierr)
call MPI_Comm_rank(comm, rank, ierr)
print *, ’Hello, World! I am process ’,rank,’ of ’,size,’.’
end subroutine sayhello
还有一个叫hello.py:
from mpi4py import MPI
import helloworld
fcomm = MPI.COMM_WORLD.py2f()
helloworld.sayhello(fcomm)
但是在ubuntu 18.04,我用的是Python 3.7.4,无法使用命令创建file.so:
f2py -m helloworld -h helloworld.pyf helloworld.f90
f2py -c helloworld.pyf hello.py
当我运行命令时:
mpirun.openmpi was unable to find the specified executable file, and
therefore
did not launch the job. This error was first reported for process
rank 0; it may have occurred for other processes as well.
你能帮我解决这个错误或提供其他命令来运行
我的电脑可以从 Python 中打开 Fortran 的 MP。另外,我可以在 Fortran 中运行 MPI。但是,我不能从 Python 调用 Fortran 的 MPI。
任何帮助将不胜感激
【问题讨论】:
-
看起来
f2py找不到 MPI 包含文件。确保已安装 mpi devel 包,并在f2py命令行上添加包含文件的路径。 -
我曾经用fortran成功运行MPI。运行 MPI。我为 C/C++/Fortran 安装了 openMPI,为 PYTHON 安装了 mpi4pi。你能给我举个例子,包括你提到的路径。
-
f2py -I/path/to/include ... -
如果您的 MPI 代码仅在 Fortran 中(也就是说,在您的 Python 中没有进行 MPI 通信),那么您根本不需要在 Python 中使用 mpi4py。只需从 Python 内部调用您的 Fortran 代码,就好像它是串行代码一样,但在运行 Python 脚本时在命令行上调用 mpiexec。不要忘记在 Fortran 代码中初始化 MPI。这样一来,您就不需要 Python 识别 MPI 库,这应该可以解决您的问题。
标签: parallel-processing fortran mpi ubuntu-18.04 f2py