]> gcc.gnu.org Git - gcc.git/blob - libgomp/testsuite/libgomp.c/examples-4/teams-3.c
Update libgomp/testsuite/*/examples-4/* according to latest version (4.0.2)
[gcc.git] / libgomp / testsuite / libgomp.c / examples-4 / teams-3.c
1 /* { dg-do run } */
2
3 #include <stdlib.h>
4
5 #define EPS 0.0001
6 #define N 1024*1024
7
8 void init (float B[], float C[], int n)
9 {
10 int i;
11 for (i = 0; i < n; i++)
12 {
13 B[i] = 0.1 * i;
14 C[i] = 0.01 * i * i;
15 }
16 }
17
18 float dotprod_ref (float B[], float C[], int n)
19 {
20 int i;
21 float sum = 0.0;
22
23 for (i = 0; i < n; i++)
24 sum += B[i] * C[i];
25
26 return sum;
27 }
28
29 float dotprod (float B[], float C[], int n)
30 {
31 int i;
32 float sum = 0;
33
34 #pragma omp target teams map(to: B[0:n], C[0:n])
35 #pragma omp distribute parallel for reduction(+:sum)
36 for (i = 0; i < n; i++)
37 sum += B[i] * C[i];
38
39 return sum;
40 }
41
42 void check (float a, float b)
43 {
44 float err = (b == 0.0) ? a : (a - b) / b;
45 if (((err > 0) ? err : -err) > EPS)
46 abort ();
47 }
48
49 int main ()
50 {
51 float *v1 = (float *) malloc (N * sizeof (float));
52 float *v2 = (float *) malloc (N * sizeof (float));
53
54 float p1, p2;
55
56 init (v1, v2, N);
57
58 p1 = dotprod_ref (v1, v2, N);
59 p2 = dotprod (v1, v2, N);
60
61 check (p1, p2);
62
63 free (v1);
64 free (v2);
65
66 return 0;
67 }
This page took 0.038231 seconds and 5 git commands to generate.