monotonic-1.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* { dg-do run } */
  2. #ifndef MONOTONIC_TYPE
  3. #include <omp.h>
  4. #include <stdlib.h>
  5. #define MONOTONIC_TYPE int
  6. #define MONOTONIC_UNDEF -1
  7. #define MONOTONIC_END(n) n
  8. #endif
  9. int
  10. main ()
  11. {
  12. MONOTONIC_TYPE i;
  13. #pragma omp parallel
  14. {
  15. int cnt = omp_get_num_threads ();
  16. int thr = omp_get_thread_num ();
  17. MONOTONIC_TYPE l = MONOTONIC_UNDEF;
  18. int c = 0;
  19. int n = 0;
  20. #pragma omp for nowait schedule(static, 5)
  21. for (i = 0; i < MONOTONIC_END (73); i++)
  22. {
  23. if (l == MONOTONIC_UNDEF)
  24. {
  25. n = 1;
  26. c++;
  27. }
  28. else if (l == i - 1)
  29. n++;
  30. else
  31. {
  32. if (l >= i)
  33. abort ();
  34. if (cnt == 1)
  35. abort ();
  36. if (n != 5)
  37. abort ();
  38. n = 1;
  39. c++;
  40. }
  41. if (n == 1)
  42. {
  43. if ((i % 5) != 0)
  44. abort ();
  45. if ((i / 5) % cnt != thr)
  46. abort ();
  47. }
  48. l = i;
  49. }
  50. if (cnt == 1)
  51. {
  52. if (n != 73 || l != 73 - 1 || c != 1)
  53. abort ();
  54. }
  55. else if (thr > 73 / 5)
  56. {
  57. if (l != MONOTONIC_UNDEF || c != 0 || n != 0)
  58. abort ();
  59. }
  60. else if (thr == 73 / 5)
  61. {
  62. if (l != 73 - 1 || c != 1 || n != 73 % 5)
  63. abort ();
  64. }
  65. else if (c == 0)
  66. abort ();
  67. else if (l == 73 - 1)
  68. {
  69. if (thr != (73 / 5) % cnt || n != 73 % 5)
  70. abort ();
  71. }
  72. else if ((n % 5) != 0)
  73. abort ();
  74. l = MONOTONIC_UNDEF;
  75. c = 0;
  76. n = 0;
  77. #pragma omp for schedule( monotonic: static, 7) nowait
  78. for (i = 0; i < MONOTONIC_END (73); i++)
  79. {
  80. if (l == MONOTONIC_UNDEF)
  81. {
  82. n = 1;
  83. c++;
  84. }
  85. else if (l == i - 1)
  86. n++;
  87. else
  88. {
  89. if (l >= i)
  90. abort ();
  91. if (cnt == 1)
  92. abort ();
  93. if (n != 7)
  94. abort ();
  95. n = 1;
  96. c++;
  97. }
  98. if (n == 1)
  99. {
  100. if ((i % 7) != 0)
  101. abort ();
  102. if ((i / 7) % cnt != thr)
  103. abort ();
  104. }
  105. l = i;
  106. }
  107. if (cnt == 1)
  108. {
  109. if (n != 73 || l != 73 - 1 || c != 1)
  110. abort ();
  111. }
  112. else if (thr > 73 / 7)
  113. {
  114. if (l != MONOTONIC_UNDEF || c != 0 || n != 0)
  115. abort ();
  116. }
  117. else if (thr == 73 / 7)
  118. {
  119. if (l != 73 - 1 || c != 1 || n != 73 % 7)
  120. abort ();
  121. }
  122. else if (c == 0)
  123. abort ();
  124. else if (l == 73 - 1)
  125. {
  126. if (thr != (73 / 7) % cnt || n != 73 % 7)
  127. abort ();
  128. }
  129. else if ((n % 7) != 0)
  130. abort ();
  131. l = MONOTONIC_UNDEF;
  132. c = 0;
  133. n = 0;
  134. #pragma omp for nowait schedule(static)
  135. for (i = 0; i < MONOTONIC_END (73); i++)
  136. {
  137. if (l == MONOTONIC_UNDEF)
  138. {
  139. n = 1;
  140. c++;
  141. }
  142. else if (l == i - 1)
  143. n++;
  144. else
  145. abort ();
  146. l = i;
  147. }
  148. if (c > 1)
  149. abort ();
  150. l = MONOTONIC_UNDEF;
  151. c = 0;
  152. n = 0;
  153. #pragma omp for nowait schedule(monotonic,simd:static)
  154. for (i = 0; i < MONOTONIC_END (73); i++)
  155. {
  156. if (l == MONOTONIC_UNDEF)
  157. {
  158. n = 1;
  159. c++;
  160. }
  161. else if (l == i - 1)
  162. n++;
  163. else
  164. abort ();
  165. l = i;
  166. }
  167. if (c > 1)
  168. abort ();
  169. l = MONOTONIC_UNDEF;
  170. c = 0;
  171. n = 0;
  172. #pragma omp for schedule(monotonic : dynamic, 5) nowait
  173. for (i = 0; i < MONOTONIC_END (73); i++)
  174. {
  175. if (l == MONOTONIC_UNDEF)
  176. {
  177. n = 1;
  178. c++;
  179. }
  180. else if (l == i - 1)
  181. n++;
  182. else
  183. {
  184. if (l >= i)
  185. abort ();
  186. if ((n % 5) != 0 || n == 0)
  187. abort ();
  188. n = 1;
  189. c++;
  190. }
  191. l = i;
  192. }
  193. if (l == 73 - 1)
  194. {
  195. if (n % 5 != 73 % 5)
  196. abort ();
  197. }
  198. else if (l == MONOTONIC_UNDEF)
  199. {
  200. if (n != 0 || c != 0)
  201. abort ();
  202. }
  203. else if ((n % 5) != 0 || n == 0)
  204. abort ();
  205. l = MONOTONIC_UNDEF;
  206. c = 0;
  207. n = 0;
  208. #pragma omp for nowait schedule(dynamic, 7) ordered(1)
  209. for (i = 0; i < MONOTONIC_END (73); i++)
  210. {
  211. if (l == MONOTONIC_UNDEF)
  212. {
  213. n = 1;
  214. c++;
  215. }
  216. else if (l == i - 1)
  217. n++;
  218. else
  219. {
  220. if (l >= i)
  221. abort ();
  222. if ((n % 7) != 0 || n == 0)
  223. abort ();
  224. n = 1;
  225. c++;
  226. }
  227. #pragma omp ordered depend(source)
  228. if (MONOTONIC_UNDEF > 0)
  229. {
  230. #pragma omp ordered depend(sink: i)
  231. }
  232. else
  233. {
  234. #pragma omp ordered depend(sink: i - 1)
  235. }
  236. l = i;
  237. }
  238. if (l == 73 - 1)
  239. {
  240. if (n % 7 != 73 % 7)
  241. abort ();
  242. }
  243. else if (l == MONOTONIC_UNDEF)
  244. {
  245. if (n != 0 || c != 0)
  246. abort ();
  247. }
  248. else if ((n % 7) != 0 || n == 0)
  249. abort ();
  250. l = MONOTONIC_UNDEF;
  251. c = 0;
  252. n = 0;
  253. #pragma omp for schedule (monotonic :guided , 7) nowait
  254. for (i = 0; i < MONOTONIC_END (73); i++)
  255. {
  256. if (l == MONOTONIC_UNDEF)
  257. {
  258. n = 1;
  259. c++;
  260. }
  261. else if (l == i - 1)
  262. n++;
  263. else
  264. {
  265. if (l >= i)
  266. abort ();
  267. if (n < 7)
  268. abort ();
  269. n = 1;
  270. c++;
  271. }
  272. l = i;
  273. }
  274. l = MONOTONIC_UNDEF;
  275. c = 0;
  276. n = 0;
  277. #pragma omp for nowait schedule(guided, 7) ordered
  278. for (i = 0; i < MONOTONIC_END (73); i++)
  279. {
  280. if (l == MONOTONIC_UNDEF)
  281. {
  282. n = 1;
  283. c++;
  284. }
  285. else if (l == i - 1)
  286. n++;
  287. else
  288. {
  289. if (l >= i)
  290. abort ();
  291. if (n < 7)
  292. abort ();
  293. n = 1;
  294. c++;
  295. }
  296. #pragma omp ordered
  297. l = i;
  298. }
  299. }
  300. return 0;
  301. }