14 #include "./logging.h" 23 inline std::vector<std::string>
Split(
const std::string& s,
char delim) {
25 std::istringstream is(s);
26 std::vector<std::string> ret;
27 while (std::getline(is, item, delim)) {
38 std::hash<T> hash_func;
39 return key ^ (hash_func(value) + 0x9e3779b9 + (key << 6) + (key >> 2));
47 return key ^ (value + 0x9e3779b9 + (key << 6) + (key >> 2));
56 std::exception_ptr omp_exception_;
64 template <
typename Function,
typename... Parameters>
65 void Run(Function f, Parameters... params) {
68 }
catch (dmlc::Error &ex) {
69 std::lock_guard<std::mutex> lock(mutex_);
70 if (!omp_exception_) {
71 omp_exception_ = std::current_exception();
73 }
catch (std::exception &ex) {
74 std::lock_guard<std::mutex> lock(mutex_);
75 if (!omp_exception_) {
76 omp_exception_ = std::current_exception();
85 if (this->omp_exception_) std::rethrow_exception(this->omp_exception_);
91 #endif // DMLC_COMMON_H_ std::vector< std::string > Split(const std::string &s, char delim)
Split a string by delimiter.
Definition: common.h:23
OMP Exception class catches, saves and rethrows exception from OMP blocks.
Definition: common.h:53
void Rethrow()
should be called from the main thread to rethrow the exception
Definition: common.h:84
size_t HashCombine(size_t key, const T &value)
hash an object and combines the key with previous keys
Definition: common.h:37
namespace for dmlc
Definition: array_view.h:12
size_t HashCombine< size_t >(size_t key, const size_t &value)
specialize for size_t
Definition: common.h:46
void Run(Function f, Parameters...params)
Parallel OMP blocks should be placed within Run to save exception.
Definition: common.h:65