task-detach-8.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, that can then be executed by
  6. any available thread. Each thread uses taskwait to wait for the
  7. child tasks to complete. */
  8. int main (void)
  9. {
  10. int x = 0, y = 0, z = 0;
  11. int thread_count;
  12. omp_event_handle_t detach_event1, detach_event2;
  13. #pragma omp target map (tofrom: x, y, z) map (from: thread_count)
  14. #pragma omp parallel private (detach_event1, detach_event2)
  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. #pragma omp taskwait
  34. }
  35. assert (x == thread_count);
  36. assert (y == thread_count);
  37. assert (z == thread_count);
  38. }