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