Text-only Table of Contents (frame/ no frame)
(11) Reduction Clause Previous Top Next

Reduction Operations


An example of a reduction operation is a summation:

!     Fortran example

do i = 1, n
sum = sum + a(i)
enddo


/* C/C++ Example */

for(i=1; i<=n; i++){
sum = sum + a[i];
}
 
How reduction works:

Example of  reduction clause

! Fortran example

!$omp parallel do reduction(+:sum)
do i = 1, n
sum = sum + a(i)
enddo

/* C/C++ example */

#pragma omp parallel for reduction(+:sum)
{
for(i=1; i<=n; i++){
sum = sum + a[i];
}
}

C/C++  Reduction Operands
OperatorInitial value
+0
*1
-0
&~0
|0
^0
&&1
||0

Fortran Reduction Operands

OperatorInitial Value
+0
*1
-0
.AND..true.
.OR..false.
.IEOR.0
.IOR.0
.IAND.All bits on
.EQV. .true.
MINLargest positive #
MAXMost negative #




Previous Top Next


reduction_clause.src  last modified Mar 23, 2009 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College