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

omp reduction example (from documentation) does not compile

mirko_vukovic
Beginner
896 Views
Hello,

the following code (which I derived from the Reduction section in the documentation), does not compile:
[bash]parameter N=10
!$OMP PARALLEL DO DEFAULT(PRIVATE),SHARED(A,B),REDUCTION(+: A,B)
DO I=1,N
CALL WORK(ALOCAL,BLOCAL)
A = A + ALOCAL
B = B + BLOCAL
END DO
!$OMP END PARALLEL DO
end
[/bash]
I tried to compile it with ifort -c -openmp doreduce.f90. The error message is
[bash]doreduce.f90(2): error #6761: An entity cannot appear explicitly in more than one clause per directive except that an entity can be specified in both a FIRSTPRIVATE and LASTPRIVATE clause.   
!$OMP PARALLEL DO DEFAULT(PRIVATE),SHARED(A,B),REDUCTION(+: A,B)
------------------------------------------------------------^
doreduce.f90(2): error #6761: An entity cannot appear explicitly in more than one clause per directive except that an entity can be specified in both a FIRSTPRIVATE and LASTPRIVATE clause.   
!$OMP PARALLEL DO DEFAULT(PRIV...
Now off I go to read the documentation and try to make it work :-)

Mirko
0 Kudos
4 Replies
pbkenned1
Employee
896 Views
That's embarrasing. A reduction variable is obviously shared, so the SHARED clause is redundant. Just remove SHARED(A,B) and the example should compile. I'll file a doc bug on this.

Patrick Kennedy
Intel Developer Support
0 Kudos
jimdempseyatthecove
Honored Contributor III
896 Views
Patrick,

A reduction variable is private within the parallel region .not. shared. When exiting the parallel region these private variables are combined into the same named variable outside the regionusing the reduction operator.

In the OP's example, using SHARED is in error when used with varibles listed within the REDUCE clause (those are implicitly PRIVATE).

Do not file a doc bug on this.

Jim Dempsey
0 Kudos
pbkenned1
Employee
896 Views
Hello Jim,
Thanks for the feedback. We do need to correct the documentation example, simply because it won't compile 'as is'. We're not trying to demonstate a coding error with the example.

It would be more accurate to say a reduction variable has a data scope unique from that of SHARED or PRIVATE, while having attributes of both.

It's a syntax error to mark reduction variables SHARED _or_ PRIVATE. Both of these produce compilation errors:

!$OMP PARALLEL DO DEFAULT(PRIVATE),SHARED(A,B),REDUCTION(+: A,B)
!$OMP PARALLEL DO DEFAULT(PRIVATE),PRIVATE(A,B),REDUCTION(+: A,B)

Regards,
Patrick
0 Kudos
jimdempseyatthecove
Honored Contributor III
896 Views
Patrick,

Yes, it is a syntax error (both ways).

The reduction variables have an additionalregion transition characteristic (going into region as well as comming out of region) but exist as private within the region (IOW held in threaddifferentiated locations/registers).IMHOPRIVATE should be permitted because:

PRIVATE means seperate same named variables per thead
PRIVATE permits COPYIN
REDUCTION is functionally equivilent to COPYIN with 0 then COPYOUT (using reduction operator).

Because PRIVATE can be augmented with COPYIN, it should be permitted orthoganality with an operation on the completion end of the parallel region(read: REDUCTION).

The OpenMP standards committee sees this differently.

Jim Dempsey
0 Kudos
Reply