Domanda

In my OpenMP project, I use a do loop over a threaded subroutine "tool" and am restricted to pass a single-variate function to the threaded subroutine "tool." However, in my mathematical model, the function has to take one more argument, so I need to feed the second thread-dependent variables to respective threads.

For the function I need, I simply add the directive "!$OMP THREADPRIVATE(i)," And it works perfect. I am wondering how to port this code to OpenACC.

It seems to me that the new OpenACC 2.0 standard can handle this problem, but I could not find any detailed tutorial with sample code over the Internet to illustrate the use of the new directive such as "routine" to invoke thread-dependent functions or subroutines within the parallel zone.

Thanks.

Lee

  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
    
È stato utile?

Soluzione

No, OpenACC does not have an equivalent to threadprivate.

If you are not restricted to the type for your function argument, you should make a derived type and send that.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top