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