PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

Is there anything like "THREADPRIVATE" for OpenMP?

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
bangbing



Joined: 28 Jul 2013
Posts: 3

PostPosted: Thu Mar 27, 2014 3:02 pm    Post subject: Is there anything like "THREADPRIVATE" for OpenMP? Reply with quote

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

Code:
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
Back to top
View user's profile
cparrott



Joined: 02 May 2011
Posts: 146

PostPosted: Thu Mar 27, 2014 5:38 pm    Post subject: Reply with quote

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:

Code:

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
Back to top
View user's profile
bangbing



Joined: 28 Jul 2013
Posts: 3

PostPosted: Thu Mar 27, 2014 9:00 pm    Post subject: Reply with quote

@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.


Code:
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
Back to top
View user's profile
cparrott



Joined: 02 May 2011
Posts: 146

PostPosted: Fri Mar 28, 2014 3:53 pm    Post subject: Reply with quote

Lee,

I'm checking on something related to this, and I will follow up soon.

Best regards,

+chris
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group