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 | |
8 | int 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 | |
24 | static 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; |
31 | int result = ompt_get_task_memory(&addr, &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(status: -1); |
47 | } |
48 | } |
49 | |
50 | static void |
51 | on_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 | |
63 | static 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; |
68 | int result = ompt_get_task_memory(&addr, &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 | |
74 | int 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 | |
87 | void ompt_finalize(ompt_data_t *tool_data) {} |
88 | |
89 | ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version, |
90 | const char *runtime_version) { |
91 | static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize, |
92 | &ompt_finalize, 0}; |
93 | return &ompt_start_tool_result; |
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 |
112 | |