1#ifndef LIGHTGBM_OPENMP_WRAPPER_H_
2#define LIGHTGBM_OPENMP_WRAPPER_H_
13class ThreadExceptionHelper {
15 ThreadExceptionHelper() {
19 ~ThreadExceptionHelper() {
23 if (ex_ptr_ !=
nullptr) {
24 std::rethrow_exception(ex_ptr_);
27 void CaptureException() {
29 if (ex_ptr_ !=
nullptr) {
return; }
30 std::unique_lock<std::mutex> guard(lock_);
31 if (ex_ptr_ !=
nullptr) {
return; }
32 ex_ptr_ = std::current_exception();
35 std::exception_ptr ex_ptr_;
39#define OMP_INIT_EX() ThreadExceptionHelper omp_except_helper
40#define OMP_LOOP_EX_BEGIN() try {
41#define OMP_LOOP_EX_END() } \
42catch(std::exception& ex) { Log::Warning(ex.what()); omp_except_helper.CaptureException(); } \
43catch(...) { omp_except_helper.CaptureException(); }
44#define OMP_THROW_EX() omp_except_helper.ReThrow()
49 #pragma warning(disable: 4068)
58 inline void omp_set_num_threads(
int) {}
59 inline void omp_set_nested(
int) {}
60 inline int omp_get_num_threads() {
return 1;}
61 inline int omp_get_thread_num() {
return 0;}
67#define OMP_LOOP_EX_BEGIN()
68#define OMP_LOOP_EX_END()
header to handle OpenMP compatibility issues