LLVM OpenMP 22.0.0git
explicit_task_thread_num.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
6#include "callback.h"
7#include <omp.h>
8
9__attribute__ ((noinline)) // workaround for bug in icc
10void print_task_info_at(int ancestor_level, int id)
11{
12#pragma omp critical
13 {
14 int task_type;
15char buffer[2048];
16ompt_data_t *parallel_data;
17ompt_data_t *task_data;
18int thread_num;
19ompt_get_task_info(ancestor_level, &task_type, &task_data, NULL, &parallel_data,
20 &thread_num);
21format_task_type(task_type, buffer);
22printf("%" PRIu64 ": ancestor_level=%d id=%d task_type=%s=%d "
23 "parallel_id=%" PRIu64 " task_id=%" PRIu64 " 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
30int main() {
31
32#pragma omp parallel num_threads(2)
33 {
34
35 if (omp_get_thread_num() == 1) {
36 // To assert that task is executed by the worker thread,
37 // if(0) is used in order to ensure that the task is immediately
38 // executed after its creation.
39#pragma omp task if (0)
40 {
41 // thread_num should be equal to 1 for both explicit and implicit task
42 print_task_info_at(0, 1);
43 print_task_info_at(1, 0);
44 };
45 }
46 }
47
48 // clang-format off
49 // Check if libomp supports the callbacks for this test.
50 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_event_parallel_begin'
51 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create'
52 // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'
53
54 // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
55 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin
56
57 // parallel region used only to determine worker thread id
58 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin
59 // CHECK: {{^}}[[WID:[0-9]+]]: ompt_event_implicit_task{{.*}}thread_num=1
60
61 // thread_num must be equal to 1 for both explicit and the implicit tasks
62 // CHECK: {{^}}[[WID]]: ancestor_level=0 id=1 task_type=ompt_task_explicit
63 // CHECK-SAME: thread_num=1
64 // CHECK: {{^}}[[WID]]: ancestor_level=1 id=0 task_type=ompt_task_implicit
65 // CHECK-SAME: thread_num=1
66 // clang-format on
67
68 return 0;
69}
static ompt_get_task_info_t ompt_get_task_info
Definition callback.h:156
static void format_task_type(int type, char *buffer)
Definition callback.h:129
static ompt_get_thread_data_t ompt_get_thread_data
Definition callback.h:158
__attribute__((noinline))
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