Parallel Programming Guide for HP-UX Systems

Parallel synchronization
Synchronizing code
Chapter 8 153
C$DIR GATE (LCD)
.
.
.
LOCK = ALLOC_GATE(LCD)
C$DIR LOOP_PARALLEL(ORDERED)
DO I = 1, N
.
.
.
IF (Z(I) .GT. 0.0) THEN
C$DIR ORDERED_SECTION(LCD)
C HERE’S THE BACKWARD LCD:
A(I) = A(I-1) + B(I)
C$DIR END_ORDERED_SECTION
ELSE
C HERE IS THE BLANK ORDERED SECTION:
C$DIR ORDERED_SECTION(LCD)
C$DIR END_ORDERED_SECTION
ENDIF
.
.
.
ENDDO
LOCK = FREE_GATE(LCD)
No matter which path through the IF statement the loop takes, and
though the ELSE section is empty, it must pass through the ordered
section. This allows the compiler to properly synchronize the ordered
loop. It is assumed that a substantial amount of parallel code exists
outside the ordered sections, to offset the synchronization overhead.
Example 8-8 Ordered section limitations
Ordered sections within nested loops can create similar, but more
difficult to recognize, problems. Consider the following Fortran example
(gate manipulation is omitted for brevity):
C$DIR LOOP_PARALLEL(ORDERED)
DO I = 1, 99
DO J = 1,M
.
.
.