1// RUN: %libomp-compile-and-run | FileCheck %s
2// REQUIRES: ompt
3
4#define USE_PRIVATE_TOOL 1
5#include "callback.h"
6
7__attribute__((noinline))
8int foo(int x) {
9#pragma omp parallel num_threads(2)
10 {
11#pragma omp atomic
12 x++;
13 }
14 return x;
15}
16
17__attribute__((noinline))
18int bar(int x) {
19#pragma omp parallel num_threads(2)
20 {
21#pragma omp critical
22 x++;
23 }
24 return x;
25}
26
27int main() {
28 int y;
29 y = foo(x: y);
30 y = bar(x: y);
31 y = foo(x: y);
32 return 0;
33
34 // CHECK-NOT: {{^}}0: Could not register callback
35 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
36
37 // First call to foo
38 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin
39 // CHECK-SAME: {{.*}}codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]
40
41 // Call to bar
42 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin
43
44 // Second call to foo
45 // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin
46 // CHECK-SAME: {{.*}}codeptr_ra=[[RETURN_ADDRESS]]
47
48}
49
50static void on_ompt_callback_thread_begin(
51 ompt_thread_t thread_type,
52 ompt_data_t *thread_data) {
53 if (thread_data->ptr)
54 printf("%s\n", "0: thread_data initially not null");
55 thread_data->value = ompt_get_unique_id();
56 printf("%" PRIu64 ":" _TOOL_PREFIX
57 " ompt_event_thread_begin: thread_type=%s=%d, thread_id=%" PRIu64 "\n",
58 ompt_get_thread_data()->value, ompt_thread_t_values[thread_type],
59 thread_type, thread_data->value);
60}
61
62static void on_ompt_callback_parallel_begin(
63 ompt_data_t *encountering_task_data,
64 const ompt_frame_t *encountering_task_frame, ompt_data_t *parallel_data,
65 uint32_t requested_team_size, int flag, const void *codeptr_ra) {
66 if (parallel_data->ptr)
67 printf("0: parallel_data initially not null\n");
68 parallel_data->value = ompt_get_unique_id();
69 int invoker = flag & 0xF;
70 const char *event = (flag & ompt_parallel_team) ? "parallel" : "teams";
71 const char *size = (flag & ompt_parallel_team) ? "team_size" : "num_teams";
72 printf("%" PRIu64 ":" _TOOL_PREFIX
73 " ompt_event_%s_begin: parent_task_id=%" PRIu64
74 ", parent_task_frame.exit=%p, parent_task_frame.reenter=%p, "
75 "parallel_id=%" PRIu64 ", requested_%s=%" PRIu32
76 ", codeptr_ra=%p, invoker=%d\n",
77 ompt_get_thread_data()->value, event, encountering_task_data->value,
78 encountering_task_frame->exit_frame.ptr,
79 encountering_task_frame->enter_frame.ptr, parallel_data->value, size,
80 requested_team_size, codeptr_ra, invoker);
81}
82
83int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
84 ompt_data_t *tool_data) {
85 ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback");
86 ompt_get_unique_id = (ompt_get_unique_id_t)lookup("ompt_get_unique_id");
87 ompt_get_thread_data = (ompt_get_thread_data_t)lookup("ompt_get_thread_data");
88
89 register_ompt_callback(ompt_callback_thread_begin);
90 register_ompt_callback(ompt_callback_parallel_begin);
91 printf("0: NULL_POINTER=%p\n", (void *)NULL);
92 return 1; // success
93}
94
95void ompt_finalize(ompt_data_t *tool_data) {}
96
97ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,
98 const char *runtime_version) {
99 static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,
100 &ompt_finalize, 0};
101 return &ompt_start_tool_result;
102}
103

source code of openmp/runtime/test/ompt/parallel/repeated_calls.c