21#ifndef mia_core_parallelcxx11_hh
22#define mia_core_parallelcxx11_hh
47#define ATOMIC std::atomic
49template <
typename Mutex>
96 m_begin(orig.m_begin),
100 m_current_wp = orig.m_current_wp.load();
105 int wp = m_current_wp++;
106 int begin = m_begin + wp * m_block;
107 int end = begin + m_block;
122 return m_begin >= m_end;
139 std::atomic<int> m_current_wp;
145template <
typename Range,
typename Func>
149 Range wp = range.get_next_workpackage();
158template <
typename Range,
typename Func>
159void pfor(Range range,
const Func& f)
162 std::thread::hardware_concurrency();
163 std::vector<std::thread> threads;
165 for (
int i = 0; i < max_treads; ++i) {
166 threads.push_back(std::thread(pfor_callback<Range, Func>, std::ref(range), f));
169 for (
int i = 0; i < max_treads; ++i) {
183 template <
typename Reduce>
206template <
typename Range,
typename Value,
typename Func,
typename Reduce>
212 Range wp = range.get_next_workpackage();
215 value = f(wp, value);
223template <
typename Range,
typename Value,
typename Func,
typename Reduce>
224Value
preduce(Range range, Value identity,
const Func& f, Reduce r)
228 std::vector<std::thread> threads;
230 for (
int i = 0; i < max_treads; ++i) {
231 threads.push_back(std::thread(preduce_callback<Range, Value, Func, Reduce>,
232 std::ref(range), std::ref(value), f, r));
235 for (
int i = 0; i < max_treads; ++i) {
C1DParallelRange get_next_workpackage()
C1DParallelRange(int begin, int end, int block=1)
C1DParallelRange(const C1DParallelRange &orig)
static int get_max_tasks()
static void set_max_tasks(int mt)
ReduceValue(const Value &i)
const Value & get_identity() const
void reduce(const Value &v, Reduce r)
const Value & get_reduced() const
TScopedLock & operator=(const TScopedLock< Mutex > &other)=delete
TScopedLock(const TScopedLock< Mutex > &other)=delete
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
#define NS_MIA_END
conveniance define to end the mia namespace
void preduce_callback(Range &range, ReduceValue< Value > &v, Func f, Reduce r)
std::recursive_mutex CRecursiveMutex
void pfor(Range range, const Func &f)
TScopedLock< CRecursiveMutex > CRecursiveScopedLock
void pfor_callback(Range &range, Func f)
Value preduce(Range range, Value identity, const Func &f, Reduce r)
TScopedLock< CMutex > CScopedLock