User's Guide
!*****************************************************************
!* In this example, fort_sub is invoked by multiple threads *
!* *
!* This example is not valid because *
!* fort_sub and another_sub both declare /block/ to be *
!* THREADLOCAL, they intend to share the common block, but *
!* they are executed via different threads. *
!* *
!* To "fix" this problem, one of the following approaches can *
!* be taken: *
!* (1) the code for another_sub should be brought into the loop *
!* (2) "j" should be passed as an argument to another_sub, and *
!* the declaration for /block/ removed from another_sub *
!* (3) the loop should be marked as "do not parallelize" by *
!* using the directive "!SMP$ PARALLEL DO IF(.FALSE.)" *
!*****************************************************************
subroutine fort_sub()
common /block/ j
integer :: j
!IBM* THREADLOCAL /block/ ! Each thread executing fort_sub
! obtains its own copy of /block/
integer a(10)
...
!IBM* INDEPENDENT
do index = 1,10
call another_sub(a(i))
enddo
...
end subroutine fort_sub
subroutine another_sub(aa) ! Multiple threads are used to
integer aa ! execute another_sub.
common /block/ j ! Each thread obtains a new copy
integer :: j ! of the common block /block/.
!IBM* THREADLOCAL /block/
aa = j ! The value of "j" is undefined.
end subroutine another_sub
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]
© Copyright IBM Corporation 1990, 1998.