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