LLVM OpenMP 19.0.0git
omp_for_nowait.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include "omp_testsuite.h"
4
5/*
6 * This test will hang if the nowait is not working properly.
7 *
8 * It relies on a thread skipping to the second for construct to
9 * release the threads in the first for construct.
10 *
11 * Also, we use static scheduling to guarantee that one
12 * thread will make it to the second for construct.
13 */
14volatile int release;
15volatile int count;
16
18{
19 fprintf(stderr, "Thread nr %d enters first for construct"
20 " and waits.\n", rank);
21 while (release == 0);
22 #pragma omp atomic
23 count++;
24}
25
27{
28 fprintf(stderr, "Thread nr %d sets release to 1\n", rank);
29 release = 1;
30 #pragma omp atomic
31 count++;
32}
33
35{
36 release = 0;
37 count = 0;
38
39 #pragma omp parallel num_threads(4)
40 {
41 int rank;
42 int i;
43
44 rank = omp_get_thread_num();
45
46 #pragma omp for schedule(static) nowait
47 for (i = 0; i < 4; i++) {
48 if (i < 3)
50 else {
51 fprintf(stderr, "Thread nr %d enters first for and goes "
52 "immediately to the next for construct to release.\n", rank);
53 #pragma omp atomic
54 count++;
55 }
56 }
57
58 #pragma omp for schedule(static)
59 for (i = 0; i < 4; i++) {
61 }
62 }
63 return (count==8);
64}
65
66int main()
67{
68 int i;
69 int num_failed=0;
70
71 for(i = 0; i < REPETITIONS; i++) {
72 if(!test_omp_for_nowait()) {
73 num_failed++;
74 }
75 }
76 return num_failed;
77}
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d __itt_event ITT_FORMAT __itt_group_mark d void const wchar_t const wchar_t int ITT_FORMAT __itt_group_sync __itt_group_fsync x void const wchar_t int const wchar_t int int ITT_FORMAT __itt_group_sync __itt_group_fsync x void ITT_FORMAT __itt_group_sync __itt_group_fsync p void ITT_FORMAT __itt_group_sync __itt_group_fsync p void size_t ITT_FORMAT lu no args __itt_obj_prop_t __itt_obj_state_t ITT_FORMAT d const char ITT_FORMAT s const char ITT_FORMAT s __itt_frame ITT_FORMAT p __itt_counter ITT_FORMAT p __itt_counter unsigned long long ITT_FORMAT lu __itt_counter unsigned long long ITT_FORMAT lu __itt_counter __itt_clock_domain unsigned long long void ITT_FORMAT p const wchar_t ITT_FORMAT S __itt_mark_type const wchar_t ITT_FORMAT S __itt_mark_type const char ITT_FORMAT s __itt_mark_type ITT_FORMAT d __itt_caller ITT_FORMAT p __itt_caller ITT_FORMAT p no args const __itt_domain __itt_clock_domain unsigned long long __itt_id ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_id __itt_id void ITT_FORMAT p const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_id __itt_string_handle __itt_scope ITT_FORMAT d const __itt_domain __itt_scope __itt_string_handle const char size_t ITT_FORMAT lu const __itt_domain __itt_clock_domain unsigned long long __itt_relation __itt_id ITT_FORMAT lu __itt_track_group __itt_string_handle __itt_track_group_type ITT_FORMAT d __itt_track ITT_FORMAT p void int rank
#define i
Definition: kmp_stub.cpp:87
void wait_for_release_then_increment(int rank)
void release_and_increment(int rank)
int test_omp_for_nowait()
volatile int release
volatile int count
int main()
#define REPETITIONS
Definition: omp_testsuite.h:13