1 // RUN: %clang %flags -shared -fPIC %s -o %T/first_tool.so
2 // RUN: %clang %flags -DTOOL -DSECOND_TOOL -shared -fPIC %s -o %T/second_tool.so
3 // RUN: %clang %flags -DTOOL -DTHIRD_TOOL -shared -fPIC %s -o %T/third_tool.so
4 // RUN: %libomp-compile -DCODE
5 // RUN: env OMP_TOOL_LIBRARIES=%T/non_existing_file.so:%T/first_tool.so:%T/second_tool.so:%T/third_tool.so \
6 // RUN: OMP_TOOL_VERBOSE_INIT=stdout %libomp-run | FileCheck %s -DPARENTPATH=%T
12 * This file contains code for three OMPT shared library tool to be
13 * loaded and the code for the OpenMP executable.
14 * No option enables code for the first shared library
15 * (without an implementation of ompt_start_tool) during compilation
16 * -DTOOL -DSECOND_TOOL enables the code for the second tool during compilation
17 * -DTOOL -DTHIRD_TOOL enables the code for the third tool during compilation
18 * -DCODE enables the code for the executable during compilation
21 // CHECK: ----- START LOGGING OF TOOL REGISTRATION -----
22 // CHECK-NEXT: Search for OMP tool in current address space... Failed.
23 // CHECK-NEXT: Searching tool libraries...
24 // CHECK-NEXT: OMP_TOOL_LIBRARIES = [[PARENTPATH]]/non_existing_file.so
25 // CHECK-SAME: [[PARENTPATH]]/first_tool.so
26 // CHECK-SAME: [[PARENTPATH]]/second_tool.so
27 // CHECK-SAME: [[PARENTPATH]]/third_tool.so
28 // CHECK-NEXT: Opening [[PARENTPATH]]/non_existing_file.so... Failed:
29 // CHECK-SAME: [[PARENTPATH]]/non_existing_file.so: cannot open shared object
30 // CHECK-SAME: file: No such file or directory
31 // CHECK-NEXT: Opening [[PARENTPATH]]/first_tool.so... Success.
32 // CHECK-NEXT: Searching for ompt_start_tool in
33 // CHECK-SAME: [[PARENTPATH]]/first_tool.so... Failed:
34 // CHECK-SAME: [[PARENTPATH]]/first_tool.so: undefined symbol: ompt_start_tool
35 // CHECK-NEXT: Opening [[PARENTPATH]]/second_tool.so... Success.
36 // CHECK-NEXT: Searching for ompt_start_tool in
37 // CHECK-SAME: [[PARENTPATH]]/second_tool.so... 0: Do not initialize tool
38 // CHECK-NEXT: Found but not using the OMPT interface.
39 // CHECK-NEXT: Continuing search...
40 // CHECK-NEXT: Opening [[PARENTPATH]]/third_tool.so... Success.
41 // CHECK-NEXT: Searching for ompt_start_tool in
42 // CHECK-SAME: [[PARENTPATH]]/third_tool.so... 0: Do initialize tool
43 // CHECK-NEXT: Success.
44 // CHECK-NEXT: Tool was started and is using the OMPT interface.
45 // CHECK-NEXT: ----- END LOGGING OF TOOL REGISTRATION -----
47 // Check if libomp supports the callbacks for this test.
49 // CHECK-NOT: {{^}}0: Could not register callback
50 // CHECK: {{^}}0: Tool initialized
51 // CHECK: {{^}}0: ompt_event_thread_begin
52 // CHECK-DAG: {{^}}0: ompt_event_thread_begin
53 // CHECK-DAG: {{^}}0: control_tool()=-1
54 // CHECK: {{^}}0: Tool finalized
60 #include "omp-tools.h"
64 #pragma omp parallel num_threads(2)
68 int result
= omp_control_tool(omp_control_tool_start
, 0, NULL
);
69 printf("0: control_tool()=%d\n", result
);
81 #include <omp-tools.h>
85 // The second tool has an implementation of ompt_start_tool that returns NULL
86 ompt_start_tool_result_t
* ompt_start_tool(
87 unsigned int omp_version
,
88 const char *runtime_version
)
90 printf("0: Do not initialize tool\n");
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
98 on_ompt_callback_thread_begin(
99 ompt_thread_t thread_type
,
100 ompt_data_t
*thread_data
)
102 printf("0: ompt_event_thread_begin\n");
105 int ompt_initialize(ompt_function_lookup_t lookup
, int initial_device_num
,
106 ompt_data_t
*tool_data
) {
107 ompt_set_callback_t ompt_set_callback
= (ompt_set_callback_t
) lookup("ompt_set_callback");
108 ompt_set_callback(ompt_callback_thread_begin
, (ompt_callback_t
)on_ompt_callback_thread_begin
);
109 printf("0: Tool initialized\n");
113 void ompt_finalize(ompt_data_t
*tool_data
)
115 printf("0: Tool finalized\n");
118 ompt_start_tool_result_t
* ompt_start_tool(
119 unsigned int omp_version
,
120 const char *runtime_version
)
122 printf("0: Do initialize tool\n");
123 static ompt_start_tool_result_t ompt_start_tool_result
= {&ompt_initialize
,&ompt_finalize
, 0};
124 return &ompt_start_tool_result
;