taskloop-8.C 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // { dg-do run }
  2. #include <string>
  3. #include <cstdlib>
  4. template <typename T>
  5. class J
  6. {
  7. public:
  8. typedef typename std::basic_string<T>::iterator iterator;
  9. J(const iterator &x, const iterator &y) : b (x), e (y) {}
  10. const iterator &begin ();
  11. const iterator &end ();
  12. private:
  13. iterator b, e;
  14. };
  15. template <typename T>
  16. const typename std::basic_string<T>::iterator &J<T>::begin () { return b; }
  17. template <typename T>
  18. const typename std::basic_string<T>::iterator &J<T>::end () { return e; }
  19. template <typename T>
  20. void
  21. baz (T &i)
  22. {
  23. if (*i < L'a' || *i >= L'a' + 2000)
  24. std::abort ();
  25. (*i)++;
  26. }
  27. void
  28. f1 (const std::basic_string<wchar_t>::iterator &x,
  29. const std::basic_string<wchar_t>::iterator &y)
  30. {
  31. #pragma omp parallel
  32. #pragma omp single
  33. #pragma omp taskloop
  34. for (std::basic_string<wchar_t>::iterator i = x; i <= y; i += 6)
  35. baz (i);
  36. }
  37. void
  38. f2 (const std::basic_string<wchar_t>::iterator &x,
  39. const std::basic_string<wchar_t>::iterator &y)
  40. {
  41. std::basic_string<wchar_t>::iterator i;
  42. #pragma omp parallel
  43. #pragma omp single
  44. #pragma omp taskloop private(i)
  45. for (i = x; i < y - 1; i = 1 - 6 + 7 + i)
  46. baz (i);
  47. }
  48. template <typename T>
  49. void
  50. f3 (const std::basic_string<wchar_t>::iterator &x,
  51. const std::basic_string<wchar_t>::iterator &y)
  52. {
  53. #pragma omp parallel
  54. #pragma omp single
  55. #pragma omp taskloop
  56. for (std::basic_string<wchar_t>::iterator i = x; i <= y; i = i + 9 - 8)
  57. baz (i);
  58. }
  59. template <typename T>
  60. void
  61. f4 (const std::basic_string<wchar_t>::iterator &x,
  62. const std::basic_string<wchar_t>::iterator &y)
  63. {
  64. std::basic_string<wchar_t>::iterator i;
  65. #pragma omp parallel
  66. #pragma omp single
  67. #pragma omp taskloop lastprivate(i)
  68. for (i = x + 2000 - 64; i > y + 10; --i)
  69. baz (i);
  70. }
  71. void
  72. f5 (const std::basic_string<wchar_t>::iterator &x,
  73. const std::basic_string<wchar_t>::iterator &y)
  74. {
  75. #pragma omp parallel
  76. #pragma omp single
  77. #pragma omp taskloop
  78. for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64;
  79. i > y + 10; i -= 10)
  80. baz (i);
  81. }
  82. template <int N>
  83. void
  84. f6 (const std::basic_string<wchar_t>::iterator &x,
  85. const std::basic_string<wchar_t>::iterator &y)
  86. {
  87. #pragma omp parallel
  88. #pragma omp single
  89. #pragma omp taskloop
  90. for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64;
  91. i > y + 10; i = i - 12 + 2)
  92. {
  93. std::basic_string<wchar_t>::iterator j = i + N;
  94. baz (j);
  95. }
  96. }
  97. template <int N>
  98. void
  99. f7 (std::basic_string<wchar_t>::iterator i,
  100. const std::basic_string<wchar_t>::iterator &x,
  101. const std::basic_string<wchar_t>::iterator &y)
  102. {
  103. #pragma omp parallel
  104. #pragma omp single
  105. #pragma omp taskloop
  106. for (i = x - 10; i <= y + 10; i += N)
  107. baz (i);
  108. }
  109. template <wchar_t N>
  110. void
  111. f8 (J<wchar_t> j)
  112. {
  113. std::basic_string<wchar_t>::iterator i;
  114. #pragma omp parallel
  115. #pragma omp single
  116. #pragma omp taskloop
  117. for (i = j.begin (); i <= j.end () + N; i += 2)
  118. baz (i);
  119. }
  120. template <typename T, int N>
  121. void
  122. f9 (const typename std::basic_string<T>::iterator &x,
  123. const typename std::basic_string<T>::iterator &y)
  124. {
  125. #pragma omp parallel
  126. #pragma omp single
  127. #pragma omp taskloop
  128. for (typename std::basic_string<T>::iterator i = x; i <= y; i = i + N)
  129. baz (i);
  130. }
  131. template <typename T, int N>
  132. void
  133. f10 (const typename std::basic_string<T>::iterator &x,
  134. const typename std::basic_string<T>::iterator &y)
  135. {
  136. typename std::basic_string<T>::iterator i;
  137. #pragma omp parallel
  138. #pragma omp single
  139. #pragma omp taskloop
  140. for (i = x; i > y; i = i + N)
  141. baz (i);
  142. }
  143. template <typename T>
  144. void
  145. f11 (const T &x, const T &y)
  146. {
  147. #pragma omp parallel
  148. {
  149. #pragma omp single nowait
  150. #pragma omp taskloop nogroup
  151. for (T i = x; i <= y; i += 3)
  152. baz (i);
  153. #pragma omp single nowait
  154. {
  155. T j = y + 3;
  156. baz (j);
  157. }
  158. }
  159. }
  160. template <typename T>
  161. void
  162. f12 (const T &x, const T &y)
  163. {
  164. T i;
  165. #pragma omp parallel
  166. #pragma omp single
  167. #pragma omp taskloop private(i)
  168. for (i = x; i > y; --i)
  169. baz (i);
  170. }
  171. template <int N>
  172. struct K
  173. {
  174. template <typename T>
  175. static void
  176. f13 (const T &x, const T &y)
  177. {
  178. #pragma omp parallel
  179. #pragma omp single
  180. #pragma omp taskloop
  181. for (T i = x; i <= y + N; i += N)
  182. baz (i);
  183. }
  184. };
  185. #define check(expr) \
  186. for (int i = 0; i < 2000; i++) \
  187. if (expr) \
  188. { \
  189. if (a[i] != L'a' + i + 1) \
  190. std::abort (); \
  191. a[i] = L'a' + i; \
  192. } \
  193. else if (a[i] != L'a' + i) \
  194. std::abort ()
  195. int
  196. main ()
  197. {
  198. std::basic_string<wchar_t> a = L"";
  199. for (int i = 0; i < 2000; i++)
  200. a += L'a' + i;
  201. f1 (a.begin () + 10, a.begin () + 1990);
  202. check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0);
  203. f2 (a.begin () + 0, a.begin () + 1999);
  204. check (i < 1998 && (i & 1) == 0);
  205. f3<char> (a.begin () + 20, a.begin () + 1837);
  206. check (i >= 20 && i <= 1837);
  207. f4<int> (a.begin () + 0, a.begin () + 30);
  208. check (i > 40 && i <= 2000 - 64);
  209. f5 (a.begin () + 0, a.begin () + 100);
  210. check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
  211. f6<-10> (a.begin () + 10, a.begin () + 110);
  212. check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0);
  213. f7<6> (std::basic_string<wchar_t>::iterator (), a.begin () + 12,
  214. a.begin () + 1800);
  215. check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0);
  216. f8<121> (J<wchar_t> (a.begin () + 14, a.begin () + 1803));
  217. check (i >= 14 && i <= 1924 && (i & 1) == 0);
  218. f9<wchar_t, 7> (a.begin () + 33, a.begin () + 1967);
  219. check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0);
  220. f10<wchar_t, -7> (a.begin () + 1939, a.begin () + 17);
  221. check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0);
  222. f11<std::basic_string<wchar_t>::iterator > (a.begin () + 16,
  223. a.begin () + 1981);
  224. check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0);
  225. f12<std::basic_string<wchar_t>::iterator > (a.begin () + 1761,
  226. a.begin () + 37);
  227. check (i > 37 && i <= 1761);
  228. K<5>::f13<std::basic_string<wchar_t>::iterator > (a.begin () + 1,
  229. a.begin () + 1935);
  230. check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0);
  231. }