1 /******************************************************************************
2 * FILE: omp_reduction.c
4 * OpenMP Example - Combined Parallel Loop Reduction - C/C++ Version
5 * This example demonstrates a sum reduction within a combined parallel loop
6 * construct. Notice that default data element scoping is assumed - there
7 * are no clauses specifying shared or private variables. OpenMP will
8 * automatically make loop index variables private within team threads, and
9 * global variables shared.
10 * AUTHOR: Blaise Barney 5/99
11 * LAST REVISED: 04/06/05
12 ******************************************************************************/
17 int main (int argc
, char *argv
[]) {
20 float a
[100], b
[100], sum
;
22 /* Some initializations */
25 a
[i
] = b
[i
] = i
* 1.0;
28 #pragma omp parallel for reduction(+:sum)
30 sum
= sum
+ (a
[i
] * b
[i
]);
32 printf(" Sum = %f\n",sum
);