We have OpenMP problem regarding the use of a COPYPRIVATE at the end of a SINGLE region with PGI 14.9.0 64-bit on X86-64. If the SINGLE clause is separated from the binding PARALLEL region, then the COPYPRIVATE causes a segfault if the variable to which it is applied is local to the subroutine and stack-allocated. The problem can be circumvented if the variable is given the ALLOCATABLE attribute and allocated explicitly within the subroutine. The code does not segfault when built with Intel, GNU, or the Cray compiler.
Many thanks for any advice.
Code:
program test
!
implicit none
!
call master()
!
end program test
!
!-------------------------------
!
subroutine master
!
implicit none
!
integer(KIND=8), ALLOCATABLE:: tts(:)
integer(KIND=8) ttt(2)
integer nt,OMP_GET_NUM_THREADS,tpi,OMP_GET_THREAD_NUM
!
nt = 4
call OMP_SET_NUM_THREADS(nt)
allocate(tts(nt))
!
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(ttt,tpi)
!
tpi = OMP_GET_THREAD_NUM() + 1
!$OMP SINGLE
call System_Clock(count_rate=ttt(1))
!$OMP END SINGLE COPYPRIVATE(ttt)
!
tts(tpi) = ttt(1)
!
!$OMP END PARALLEL
!
write(,) ‘All embedded:’
do tpi=1,nt
write(,) 'Thread ‘,tpi,’: ',tts(tpi)
end do
!
!
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(ttt,tpi)
!
tpi = OMP_GET_NUM_THREADS()
call do_the_same_hidden(tpi,tts)
!
!$OMP END PARALLEL
!
write(,) ‘Hidden:’
do tpi=1,nt
write(,) 'Thread ‘,tpi,’: ',tts(tpi)
end do
!
end subroutine master
!
!----------------------------------------
!
subroutine do_the_same_hidden(tpn,tts)
!
implicit none
!
integer, INTENT(IN):: tpn
!
integer(KIND=8) tts(tpn)
integer(KIND=8) ttt(2) ! this will not work with PGI
! integer (KIND=8), ALLOCATABLE:: ttt(:) ! this will work with PGI
integer OMP_GET_THREAD_NUM,tpi
!
! allocate(ttt(tpn)) ! see above
tpi = OMP_GET_THREAD_NUM() + 1
!$OMP SINGLE
call System_Clock(count_rate=ttt(1))
!$OMP END SINGLE COPYPRIVATE(ttt)
!
tts(tpi) = ttt(1)
! deallocate(ttt) ! see above
!
end subroutine do_the_same_hidden