PR rtl-optimization/77919
[official-gcc.git] / libgomp / testsuite / libgomp.c / target-2.c
blob0ba766c0a82b20cc72491be2a9cc28a199ccc3c8
1 extern
2 #ifdef __cplusplus
3 "C"
4 #endif
5 void abort (void);
7 void
8 fn1 (double *x, double *y, int z)
10 int i;
11 for (i = 0; i < z; i++)
13 x[i] = i & 31;
14 y[i] = (i & 63) - 30;
18 double
19 fn2 (int x)
21 double s = 0;
22 double b[3 * x], c[3 * x], d[3 * x], e[3 * x];
23 int i;
24 fn1 (b, c, x);
25 fn1 (e, d + x, x);
26 #pragma omp target map(to: b, c[:x], d[x:x], e) map(tofrom: s)
27 #pragma omp parallel for reduction(+:s)
28 for (i = 0; i < x; i++)
29 s += b[i] * c[i] + d[x + i] + sizeof (b) - sizeof (c);
30 return s;
33 double
34 fn3 (int x)
36 double s = 0;
37 double b[3 * x], c[3 * x], d[3 * x], e[3 * x];
38 int i;
39 fn1 (b, c, x);
40 fn1 (e, d, x);
41 #pragma omp target map(tofrom: s)
42 #pragma omp parallel for reduction(+:s)
43 for (i = 0; i < x; i++)
44 s += b[i] * c[i] + d[i];
45 return s;
48 double
49 fn4 (int x)
51 double s = 0;
52 double b[3 * x], c[3 * x], d[3 * x], e[3 * x];
53 int i;
54 fn1 (b, c, x);
55 fn1 (e, d + x, x);
56 #pragma omp target data map(from: b, c[:x], d[x:x], e)
58 #pragma omp target update to(b, c[:x], d[x:x], e)
59 #pragma omp target map(c[:x], d[x:x], s)
60 #pragma omp parallel for reduction(+:s)
61 for (i = 0; i < x; i++)
63 s += b[i] * c[i] + d[x + i] + sizeof (b) - sizeof (c);
64 b[i] = i + 0.5;
65 c[i] = 0.5 - i;
66 d[x + i] = 0.5 * i;
69 for (i = 0; i < x; i++)
70 if (b[i] != i + 0.5 || c[i] != 0.5 - i || d[x + i] != 0.5 * i)
71 abort ();
72 return s;
75 int
76 main ()
78 double a = fn2 (128);
79 if (a != 14080.0)
80 abort ();
81 double b = fn3 (128);
82 if (a != b)
83 abort ();
84 double c = fn4 (256);
85 if (c != 28160.0)
86 abort ();
87 return 0;