在我的MPI fortran应用程序中,我有:
call MPI_INIT(ierror )
调试结果: ierror .eq。 MPI_SUCCESS
然后立即以相同的例程调用
call MPI_INITIALIZED(initialzed_flag,initialzed_ierror )
调试结果:initialzed_ierror .eq. MPI_SUCCESS
= 0
但是:initialzed_flag .eq. .false
表示存在MPI,但尚未初始化。如何调试这种情况?我正在将intel编译器与intel MPI,ifort版本18.0.5(2018)一起使用。
我尝试过:
export I_MPI_DEBUG=6
export I_MPI_HYDRA_DEBUG=on
但是我没有学到任何有用的东西。我怀疑问题是在运行时发生的,那是什么?
这是一个最小的工作示例:
program main
include 'mpif.h'
integer error
integer id
integer p
LOGICAL initialzed_flag
INTEGER initialzed_ierror
!
! Initialize MPI.
!
call MPI_Init ( error )
if (error .ne. MPI_SUCCESS) then
write(*,*)"MPI_INIT error at",__FILE__," line ",__LINE__
stop "Error MPI_INIT"
endif
c initialize the error to something other than success
initialzed_ierror = MPI_ERR_OTHER
call MPI_INITIALIZED(initialzed_flag,initialzed_ierror )
write(*,*)'initialzed_ierror =',initialzed_ierror
if ( initialzed_ierror .ne. MPI_SUCCESS) then
write(*,*)"Checking for MPI initialzed failed."
endif
if(.not. initialzed_flag)then
write(*,"(A85,1x,I3)")"MPI not initialized in " //
& trim(__FILE__) // " line ",__LINE__
STOP "MPI initialzing error"
else
write(*,*)"MPI was initialzed"
endif
!
! Get the number of processes.
!
call MPI_Comm_size ( MPI_COMM_WORLD,p,error )
!
! Get the individual process ID.
!
call MPI_Comm_rank ( MPI_COMM_WORLD,id,error )
! Every MPI process will print this message.
!
write ( *,'(a,i1,2x,a)' ) 'P','"Hello,world!"'
!
! Shut down MPI.
!
call MPI_Finalize ( error )
!
! Terminate.
stop
end
上面的文件名为hello_mpi.F。 生成文件:
all: a.out_mpif90 a.out_mpiifort
a.out_mpif90:
mpif90 -f90=ifort hello_mpi.F -o a.out_mpif90 # mimics my error
a.out_mpiifort:
mpiifort hello_mpi.F -o a.out_mpiifort
即使我使用mpiifort,文件a.out_mpif90
似乎也可以模仿我在整个代码中遇到的mwe错误。
我还发现:
ldd -v a.out_mpiifort # gives the same result as the commend below
ldd -v a.out_mpif90
在不正确的情况下输出(mpirun -np 2):
MPI_INIT error athello_mpi.F line 15
MPI_INIT error athello_mpi.F line 15
STOP Error MPI_INIT
STOP Error MPI_INIT