根据Fortran标准,我不确定这是否合法。我有一个通过重载调用的子例程。这里的意思是有时我可能会调用子例程,在该子例程中我有指向real
的指针别名。
请看一下完整的代码。
module mpi_intf_exam
use mpi
interface GLB_SUM
module procedure GLB_SUM_INT
module procedure GLB_SUM_FLT
module procedure GLB_SUM_FLT_INPLACE
end interface
integer :: mpierr
contains
subroutine GLB_SUM_INT(buf,buf_out,n)
implicit none
integer,intent(in) :: n
integer,intent(in) :: buf(n)
integer,intent(out) :: buf_out(n)
call mpi_allreduce( buf,n,MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,mpierr)
end subroutine
subroutine GLB_SUM_FLT(buf,intent(in) :: n
real,intent(in) :: buf(n)
real,MPI_REAL,mpierr)
end subroutine
subroutine GLB_SUM_FLT_INPLACE(buf,intent(inout) :: buf(n)
call mpi_allreduce( MPI_IN_PLACE,buf,mpierr)
end subroutine
end module
program test_gather
use mpi_intf_exam
implicit none
integer :: rank,ierr,nranks,i
real,allocatable,target :: bufs(:),bufr(:)
real,pointer :: ptr(:)
call mpi_init(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,ierr)
n = 10
allocate(bufs(n))
ptr => bufs
call random_number(ptr)
ptr = ptr*(rank+1)
print*,sum(bufs),"BEF"
call GLB_SUM(ptr,n) !
print*,rank
end program
我的呼叫call GLB_SUM(ptr,n)
旨在调用例程GLB_SUM_FLT_INPLACE
。但是正如您所看到的,当我使用real pointer
调用它时,该子例程具有真正的哑元参数。
对于此特定示例,它适用于IFORT V19.0.5。但这有效吗?我找不到标准对这种电话的评价。