User Guide


OpenMP Reduction Operations

OpenMP reduction operations can be used for simple cases, such as incrementing a shared numeric variable or the summation of an array into a shared numeric variable. To implement a reduction operation, add the
clause within a parallel region to instruct the compiler to perform the summation operation in parallel using the specified operation and variable.
Consider this annotated C/C++ serial code:
int i, n=500000; float *array, total=0.0; ... for (i=0; i <n ; ++i { ANNOTATE_LOCK_ACQUIRE(0); total+ = array[i]; ANNOTATE_LOCK_RELEASE(0); } . . .
The parallel C/C++ code after adding
#include <omp.h>
#pragma omp parallel for reduction
#include <omp.h> //prevents a load-time problem with a .dll not being found int i, n=500000; float *array, total=0.0; ... #pragma omp parallel for reduction(+:total) for (i=0; i <n ; ++i { total+ = array[i]; } . . .
Consider this annotated Fortran serial code:
integer(4) n real(4) array(50000), total = 0.0 n = 500000 ... do i=1, n call annotate_lock_acquire(0) total = total + array(i) call annotate_lock_release(0) . . . end do
Consider this parallel Fortran code after adding
use omp_lib
!$omp parallel do reduction(+:total)
, and
!$omp end parallel do
use omp_lib integer(4) n real(4) array(50000), total = 0.0 n = 500000 ... !$omp parallel do reduction(+:total) do i=1, n total = total + array(i) !$omp end parallel do . . . end do

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804