diff --git a/Makefile b/Makefile index 8db7e81c8..8fd04e3cd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ export CC = gcc export CXX = g++ -export CFLAGS = -Wall -O3 -msse2 -fopenmp +export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas # specify tensor path BIN = xgboost diff --git a/booster/tree/xgboost_col_treemaker.hpp b/booster/tree/xgboost_col_treemaker.hpp index 22a03c432..7bd2a3c77 100644 --- a/booster/tree/xgboost_col_treemaker.hpp +++ b/booster/tree/xgboost_col_treemaker.hpp @@ -7,9 +7,9 @@ * \author Tianqi Chen: tianqi.tchen@gmail.com */ // use openmp -#include #include #include "xgboost_tree_model.h" +#include "../../utils/xgboost_omp.h" #include "../../utils/xgboost_random.h" namespace xgboost{ diff --git a/booster/xgboost_gbmbase.h b/booster/xgboost_gbmbase.h index 841e62a69..4bbd8a8a2 100644 --- a/booster/xgboost_gbmbase.h +++ b/booster/xgboost_gbmbase.h @@ -1,9 +1,9 @@ #ifndef XGBOOST_GBMBASE_H #define XGBOOST_GBMBASE_H -#include #include #include "xgboost.h" +#include "../utils/xgboost_omp.h" #include "../utils/xgboost_config.h" /*! * \file xgboost_gbmbase.h diff --git a/regression/xgboost_reg.h b/regression/xgboost_reg.h index 4c2debe2e..5096aec5e 100644 --- a/regression/xgboost_reg.h +++ b/regression/xgboost_reg.h @@ -8,9 +8,9 @@ #include #include #include -#include #include "xgboost_reg_data.h" #include "xgboost_reg_eval.h" +#include "../utils/xgboost_omp.h" #include "../booster/xgboost_gbmbase.h" #include "../utils/xgboost_utils.h" #include "../utils/xgboost_stream.h" diff --git a/regression/xgboost_reg_eval.h b/regression/xgboost_reg_eval.h index 5cd40eb83..807f331cc 100644 --- a/regression/xgboost_reg_eval.h +++ b/regression/xgboost_reg_eval.h @@ -5,11 +5,12 @@ * \brief evaluation metrics for regression and classification * \author Kailong Chen: chenkl198812@gmail.com, Tianqi Chen: tianqi.tchen@gmail.com */ -#include + #include #include #include #include "../utils/xgboost_utils.h" +#include "../utils/xgboost_omp.h" namespace xgboost{ namespace regression{ diff --git a/utils/xgboost_omp.h b/utils/xgboost_omp.h new file mode 100644 index 000000000..34a0e041a --- /dev/null +++ b/utils/xgboost_omp.h @@ -0,0 +1,18 @@ +#ifndef XGBOOST_OMP_H +#define XGBOOST_OMP_H +/*! + * \file xgboost_omp.h + * \brief header to handle OpenMP compatibility issues + * + * \author Tianqi Chen: tianqi.tchen@gmail.com + */ + +#if defined(_OPENMP) +#include +#else +#warning "OpenMP is not available, compile to single thread code" +inline int omp_get_thread_num() { return 0; } +inline int omp_get_num_threads() { return 1; } +inline void omp_set_num_threads( int nthread ) {} +#endif +#endif