The following Fortran program freezes on call to print_test.
program test_prg
implicit none
integer :: mpi_enabled, ierr
call MPI_Initialized(mpi_enabled, ierr)
print *, print_test()
contains
function print_test() result(res)
real :: res
res = 0
print *, 'HELLO'
end function
end program
The call to print_test can even be before the call to MPI_Initialized and still freeze as long as the call to MPI_Initialized and print *, print_test() is present somewhere in the program. The same problem can also be reproduced if MPI_Initialized is replaced with MPI_Init, but not if I remove it. If I remove print *, 'HELLO', then it works. If I call print_test on a separate line and then print the result, then it works. The problem is observed when compiled with gfortran 9.3.0 (through mpifort). The same program works without issues when compiled with ifort. MPICH version is 3.3.2.
Is this a gfortran bug? Does anyone know how to fix this issue?