提问人:DrunkenEngineer 提问时间:2/14/2023 最后编辑:DrunkenEngineer 更新时间:3/10/2023 访问量:336
使用 Cygwin64 的 Fortran MPI
Fortran MPI using Cygwin64
问:
我正在使用 Codeblock IDE 来编写和编译我的 Fortran 程序。现在我想将 MPI 包含在我的 GNU Fortran 编译器中。在遵循了 GNU GCC 编译器的一些指南之后,我突然想到我需要为 MPICH2 设置以下内容(有两个指南):
(1) 将 mpi.lib 添加到链接器设置中 (2) 将包含文件添加到搜索目录
但是,由于下面这一行的错误,这些设置将无法编译,并说它有一个意外的 EoF: 使用 MPI
所以,然后我尝试使用 Cygwin 包含文件(带有来自 MPICH2 的 mpi.lib),奇怪的是,它编译得很好,即使使用:
call mpi_init (ierr)
call mpi_comm_rank (mpi_comm_world,rank,ierr)
call mpi_finalize (ierr)
但是,当我尝试运行该程序时。它不会执行以下操作:
call mpi_init (ierr)
然后我尝试手动编译程序,它显示:
C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x18c): undefined reference to mpi_init_' C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x1fd): undefined reference to mpi_comm_rank_’
C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x276): undefined reference to `mpi_finalize_’
collect2.exe: error: ld returned 1 exit status
也许我还没有为 MPI 环境设置一个设置,或者我需要获取 Cygwin mpi.lib,从 Cygwin 安装完整的 MPI 包后我找不到它。
在尝试了许多其他方法后,我意识到,为什么 Cygwin64 上没有“include”文件夹
也许我需要的是如何在 Cygwin64 环境中为 MPI 设置链接器/搜索目录/路径的指南?
有人可以在这里帮我吗? 非常感谢您的帮助
编辑:我已经从最后一次机会中执行了解决方案。链接过程中似乎有错误。下面是命令窗口响应:
C:\Windows\system32>cd C:\Batch
C:\Batch>do_intel 测试
C:\Batch>rem ifort -c test.f90 /traceback /check:all /Qparallel -I“C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
C:\Batch>ifort -c test.f90 /Qparallel /O3 -I“C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel Intel(R) Fortran Intel(R) 64 适用于在 IA-32 上运行的应用程序的 Compiler Classic,版本 2021.6.0 Build 20220226_000000 版权所有 (C) 1985-2022 英特尔公司。都 版权。
C:\Batch>ifort test.obj -o 测试.exe “C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpi.lib“ ”C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpifec.lib“ 英特尔(R) Fortran 英特尔(R) 64 编译器 适用于在 IA-32 上运行的应用程序的经典版本,版本 2021.6.0 内部版本 20220226_000000 版权所有 (C) 1985-2022 英特尔公司。所有权利 保留。
link: 未知选项 -- s 尝试“link --help”以获取更多信息。
C:\Batch>runmpi 测试.exe 2
C:\Batch>设置 OPT=“C:\Program Files\Microsoft MPI\bin”
C:\Batch>“C:\Program Files\Microsoft MPI\bin”\mpiexec -n 2 测试.exe
C:\Batch>link --help 用法:链接 FILE1 FILE2 或:链接 OPTION 调用 link 函数,用于创建指向现有 FILE1 的名为 FILE2 的链接。
--help display this help and exit --version output version information and exit
GNU coreutils 在线帮助: https://www.gnu.org/software/coreutils/ 将任何翻译错误报告给 https://translationproject.org/team/ 完整文档 https://www.gnu.org/software/coreutils/link 或 本地可用:info '(coreutils) link invocation'
C:\批处理>
编辑2:以下是我尝试逐个手动运行批处理文件时CMD的响应(第一行没有响应):
C:\Batch>rem ifort -c %1.f90 /traceback /check:all /Qparallel -I“C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
C:\Batch>ifort -c %1.f90 /Qparallel /O3 -I“C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel Intel(R) Fortran Intel(R) 64 适用于在 IA-32 上运行的应用程序的 Compiler Classic,版本 2021.6.0 Build 20220226_000000 版权所有 (C) 1985-2022 英特尔公司。都 版权。
fortcom:严重:没有这样的文件或目录
...文件为 %1.f90 的“%1.f90”编译已中止(代码 1)
注意:我还尝试将所有 1.f90 更改为 test.f90,仍然出现相同的结果
非常感谢您的帮助~
答:
您可以使用以下方法执行以下操作:
- Windows 10 命令行(不是 Cygwin)
- 英特尔 Fortran 编译器 (ifort)
- Microsoft MPI
(1) 在 Windows 命令窗口中安装并能够使用英特尔编译器(您的问题)。
(2) 通过从 https://www.microsoft.com/en-us/download/details.aspx?id=100593 下载 来安装 Microsoft MPI 您需要下载并安装 msmpisetup.exe 和 msmpisdk.msi
(3) 您需要在 MS-MPI include 目录中使用编译器 (ifort) 编译 mpi.f90(您需要管理员权限)。
(i) 在 Windows 搜索栏中输入“cmd”,然后选择 (RHS) “以管理员身份运行”。您需要确保在此状态下仍可运行 ifort 编译器:一种替代方法是从 Windows 开始菜单中的编译器选项中启动命令窗口,但请确保在此处使用右键单击并以管理员身份运行。
(ii) 在此管理员命令窗口中,导航到 MS-MPI 包含目录(例如 C:\Program Files (x86)\Microsoft SDKs\MPI\Include) 并创建一个新的子目录“intel”。
(iii) 将文件 mpi.f90 从 include 目录复制到 .\intel 子目录中。此外,将文件 mpifptr.h 从 .\x64 子目录复制到 .\intel 子目录中。
(iv) 在此命令窗口中,导航到 .\intel 子目录并键入命令“ifort -c mpi.f90”。现在,您应该有相关的 mpi 模块文件可用。
(4) 在 C 盘的某处创建一个普通目录,并将以下批处理文件和 MPI/fortran 源文件放入其中:
do_intel.bat
rem ifort -c %1.f90 /traceback /check:all /Qparallel -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
ifort -c %1.f90 /Qparallel /O3 -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\intel
ifort %1.obj -o %1.exe "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpi.lib" "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpifec.lib"
runmpi.bat
set OPT="C:\Program Files\Microsoft MPI\bin"
%OPT%\mpiexec -n %2 %1
测试.f90
program main
use mpi
implicit none
integer size, rank, tag
integer stat(mpi_status_size), ierr
integer I
real R
call mpi_init( ierr )
call mpi_comm_size( mpi_comm_world, size, ierr )
call mpi_comm_rank( mpi_comm_world, rank, ierr )
write( *, * ) "Processor ", rank, " of ", size, " is alive"
tag = 0
if ( rank == 0 ) then
I = 42
R = 3.14152
call mpi_send( I, 1, mpi_integer, 1, tag, mpi_comm_world, ierr )
write( *, * ) "Processor ", rank, " sent integer ", I
call mpi_send( R, 1, mpi_real , 1, tag, mpi_comm_world, ierr )
write( *, * ) "Processor ", rank, " sent real ", R
else if ( rank == 1 ) then
call mpi_recv( I, 1, mpi_integer, 0, tag, mpi_comm_world, stat, ierr )
write( *, * ) "Processor ", rank, " received integer ", I
call mpi_recv( R, 1, mpi_real, 0, tag, mpi_comm_world, stat, ierr )
write( *, * ) "Processor ", rank, " received real ", R
end if
call mpi_finalize( ierr )
end program main
(5) 使用命令窗口,在 do_intel.bat、runmpi 和 test.f90 所在的目录中.bat键入
do_intel test
它应该(希望!)编译和链接测试文件。
(6) 如果全部编译正确,则键入
runmpi test.exe 2
使用两个处理器运行测试程序。
gfortran 也可以与 Microsoft MPI 一起运行,尽管要让它运行起来更难,而且我发现它“不可靠”。
编译 mpi.f90 文件(假定位于 MS-MPI 包含目录的 .\gfortran 子控制器中)需要以下命令:
gfortran -c -fallow-invalid-boz -fno-range-check mpi.f90
下面的批处理文件可以编译和链接测试文件:
rem gfortran -c %1.f90 -Wall -Wextra -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\gfortran" -fallow-argument-mismatch -ff2c
gfortran -c %1.f90 -O3 -I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\gfortran" -fallow-argument-mismatch -ff2c
gfortran -o %1.exe %1.o "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpi.lib" "C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\msmpifec.lib"
对于我的许多更复杂的进程,带有 MS-MPI 的 gfortran 适用于少数处理器,然后挂起或崩溃;我无法找出原因,因为该问题在英特尔编译器上工作正常。
评论
Cygwin 有 OpenMPI 软件包
对于开发,您需要安装
https://cygwin.com/packages/summary/libopenmpi-devel.htmllibopenmpi-devel
软件包
https://cygwin.com/packages/x86_64/openmpi/openmpi-4.1.5-1
提供了大多数 GNU GCC 编译器的接口。查看内容摘录openmpi
usr/bin/mpic++ -> opal_wrapper.exe
usr/bin/mpicc -> opal_wrapper.exe
usr/bin/mpicxx -> opal_wrapper.exe
usr/bin/mpiexec -> orterun.exe
usr/bin/mpif77 -> opal_wrapper.exe
usr/bin/mpif90 -> opal_wrapper.exe
usr/bin/mpifort -> opal_wrapper.exe
重用另一个答案中报告的示例
$ mpif90 test.f90 -o prova
$ mpirun -n 4 ./prova
Processor 0 of 4 is alive
Processor 0 sent integer 42
Processor 0 sent real 3.14152002
Processor 1 of 4 is alive
Processor 1 received integer 42
Processor 1 received real 3.14152002
Processor 2 of 4 is alive
Processor 3 of 4 is alive
评论
mpirun
mpifort
gfortran
mpifort --showme