LLVM OpenMP 22.0.0git
task_memory.c
Go to the documentation of this file.
1// clang-format off
2// RUN: %libomp-compile-and-run | FileCheck %s
3// REQUIRES: ompt
4// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7
5// clang-format on
6#define USE_PRIVATE_TOOL 1
7#include "callback.h"
8#include <omp.h>
9
10int main() {
11 int x;
12#pragma omp parallel num_threads(2)
13 {
14#pragma omp master
15 {
16#pragma omp task
17 { x++; }
18#pragma omp task firstprivate(x)
19 { x++; }
20 }
21 }
22
23 return 0;
24}
25
26static void on_ompt_callback_implicit_task(ompt_scope_endpoint_t endpoint,
27 ompt_data_t *parallel_data,
28 ompt_data_t *task_data,
29 unsigned int team_size,
30 unsigned int thread_num, int flag) {
31 void *addr = NULL;
32 size_t size = 0;
34 switch (endpoint) {
35 case ompt_scope_begin:
36 task_data->value = ompt_get_unique_id();
37 printf("ompt_event_implicit_task_begin: task_id=%" PRIu64
38 ", memory_addr=%p, memory_size=%lu, result=%d \n",
39 task_data->value, addr, size, result);
40 break;
41 case ompt_scope_end:
42 printf("ompt_event_implicit_task_end: task_id=%" PRIu64
43 ", memory_addr=%p, memory_size=%lu, result=%d \n",
44 task_data->value, addr, size, result);
45 break;
46 case ompt_scope_beginend:
47 printf("ompt_scope_beginend should never be passed to %s\n", __func__);
48 exit(-1);
49 }
50}
51
52static void
53on_ompt_callback_task_create(ompt_data_t *encountering_task_data,
54 const ompt_frame_t *encountering_task_frame,
55 ompt_data_t *new_task_data, int flags,
56 int has_dependences, const void *codeptr_ra) {
57 if (flags & ompt_task_initial)
58 return; // not interested in the initial task
59 new_task_data->value = ompt_get_unique_id();
60 void *addr = NULL;
61 size_t size = 0;
62 printf("ompt_event_task_create: task_id=%" PRIu64 "\n", new_task_data->value);
63}
64
65static void on_ompt_callback_task_schedule(ompt_data_t *first_task_data,
66 ompt_task_status_t prior_task_status,
67 ompt_data_t *second_task_data) {
68 void *addr = NULL;
69 size_t size = 0;
71 printf("ompt_event_task_schedule: task_id=%" PRIu64
72 ", memory_addr=%p, memory_size=%lu, result=%d\n",
73 first_task_data->value, addr, size, result);
74}
75
76int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
77 ompt_data_t *tool_data) {
78 ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback");
79 ompt_get_unique_id = (ompt_get_unique_id_t)lookup("ompt_get_unique_id");
80 ompt_get_task_memory = (ompt_get_task_memory_t)lookup("ompt_get_task_memory");
81
82 register_ompt_callback(ompt_callback_implicit_task);
83 register_ompt_callback(ompt_callback_task_create);
84 register_ompt_callback(ompt_callback_task_schedule);
85 printf("0: NULL_POINTER=%p\n", (void *)NULL);
86 return 1; // success
87}
88
89void ompt_finalize(ompt_data_t *tool_data) {}
90
91ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,
92 const char *runtime_version) {
94 &ompt_finalize, 0};
96}
97
98// clang-format off
99// CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]]
100
101// CHECK: ompt_event_implicit_task_begin: task_id=[[TASK_ID:[0-f]+]]
102// CHECK-SAME: memory_addr=[[NULL]], memory_size=0, result=0
103
104// CHECK: ompt_event_task_create: task_id=[[TASK_ID_0:[0-9]+]]
105// CHECK-DAG: ompt_event_task_create: task_id=[[TASK_ID_1:[0-9]+]]
106
107// Expects non-zero address, size, and result
108// CHECK-DAG: ompt_event_task_schedule: task_id=[[TASK_ID_0]],
109// memory_addr={{(0x)?[0-f]+}}, memory_size={{[1-9][0-9]*}}, result=1
110// CHECK-DAG: ompt_event_task_schedule: task_id=[[TASK_ID_1]],
111// memory_addr={{(0x)?[0-f]+}}, memory_size={{[1-9][0-9]*}}, result=1
112
113// CHECK: ompt_event_implicit_task_end: task_id=[[TASK_ID]]
114// CHECK-SAME: memory_addr=[[NULL]], memory_size=0, result=0
115// clang-format on
static ompt_set_callback_t ompt_set_callback
Definition callback.h:153
#define register_ompt_callback(name)
Definition callback.h:383
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, ompt_data_t *tool_data)
Definition callback.h:1021
static ompt_get_task_memory_t ompt_get_task_memory
Definition callback.h:157
void ompt_finalize(ompt_data_t *tool_data)
Definition callback.h:1081
static ompt_get_unique_id_t ompt_get_unique_id
Definition callback.h:160
int result[2]
void * addr
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 size
struct ompt_start_tool_result_t ompt_start_tool_result_t
static ompt_start_tool_result_t * ompt_start_tool_result
#define ompt_start_tool
volatile int flag
static void on_ompt_callback_task_schedule(ompt_data_t *first_task_data, ompt_task_status_t prior_task_status, ompt_data_t *second_task_data)
Definition task_memory.c:65
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, ompt_data_t *tool_data)
Definition task_memory.c:76
void ompt_finalize(ompt_data_t *tool_data)
Definition task_memory.c:89
static void on_ompt_callback_implicit_task(ompt_scope_endpoint_t endpoint, ompt_data_t *parallel_data, ompt_data_t *task_data, unsigned int team_size, unsigned int thread_num, int flag)
Definition task_memory.c:26
int main()
Definition task_memory.c:10
static void on_ompt_callback_task_create(ompt_data_t *encountering_task_data, const ompt_frame_t *encountering_task_frame, ompt_data_t *new_task_data, int flags, int has_dependences, const void *codeptr_ra)
Definition task_memory.c:53