loop-12.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /* { dg-do run } */
  2. #include <omp.h>
  3. extern void abort (void);
  4. #define LLONG_MAX __LONG_LONG_MAX__
  5. #define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
  6. #define INT_MAX __INT_MAX__
  7. int arr[6 * 5];
  8. void
  9. set (int loopidx, int idx)
  10. {
  11. #pragma omp atomic
  12. arr[loopidx * 5 + idx]++;
  13. }
  14. #define check(var, val, loopidx, idx) \
  15. if (var == (val)) set (loopidx, idx); else
  16. #define test(loopidx, count) \
  17. for (idx = 0; idx < 5; idx++) \
  18. if (arr[loopidx * 5 + idx] != idx < count) \
  19. abort (); \
  20. else \
  21. arr[loopidx * 5 + idx] = 0
  22. int
  23. test1 (void)
  24. {
  25. int e = 0, idx;
  26. #pragma omp parallel reduction(+:e)
  27. {
  28. long long i;
  29. unsigned long long j;
  30. #pragma omp for schedule(dynamic,1) nowait
  31. for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000)
  32. {
  33. check (i, LLONG_MAX - 30001, 0, 0)
  34. check (i, LLONG_MAX - 20001, 0, 1)
  35. check (i, LLONG_MAX - 10001, 0, 2)
  36. e = 1;
  37. }
  38. #pragma omp for schedule(dynamic,1) nowait
  39. for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000)
  40. {
  41. check (i, -LLONG_MAX + 30000, 1, 0)
  42. check (i, -LLONG_MAX + 20000, 1, 1)
  43. check (i, -LLONG_MAX + 10000, 1, 2)
  44. e = 1;
  45. }
  46. #pragma omp for schedule(dynamic,1) nowait
  47. for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL)
  48. {
  49. check (j, 20, 2, 0)
  50. e = 1;
  51. }
  52. #pragma omp for schedule(dynamic,1) nowait
  53. for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL)
  54. {
  55. check (j, ULLONG_MAX - 3, 3, 0)
  56. e = 1;
  57. }
  58. #pragma omp for schedule(dynamic,1) nowait
  59. for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL)
  60. {
  61. check (j, LLONG_MAX - 20000ULL, 4, 0)
  62. check (j, LLONG_MAX - 10000ULL, 4, 1)
  63. check (j, LLONG_MAX, 4, 2)
  64. check (j, LLONG_MAX + 10000ULL, 4, 3)
  65. e = 1;
  66. }
  67. #pragma omp for schedule(dynamic,1) nowait
  68. for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL)
  69. {
  70. check (i, -3LL * INT_MAX - 20000LL, 5, 0)
  71. check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
  72. check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
  73. check (i, -20000LL + 600LL, 5, 3)
  74. check (i, INT_MAX - 20000LL + 800LL, 5, 4)
  75. e = 1;
  76. }
  77. }
  78. if (e)
  79. abort ();
  80. test (0, 3);
  81. test (1, 3);
  82. test (2, 1);
  83. test (3, 1);
  84. test (4, 4);
  85. test (5, 5);
  86. return 0;
  87. }
  88. int
  89. test2 (void)
  90. {
  91. int e = 0, idx;
  92. #pragma omp parallel reduction(+:e)
  93. {
  94. long long i;
  95. unsigned long long j;
  96. #pragma omp for schedule(guided,1) nowait
  97. for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000)
  98. {
  99. check (i, LLONG_MAX - 30001, 0, 0)
  100. check (i, LLONG_MAX - 20001, 0, 1)
  101. check (i, LLONG_MAX - 10001, 0, 2)
  102. e = 1;
  103. }
  104. #pragma omp for schedule(guided,1) nowait
  105. for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000)
  106. {
  107. check (i, -LLONG_MAX + 30000, 1, 0)
  108. check (i, -LLONG_MAX + 20000, 1, 1)
  109. check (i, -LLONG_MAX + 10000, 1, 2)
  110. e = 1;
  111. }
  112. #pragma omp for schedule(guided,1) nowait
  113. for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL)
  114. {
  115. check (j, 20, 2, 0)
  116. e = 1;
  117. }
  118. #pragma omp for schedule(guided,1) nowait
  119. for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL)
  120. {
  121. check (j, ULLONG_MAX - 3, 3, 0)
  122. e = 1;
  123. }
  124. #pragma omp for schedule(guided,1) nowait
  125. for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL)
  126. {
  127. check (j, LLONG_MAX - 20000ULL, 4, 0)
  128. check (j, LLONG_MAX - 10000ULL, 4, 1)
  129. check (j, LLONG_MAX, 4, 2)
  130. check (j, LLONG_MAX + 10000ULL, 4, 3)
  131. e = 1;
  132. }
  133. #pragma omp for schedule(guided,1) nowait
  134. for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL)
  135. {
  136. check (i, -3LL * INT_MAX - 20000LL, 5, 0)
  137. check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
  138. check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
  139. check (i, -20000LL + 600LL, 5, 3)
  140. check (i, INT_MAX - 20000LL + 800LL, 5, 4)
  141. e = 1;
  142. }
  143. }
  144. if (e)
  145. abort ();
  146. test (0, 3);
  147. test (1, 3);
  148. test (2, 1);
  149. test (3, 1);
  150. test (4, 4);
  151. test (5, 5);
  152. return 0;
  153. }
  154. int
  155. test3 (void)
  156. {
  157. int e = 0, idx;
  158. #pragma omp parallel reduction(+:e)
  159. {
  160. long long i;
  161. unsigned long long j;
  162. #pragma omp for schedule(static) nowait
  163. for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000)
  164. {
  165. check (i, LLONG_MAX - 30001, 0, 0)
  166. check (i, LLONG_MAX - 20001, 0, 1)
  167. check (i, LLONG_MAX - 10001, 0, 2)
  168. e = 1;
  169. }
  170. #pragma omp for schedule(static) nowait
  171. for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000)
  172. {
  173. check (i, -LLONG_MAX + 30000, 1, 0)
  174. check (i, -LLONG_MAX + 20000, 1, 1)
  175. check (i, -LLONG_MAX + 10000, 1, 2)
  176. e = 1;
  177. }
  178. #pragma omp for schedule(static) nowait
  179. for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL)
  180. {
  181. check (j, 20, 2, 0)
  182. e = 1;
  183. }
  184. #pragma omp for schedule(static) nowait
  185. for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL)
  186. {
  187. check (j, ULLONG_MAX - 3, 3, 0)
  188. e = 1;
  189. }
  190. #pragma omp for schedule(static) nowait
  191. for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL)
  192. {
  193. check (j, LLONG_MAX - 20000ULL, 4, 0)
  194. check (j, LLONG_MAX - 10000ULL, 4, 1)
  195. check (j, LLONG_MAX, 4, 2)
  196. check (j, LLONG_MAX + 10000ULL, 4, 3)
  197. e = 1;
  198. }
  199. #pragma omp for schedule(static) nowait
  200. for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL)
  201. {
  202. check (i, -3LL * INT_MAX - 20000LL, 5, 0)
  203. check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
  204. check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
  205. check (i, -20000LL + 600LL, 5, 3)
  206. check (i, INT_MAX - 20000LL + 800LL, 5, 4)
  207. e = 1;
  208. }
  209. }
  210. if (e)
  211. abort ();
  212. test (0, 3);
  213. test (1, 3);
  214. test (2, 1);
  215. test (3, 1);
  216. test (4, 4);
  217. test (5, 5);
  218. return 0;
  219. }
  220. int
  221. test4 (void)
  222. {
  223. int e = 0, idx;
  224. #pragma omp parallel reduction(+:e)
  225. {
  226. long long i;
  227. unsigned long long j;
  228. #pragma omp for schedule(static,1) nowait
  229. for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000)
  230. {
  231. check (i, LLONG_MAX - 30001, 0, 0)
  232. check (i, LLONG_MAX - 20001, 0, 1)
  233. check (i, LLONG_MAX - 10001, 0, 2)
  234. e = 1;
  235. }
  236. #pragma omp for schedule(static,1) nowait
  237. for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000)
  238. {
  239. check (i, -LLONG_MAX + 30000, 1, 0)
  240. check (i, -LLONG_MAX + 20000, 1, 1)
  241. check (i, -LLONG_MAX + 10000, 1, 2)
  242. e = 1;
  243. }
  244. #pragma omp for schedule(static,1) nowait
  245. for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL)
  246. {
  247. check (j, 20, 2, 0)
  248. e = 1;
  249. }
  250. #pragma omp for schedule(static,1) nowait
  251. for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL)
  252. {
  253. check (j, ULLONG_MAX - 3, 3, 0)
  254. e = 1;
  255. }
  256. #pragma omp for schedule(static,1) nowait
  257. for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL)
  258. {
  259. check (j, LLONG_MAX - 20000ULL, 4, 0)
  260. check (j, LLONG_MAX - 10000ULL, 4, 1)
  261. check (j, LLONG_MAX, 4, 2)
  262. check (j, LLONG_MAX + 10000ULL, 4, 3)
  263. e = 1;
  264. }
  265. #pragma omp for schedule(static,1) nowait
  266. for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL)
  267. {
  268. check (i, -3LL * INT_MAX - 20000LL, 5, 0)
  269. check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
  270. check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
  271. check (i, -20000LL + 600LL, 5, 3)
  272. check (i, INT_MAX - 20000LL + 800LL, 5, 4)
  273. e = 1;
  274. }
  275. }
  276. if (e)
  277. abort ();
  278. test (0, 3);
  279. test (1, 3);
  280. test (2, 1);
  281. test (3, 1);
  282. test (4, 4);
  283. test (5, 5);
  284. return 0;
  285. }
  286. int
  287. test5 (void)
  288. {
  289. int e = 0, idx;
  290. #pragma omp parallel reduction(+:e)
  291. {
  292. long long i;
  293. unsigned long long j;
  294. #pragma omp for schedule(runtime) nowait
  295. for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000)
  296. {
  297. check (i, LLONG_MAX - 30001, 0, 0)
  298. check (i, LLONG_MAX - 20001, 0, 1)
  299. check (i, LLONG_MAX - 10001, 0, 2)
  300. e = 1;
  301. }
  302. #pragma omp for schedule(runtime) nowait
  303. for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000)
  304. {
  305. check (i, -LLONG_MAX + 30000, 1, 0)
  306. check (i, -LLONG_MAX + 20000, 1, 1)
  307. check (i, -LLONG_MAX + 10000, 1, 2)
  308. e = 1;
  309. }
  310. #pragma omp for schedule(runtime) nowait
  311. for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL)
  312. {
  313. check (j, 20, 2, 0)
  314. e = 1;
  315. }
  316. #pragma omp for schedule(runtime) nowait
  317. for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL)
  318. {
  319. check (j, ULLONG_MAX - 3, 3, 0)
  320. e = 1;
  321. }
  322. #pragma omp for schedule(runtime) nowait
  323. for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL)
  324. {
  325. check (j, LLONG_MAX - 20000ULL, 4, 0)
  326. check (j, LLONG_MAX - 10000ULL, 4, 1)
  327. check (j, LLONG_MAX, 4, 2)
  328. check (j, LLONG_MAX + 10000ULL, 4, 3)
  329. e = 1;
  330. }
  331. #pragma omp for schedule(runtime) nowait
  332. for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL)
  333. {
  334. check (i, -3LL * INT_MAX - 20000LL, 5, 0)
  335. check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
  336. check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
  337. check (i, -20000LL + 600LL, 5, 3)
  338. check (i, INT_MAX - 20000LL + 800LL, 5, 4)
  339. e = 1;
  340. }
  341. }
  342. if (e)
  343. abort ();
  344. test (0, 3);
  345. test (1, 3);
  346. test (2, 1);
  347. test (3, 1);
  348. test (4, 4);
  349. test (5, 5);
  350. return 0;
  351. }
  352. int
  353. main (void)
  354. {
  355. if (2 * sizeof (int) != sizeof (long long))
  356. return 0;
  357. test1 ();
  358. test2 ();
  359. test3 ();
  360. test4 ();
  361. omp_set_schedule (omp_sched_static, 0);
  362. test5 ();
  363. omp_set_schedule (omp_sched_static, 3);
  364. test5 ();
  365. omp_set_schedule (omp_sched_dynamic, 5);
  366. test5 ();
  367. omp_set_schedule (omp_sched_guided, 2);
  368. test5 ();
  369. return 0;
  370. }