brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · f798325 Raw
94 lines · c
1// clang-format off2// RUN: %libomp-compile-and-run | FileCheck %s3// REQUIRES: ompt4// GCC generates code that does not call the runtime for the master construct5// XFAIL: gcc6// clang-format on7 8#define USE_PRIVATE_TOOL 19#include "callback.h"10#include <omp.h>11 12int main() {13  int x = 0;14#pragma omp parallel num_threads(2)15  {16#pragma omp master17    {18      print_fuzzy_address(1);19      x++;20    }21    print_current_address(2);22  }23 24  printf("%" PRIu64 ": x=%d\n", ompt_get_thread_data()->value, x);25 26  return 0;27}28 29static void on_ompt_callback_master(ompt_scope_endpoint_t endpoint,30                                    ompt_data_t *parallel_data,31                                    ompt_data_t *task_data,32                                    const void *codeptr_ra) {33  switch (endpoint) {34  case ompt_scope_begin:35    printf("%" PRIu64 ":" _TOOL_PREFIX36           " ompt_event_master_begin: codeptr_ra=%p\n",37           ompt_get_thread_data()->value, codeptr_ra);38    break;39  case ompt_scope_end:40    printf("%" PRIu64 ":" _TOOL_PREFIX41           " ompt_event_master_end: codeptr_ra=%p\n",42           ompt_get_thread_data()->value, codeptr_ra);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 on_ompt_callback_thread_begin(ompt_thread_t thread_type,51                                          ompt_data_t *thread_data) {52  if (thread_data->ptr)53    printf("%s\n", "0: thread_data initially not null");54  thread_data->value = ompt_get_unique_id();55  printf("%" PRIu64 ":" _TOOL_PREFIX56         " ompt_event_thread_begin: thread_type=%s=%d, thread_id=%" PRIu64 "\n",57         ompt_get_thread_data()->value, ompt_thread_t_values[thread_type],58         thread_type, thread_data->value);59}60 61int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,62                    ompt_data_t *tool_data) {63  ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback");64  ompt_get_unique_id = (ompt_get_unique_id_t)lookup("ompt_get_unique_id");65  ompt_get_thread_data = (ompt_get_thread_data_t)lookup("ompt_get_thread_data");66 67  register_ompt_callback(ompt_callback_master);68  printf("0: NULL_POINTER=%p\n", (void *)NULL);69  return 1; // success70}71 72void ompt_finalize(ompt_data_t *tool_data) {}73 74ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,75                                          const char *runtime_version) {76  static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,77                                                            &ompt_finalize, 0};78  return &ompt_start_tool_result;79}80 81// clang-format off82// Check if libomp supports the callbacks for this test.83// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_master'84 85// CHECK: 0: NULL_POINTER=[[NULL:.*$]]86 87// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_master_begin:88// CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS:(0x)?[0-f]+]]{{[0-f][0-f]}}89// CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]90// CHECK: {{^}}[[MASTER_ID]]: ompt_event_master_end:91// CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS_END:(0x)?[0-f]+]]92// CHECK: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS_END]]93// clang-format on94