LLVM OpenMP 19.0.0git
omp_sections_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 sections construct to
9 * release the threads in the first sections construct
10 *
11 * Also, since scheduling of sections is implementation defined, it is
12 * necessary to have all four sections in the second sections construct
13 * release the threads since we can't guarantee which section a single thread
14 * will execute.
15 */
16volatile int release;
17volatile int count;
18
20{
21 fprintf(stderr, "Thread nr %d enters first section"
22 " and waits.\n", rank);
23 while (release == 0);
24 #pragma omp atomic
25 count++;
26}
27
29{
30 fprintf(stderr, "Thread nr %d sets release to 1\n", rank);
31 release = 1;
32 #pragma omp flush(release)
33 #pragma omp atomic
34 count++;
35}
36
38{
39 release = 0;
40 count = 0;
41
42 #pragma omp parallel num_threads(4)
43 {
44 int rank;
45 rank = omp_get_thread_num ();
46 #pragma omp sections nowait
47 {
48 #pragma omp section
49 {
51 }
52 #pragma omp section
53 {
55 }
56 #pragma omp section
57 {
59 }
60 #pragma omp section
61 {
62 fprintf(stderr, "Thread nr %d enters first sections and goes "
63 "immediately to next sections construct to release.\n", rank);
64 #pragma omp atomic
65 count++;
66 }
67 }
68 /* Begin of second sections environment */
69 #pragma omp sections
70 {
71 #pragma omp section
72 {
74 }
75 #pragma omp section
76 {
78 }
79 #pragma omp section
80 {
82 }
83 #pragma omp section
84 {
86 }
87 }
88 }
89 // Check to make sure all eight sections were executed
90 return (count==8);
91}
92
93int main()
94{
95 int i;
96 int num_failed=0;
97
98 for(i = 0; i < REPETITIONS; i++) {
100 num_failed++;
101 }
102 }
103 return num_failed;
104}
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)
volatile int release
int test_omp_sections_nowait()
volatile int count
int main()
#define REPETITIONS
Definition: omp_testsuite.h:13