通过带有 gfortran 的 mpi_f08 模块支持 MPI Fortran

问题描述

我有一些 Fortran 代码,我想与 MPI 并行化。显然,在 Fortran 中使用 MPI(在我的情况下为 MPICH)的推荐方法是通过 mpi_f08 模块(mpi-forum entry on the matter),但我无法使其正常工作,因为根本没有创建相应的 mod 文件(与mpi.mod,它工作正常,但它不是最新的 Fortran 标准)。 This discussion 给我留下的印象是 gfortran 无法构建 F08 绑定。您可以在下面看到我的配置,gfortran 和 mpich 都已通过 apt install 在 ubuntu 上安装,并且应该是最新的。我不确定一些事情:

  • 有什么方法可以使 Fortran 2008 MPI 语法与 gfortran 一起使用?从我遇到的情况来看,答案似乎是否定的,但希望有人可能知道解决方法。我对此不太精通,因此不胜感激任何相关链接或更多入门级解释。
  • 可以使用不同的编译器帮助吗?英特尔编译器* 也许?如果合理,我宁愿坚持使用 gfortran。
  • 也许与当前标准保持一致并不是什么大问题。根据您的经验,通过 mpi.mod 模块获得支持会更好吗?那时我会遇到什么问题?我的应用程序没有太大的长远目标,所以如果它现在可以正常运行,一段时间后失去支持也不是什么大问题。

编辑

似乎是使用过时版本的 gfortran 的问题。这将我的问题简化为如何使用 gfortran-10 构建 MPICH。


* 因此 [intel-fortran] 标签,如果您认为它多余,请随意删除

为了清楚起见,这是我的 gfortran 和 mpich 配置

pavel@pavel:~$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 
pavel@pavel:~$ mpiexec --version
HYDRA build details:
    Version:                                 3.3a2
    Release Date:                            Sun Nov 13 09:12:11 MST 2016
    CC:                              gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro 
    CXX:                             g++   -Wl,relro 
    F77:                             gfortran  -Wl,relro 
    F90:                             gfortran  -Wl,relro 
    Configure options:                       '--disable-option-checking' '--prefix=/usr' '--build=x86_64-linux-gnu' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-silent-rules' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--libexecdir=${prefix}/lib/x86_64-linux-gnu' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-libfabric' '--enable-shared' '--enable-fortran=all' '--disable-rpath' '--disable-wrapper-rpath' '--sysconfdir=/etc/mpich' '--libdir=/usr/lib/x86_64-linux-gnu' '--includedir=/usr/include/mpich' '--docdir=/usr/share/doc/mpich' '--with-hwloc-prefix=system' '--enable-checkpointing' '--with-hydra-ckpointlib=blcr' 'CPPFLAGS= -Wdate-time -D_FORTIFY_SOURCE=2 -I/build/mpich-O9at2o/mpich-3.3~a2/src/mpl/include -I/build/mpich-O9at2o/mpich-3.3~a2/src/mpl/include -I/build/mpich-O9at2o/mpich-3.3~a2/src/openpa/src -I/build/mpich-O9at2o/mpich-3.3~a2/src/openpa/src -D_REENTRANT -I/build/mpich-O9at2o/mpich-3.3~a2/src/mpi/romio/include' 'CFLAGS= -g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong -Wformat -Werror=format-security -O2' 'CXXFLAGS= -g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong -Wformat -Werror=format-security -O2' 'FFLAGS= -g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong -O2' 'FCFLAGS= -g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong -O2' 'build_alias=x86_64-linux-gnu' 'MPICHLIB_CFLAGS=-g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong -Wformat -Werror=format-security' 'MPICHLIB_CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'MPICHLIB_CXXFLAGS=-g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong -Wformat -Werror=format-security' 'MPICHLIB_FFLAGS=-g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong' 'MPICHLIB_FCFLAGS=-g -O2 -fdebug-prefix-map=/build/mpich-O9at2o/mpich-3.3~a2=. -fstack-protector-strong' 'LDFLAGS=-Wl,relro' 'FC=gfortran' 'F77=gfortran' 'MPILIBNAME=mpich' '--cache-file=/dev/null' '--srcdir=.' 'CC=gcc' 'LIBS=' 'MPLLIBNAME=mpl'
    Process Manager:                         pmi
    Launchers available:                     ssh rsh fork slurm ll lsf sge manual persist
    Topology libraries available:            hwloc
    Resource management kernels available:   user slurm ll lsf sge pbs cobalt
    Checkpointing libraries available:       blcr
    Demux engines available:                 poll select

尝试使用 mpif90 编译我的代码导致

something.f90:2:5:

  use mpi_f08
     1
Fatal error: Can't open module file ‘mpi_f08.mod’ for reading at (1): File does not exist
compilation terminated.

解决方法

MPICH 要求 Fortran 编译器支持技术规范 29113 的数组描述符,而这仅在最新版本的 gfortran 中受支持(GNU 10 可以)。 英特尔编译器已经有一段时间了。

请注意,Open MPI 并不是那么挑剔。 TS 29113 并且不需要对数组描述符的支持。 GNU 7.5 可用于生成 mpi_f08 模块。

最重要的是,您有两个选择 w.r.t. mpi_f08 Fortran 模块:

  • 使用符合 MPICH 期望的 Fortran 支持 w.r.t. TS 29113(例如 GNU 10 或英特尔编译器)
  • 转向 Open MPI