LLVM OpenMP 22.0.0git
task_types.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#include "callback.h"
6#include <omp.h>
7#include <math.h>
8
9int main() {
10 // initialize the OpenMP runtime
12
13 // initial task
14 print_ids(0);
15
16 int x;
17// implicit task
18#pragma omp parallel num_threads(1)
19 {
20 print_ids(0);
21 x++;
22 }
23
24#pragma omp parallel num_threads(2)
25 {
26// explicit task
27#pragma omp single
28#pragma omp task
29 {
30 print_ids(0);
31 x++;
32 }
33// explicit task with undeferred
34#pragma omp single
35#pragma omp task if (0)
36 {
37 print_ids(0);
38 x++;
39 }
40
41// explicit task with untied
42#pragma omp single
43#pragma omp task untied
44 {
45 // Output of thread_id is needed to know on which thread task is executed
46 printf("%" PRIu64 ": explicit_untied\n", ompt_get_thread_data()->value);
47 print_ids(0);
48 print_frame(1);
49 x++;
50#pragma omp taskyield
51 printf("%" PRIu64 ": explicit_untied(2)\n",
53 print_ids(0);
54 print_frame(1);
55 x++;
56#pragma omp taskwait
57 printf("%" PRIu64 ": explicit_untied(3)\n",
59 print_ids(0);
60 print_frame(1);
61 x++;
62 }
63// explicit task with final
64#pragma omp single
65#pragma omp task final(1)
66 {
67 print_ids(0);
68 x++;
69// nested explicit task with final and undeferred
70#pragma omp task
71 {
72 print_ids(0);
73 x++;
74 }
75 }
76
77 // Mergeable task test deactivated for now
78 // explicit task with mergeable
79 /*
80 #pragma omp task mergeable if((int)sin(0))
81 {
82 print_ids(0);
83 x++;
84 }
85 */
86
87 // TODO: merged task
88 }
89
90 // clang-format off
91 // Check if libomp supports the callbacks for this test.
92 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create'
93 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'
94
95 // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
96
97 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin: parallel_id={{[0-f]+}}
98 // CHECK-SAME: task_id=[[INITIAL_TASK_ID:[0-f]+]], actual_parallelism=1, index=1, flags=1
99
100 // CHECK-NOT: 0: parallel_data initially not null
101
102 // initial task
103 // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id={{[0-f]+}}
104 // CHECK-SAME: task_id=[[INITIAL_TASK_ID]], exit_frame=[[NULL]]
105 // CHECK-SAME: reenter_frame=[[NULL]]
106 // CHECK-SAME: task_type=ompt_task_initial=1, thread_num=0
107
108 // implicit task
109 // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id={{[0-f]+}}
110 // CHECK-SAME: task_id={{[0-f]+}}, exit_frame={{(0x)?[0-f]+}}
111 // CHECK-SAME: reenter_frame=[[NULL]]
112 // CHECK-SAME: task_type=ompt_task_implicit|ompt_task_undeferred=134217730
113 // CHECK-SAME: thread_num=0
114
115 // explicit task
116 // CHECK: {{^[0-9]+}}: ompt_event_task_create: parent_task_id={{[0-f]+}}
117 // CHECK-SAME: parent_task_frame.exit={{(0x)?[0-f]+}}
118 // CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
119 // CHECK-SAME: new_task_id=[[EXPLICIT_TASK_ID:[0-f]+]]
120 // CHECK-SAME: codeptr_ra={{(0x)?[0-f]+}}
121 // CHECK-SAME: task_type=ompt_task_explicit=4
122 // CHECK-SAME: has_dependences=no
123
124 // CHECK: [[THREAD_ID_1:[0-9]+]]: ompt_event_task_schedule:
125 // CHECK-SAME: second_task_id=[[EXPLICIT_TASK_ID]]
126
127 // CHECK: [[THREAD_ID_1]]: task level 0: parallel_id=[[PARALLEL_ID:[0-f]+]]
128 // CHECK-SAME: task_id=[[EXPLICIT_TASK_ID]], exit_frame={{(0x)?[0-f]+}}
129 // CHECK-SAME: reenter_frame=[[NULL]], task_type=ompt_task_explicit=4
130 // CHECK-SAME: thread_num={{[01]}}
131
132 // explicit task with undeferred
133 // CHECK: {{^[0-9]+}}: ompt_event_task_create: parent_task_id={{[0-f]+}}
134 // CHECK-SAME: parent_task_frame.exit={{(0x)?[0-f]+}}
135 // CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
136 // CHECK-SAME: new_task_id=[[EXPLICIT_UNDEFERRED_TASK_ID:[0-f]+]]
137 // CHECK-SAME: codeptr_ra={{(0x)?[0-f]+}}
138 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_undeferred=134217732
139 // CHECK-SAME: has_dependences=no
140
141 // CHECK: [[THREAD_ID_2:[0-9]+]]: ompt_event_task_schedule:
142 // CHECK-SAME: second_task_id=[[EXPLICIT_UNDEFERRED_TASK_ID]]
143
144 // CHECK: [[THREAD_ID_2]]: task level 0: parallel_id=[[PARALLEL_ID]]
145 // CHECK-SAME: task_id=[[EXPLICIT_UNDEFERRED_TASK_ID]]
146 // CHECK-SAME: exit_frame={{(0x)?[0-f]+}}, reenter_frame=[[NULL]]
147 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_undeferred=134217732
148 // CHECK-SAME: thread_num={{[01]}}
149
150 // explicit task with untied
151 // CHECK: {{^[0-9]+}}: ompt_event_task_create: parent_task_id={{[0-f]+}}
152 // CHECK-SAME: parent_task_frame.exit={{(0x)?[0-f]+}}
153 // CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
154 // CHECK-SAME: new_task_id=[[EXPLICIT_UNTIED_TASK_ID:[0-f]+]]
155 // CHECK-SAME: codeptr_ra={{(0x)?[0-f]+}}
156 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_untied=268435460
157 // CHECK-SAME: has_dependences=no
158
159 // Here the thread_id cannot be taken from a schedule event as there
160 // may be multiple of those
161 // CHECK: [[THREAD_ID_3:[0-9]+]]: explicit_untied
162 // CHECK: [[THREAD_ID_3]]: task level 0: parallel_id=[[PARALLEL_ID]]
163 // CHECK-SAME: task_id=[[EXPLICIT_UNTIED_TASK_ID]]
164 // CHECK-SAME: exit_frame={{(0x)?[0-f]+}}, reenter_frame=[[NULL]]
165 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_untied=268435460
166 // CHECK-SAME: thread_num={{[01]}}
167
168 // after taskyield
169 // CHECK: [[THREAD_ID_3_2:[0-9]+]]: explicit_untied(2)
170 // CHECK: [[THREAD_ID_3_2]]: task level 0: parallel_id=[[PARALLEL_ID]]
171 // CHECK-SAME: task_id=[[EXPLICIT_UNTIED_TASK_ID]]
172 // CHECK-SAME: exit_frame={{(0x)?[0-f]+}}, reenter_frame=[[NULL]]
173 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_untied=268435460
174 // CHECK-SAME: thread_num={{[01]}}
175
176 // after taskwait
177 // CHECK: [[THREAD_ID_3_3:[0-9]+]]: explicit_untied(3)
178 // CHECK: [[THREAD_ID_3_3]]: task level 0: parallel_id=[[PARALLEL_ID]]
179 // CHECK-SAME: task_id=[[EXPLICIT_UNTIED_TASK_ID]]
180 // CHECK-SAME: exit_frame={{(0x)?[0-f]+}}, reenter_frame=[[NULL]]
181 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_untied=268435460
182 // CHECK-SAME: thread_num={{[01]}}
183
184 // explicit task with final
185 // CHECK: {{^[0-9]+}}: ompt_event_task_create: parent_task_id={{[0-f]+}}
186 // CHECK-SAME: parent_task_frame.exit={{(0x)?[0-f]+}}
187 // CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
188 // CHECK-SAME: new_task_id=[[EXPLICIT_FINAL_TASK_ID:[0-f]+]]
189 // CHECK-SAME: codeptr_ra={{(0x)?[0-f]+}}
190 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_final=536870916
191 // CHECK-SAME: has_dependences=no
192
193 // CHECK: [[THREAD_ID_4:[0-9]+]]: ompt_event_task_schedule:
194 // CHECK-SAME: second_task_id=[[EXPLICIT_FINAL_TASK_ID]]
195
196 // CHECK: [[THREAD_ID_4]]: task level 0: parallel_id=[[PARALLEL_ID]]
197 // CHECK-SAME: task_id=[[EXPLICIT_FINAL_TASK_ID]]
198 // CHECK-SAME: exit_frame={{(0x)?[0-f]+}}, reenter_frame=[[NULL]]
199 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_final=536870916
200 // CHECK-SAME: thread_num={{[01]}}
201
202 // nested explicit task with final and undeferred
203 // CHECK: {{^[0-9]+}}: ompt_event_task_create: parent_task_id={{[0-f]+}}
204 // CHECK-SAME: parent_task_frame.exit={{(0x)?[0-f]+}}
205 // CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
206 // CHECK-SAME: new_task_id=[[NESTED_FINAL_UNDEFERRED_TASK_ID:[0-f]+]]
207 // CHECK-SAME: codeptr_ra={{(0x)?[0-f]+}}
208 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_undeferred
209 // CHECK-SAME:|ompt_task_final=671088644
210 // CHECK-SAME: has_dependences=no
211
212 // CHECK: [[THREAD_ID_5:[0-9]+]]: ompt_event_task_schedule:
213 // CHECK-SAME: second_task_id=[[NESTED_FINAL_UNDEFERRED_TASK_ID]]
214
215 // CHECK: [[THREAD_ID_5]]: task level 0: parallel_id=[[PARALLEL_ID]]
216 // CHECK-SAME: task_id=[[NESTED_FINAL_UNDEFERRED_TASK_ID]]
217 // CHECK-SAME: exit_frame={{(0x)?[0-f]+}}, reenter_frame=[[NULL]]
218 // CHECK-SAME: task_type=ompt_task_explicit|ompt_task_undeferred
219 // CHECK-SAME:|ompt_task_final=671088644
220 // CHECK-SAME: thread_num={{[01]}}
221 // clang-format on
222
223 return 0;
224}
#define print_frame(level)
Definition callback.h:210
static void print_ids(int level)
Definition callback.h:187
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
int main()
Definition task_types.c:9
int omp_get_num_threads()