Skip to content

Commit 7cca1c7

Browse files
authored
Try new way to find omp library
1 parent 6054626 commit 7cca1c7

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/test_xcpp_kernel.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,19 @@ class XCppTests(jupyter_kernel_test.KernelTests):
134134
code_omp="""
135135
#include <omp.h>
136136
#include <iostream>
137-
#include <clang/Interpreter/CppInterOp.h>
138-
bool loaded=Cpp::LoadLibrary("libomp");
139-
if(loaded) {
140-
int max_threads = omp_get_max_threads();
141-
omp_set_thread_num(max_threads);
142-
std::cerr<<"OpenMP library loaded"<<std::endl;
143-
}
144-
else
145-
{
146-
std::cerr<<"OpenMP library not loaded"<<std::endl;
147-
}
137+
#include <clang/Interpreter/CppInterOp.h>
138+
#include "llvm/Support/FileSystem.h"
139+
#include "llvm/Support/Path.h"
140+
std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr);
141+
llvm::StringRef Dir = llvm::sys::path::parent_path(BinaryPath);
142+
Cpp::AddSearchPath(Dir.str().c_str());
143+
#ifdef __APPLE__
144+
std::string PathToTestSharedLib = Cpp::SearchLibrariesForSymbol("_omp_get_max_threads_", /*system_search=*/false);
145+
#else
146+
std::string PathToTestSharedLib = Cpp::SearchLibrariesForSymbol("omp_get_max_threads_", /*system_search=*/false);
147+
#endif // __APPLE__
148+
bool loaded=Cpp::LoadLibrary("PathToTestSharedLib.c_str())");
149+
std::cerr<<loaded<<std::endl;
148150
"""
149151
def test_xcpp_omp(self):
150152
self.flush_channels()

0 commit comments

Comments
 (0)