21 #ifndef mia_core_parallelcxx11_hh 22 #define mia_core_parallelcxx11_hh 40 static int get_max_tasks();
41 static void set_max_tasks(
int mt);
46 #define ATOMIC std::atomic 48 template <
typename Mutex>
86 m_begin(orig.m_begin),
90 m_current_wp = orig.m_current_wp.load();
94 int wp = m_current_wp++;
95 int begin = m_begin + wp * m_block;
96 int end = begin + m_block;
107 return m_begin >= m_end;
122 std::atomic<int> m_current_wp;
125 template <
typename Range,
typename Func>
129 Range wp = range.get_next_workpackage();
137 template <
typename Range,
typename Func>
138 void pfor(Range range, Func f) {
142 std::thread::hardware_concurrency();
144 std::vector<std::thread> threads;
145 for (
int i = 0; i < max_treads; ++i) {
146 threads.push_back(std::thread(pfor_callback<Range, Func>, std::ref(range), f));
149 for (
int i = 0; i < max_treads; ++i) {
154 template <
typename V>
161 template <
typename Reduce>
179 template <
typename Range,
typename Value,
typename Func,
typename Reduce>
184 Range wp = range.get_next_workpackage();
186 value = f(wp, value);
193 template <
typename Range,
typename Value,
typename Func,
typename Reduce>
194 Value
preduce(Range range, Value identity, Func f, Reduce r)
200 std::vector<std::thread> threads;
201 for (
int i = 0; i < max_treads; ++i) {
202 threads.push_back(std::thread(preduce_callback<Range, Value, Func, Reduce>,
203 std::ref(range), std::ref(value), f, r));
206 for (
int i = 0; i < max_treads; ++i) {
const Value & get_reduced() const
Value preduce(Range range, Value identity, Func f, Reduce r)
C1DParallelRange get_next_workpackage()
TScopedLock< CRecursiveMutex > CRecursiveScopedLock
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
void reduce(const Value &v, Reduce r)
ReduceValue(const Value &i)
std::recursive_mutex CRecursiveMutex
static int get_max_tasks()
void pfor_callback(Range &range, Func f)
C1DParallelRange(const C1DParallelRange &orig)
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
const Value & get_identity() const
TScopedLock< CMutex > CScopedLock
void preduce_callback(Range &range, ReduceValue< Value > &v, Func f, Reduce r)
C1DParallelRange(int begin, int end, int block=1)
#define NS_MIA_END
conveniance define to end the mia namespace
void pfor(Range range, Func f)