2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / taskloop-8.C
blobd164907d1d6e8ad8b9cfda274fa7483693335341
1 // { dg-do run }
3 #include <string>
4 #include <cstdlib>
6 template <typename T>
7 class J
9 public:
10   typedef typename std::basic_string<T>::iterator iterator;
11   J(const iterator &x, const iterator &y) : b (x), e (y) {}
12   const iterator &begin ();
13   const iterator &end ();
14 private:
15   iterator b, e;
18 template <typename T>
19 const typename std::basic_string<T>::iterator &J<T>::begin () { return b; }
20 template <typename T>
21 const typename std::basic_string<T>::iterator &J<T>::end () { return e; }
23 template <typename T>
24 void
25 baz (T &i)
27   if (*i < L'a' || *i >= L'a' + 2000)
28     std::abort ();
29   (*i)++;
32 void
33 f1 (const std::basic_string<wchar_t>::iterator &x,
34     const std::basic_string<wchar_t>::iterator &y)
36 #pragma omp parallel
37 #pragma omp single
38 #pragma omp taskloop
39   for (std::basic_string<wchar_t>::iterator i = x; i <= y; i += 6)
40     baz (i);
43 void
44 f2 (const std::basic_string<wchar_t>::iterator &x,
45     const std::basic_string<wchar_t>::iterator &y)
47   std::basic_string<wchar_t>::iterator i;
48 #pragma omp parallel
49 #pragma omp single
50 #pragma omp taskloop private(i)
51   for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
52     baz (i);
55 template <typename T>
56 void
57 f3 (const std::basic_string<wchar_t>::iterator &x,
58     const std::basic_string<wchar_t>::iterator &y)
60 #pragma omp parallel
61 #pragma omp single
62 #pragma omp taskloop
63   for (std::basic_string<wchar_t>::iterator i = x; i <= y; i = i + 9 - 8)
64     baz (i);
67 template <typename T>
68 void
69 f4 (const std::basic_string<wchar_t>::iterator &x,
70     const std::basic_string<wchar_t>::iterator &y)
72   std::basic_string<wchar_t>::iterator i;
73 #pragma omp parallel
74 #pragma omp single
75 #pragma omp taskloop lastprivate(i)
76   for (i = x + 2000 - 64; i > y + 10; --i)
77     baz (i);
80 void
81 f5 (const std::basic_string<wchar_t>::iterator &x,
82     const std::basic_string<wchar_t>::iterator &y)
84 #pragma omp parallel
85 #pragma omp single
86 #pragma omp taskloop
87   for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64;
88        i > y + 10; i -= 10)
89     baz (i);
92 template <int N>
93 void
94 f6 (const std::basic_string<wchar_t>::iterator &x,
95     const std::basic_string<wchar_t>::iterator &y)
97 #pragma omp parallel
98 #pragma omp single
99 #pragma omp taskloop
100   for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64;
101        i > y + 10; i = i - 12 + 2)
102     {
103       std::basic_string<wchar_t>::iterator j = i + N;
104       baz (j);
105     }
108 template <int N>
109 void
110 f7 (std::basic_string<wchar_t>::iterator i,
111     const std::basic_string<wchar_t>::iterator &x,
112     const std::basic_string<wchar_t>::iterator &y)
114 #pragma omp parallel
115 #pragma omp single
116 #pragma omp taskloop
117   for (i = x - 10; i <= y + 10; i += N)
118     baz (i);
121 template <wchar_t N>
122 void
123 f8 (J<wchar_t> j)
125   std::basic_string<wchar_t>::iterator i;
126 #pragma omp parallel
127 #pragma omp single
128 #pragma omp taskloop
129   for (i = j.begin (); i <= j.end () + N; i += 2)
130     baz (i);
133 template <typename T, int N>
134 void
135 f9 (const typename std::basic_string<T>::iterator &x,
136     const typename std::basic_string<T>::iterator &y)
138 #pragma omp parallel
139 #pragma omp single
140 #pragma omp taskloop
141   for (typename std::basic_string<T>::iterator i = x; i <= y; i = i + N)
142     baz (i);
145 template <typename T, int N>
146 void
147 f10 (const typename std::basic_string<T>::iterator &x,
148      const typename std::basic_string<T>::iterator &y)
150   typename std::basic_string<T>::iterator i;
151 #pragma omp parallel
152 #pragma omp single
153 #pragma omp taskloop
154   for (i = x; i > y; i = i + N)
155     baz (i);
158 template <typename T>
159 void
160 f11 (const T &x, const T &y)
162 #pragma omp parallel
163   {
164 #pragma omp single nowait
165 #pragma omp taskloop nogroup
166     for (T i = x; i <= y; i += 3)
167       baz (i);
168 #pragma omp single nowait
169     {
170       T j = y + 3;
171       baz (j);
172     }
173   }
176 template <typename T>
177 void
178 f12 (const T &x, const T &y)
180   T i;
181 #pragma omp parallel
182 #pragma omp single
183 #pragma omp taskloop private(i)
184   for (i = x; i > y; --i)
185     baz (i);
188 template <int N>
189 struct K
191   template <typename T>
192   static void
193   f13 (const T &x, const T &y)
194   {
195 #pragma omp parallel
196 #pragma omp single
197 #pragma omp taskloop
198     for (T i = x; i <= y + N; i += N)
199       baz (i);
200   }
203 #define check(expr) \
204   for (int i = 0; i < 2000; i++)                        \
205     if (expr)                                           \
206       {                                                 \
207         if (a[i] != L'a' + i + 1)                       \
208           std::abort ();                                \
209         a[i] = L'a' + i;                                \
210       }                                                 \
211     else if (a[i] != L'a' + i)                          \
212       std::abort ()
215 main ()
217   std::basic_string<wchar_t> a = L"";
218   for (int i = 0; i < 2000; i++)
219     a += L'a' + i;
220   f1 (a.begin () + 10, a.begin () + 1990);
221   check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
222   f2 (a.begin () + 0, a.begin () + 1999);
223   check (i < 1998 && (i & 1) == 0);
224   f3<char> (a.begin () + 20, a.begin () + 1837);
225   check (i >= 20 && i <= 1837);
226   f4<int> (a.begin () + 0, a.begin () + 30);
227   check (i > 40 && i <= 2000 - 64);
228   f5 (a.begin () + 0, a.begin () + 100);
229   check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
230   f6<-10> (a.begin () + 10, a.begin () + 110);
231   check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
232   f7<6> (std::basic_string<wchar_t>::iterator (), a.begin () + 12,
233          a.begin () + 1800);
234   check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
235   f8<121> (J<wchar_t> (a.begin () + 14, a.begin () + 1803));
236   check (i >= 14 && i <= 1924 && (i & 1) == 0);
237   f9<wchar_t, 7> (a.begin () + 33, a.begin () + 1967);
238   check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
239   f10<wchar_t, -7> (a.begin () + 1939, a.begin () + 17);
240   check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
241   f11<std::basic_string<wchar_t>::iterator > (a.begin () + 16,
242                                               a.begin () + 1981);
243   check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
244   f12<std::basic_string<wchar_t>::iterator > (a.begin () + 1761,
245                                               a.begin () + 37);
246   check (i > 37 && i <= 1761);
247   K<5>::f13<std::basic_string<wchar_t>::iterator > (a.begin () + 1,
248                                                     a.begin () + 1935);
249   check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);