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