ordered-2.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Trivial test of ordered. */
  2. /* { dg-require-effective-target sync_int_long } */
  3. #include <omp.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include "libgomp_g.h"
  7. #define N 100
  8. static int next;
  9. static int CHUNK, NTHR;
  10. static void clean_data (void)
  11. {
  12. next = 0;
  13. }
  14. static void set_data (long i)
  15. {
  16. int n = __sync_fetch_and_add (&next, 1);
  17. assert (n == i);
  18. }
  19. #define TMPL_1(sched) \
  20. static void f_##sched##_1 (void *dummy) \
  21. { \
  22. long s0, e0, i; \
  23. if (GOMP_loop_ordered_##sched##_start (0, N, 1, CHUNK, &s0, &e0)) \
  24. do \
  25. { \
  26. for (i = s0; i < e0; ++i) \
  27. { \
  28. GOMP_ordered_start (); \
  29. set_data (i); \
  30. GOMP_ordered_end (); \
  31. } \
  32. } \
  33. while (GOMP_loop_ordered_##sched##_next (&s0, &e0)); \
  34. GOMP_loop_end (); \
  35. } \
  36. static void t_##sched##_1 (void) \
  37. { \
  38. clean_data (); \
  39. GOMP_parallel_start (f_##sched##_1, NULL, NTHR); \
  40. f_##sched##_1 (NULL); \
  41. GOMP_parallel_end (); \
  42. }
  43. TMPL_1(static)
  44. TMPL_1(dynamic)
  45. TMPL_1(guided)
  46. static void test (void)
  47. {
  48. t_static_1 ();
  49. t_dynamic_1 ();
  50. t_guided_1 ();
  51. }
  52. int main()
  53. {
  54. omp_set_dynamic (0);
  55. NTHR = 4;
  56. CHUNK = 1;
  57. test ();
  58. CHUNK = 5;
  59. test ();
  60. CHUNK = 7;
  61. test ();
  62. CHUNK = 0;
  63. t_static_1 ();
  64. return 0;
  65. }