| United States-English |
|
|
|
![]() |
Parallel Programming Guide for HP-UX Systems: K-Class and V-Class Servers > Chapter 6 Parallel optimization featuresReductions |
|
In many cases, the compiler can recognize and parallelize loops containing a special class of dependence known as a reduction. In general, a reduction has the form: X = X operator Y where
The compiler also recognizes reductions of the form: X = function(X,Y) where
Generally, the compiler automatically recognizes reductions in a loop and is able to parallelize the loop. If the loop is under the influence of the prefer_parallel directive or pragma, the compiler still recognizes reductions. However, in a loop being manipulated by the loop_parallel directive or pragma, reduction analysis is not performed. Consequently, the loop may not be correctly parallelized unless the reduction is enforced using the reduction directive or pragma. The form of this directive and pragma is shown in Table 6-3 “Form of reduction directive and pragma”. Table 6-3 Form of reduction directive and pragma
Reduction Reductions commonly appear in the form of sum operations, as shown in the following Fortran example:
Assuming this loop does not contain any parallelization-inhibiting code, the compiler would automatically parallelize it. The code generated to accomplish this creates temporary, thread-specific copies of ASUM for each thread that runs the loop. When each parallel thread completes its portion of the loop, thread 0 for the current spawn context accumulates the thread-specific values into the global ASUM. The following Fortran example shows the use of the reduction directive on the above code. loop_parallel is described on “loop_parallel”. loop_private is described on “loop_private”.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||