LLVM OpenMP 22.0.0git
nested_lwt_thread_num.c
Go to the documentation of this file.
1// clang-format off
2// RUN: %libomp-compile-and-run | FileCheck %s
3// REQUIRES: ompt
4// clang-format on
5
6#include "callback.h"
7#include <omp.h>
8
9__attribute__ ((noinline)) // workaround for bug in icc
10void print_task_info_at(int ancestor_level, int id)
11{
12#pragma omp critical
13 {
14 int task_type;
15char buffer[2048];
16ompt_data_t *parallel_data;
17ompt_data_t *task_data;
18int thread_num;
19ompt_get_task_info(ancestor_level, &task_type, &task_data, NULL, &parallel_data,
20 &thread_num);
21format_task_type(task_type, buffer);
22printf("%" PRIu64 ": ancestor_level=%d id=%d task_type=%s=%d "
23 "parallel_id=%" PRIx64 " task_id=%" PRIx64 " thread_num=%d\n",
24 ompt_get_thread_data()->value, ancestor_level, id, buffer, task_type,
25 parallel_data->value, task_data->value, thread_num);
26}
27}
28;
29
30__attribute__ ((noinline)) // workaround for bug in icc
31void print_innermost_task_info(int id)
32{
33 print_task_info_at(0, id);
34}
35
36int main() {
37
38#pragma omp parallel num_threads(2)
39 {
40 // sync threads before checking the output
41#pragma omp barrier
42 // region 0
43 if (omp_get_thread_num() == 1) {
44 // executed by worker thread only
45 // assert that thread_num is 1
46 print_innermost_task_info(1);
47
48#pragma omp parallel num_threads(1)
49 {
50 // serialized region 1
51 // assert that thread_num is 0
52 print_innermost_task_info(2);
53
54#pragma omp parallel num_threads(1)
55 {
56 // serialized region 2
57 // assert that thread_num is 0
58 print_innermost_task_info(3);
59
60 // Check the value of thread_num while iterating over the hierarchy
61 // of active tasks.
62 print_task_info_at(0, 3);
63 print_task_info_at(1, 2);
64 print_task_info_at(2, 1);
65 }
66 }
67 }
68 }
69
70 // clang-format off
71 // Check if libomp supports the callbacks for this test.
72 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create'
73 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'
74
75
76 // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
77 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin: parallel_id=[[PARALLEL_ID_0:[0-9]+]], task_id=[[TASK_ID_0:[0-9]+]], actual_parallelism=1, index=1, flags=1
78
79 // region 0
80 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin: parent_task_id=[[TASK_ID_0]],
81 // CHECK-SAME: parallel_id=[[PARALLEL_ID_1:[0-9]+]]
82 // CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_1]], task_id=[[TASK_ID_1:[0-9]+]]
83 // CHECK-DAG: {{^}}[[WORKER_ID:[0-9]+]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_1]], task_id=[[TASK_ID_2:[0-9]+]]
84 // assert some info about implicit task executed by worker thread
85 // thread_num is the most important
86 // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=1
87 // CHECK-SAME: parallel_id=[[PARALLEL_ID_1]] task_id=[[TASK_ID_2]]
88 // CHECK-SAME: thread_num=1
89
90 // serialized region 1
91 // CHECK: {{^}}[[WORKER_ID]]: ompt_event_parallel_begin: parent_task_id=[[TASK_ID_2]],
92 // CHECK-SAME: parallel_id=[[PARALLEL_ID_2:[0-9]+]]
93 // CHECK-DAG: {{^}}[[WORKER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_2]], task_id=[[TASK_ID_3:[0-9]+]]
94 // assert some information about the implicit task of the serialized region 1
95 // pay attention that thread_num should take value 0
96 // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=2
97 // CHECK-SAME: parallel_id=[[PARALLEL_ID_2]] task_id=[[TASK_ID_3]]
98 // CHECK-SAME: thread_num=0
99
100 // serialized region 2
101 // CHECK: {{^}}[[WORKER_ID]]: ompt_event_parallel_begin: parent_task_id=[[TASK_ID_3]],
102 // CHECK-SAME: parallel_id=[[PARALLEL_ID_3:[0-9]+]]
103 // CHECK-DAG: {{^}}[[WORKER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID_3]], task_id=[[TASK_ID_4:[0-9]+]]
104 // assert some information about the implicit task of the serialized region 2
105 // pay attention that thread_num should take value 0
106 // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=3
107 // CHECK-SAME: parallel_id=[[PARALLEL_ID_3]] task_id=[[TASK_ID_4]]
108 // CHECK-SAME: thread_num=0
109
110 // Check the value of thread_num argument while iterating over the hierarchy
111 // of active tasks. The expected is that thread_num takes the value checked
112 // above in the test case (0, 0, 1 - respectively).
113
114 // Thread is the master thread of the region 2, so thread_num should be 0.
115 // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=0 id=3
116 // CHECK-SAME: parallel_id=[[PARALLEL_ID_3]] task_id=[[TASK_ID_4]]
117 // CHECK-SAME: thread_num=0
118
119 // Thread is the master thread of the region 1, so thread_num should be 0.
120 // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=1 id=2
121 // CHECK-SAME: parallel_id=[[PARALLEL_ID_2]] task_id=[[TASK_ID_3]]
122 // CHECK-SAME: thread_num=0
123
124 // Thread is the worker thread of the region 0, so thread_num should be 1.
125 // CHECK: {{^}}[[WORKER_ID]]: ancestor_level=2 id=1
126 // CHECK-SAME: parallel_id=[[PARALLEL_ID_1]] task_id=[[TASK_ID_2]]
127 // CHECK-SAME: thread_num=1
128 // clang-format on
129
130 return 0;
131}
static ompt_get_task_info_t ompt_get_task_info
Definition callback.h:156
static void format_task_type(int type, char *buffer)
Definition callback.h:129
static ompt_get_thread_data_t ompt_get_thread_data
Definition callback.h:158
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 value
__attribute__((noinline))
int main()