Parallel Programming Guide for HP-UX Systems

Parallel synchronization
Synchronization tools
Chapter 8144
loop_parallel(ordered)
The loop_parallel(ordered)directive and pragma is designed to be
used with ordered sections to execute loops with ordered dependences in
loop order. It accomplishes this by parallelizing the loop so that
consecutive iterations are initiated on separate processors, in loop order.
While loop_parallel(ordered) guarantees starting order, it does not
guarantee ending order, and it provides no automatic synchronization.
To avoid wrong answers, you must manually synchronize dependences
using the ordered section directives, pragmas, or the synchronization
intrinsics (see “Critical sections” on page 145 of this chapter for more
information).
Example 8-3 loop_parallel, ordered
The following Fortran code shows how
loop_parallel(ordered) is structured:
C$DIR LOOP_PARALLEL(ORDERED)
DO I = 1, 100
.
. !CODE CONTAINING ORDERED SECTION
.
ENDDO
Assume that the body of this loop contains code that is parallelizable
except for an ordered data dependence (otherwise there is no need to
order the parallelization). Also assume that 8 threads, numbered 0..7,
are available to run the loop in parallel. Each thread would then execute
code equivalent to the following:
DO I = (my_thread()+1), 100, num_threads()
...
ENDDO