ordered-1.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Test that all loop iterations are touched. This doesn't verify
  2. scheduling order, merely coverage. */
  3. /* Note that we never call GOMP_ordered_start in here. AFAICS, this is
  4. valid; the only requirement is "not more than once per iteration". */
  5. /* { dg-require-effective-target sync_int_long } */
  6. #include <omp.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include "libgomp_g.h"
  10. #define N 1000
  11. static int S, E, INCR, CHUNK, NTHR;
  12. static int data[N];
  13. static void clean_data (void)
  14. {
  15. memset (data, -1, sizeof (data));
  16. }
  17. static void test_data (void)
  18. {
  19. int i, j;
  20. for (i = 0; i < S; ++i)
  21. assert (data[i] == -1);
  22. for (j = 0; i < E; ++i, j = (j + 1) % INCR)
  23. if (j == 0)
  24. assert (data[i] != -1);
  25. else
  26. assert (data[i] == -1);
  27. for (; i < N; ++i)
  28. assert (data[i] == -1);
  29. }
  30. static void set_data (long i, int val)
  31. {
  32. int old;
  33. assert (i >= 0 && i < N);
  34. old = __sync_lock_test_and_set (data+i, val);
  35. assert (old == -1);
  36. }
  37. #define TMPL_1(sched) \
  38. static void f_##sched##_1 (void *dummy) \
  39. { \
  40. int iam = omp_get_thread_num (); \
  41. long s0, e0, i; \
  42. if (GOMP_loop_ordered_##sched##_start (S, E, INCR, CHUNK, &s0, &e0)) \
  43. do \
  44. { \
  45. for (i = s0; i < e0; i += INCR) \
  46. set_data (i, iam); \
  47. } \
  48. while (GOMP_loop_ordered_##sched##_next (&s0, &e0)); \
  49. GOMP_loop_end (); \
  50. } \
  51. static void t_##sched##_1 (void) \
  52. { \
  53. clean_data (); \
  54. GOMP_parallel_start (f_##sched##_1, NULL, NTHR); \
  55. f_##sched##_1 (NULL); \
  56. GOMP_parallel_end (); \
  57. test_data (); \
  58. }
  59. TMPL_1(static)
  60. TMPL_1(dynamic)
  61. TMPL_1(guided)
  62. static void test (void)
  63. {
  64. t_static_1 ();
  65. t_dynamic_1 ();
  66. t_guided_1 ();
  67. }
  68. int main()
  69. {
  70. omp_set_dynamic (0);
  71. NTHR = 4;
  72. S = 0, E = N, INCR = 1, CHUNK = 4;
  73. test ();
  74. S = 0, E = N, INCR = 2, CHUNK = 4;
  75. test ();
  76. S = 1, E = N-1, INCR = 1, CHUNK = 5;
  77. test ();
  78. S = 1, E = N-1, INCR = 2, CHUNK = 5;
  79. test ();
  80. S = 2, E = 4, INCR = 1, CHUNK = 1;
  81. test ();
  82. S = 0, E = N, INCR = 1, CHUNK = 0;
  83. t_static_1 ();
  84. S = 1, E = N-1, INCR = 1, CHUNK = 0;
  85. t_static_1 ();
  86. NTHR = 10;
  87. S = 1, E = 9, INCR = 1, CHUNK = 0;
  88. t_static_1 ();
  89. return 0;
  90. }