Fortran/MPI 编译错误 IMPLICIT NONE 语句不能跟在属性声明之后

Fortran/MPI Compilation Error IMPLICIT NONE statement cannot follow attribute declaration

我正在学习 fort运行 中的 MPI,所以我一直在编写一些小函数来在 MPI 中执行简单的任务,以便很好地处理它。然而,中途,我在尝试编译时开始遇到这个错误

$ mpif90 example.f90 -o example.out
example.f90:108:17:

  108 |     implicit none
      |                 1
Error: IMPLICIT NONE statement at (1) cannot follow attribute declaration statement at (2)

它甚至没有告诉我 (2) 在哪里,所以我不知道是什么导致了错误。但是当我注释掉 implicit none 时,它编译得很好并且 运行 正确。关于这里发生的事情有什么想法吗?

代码:

program send_vec
    include 'mpif.h'
    implicit none

    integer :: process_rank, cluster_size, ierror, message_item
    integer :: i
    integer, dimension(:), allocatable :: buffer_vector

    allocate(buffer_vector(1:10))

    call MPI_INIT(ierror)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, cluster_size, ierror)
    call MPI_COMM_RANK(MPI_COMM_WORLD, process_rank, ierror)

    if ( process_rank == 0 ) then
        do i = 1, 10
            buffer_vector(i) = i
        end do
        write (*,*) "sent:", buffer_vector
        call MPI_SEND(buffer_vector, 10, MPI_INT, 1, 1, MPI_COMM_WORLD, ierror)
    else if (process_rank == 1) then
        call MPI_RECV(buffer_vector, 10, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE, ierror)
        write (*,*) "recieved:", buffer_vector
    end if

    call MPI_FINALIZE(ierror)
    
end program send_vec

这也是 mpif90 -v

mpifort for MPICH version 3.4.1
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-7ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --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-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2) 

implicit none 必须出现在之前 include 'mpif.h'

也就是说,这很容易出错,你至少应该使用

program send_vec
use mpi
implicit none
...

(注意 implicit noneuse mpi 之后)

理想情况下,您会

program send_vec
use mpi_f08
implicit none
...

但这可能需要您对代码进行现代化改造 (例如,数据类型有自己的类型(例如 Type(MPI_Datatype) 而不是 INTEGER