Community
cancel
Showing results for 
Search instead for 
Did you mean: 
maria
Beginner
30 Views

allocatable arrays in openMP

In ourcode, we have many allocatable arrays before parallel do session.

To remove the data dependence, at the present, our code is like this:

allocate(A(M1,N1,number_of_threads))
allocate(B(M2,N2,L2,number_of_threads))

!$OMP parallel do
DO I = 1, II
....
ENDDO



Since ourarrays size is very large and we would like to reduce the memory. If the following is
more efficient in terms of memory usage as well as the performance?

!$OMP parallel do
DO I =1, II
Allocate(A(M1,N1))
Allocate(B(M2,N2,L2))
.....

deallocate(A,B)
ENDDO

Thanks
0 Kudos
1 Reply
jimdempseyatthecove
Black Belt
30 Views

The following will yield better performance

!$OMP parallel
Allocate(A(M1,N1))
Allocate(B(M2,N2,L2))
!$OMP do
DO I =1, II
.....
ENDDO
deallocate(A,B)
!$OMP end parallel

The total storage for allocations in your original example and in the above will be the same.
The number of times you perform allocations will be less.

*** However
The allocations are in smaller chunks (i.e. not *number_of_threads)
Smaller allocation size has higher probability of being granted as memory fragments.

If A and B are temps .AND. if I represents one of the indexes for both .AND. if the I'th element of both arrays are completely independent from the I'th+x element .AND. if II is relatively large. Then consider breaking the iteration space into smaller pieces, each piece done in parallel.

Jim Dempsey

0 Kudos