I have the following MWE:
program main
implicit none
integer i,ints(5)
ints(:)=0
call omp_set_num_threads(5)
!$omp parallel do default(shared) private(ints,i)
do i=1,5
associate(ii=>ints(i))
write(*,*) ii
end associate
end do
!$omp end parallel do
end
whose expected output would be five zeros. However, this code prints random numbers when compiling with ifort version 2021.7.1.. My question would be how to resolve this conflict between OpenMP and associate?
Based on suggestions found on https://community.intel.com/t5/Intel-Fortran-Compiler/OpenMP-with-associate-define-private/m-p/1180441, I tried the following two modifications:
program main
implicit none
integer i,ints(5)
ints(:)=0
call omp_set_num_threads(5)
!$omp parallel do default(shared) private(ints,i)
do i=1,5
block
associate(ii=>ints(i))
write(*,*) ii
end associate
end block
end do
!$omp end parallel do
end
and
program main
implicit none
integer i,ints(5)
integer,pointer :: ii
call omp_set_num_threads(5)
ints(:)=0
!$omp parallel do default(shared) private(ints,i,ii)
do i=1,5
associate(ii=>ints(i))
write(*,*) ii
end associate
end do
!$omp end parallel do
end
but both of them print random numbers.