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