I have created the code below to reproduce an error I am receiving in a much larger and more complex program.
An Array is defined in a module. The main program calls a subroutine which uses this module. The Subroutine allocates the array, does something and deallocates it again. Without OpenMP or with $OMP_NUM_THREADS=1 this works fine. As soon as the subroutine is called by multiple threads, only the first subroutine can allocate, because the Array is obviously shared.
I wonder if there is any possiblity to set the scope of this array to private, without declaring and allocating it before the parallel section or even within its lexical extent.
I was hoping that if the module is "used" the first time in the subroutine which is called from within the parallel region, a default(private) should help, but it didnt. Any suggestions would be very welcome.
If this question was already discussed I am sorry and would be grateful if anybody could shoot me a link. I did search but did not find!
Here is the example code:
- Code: Select all
integer, dimension(:),allocatable :: field1
end module common
integer :: i
!$omp parallel do default(private)
do i = 1,8
!$omp end parallel do
print*,'all good, goodbye'
end program hbtest
integer :: OMP_GET_THREAD_NUM
!$ print*,OMP_GET_THREAD_NUM(),' is allocating'
do i = 1,10000000
field1(1) = i * i / (i*1.0)
!$ print*,OMP_GET_THREAD_NUM(),' is deallocating'
end subroutine sr
For simplicity i ran it with 2 Threads. The resulting error is:
forrtl: severe (151): allocatable array is already allocated
Thanks in advance