1 // RUN: %libomp-compile-and-run
3 #include "omp_testsuite.h"
6 * This test will hang if the nowait is not working properly.
8 * It relies on a thread skipping to the second for construct to
9 * release the threads in the first for construct.
11 * Also, we use static scheduling to guarantee that one
12 * thread will make it to the second for construct.
17 void wait_for_release_then_increment(int rank
)
19 fprintf(stderr
, "Thread nr %d enters first for construct"
20 " and waits.\n", rank
);
26 void release_and_increment(int rank
)
28 fprintf(stderr
, "Thread nr %d sets release to 1\n", rank
);
34 int test_omp_for_nowait()
39 #pragma omp parallel num_threads(4)
44 rank
= omp_get_thread_num();
46 #pragma omp for schedule(static) nowait
47 for (i
= 0; i
< 4; i
++) {
49 wait_for_release_then_increment(rank
);
51 fprintf(stderr
, "Thread nr %d enters first for and goes "
52 "immediately to the next for construct to release.\n", rank
);
58 #pragma omp for schedule(static)
59 for (i
= 0; i
< 4; i
++) {
60 release_and_increment(rank
);
71 for(i
= 0; i
< REPETITIONS
; i
++) {
72 if(!test_omp_for_nowait()) {