]> gcc.gnu.org Git - gcc.git/blame - libgomp/testsuite/libgomp.c/omp_orphan.c
re PR c++/34513 (static variable not found for C++ OpenMP)
[gcc.git] / libgomp / testsuite / libgomp.c / omp_orphan.c
CommitLineData
953ff289
DN
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
14
15float a[VECLEN], b[VECLEN], sum;
16
17float dotprod ()
18{
19int i,tid;
20
21tid = omp_get_thread_num();
22#pragma omp for reduction(+:sum)
23 for (i=0; i < VECLEN; i++)
24 {
25 sum = sum + (a[i]*b[i]);
26 printf(" tid= %d i=%d\n",tid,i);
27 }
28
29return(sum);
30}
31
32
33int main (int argc, char *argv[])
34{
35int i;
36
37for (i=0; i < VECLEN; i++)
38 a[i] = b[i] = 1.0 * i;
39sum = 0.0;
40
41#pragma omp parallel
42 sum = dotprod();
43
44printf("Sum = %f\n",sum);
45
46 return 0;
47}
This page took 0.151085 seconds and 5 git commands to generate.