1 // RUN: %libomp-compile && env KMP_ENABLE_TASK_THROTTLING=0 %libomp-run
2 // RUN: %libomp-compile && env KMP_ENABLE_TASK_THROTTLING=1 %libomp-run
9 * Test the task throttling behavior of the runtime.
10 * Unless OMP_NUM_THREADS is 1, the master thread pushes tasks to its own tasks
11 * queue until either of the following happens:
12 * - the task queue is full, and it starts serializing tasks
13 * - all tasks have been pushed, and it can begin execution
14 * The idea is to create a huge number of tasks which execution are blocked
15 * until the master thread comes to execute tasks (they need to be blocking,
16 * otherwise the second thread will start emptying the queue).
17 * At this point we can check the number of enqueued tasks: iff all tasks have
18 * been enqueued, then there was no task throttling.
19 * Otherwise there has been some sort of task throttling.
20 * If what we detect doesn't match the value of the environment variable, the
25 #define NUM_TASKS 2000
32 int throttling
= strcmp(getenv("KMP_ENABLE_TASK_THROTTLING"), "1") == 0;
36 #pragma omp parallel num_threads(2)
39 for (i
= 0; i
< NUM_TASKS
; i
++) {
44 tid
= omp_get_thread_num();
46 // As soon as the master thread starts executing task we should unlock
47 // all tasks, and detect the test failure if it has not been done yet.
49 failed
= throttling
? enqueued
== NUM_TASKS
: enqueued
< NUM_TASKS
;
50 #pragma omp atomic write
55 #pragma omp atomic read