Showing results for 
Search instead for 
Did you mean: 

Seeking for suggestions on OpenMP copyin of module variables...


I am trying to hybridize a pure-MPI code with OpenMP. But I am not expert on it, and I face a problem related to copyin the variables initialized from modules.

The arrays are initialized in 2 different modules, and they are then revalued and used to generate the output array in a do loop. Therefore, I have to copyin them in the OMP threads. However, these arrays are private in the modules, while the OMP part is in the subroutine outside the modules. And the calling relationship are a bit of complicated.

I really appreciate any suggestion on how to solve this problem. Thanks a lot in advance!




The following is the structure of the code:


subroutine main()

      use module1

      call initialize_module1 ! In module 1, a list of arrays are given initial values.

      call step1()

      call finalize_module1

end subroutine main

subroutine step1()

      use module2

      call initialize_module2 ! In module 2, a list of arrays are also given initial values...

      do loop (very big --> OpenMP) ! Here I think I have to copyin the arrays initialized in both module1 and module2, because in step2 they are revalued...

            call step2()

      end do

      call finalize_module2

end subroutine step1

subroutine step2()

      use module1

      use module2

      call work_module1()

      call work_module2()


end subroutine step2


module module1

      private array11, array12, ...


      subroutine initialize_module1() ! Give initial values of array11, array12, etc

      subroutine work_module1() ! Here array11, array12 are revalued...

      subroutine finalize_module1()

end module1

module module2

      private array21, array22, ...


      subroutine initialize_module2()

      subroutine work_module2() ! revalue array21, array22,...

      subroutine finalize_module2()

end module2

0 Kudos
1 Reply

One way to do this is to make the module arrays (that get revalued by different threads) thread private. Then where you call the initialize_module1, etc... perform that in a parallel region. IOW initialize each thread's context. Note, subsequent use of these contexts may be complicated if you use nested and/or dynamic scheduled threads.

You also may have to look into your finalize_module routines to see if a reduction is required (IOW if the contents of the individual threads results need to be combined in some manner).

Jim Dempsey


0 Kudos