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

Allocatable array in openMP

maria
Beginner
460 Views

Our software were written in FORTRAN 90 and compiled using IVF. Recently, we want to apply openMP to our software. However, we found that we have many allocatable arrays in our code which is difficult to implement openMP.

Below is one simple example. Arrays A, B, and C are allocated at the beginning. Array C can be SHARED. Array B should be PRIVATE for each thread. However, the openMP requires
that array B must be explicit shape array to be defined as PRIVATE. Array A should be defined as FIRSTPRIVATE, which also required explicit shape array. This seems a backward step to change the array from allocatable ones to explicit ones. Our programs are full of these arrays. Do you have any suggestions about how to implement openMP for the following simple example? Thanks.

***********************************
A(:)=
C(:,:)=
!$ OMP parallel do
DO I = 1, II
DO J = 1, JJ
B(I)=
A(I) = A(I)+ C(I,J)+B(I)
ENDDO
ENDDO
!$OMP end parallel do
********************************************

0 Kudos
4 Replies
TimP
Honored Contributor III
460 Views

If the purpose is to leave the final values in B(:), it may be sufficient to move that array assignment out of the inner loop:

!$ OMP parallel do private(tmpB)
DO I = 1, II
DO J = 1, JJ
tmpB=
A(I) = A(I)+ C(I,J)+tmpB

ENDDO
B(I)=tmpB

ENDDO

end parallel do is redundant here

Presumably, you are hoping also that the compiler automatically delays the A(:) assignment until completion of the inner loop.

0 Kudos
maria
Beginner
460 Views

Thanks. When you say 'Presumably, you are hoping also that the compiler automatically delays the A(:) assignment until completion of the inner loop', you mean that some compilers may not act that way and the results will be wrong then. Is this correct understanding?

In addition, array A is initialized outside DO loop and updated inside do loop. How should I specify array A in this example?

When I used the above example, I oversimplied our code. There are many do loop nests with many allocatable arrays in our code. Some of them are initialized before outer most do loop; some of them are assigned values inside the do loop; the values of some arrays are updated with each loop. Also, we have many temp. arrays that are allocated before the do loop and deallocated after the do loop. Does this mean that it's almost impossible to implement openMP to our code?

0 Kudos
TimP
Honored Contributor III
460 Views

No, I'm not talking about a correctness issue, but it should make a large difference in performance. As long as the compiler isn't concerned about A(:) aliasing with other arrays, it should delay the store. You could make a temporary private scalar assignment and set the array element after the loop. Depending on the size of the arrays, this could make more difference than OpenMP threading.

You probably can't answer your own question until you've worked on it. It's certainly possible to use local arrays, marking the entire array private if suitable, or firstprivate and/or lastprivate, if necessary, but this could easily defeat the expected performance gain.

0 Kudos
IDZ_A_Intel
Employee
460 Views
Maria,

The OpenMP 3.0API was the first to allow allocatable arrays in private clauses (from p.316 of the API):


"In Version 3.0, Fortran allocatable arrays may appear in private,

firstprivate, lastprivate, reduction, copyin and copyprivate

clauses. (see Section 2.9.2 on page 81, Section 2.9.3.3 on page 89, Section 2.9.3.4 on

page 92, Section 2.9.3.5 on page 94, Section 2.9.3.6 on page 96, Section 2.9.4.1 on

page 101 and Section 2.9.4.2 on page 102)."


In Section 2.9.3.3, on Page 90, the OpenMP 3.0 API states the following:


"For a list item with the ALLOCATABLE attribute:

if the list item is "not currently allocated", the new list item will have an initial state

of "not currently allocated";

if the list item is allocated, the new list item will have an initial state of allocated

with the same array bounds."


So if the Intel Fortran compilers since version 11.0 do not allow allocatable arrays on private clauses, then please submit a bug report at http://premier.intel.com.

0 Kudos
Reply