Debian Codegraph @

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

raw
1 // { dg-require-effective-target size32plus }
2
3 extern "C" void abort ();
4
5 template <typename T>
6 struct S {
7 inline S ();
8 inline ~S ();
9 inline S (const S &);
10 inline S & operator= (const S &);
11 T s;
12 };
13
14 template <typename T>
15 S<T>::S () : s (0)
16 {
17 }
18
19 template <typename T>
20 S<T>::~S ()
21 {
22 }
23
24 template <typename T>
25 S<T>::S (const S &x)
26 {
27 s = x.s;
28 }
29
30 template <typename T>
31 S<T> &
32 S<T>::operator= (const S &x)
33 {
34 s = x.s;
35 return *this;
36 }
37
38 template <typename T>
39 static inline void
40 ini (S<T> &x)
41 {
42 x.s = 0;
43 }
44
45 S<int> r, a[1024], b[1024];
46
47 #pragma omp declare reduction (+: S<int>: omp_out.s += omp_in.s)
48 #pragma omp declare reduction (plus: S<int>: omp_out.s += omp_in.s) initializer (ini (omp_priv))
49
50 template <typename T>
51 __attribute__((noipa)) void
52 foo (S<T> *a, S<T> *b)
53 {
54 #pragma omp for reduction (inscan, +:r)
55 for (int i = 0; i < 1024; i++)
56 {
57 b[i] = r;
58 #pragma omp scan exclusive(r)
59 r.s += a[i].s;
60 }
61 }
62
63 template <typename T>
64 __attribute__((noipa)) S<T>
65 bar (void)
66 {
67 S<T> s;
68 #pragma omp parallel
69 #pragma omp for reduction (inscan, plus:s)
70 for (int i = 0; i < 1024; i++)
71 {
72 b[i] = s;
73 #pragma omp scan exclusive(s)
74 s.s += 2 * a[i].s;
75 }
76 return S<T> (s);
77 }
78
79 __attribute__((noipa)) void
80 baz (S<int> *a, S<int> *b)
81 {
82 #pragma omp parallel for reduction (inscan, +:r)
83 for (int i = 0; i < 1024; i++)
84 {
85 b[i] = r;
86 #pragma omp scan exclusive(r)
87 r.s += a[i].s;
88 }
89 }
90
91 __attribute__((noipa)) S<int>
92 qux (void)
93 {
94 S<int> s;
95 #pragma omp parallel for reduction (inscan, plus:s)
96 for (int i = 0; i < 1024; i++)
97 {
98 b[i] = s;
99 #pragma omp scan exclusive(s)
100 s.s += 2 * a[i].s;
101 }
102 return S<int> (s);
103 }
104
105 int
106 main ()
107 {
108 S<int> s;
109 for (int i = 0; i < 1024; ++i)
110 {
111 a[i].s = i;
112 b[i].s = -1;
113 asm ("" : "+g" (i));
114 }
115 #pragma omp parallel
116 foo (a, b);
117 if (r.s != 1024 * 1023 / 2)
118 abort ();
119 for (int i = 0; i < 1024; ++i)
120 {
121 if (b[i].s != s.s)
122 abort ();
123 else
124 b[i].s = 25;
125 s.s += i;
126 }
127 if (bar<int> ().s != 1024 * 1023)
128 abort ();
129 s.s = 0;
130 for (int i = 0; i < 1024; ++i)
131 {
132 if (b[i].s != s.s)
133 abort ();
134 s.s += 2 * i;
135 }
136 r.s = 0;
137 baz (a, b);
138 if (r.s != 1024 * 1023 / 2)
139 abort ();
140 s.s = 0;
141 for (int i = 0; i < 1024; ++i)
142 {
143 if (b[i].s != s.s)
144 abort ();
145 else
146 b[i].s = 25;
147 s.s += i;
148 }
149 if (qux ().s != 1024 * 1023)
150 abort ();
151 s.s = 0;
152 for (int i = 0; i < 1024; ++i)
153 {
154 if (b[i].s != s.s)
155 abort ();
156 s.s += 2 * i;
157 }
158 }