1

I am trying to parallelize a fairly complicated simulation code used for oil field calculations.

My question is, if I can declare a variable or some allocatable arrays and a few subroutines in a module, then use this module in another module/subroutine which contains the parallel region, will those variables and arrays be considered private to each thread (i.e. they will have separate copies of those variables and changes made to a variables in a thread won't be seen by other threads) or they'll be shared?

Like this:

module m2
implicit none
integer :: global
contains

    subroutine s2()
        implicit none
        integer :: tid
        tid = ! Some calculation
    end subroutine s2
end module m2

module m1
    use m2
    implicit none
contains
    subroutine s1
        !$omp parallel do
            do i=1, 9
                call s2()
            end do
        !$omp end parallel do
    end subroutine s1
end module m1

Will tid and global be private or shared?

Any help is greatly appreciated!

Mark Johnson
  • 59
  • 1
  • 1
  • 7

1 Answers1

2

Module variables are always shared in OpenMP unless you use the threadprivate directive. See Difference between OpenMP threadprivate and private for detailed description of threadprivate. So global will be shared.

The local variable tid is declared in the subroutine and called from the parallel region. Therefore it will be private unless it has the save attribute.

(Note that initialization like integer :: tid = 0 also adds the save implicitly, so be careful.)

Community
  • 1
  • 1