In my OpenMP project, I use a DO LOOP over a threaded subroutine “tool” and need to pass a single-variate function “func” as an input argument to the subroutine.
However, a tricky issue is that I have to let the single-variate function take one more argument and this argument is thread specific. In the sample code below, this thread specific variable is “i”.
With OpenMP, all I have to do is simply to add the directive “!$OMP THREADPRIVATE…” in the declaration area of a Module where the threaded subroutine and the single-variate function are defined (Please see the sample code below).
May I ask if there is a way with OpenACC to perform the same operation?
- main.f90
program main
use toolbox
integer :: ja = [((j),j=1,9,2)]
b = [((j),j=2,10,2)]!$OMP PARALLEL DO DEFAULT(SHARED)
do j=1,5
i=j
call tool(fun1,a(j),c(j))
enddo
!$OMP END PARALLEL DO
print*, 'output c array: ', c
end program main
- toolbox.f90
module toolbox
integer :: i
!$OMP THREADPRIVATE(i)
real :: a(5), b(5), c(5)
contains
subroutine tool(func,x1,y1)
interface
real function func(x)
real :: x
end function func
end interface
real :: x1,y1
y1=func(x1)
end subroutine toolfunction func(x)
real :: func,x
func=x+b(i)
end function func
end module toolbox