[llvm] Stop including unordered_map (NFC)
[llvm-project.git] / openmp / runtime / test / ompt / parallel / nested_lwt_thread_num.c
blob63d900526371350630c6e14ba1cc53555fcc5c54
1 // RUN: %libomp-compile-and-run | FileCheck %s
2 // REQUIRES: ompt
4 #include "callback.h"
5 #include <omp.h>
8 __attribute__ ((noinline)) // workaround for bug in icc
9 void print_task_info_at(int ancestor_level, int id)
11 #pragma omp critical
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);
29 __attribute__ ((noinline)) // workaround for bug in icc
30 void print_innermost_task_info(int id)
32 print_task_info_at(0, id);
36 int main()
39 #pragma omp parallel num_threads(2)
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);
49 #pragma omp parallel num_threads(1)
51 // serialized region 1
52 // assert that thread_num is 0
53 print_innermost_task_info(2);
55 #pragma omp parallel num_threads(1)
57 // serialized region 2
58 // assert that thread_num is 0
59 print_innermost_task_info(3);
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);
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'
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
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
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
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
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).
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
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
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
132 return 0;