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 } 45 } 46 47 static void 48 on_ompt_callback_task_create(ompt_data_t *encountering_task_data, 49 const ompt_frame_t *encountering_task_frame, 50 ompt_data_t *new_task_data, int flags, 51 int has_dependences, const void *codeptr_ra) { 52 if (flags & ompt_task_initial) 53 return; // not interested in the initial task 54 new_task_data->value = ompt_get_unique_id(); 55 void *addr = NULL; 56 size_t size = 0; 57 printf("ompt_event_task_create: task_id=%" PRIu64 "\n", new_task_data->value); 58 } 59 60 static void on_ompt_callback_task_schedule(ompt_data_t *first_task_data, 61 ompt_task_status_t prior_task_status, 62 ompt_data_t *second_task_data) { 63 void *addr = NULL; 64 size_t size = 0; 65 int result = ompt_get_task_memory(&addr, &size, 0); 66 printf("ompt_event_task_schedule: task_id=%" PRIu64 67 ", memory_addr=%p, memory_size=%lu, result=%d\n", 68 first_task_data->value, addr, size, result); 69 } 70 71 int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, 72 ompt_data_t *tool_data) { 73 ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback"); 74 ompt_get_unique_id = (ompt_get_unique_id_t)lookup("ompt_get_unique_id"); 75 ompt_get_task_memory = (ompt_get_task_memory_t)lookup("ompt_get_task_memory"); 76 77 register_callback(ompt_callback_implicit_task); 78 register_callback(ompt_callback_task_create); 79 register_callback(ompt_callback_task_schedule); 80 printf("0: NULL_POINTER=%p\n", (void *)NULL); 81 return 1; // success 82 } 83 84 void ompt_finalize(ompt_data_t *tool_data) {} 85 86 ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version, 87 const char *runtime_version) { 88 static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize, 89 &ompt_finalize, 0}; 90 return &ompt_start_tool_result; 91 } 92 93 // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] 94 95 // CHECK: ompt_event_implicit_task_begin: task_id=[[TASK_ID:[0-9]+]] 96 // CHECK-SAME: memory_addr=[[NULL]], memory_size=0, result=0 97 98 // CHECK: ompt_event_task_create: task_id=[[TASK_ID_0:[0-9]+]] 99 // CHECK-DAG: ompt_event_task_create: task_id=[[TASK_ID_1:[0-9]+]] 100 101 // Expects non-zero address, size, and result 102 // CHECK-DAG: ompt_event_task_schedule: task_id=[[TASK_ID_0]], 103 // memory_addr=0x{{[0-f]+}}, memory_size={{[1-9][0-9]*}}, result=1 104 // CHECK-DAG: ompt_event_task_schedule: task_id=[[TASK_ID_1]], 105 // memory_addr=0x{{[0-f]+}}, memory_size={{[1-9][0-9]*}}, result=1 106 107 // CHECK: ompt_event_implicit_task_end: task_id=[[TASK_ID]] 108 // CHECK-SAME: memory_addr=[[NULL]], memory_size=0, result=0 109