Parallel Programming Guide for HP-UX Systems

Parallel synchronization
Synchronizing code
Chapter 8152
The ordered section containing the A(I) assignment executes in
iteration order. This ensures that the value of A(I-1) used in the
assignment is always valid. Assuming this loop runs on four threads, the
synchronization of statement execution between threads is illustrated in
Figure 8-2.
Figure 8-2 LOOP_PARALLEL(ORDERED) synchronization
As shown by the dashed lines between initial iterations for each thread,
one ordered section must be completed before the next is allowed to begin
execution. Once a thread exits an ordered section, it cannot reenter until
all other threads have passed through in sequence.
Overlap of nonordered statements, represented as lightly shaded boxes,
allows all threads to proceed fully loaded. Only brief idle periods occur on
1, 2, and 3 at the beginning of the loop, and on 0, 1, and 2 at the end.
Example 8-7 Ordered section limitations
Each thread in a parallel loop containing an ordered section must pass
through the ordered section exactly once on every iteration of the loop. If
you execute an ordered section conditionally, you must execute it in all
possible branches of the condition. If the code contained in the section is
not valid for some branches, you can insert a blank ordered section, as
shown in the following Fortran example:
THREADS
0
1
2
3
I=1
I=5 I=9 I=13 I=17
I=2 I=6
I=10 I=14
I=18
I=3 I=7 I=11 I=15 I=19
I=4 I=8 I=12 I=16 I=20
Order of statement execution
Statements contained within ordered sections
Nonordered section statements