1 // RUN: %libomp-compile-and-run
2 // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-8
4 // support for taskwait with depend clause introduced in clang-14
5 // UNSUPPORTED: clang-5, clang-6, clang-6, clang-8, clang-9, clang-10, clang-11,
8 // icc does not yet support taskwait with depend clause
14 #include "omp_my_sleep.h"
17 int task_grabbed
= 0, task_can_proceed
= 0;
18 int task2_grabbed
= 0, task2_can_proceed
= 0;
20 static void wait_on_flag(int *flag
) {
25 #pragma omp atomic read
29 if (secs
== timelimit
) {
30 fprintf(stderr
, "error: timeout in wait_on_flag()\n");
33 } while (flag_value
== 0);
36 static void signal_flag(int *flag
) {
41 int main(int argc
, char** argv
) {
43 // Ensure two threads are running
44 int num_threads
= omp_get_max_threads();
46 omp_set_num_threads(2);
48 #pragma omp parallel shared(a)
51 // Let us be extra safe here
52 if (omp_get_num_threads() > 1) {
53 #pragma omp single nowait
55 // Schedule independent child task that
56 // waits to be flagged after sebsequent taskwait depend()
59 signal_flag(&task_grabbed
);
60 wait_on_flag(&task_can_proceed
);
62 // Let another worker thread grab the task to execute
63 wait_on_flag(&task_grabbed
);
64 // This should be ignored since the task above has
65 // no dependency information
66 #pragma omp taskwait depend(inout: a)
67 // Signal the independent task to proceed
68 signal_flag(&task_can_proceed
);
70 // Schedule child task with dependencies that taskwait does
72 #pragma omp task depend(inout: b)
74 signal_flag(&task2_grabbed
);
75 wait_on_flag(&task2_can_proceed
);
79 // Let another worker thread grab the task to execute
80 wait_on_flag(&task2_grabbed
);
81 // This should be ignored since the task above has
82 // dependency information on b instead of a
83 #pragma omp taskwait depend(inout: a)
84 // Signal the task to proceed
85 signal_flag(&task2_can_proceed
);
87 // Generate one child task for taskwait
88 #pragma omp task shared(a) depend(inout: a)
94 #pragma omp taskwait depend(inout: a)
96 #pragma omp atomic read
100 fprintf(stderr
, "error: dependent task was not executed before "
101 "taskwait finished\n");
104 } // #pragma omp single
105 } // if (num_threads > 1)
106 } // #pragma omp parallel