- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following sequential code (aside from any typos) uses a module so that repeated subroutine calls in the loop can operate on an array that has size and content dependent on the loop. Importantly (for the question being asked here) the subroutines access the array via the module and so the array does not have to be one of the elements in the subroutine parameter list.
Is there a way to thread the loop, keeping the array thread-safe, but NOT have to list the array as a subroutine parameter? Can modules (or parts of modules) be copied and made private?
module PlaceForArray
real(4), allocatable :: array(:,:)
end module
program testit
use PlaceForArray
do j = 1,10
allocate( array(j,j) )
array = float(j)
call foo1(Summation)
!do something with Summation
call foo1(Prod)
!do something with Prod
deallocate( array )
end do
end program testit
subroutine foo1(ArraySum)
use PlaceForArray
ArraySum = sum(array)
array = ArraySum
end subroutine foo1
subroutine foo2(ArrayProd)
use PlaceForArray
ArrayProd = product(array)
end subroutine foo2
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If (when) you want the module array "array" to be used exclusively by each thread, then declare the array threadprivate.
module PlaceForArray
!$omp threadprivate(array)
real(4), allocatable :: array(:,:)
end module
Doing so, provides separate arrays (same name) to each thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
**** Note, each thread must perform an allocation of their array.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page