fortran/mpi汇编错误隐含无语句不能遵循属性声明

发布于 2025-01-21 09:46:35 字数 2968 浏览 2 评论 0原文

我正在Fortran学习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)在哪里,所以我不知道是什么原因导致错误。但是,当我评论隐式无时,它会恰当地编译并正确运行。关于这里发生的事情有什么想法吗?

代码:

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) 

I am in the process of learning MPI in fortran, and so I've been writing a bunch of small functions that do simple tasks in MPI to get a good handle on it. However, halfway through, i began getting this error when trying to compile

$ 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)

which doesn't even show me where (2) is so I don't know whats causing the error. But when I commented out implicit none, it compiled fine and ran correctly. Any ideas as to what is happening here?

Code:

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

Also this is 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) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一桥轻雨一伞开 2025-01-28 09:46:35

隐式无必须出现 incomn'mpif.h'

说这是非常错误的,您至少应该使用

program send_vec
use mpi
implicit none
...

(请注意隐式无是之后 使用mpi line)

理想情况下,您

program send_vec
use mpi_f08
implicit none
...

可能会要求您现代化代码
(例如,数据类型具有自己的类型(例如类型(MPI_DATATYPE)而不是Integer

implicit none must appear before include 'mpif.h'

That being said, this is very error prone, and you should at least use

program send_vec
use mpi
implicit none
...

(note the implicit none is after the use mpi line)

Ideally, you would

program send_vec
use mpi_f08
implicit none
...

but that will likely require you to modernize your code
(for example, a datatype has its own type (e.g. Type(MPI_Datatype) instead of INTEGER)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文