Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29249 Discussions

Question about local allocatable arrays in FORTRAN subroutines with OpenMP

Wuwei_L_
Beginner
756 Views
I'm trying to parallelize my FORTAN code using OpenMP. There are local allocatable arrays in subroutines. I wonder if these local allocatable arrays are private or shared. The results seemed to tell that these arrays were private. But the Intel Inspector XE reported quite a few data race problems with these allocatable arrays.
0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
756 Views
Are the allocations performed within a parallel region in the subroutine where the array descriptor is declared? If so, you willneed to declare the (unallocated)array descriptor private.

.OR.

Are the subroutines called from within a parallel region? (including nested calls begun in a parallel region).
If so, then are these subroutines compiled with -openmp .OR. attributed with RECURSIVE?

Recursive subroutines have the property where the array descriptor default placement is on the stack (you can override this with SAVE). -openmp has the effect of adding RECURSIVE to the subroutine (it wouldn't hurt to explicitly mark this subroutine as RECURSIVE).

Posting problem code samples may help us in diagnosing your problem.

Jim Dempsey

0 Kudos
Wuwei_L_
Beginner
756 Views
The subroutine is called within a parallel region and the array is allocated and deallocated with the parallel region. The following sample code illustrates the problem. The 'recursive' flag wasn't used in compiling the code.
-------------------------
program main

integer :: i

!$OMP PARALLEL DO
do i = 1, 4
call sub(i)
enddo
!$OMP END PARALLEL DO


contains

subroutine sub(i)
integer :: i
integer, allocatable :: a(:)

allocate(a(3))

a = i

!$omp critical
write(*,*) a(1:3)
!$omp end critical

deallocate(a)
end subroutine
end program

0 Kudos
jimdempseyatthecove
Honored Contributor III
756 Views
The above should be fine. However you report it is not...

See what happens with

recursive subroutine sub(i)

or

subroutine sub(i)
integer :: i
integer, automatic,allocatable :: a(:)

The recursive should be implicit when compiled for OpenMP. Stick it on to see what happens.
Also "automatic" is Intel specific (non-portable) which forces the array descriptor to go on stack.
Is the error sensitive to optimization level?

Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
756 Views
Is the inspector message a report of a conflict (error) or performance issue. Allocate will use a critical section, but Inspector XE should special case allocation/deallocation.

Jim Dempsey
0 Kudos
Reply