task-detach-10.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* { dg-do run } */
  2. #include <omp.h>
  3. #include <assert.h>
  4. /* Test tasks with detach clause on an offload device. Each device
  5. thread spawns off a chain of tasks in a taskgroup, that can then
  6. be executed by any available thread. */
  7. int main (void)
  8. {
  9. int x = 0, y = 0, z = 0;
  10. int thread_count;
  11. omp_event_handle_t detach_event1, detach_event2;
  12. #pragma omp target map (tofrom: x, y, z) map (from: thread_count)
  13. #pragma omp parallel private (detach_event1, detach_event2)
  14. #pragma omp taskgroup
  15. {
  16. #pragma omp single
  17. thread_count = omp_get_num_threads ();
  18. #pragma omp task detach (detach_event1) untied
  19. #pragma omp atomic update
  20. x++;
  21. #pragma omp task detach (detach_event2) untied
  22. {
  23. #pragma omp atomic update
  24. y++;
  25. omp_fulfill_event (detach_event1);
  26. }
  27. #pragma omp task untied
  28. {
  29. #pragma omp atomic update
  30. z++;
  31. omp_fulfill_event (detach_event2);
  32. }
  33. }
  34. assert (x == thread_count);
  35. assert (y == thread_count);
  36. assert (z == thread_count);
  37. }