为什么 Intel Fortran + Intel MPI 在使用 MPI_Bcast 时报告警告(错误)?

问题描述 投票:0回答:1

这是一个带有 MPI 的 fortran 简单代码:

program mpi_broadcast_example
    use mpi

    implicit none

    integer :: ierr, rank, size, root
    integer :: a

    call MPI_Init(ierr)
    call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
    call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)

    root = 0

    if (rank == root) then
        ! Initialize the value of variable a on the root process
        a = 42
    endif

    ! Broadcast the value of variable a from the root process to all other processes
    call MPI_Bcast(a, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)

    ! Output the received value of variable a on all processes
    write(*,*) 'Process', rank, ': Received a =', a

    call MPI_Finalize(ierr)
end program mpi_broadcast_example

它只是使用 MPI_Bcast 将

a
从 0 级传递到其他等级。 当我使用Intel Fortran + Intel MPI编译它时,报告警告:

mpiifx test.f90 -o test -warn all
test.f90(21): warning #8889: Explicit interface or EXTERNAL declaration is required.   [MPI_BCAST]
    call MPI_Bcast(a, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)
---------^

我对这个警告感到困惑。 我在另一个项目中大量使用 MPI_Bcast,因此有很多警告,但对于其他 MPI 子例程,根本没有警告。这是编译器错误吗?我发现似乎不影响使用,但确实影响心情。 而我如果把

implicit none
改成
implicit none(type, external)
,就会直接报错:

mpiifx test.f90 -o test -warn all
test.f90(21): error #8889: Explicit interface or EXTERNAL declaration is required.   [MPI_BCAST]
    call MPI_Bcast(a, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)
---------^
compilation aborted for test.f90 (code 1)

我希望有人可以向我解释发生了什么以及这是否是一个编译错误。

fortran mpi intel-fortran intel-mpi
1个回答
0
投票

原因是,正如警告所述,

mpi
模块不包含
mpi_bcast
的接口。没有对其他例程发出警告的原因是
mpi
模块确实有这些例程的接口。

这是为什么呢?那么你必须询问那些实现

mpi
模块的人以获得明确的答案。但作为猜测答案的一步,让我注意到
mpi_bcast
与其他例程有一个根本区别 - 它有一个 choice 参数。换句话说,
mpi_bcast
的接口必须处理其第一个参数的许多不同类型、种类和等级,而作为示例和对比,
mpi_comm_rank
始终对其所有参数采用完全相同的类型、种类和等级。论据。在 Fortran-2003 之前,不可能为具有捕获所有可能情况的选择参数的例程编写接口。因此,
mpi
模块不需要包含具有一个或多个选择参数的任何例程的接口。另一方面,更现代的 mpi_f08 模块
 需要包含适当的接口,并且更改代码以使用此模块会导致警告消息消失:
ijb@ijb-Latitude-5410:~/work/stack$ cat bcast_f08.f90
program mpi_broadcast_example
    use mpi_f08

    implicit none

    integer :: ierr, rank, size, root
    integer :: a

    call MPI_Init(ierr)
    call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
    call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)

    root = 0

    if (rank == root) then
        ! Initialize the value of variable a on the root process
        a = 42
    endif

    ! Broadcast the value of variable a from the root process to all other processes
    call MPI_Bcast(a, 1, MPI_INTEGER, root, MPI_COMM_WORLD, ierr)

    ! Output the received value of variable a on all processes
    write(*,*) 'Process', rank, ': Received a =', a

    call MPI_Finalize(ierr)
end program mpi_broadcast_example
ijb@ijb-Latitude-5410:~/work/stack$ ifx -v
ifx version 2023.2.0
ijb@ijb-Latitude-5410:~/work/stack$ mpiifx -warn all bcast_f08.f90
ijb@ijb-Latitude-5410:~/work/stack$ 

© www.soinside.com 2019 - 2024. All rights reserved.