2 /* { dg-set-target-env-var OMP_MAX_TASK_PRIORITY "10" } */
4 /* This test verifies that the "priority" clause of omp task works as
7 Testing the OpenMP task scheduler is a bit tricky, especially when
8 trying to determine what ran first (without explicitly calling
9 time() and/or synchronizing between threads). What we do here is
10 run in single threaded mode which guarantees that we won't run into
11 data races while accessing the "prio" array.
13 We give each task a priority from 0..63, while setting
14 OMP_MAX_TASK_PRIORITY to 10, which basically gives us 10 lower
15 priority tasks, and the rest scheduled to run earlier. We verify
16 that the priority < 10 tasks run last. */
25 int tsknum
=0, prio
[N
];
26 int max_priority
= omp_get_max_task_priority ();
27 int saved_tsknum
= -1;
30 #pragma omp parallel num_threads(1)
31 #pragma omp single private (i)
33 for (i
= 0; i
< N
; i
++)
34 #pragma omp task priority(i ^ 1)
37 #pragma omp atomic capture seq_cst
41 #pragma omp atomic read seq_cst
42 saved_tsknum
= tsknum
;
45 /* If any of the tasks have run before all tasks were created, don't
46 make any assumption on the task order. Otherwise, we should have
47 tasks with >= max_priority scheduled first in arbitrary order,
48 followed by the rest of tasks in decreasing priority order, as
49 there is only one thread that can schedule them. */
50 if (saved_tsknum
== 0)
52 for (i
= 0; i
< N
; i
++)
53 if (i
< N
- max_priority
)
55 if (prio
[i
] < max_priority
)
58 else if (i
!= N
- prio
[i
] - 1)