File indexing completed on 2024-10-17 22:59:03
0001 #ifndef RecoTracker_MkFitCore_src_Debug_h
0002
0003 namespace mkfit {
0004 extern bool g_debug;
0005 }
0006
0007 #ifdef DEBUG
0008 #define RecoTracker_MkFitCore_src_Debug_h
0009
0010 #ifdef dprint
0011
0012 #undef dprint
0013 #undef dprint_np
0014 #undef dcall
0015 #undef dprintf
0016 #undef dprintf_np
0017
0018 #endif
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #include <mutex>
0053
0054 #define dmutex_guard std::lock_guard<std::mutex> dlock(debug_mutex)
0055 #define dprint(x) \
0056 if (debug && g_debug) { \
0057 dmutex_guard; \
0058 std::cout << x << std::endl; \
0059 }
0060 #define dprint_np(n, x) \
0061 if (debug && g_debug && n < N_proc) { \
0062 dmutex_guard; \
0063 std::cout << n << ": " << x << std::endl; \
0064 }
0065 #define dcall(x) \
0066 if (debug && g_debug) { \
0067 dmutex_guard; \
0068 x; \
0069 }
0070 #define dprintf(...) \
0071 if (debug && g_debug) { \
0072 dmutex_guard; \
0073 printf(__VA_ARGS__); \
0074 }
0075 #define dprintf_np(n, ...) \
0076 if (debug && g_debug && n < N_proc) { \
0077 dmutex_guard; \
0078 std::cout << n << ": "; \
0079 printf(__VA_ARGS__); \
0080 }
0081
0082 namespace {
0083 bool debug = false;
0084 std::mutex debug_mutex;
0085
0086 struct debug_guard {
0087 bool m_prev_debug;
0088 debug_guard(bool state = true) : m_prev_debug(debug) { debug = state; }
0089 ~debug_guard() { debug = m_prev_debug; }
0090 };
0091 }
0092
0093 #else
0094
0095 #define dprint(x) (void(0))
0096 #define dprint_np(n, x) (void(0))
0097 #define dcall(x) (void(0))
0098 #define dprintf(...) (void(0))
0099 #define dprintf_np(n, ...) (void(0))
0100
0101 #endif
0102
0103
0104
0105 #ifdef TBB_DISABLE
0106 #include "oneapi/tbb/blocked_range.h"
0107 #include "oneapi/tbb/partitioner.h"
0108
0109 #define TBB_PARALLEL_FOR mkfit_tbb::parallel_for
0110 #define TBB_PARALLEL_FOR_EACH mkfit_tbb::parallel_for_each
0111
0112 namespace mkfit_tbb {
0113
0114 template <typename Range, typename Body>
0115 void parallel_for(const Range& range, const Body& body) {
0116 typename Range::const_iterator step = range.grainsize();
0117 for (auto i = range.begin(); i < range.end(); i += step) {
0118 step = std::min(step, range.end() - i);
0119 body(Range(i, i + step, 1));
0120 }
0121 }
0122
0123 template <typename Range, typename Body>
0124 void parallel_for(const Range& range, const Body& body, const tbb::simple_partitioner& partitioner) {
0125 typename Range::const_iterator step = range.grainsize();
0126 for (auto i = range.begin(); i < range.end(); i += step) {
0127 step = std::min(step, range.end() - i);
0128 body(Range(i, i + step, 1));
0129 }
0130 }
0131
0132 template <typename InputIterator, typename Function>
0133 void parallel_for_each(InputIterator first, InputIterator last, const Function& f) {
0134 for (auto& i = first; i != last; ++i) {
0135 f(*i);
0136 }
0137 }
0138
0139 }
0140
0141 #else
0142
0143 #define TBB_PARALLEL_FOR tbb::parallel_for
0144 #define TBB_PARALLEL_FOR_EACH tbb::parallel_for_each
0145
0146 #endif
0147
0148 #endif