Hello,
I like to switch my code from OpenMP to OpenACC. In my OpenMP code, I pass “thread-dependent” arrays to designated threads. I am wondering whether I can do the same thing using OpenACC.
I outline the function I need in the following code snippet: I want to pass two more variables, “istart” and “iend”, into the subroutine “work” which only takes one input argument. Thanks.
Lee
module model
integer :: istart,iend
!$omp threadprivate(istart,iend)
implicit none
contains
subroutine work(iarray)
...
integer iarray(10000)
do i = istart, iend
iarray(i) = i * i
enddo
end subroutine work
end module model
program main
use parameters !not completely necessary here
use model
implicit none
...
integer iarray(10000)
N = 10000
!$omp parallel private(iam, nthreads, chunk)
nthreads = omp_get_num_threads()
iam = omp_get_thread_num()
chunk = (N + nthreads – 1)/nthreads
istart = iam * chunk + 1
iend = min((iam + 1) * chunk, N)
call work(iarray)
!$omp end parallel
end program main
Lee,
I think OpenACC can intelligently chunk up your array for you without all the explicit OpenMP chunking you are doing here. Try something like this:
subroutine work(iarray)
...
integer iarray(10000)
!$acc kernels loop copyin(iarray(1:10000))
do i = istart, iend
iarray(i) = i * i
enddo
end subroutine work
Hope this helps,
+chris
@Chris,
Thanks for the reply. I need to rephrase my question so that you can know what I came across in my project. I have the following two files. I use a do loop over a threaded subroutine “tool” and am restricted to pass a single- variate function to the subroutine. However, in my mathematical model, the function have two arguments, so I need to feed thread-dependent variables to respective threads.
In OpenMP, I can simply add the directive “!$OMP THREADPRIVATE(i).” I am wondering how to port this code to OpenACC. Thanks.
1. MAIN.F90
program main
use toolbox
real :: a(5),c(5)
integer :: j
a = [((j),j=1,9,2)]
b = [((j),j=2,10,2)]
!$OMP PARALLEL DO SHARED(b)
do j=1,5
i=j
call tool(fun1,a(j),c(j))
enddo
!$OMP END PARALLEL DO
write(6,'5(f3,x)') c
end program main
2. MODEL.F90
module toolbox
integer :: i
!$OMP THREADPRIVATE(i)
real :: b(5)
contains
subroutine tool(func,e,f)
interface
real function func(x)
real :: x
end function func
end interface
real :: e,f
f=func(e)
end subroutine tool
function fun1(z)
real :: fun1,z
fun1=z+b(i)
end function fun1
end module toolbox
Lee,
I’m checking on something related to this, and I will follow up soon.
Best regards,
+chris