LLVM OpenMP 22.0.0git
tool_available_search.c
Go to the documentation of this file.
1// clang-format off
2// RUN: mkdir -p %t.tool_dir
3// RUN: %clang %flags -shared -fPIC %s -o %t.tool_dir/first_tool.so
4// RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %t.tool_dir/second_tool.so
5// RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %t.tool_dir/third_tool.so
6// RUN: %libomp-compile -DCODE
7// RUN: env OMP_TOOL_LIBRARIES=%t.tool_dir/non_existing_file.so:%t.tool_dir/first_tool.so:%t.tool_dir/second_tool.so:%t.tool_dir/third_tool.so \
8// RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s -DPARENTPATH=%t.tool_dir
9
10// REQUIRES: ompt
11// XFAIL: darwin
12// clang-format on
13
14/*
15 * This file contains code for three OMPT shared library tool to be
16 * loaded and the code for the OpenMP executable.
17 * No option enables code for the first shared library
18 * (without an implementation of ompt_start_tool) during compilation
19 * -DTOOL -DSECOND_TOOL enables the code for the second tool during compilation
20 * -DTOOL -DTHIRD_TOOL enables the code for the third tool during compilation
21 * -DCODE enables the code for the executable during compilation
22 */
23
24// clang-format off
25// CHECK: ----- START LOGGING OF TOOL REGISTRATION -----
26// CHECK-NEXT: Search for OMP tool in current address space... Failed.
27// CHECK-NEXT: Searching tool libraries...
28// CHECK-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/non_existing_file.so
29// CHECK-SAME: [[PARENTPATH]]/first_tool.so
30// CHECK-SAME: [[PARENTPATH]]/second_tool.so
31// CHECK-SAME: [[PARENTPATH]]/third_tool.so
32// CHECK-NEXT: Opening [[PARENTPATH]]/non_existing_file.so... Failed:
33// CHECK-SAME: [[PARENTPATH]]/non_existing_file.so: {{cannot open shared object file|open failed}}:
34// CHECK-SAME: No such file or directory
35// CHECK-NEXT: Opening [[PARENTPATH]]/first_tool.so... Success.
36// CHECK-NEXT: Searching for ompt_start_tool in
37// CHECK-SAME: [[PARENTPATH]]/first_tool.so... Failed:
38// CHECK-SAME: {{.*/first_tool.so: undefined symbol: ompt_start_tool|ld.so.1: .*: ompt_start_tool: can't find symbol}}
39// CHECK-NEXT: Opening [[PARENTPATH]]/second_tool.so... Success.
40// CHECK-NEXT: Searching for ompt_start_tool in
41// CHECK-SAME: [[PARENTPATH]]/second_tool.so... 0: Do not initialize tool
42// CHECK-NEXT: Found but not using the OMPT interface.
43// CHECK-NEXT: Continuing search...
44// CHECK-NEXT: Opening [[PARENTPATH]]/third_tool.so... Success.
45// CHECK-NEXT: Searching for ompt_start_tool in
46// CHECK-SAME: [[PARENTPATH]]/third_tool.so... 0: Do initialize tool
47// CHECK-NEXT: Success.
48// CHECK-NEXT: Tool was started and is using the OMPT interface.
49// CHECK-NEXT: ----- END LOGGING OF TOOL REGISTRATION -----
50
51// Check if libomp supports the callbacks for this test.
52
53// CHECK-NOT: {{^}}0: Could not register callback
54// CHECK: {{^}}0: Tool initialized
55// CHECK: {{^}}0: ompt_event_thread_begin
56// CHECK-DAG: {{^}}0: ompt_event_thread_begin
57// CHECK-DAG: {{^}}0: control_tool()=-1
58// CHECK: {{^}}0: Tool finalized
59// clang-format on
60
61#ifdef CODE
62#include "stdio.h"
63#include "omp.h"
64#include "omp-tools.h"
65
66int main() {
67#pragma omp parallel num_threads(2)
68 {
69#pragma omp master
70 {
71 int result = omp_control_tool(omp_control_tool_start, 0, NULL);
72 printf("0: control_tool()=%d\n", result);
73 }
74 }
75
76 return 0;
77}
78
79#endif /* CODE */
80
81#ifdef TOOL
82
83#include <omp-tools.h>
84#include "stdio.h"
85
86#ifdef SECOND_TOOL
87// The second tool has an implementation of ompt_start_tool that returns NULL
88ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,
89 const char *runtime_version) {
90 printf("0: Do not initialize tool\n");
91 return NULL;
92}
93#elif defined(THIRD_TOOL)
94// The third tool has an implementation of ompt_start_tool that returns a
95// pointer to a valid instance of ompt_start_tool_result_t
96
97static void on_ompt_callback_thread_begin(ompt_thread_t thread_type,
98 ompt_data_t *thread_data) {
99 printf("0: ompt_event_thread_begin\n");
100}
101
102int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
103 ompt_data_t *tool_data) {
104 ompt_set_callback_t ompt_set_callback =
105 (ompt_set_callback_t)lookup("ompt_set_callback");
106 ompt_set_callback(ompt_callback_thread_begin,
107 (ompt_callback_t)on_ompt_callback_thread_begin);
108 printf("0: Tool initialized\n");
109 return 1;
110}
111
112void ompt_finalize(ompt_data_t *tool_data) { printf("0: Tool finalized\n"); }
113
114ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,
115 const char *runtime_version) {
116 printf("0: Do initialize tool\n");
118 &ompt_finalize, 0};
120}
121#endif
122
123#endif /* TOOL */
static ompt_set_callback_t ompt_set_callback
Definition callback.h:153
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, ompt_data_t *tool_data)
Definition callback.h:1021
void ompt_finalize(ompt_data_t *tool_data)
Definition callback.h:1081
static void on_ompt_callback_thread_begin(ompt_thread_t thread_type, ompt_data_t *thread_data)
Definition callback.h:958
int result[2]
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
int main()
Definition test-touch.c:21