1 /******************************************************************************
4 * OpenMP Example - Parallel region with an orphaned directive - C/C++ Version
5 * This example demonstrates a dot product being performed by an orphaned
6 * loop reduction construct. Scoping of the reduction variable is critical.
7 * AUTHOR: Blaise Barney 5/99
8 * LAST REVISED: 04/06/05
9 ******************************************************************************/
15 float a[VECLEN], b[VECLEN], sum;
21 tid = omp_get_thread_num();
22 #pragma omp for reduction(+:sum)
23 for (i=0; i < VECLEN; i++)
25 sum = sum + (a[i]*b[i]);
26 printf(" tid= %d i=%d\n",tid,i);
33 int main (int argc, char *argv[])
37 for (i=0; i < VECLEN; i++)
38 a[i] = b[i] = 1.0 * i;
44 printf("Sum = %f\n",sum);