116 lines · c
1// clang-format off2// RUN: %libomp-compile-and-run | FileCheck %s3// REQUIRES: ompt4// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-75// clang-format on6#define USE_PRIVATE_TOOL 17#include "callback.h"8#include <omp.h>9 10int main() {11 int x;12#pragma omp parallel num_threads(2)13 {14#pragma omp master15 {16#pragma omp task17 { 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;33 int result = ompt_get_task_memory(&addr, &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=%" PRIu6438 ", 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=%" PRIu6443 ", 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 void53on_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 task59 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;70 int result = ompt_get_task_memory(&addr, &size, 0);71 printf("ompt_event_task_schedule: task_id=%" PRIu6472 ", 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; // success87}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) {93 static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,94 &ompt_finalize, 0};95 return &ompt_start_tool_result;96}97 98// clang-format off99// 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=0103 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 result108// CHECK-DAG: ompt_event_task_schedule: task_id=[[TASK_ID_0]],109// memory_addr={{(0x)?[0-f]+}}, memory_size={{[1-9][0-9]*}}, result=1110// CHECK-DAG: ompt_event_task_schedule: task_id=[[TASK_ID_1]],111// memory_addr={{(0x)?[0-f]+}}, memory_size={{[1-9][0-9]*}}, result=1112 113// CHECK: ompt_event_implicit_task_end: task_id=[[TASK_ID]]114// CHECK-SAME: memory_addr=[[NULL]], memory_size=0, result=0115// clang-format on116