[J3] print in do concurrent
Jeff Hammond
jehammond at nvidia.com
Sun Oct 23 13:56:13 UTC 2022
As best I can tell from the standard, one can print inside of do concurrent (DC) but only directly, and not via a procedure. Is this intended? It is not obvious why a procedure makes print any worse, other than the compiler can automatically add a critical section around it when it is in the body of the DC directly.
Program 1 and 2 illustrate this. The Intel compiler has no trouble with the former, and emits a nice result when executed in parallel: each line is as expected, albeit in a non-sequential order. Program 2 fails to compile for obvious reasons.
If compilers are expected to make print work inside of DC even though it is an impure notion, then why can’t we expect compilers to do whatever they do for print with *all* impure procedures inside of DC?
I would like this situation to be consistent. Either print is disallowed in DC altogether, or we allow impure procedures in DC and expect compilers to make this work in the same way that they make print work.
Thanks,
Jeff
Program 1
program main
integer :: i
do concurrent (i=1:10)
print*,i
end do
end program main
Program 2
module m
contains
! pure not allowed here because print makes it impure
pure subroutine p(i)
integer, intent(in) :: i
print*,i
end subroutine p
end module m
program main
use m
integer :: i
do concurrent (i=1:10)
! p has to be pure here
call p(i)
end do
end program main
More information about the J3
mailing list