2013-06-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgomp / testsuite / libgomp.c / omp_orphan.c
blobcbf7abf3756566616a155c26224a0325ffaff201
1 /******************************************************************************
2 * FILE: omp_orphan.c
3 * DESCRIPTION:
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 ******************************************************************************/
10 #include <omp.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #define VECLEN 100
15 float a[VECLEN], b[VECLEN], sum;
17 float dotprod ()
19 int i,tid;
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);
29 return(sum);
33 int main (int argc, char *argv[])
35 int i;
37 for (i=0; i < VECLEN; i++)
38 a[i] = b[i] = 1.0 * i;
39 sum = 0.0;
41 #pragma omp parallel
42 sum = dotprod();
44 printf("Sum = %f\n",sum);
46 return 0;