Debian Codegraph @

libgomp/testsuite/libgomp.c++/scan-6.C

raw
1 // { dg-require-effective-target size32plus }
2
3 extern "C" void abort ();
4 int r, a[1024], b[1024], q;
5
6 template <typename T, typename U>
7 __attribute__((noipa)) void
8 foo (T a, T b, U r)
9 {
10 #pragma omp for reduction (inscan, +:r)
11 for (int i = 0; i < 1024; i++)
12 {
13 b[i] = r;
14 #pragma omp scan exclusive(r)
15 r += a[i];
16 }
17 }
18
19 template <typename T>
20 __attribute__((noipa)) T
21 bar ()
22 {
23 T &s = q;
24 q = 0;
25 #pragma omp parallel
26 #pragma omp for reduction (inscan, +:s)
27 for (int i = 0; i < 1024; i++)
28 {
29 b[i] = s;
30 #pragma omp scan exclusive(s)
31 s += 2 * a[i];
32 }
33 return s;
34 }
35
36 template <typename T>
37 __attribute__((noipa)) void
38 baz (T *a, T *b, T &r)
39 {
40 #pragma omp parallel for reduction (inscan, +:r)
41 for (T i = 0; i < 1024; i++)
42 {
43 b[i] = r;
44 #pragma omp scan exclusive(r)
45 r += a[i];
46 }
47 }
48
49 template <typename T>
50 __attribute__((noipa)) int
51 qux ()
52 {
53 T s = q;
54 q = 0;
55 #pragma omp parallel for reduction (inscan, +:s)
56 for (int i = 0; i < 1024; i++)
57 {
58 b[i] = s;
59 #pragma omp scan exclusive(s)
60 s += 2 * a[i];
61 }
62 return s;
63 }
64
65 int
66 main ()
67 {
68 int s = 0;
69 for (int i = 0; i < 1024; ++i)
70 {
71 a[i] = i;
72 b[i] = -1;
73 asm ("" : "+g" (i));
74 }
75 #pragma omp parallel
76 foo<int *, int &> (a, b, r);
77 if (r != 1024 * 1023 / 2)
78 abort ();
79 for (int i = 0; i < 1024; ++i)
80 {
81 if (b[i] != s)
82 abort ();
83 else
84 b[i] = 25;
85 s += i;
86 }
87 if (bar<int> () != 1024 * 1023)
88 abort ();
89 s = 0;
90 for (int i = 0; i < 1024; ++i)
91 {
92 if (b[i] != s)
93 abort ();
94 else
95 b[i] = -1;
96 s += 2 * i;
97 }
98 r = 0;
99 baz<int> (a, b, r);
100 if (r != 1024 * 1023 / 2)
101 abort ();
102 s = 0;
103 for (int i = 0; i < 1024; ++i)
104 {
105 if (b[i] != s)
106 abort ();
107 else
108 b[i] = -25;
109 s += i;
110 }
111 if (qux<int &> () != 1024 * 1023)
112 abort ();
113 s = 0;
114 for (int i = 0; i < 1024; ++i)
115 {
116 if (b[i] != s)
117 abort ();
118 s += 2 * i;
119 }
120 }