1 #ifndef DM_OMP_MACROS_HPP_INCLUDED
2 #define DM_OMP_MACROS_HPP_INCLUDED
10 #include <boost/throw_exception.hpp>
11 #include <boost/exception/exception.hpp>
12 #include <boost/exception_ptr.hpp>
13 #include <boost/preprocessor/seq/for_each.hpp>
40 #define DM_OMP_OUTSIDE_LOOP_PREFIX \
41 ::boost::exception_ptr omp_error; \
42 ::omp_lock_t omp_lock; \
43 ::omp_init_lock(&omp_lock); \
46 #define DM_OMP_HAS_EXCEPTION_OCCURED() \
47 DM::OpenMP::has_exception_occured(omp_lock,omp_error) \
49 #define DM_OMP_INSIDE_LOOP_PREFIX \
52 ::omp_set_lock(&omp_lock); \
53 bool occured = omp_error; \
54 ::omp_unset_lock(&omp_lock); \
61 #define DM_OMP_CATCH_BLOCK(r, FUNCTION, EXCEPTION) \
62 catch(const EXCEPTION &exc) \
65 throw ::boost::enable_current_exception(::boost::enable_error_info(exc)); \
69 #define DM_OMP_INSIDE_LOOP_SUFFIX(EXCEPTION_SEQUENCE, FUNCTION) \
71 BOOST_PP_SEQ_FOR_EACH( DM_OMP_CATCH_BLOCK, FUNCTION, EXCEPTION_SEQUENCE ) \
75 ::boost::throw_exception( ::std::exception() ); \
80 ::omp_set_lock(&omp_lock); \
82 omp_error = ::boost::current_exception(); \
83 ::omp_unset_lock(&omp_lock); \
87 #define DM_OMP_OUTSIDE_LOOP_SUFFIX(EXCEPTION_SEQUENCE) \
88 ::omp_destroy_lock(&omp_lock); \
90 ::boost::rethrow_exception(omp_error); \
96 template<
typename ExceptionT>
97 inline void do_nothing(ExceptionT &e) {}
98 inline void do_nothing() {}
100 inline bool has_exception_occured(::omp_lock_t &omp_lock, ::boost::exception_ptr &omp_error) {
101 ::omp_set_lock(&omp_lock);
102 bool occured = omp_error;
103 ::omp_unset_lock(&omp_lock);
111 #endif //DM_OMP_MACROS_HPP_INCLUDED