Debian Codegraph @

openmp/runtime/test/ompt/parallel/nested_lwt_thread_num.c

raw
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
10 void print_task_info_at(int ancestor_level, int id)
11 {
12 #pragma omp critical
13 {
14 int task_type;
15 char buffer[2048];
16 ompt_data_t *parallel_data;
17 ompt_data_t *task_data;
18 int thread_num;
19 ompt_get_task_info(ancestor_level, &task_type, &task_data, NULL, &parallel_data,
20 &thread_num);
21 format_task_type(task_type, buffer);
22 printf("%" 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
31 void print_innermost_task_info(int id)
32 {
33 print_task_info_at(0, id);
34 }
35
36 int 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 }