11 template<
typename Impl,
typename... Types>
14 template<
typename Impl,
typename Type,
typename... Rest>
17 using RestType =
typename Impl::template RMType<Impl, Rest...>;
23 template<
typename F,
typename... Args>
24 typename std::result_of<F(Type&, Args...)>::type
call(
const F& to_call, Args&& ... args) {
25 auto& value = m_values[omp_get_thread_num()];
26 if (value ==
nullptr) {
27 value =
new Type(std::move(this->m_func()));
29 return this->m_rest.call(to_call, *value, std::forward<Args>(args)...);
33 m_values.resize(size,
nullptr);
34 this->m_rest.init(size);
38 for (
auto& v: m_values) {
50 template<
typename Impl>
58 template<
typename Impl,
typename... Types>
64 m_nthreads = omp_get_num_threads();
75 template<
typename IndexF,
typename IndexL,
typename IndexS,
typename Func,
typename RM>
76 void parallelFor(IndexF first, IndexL last, IndexS step,
const Func& f, RM& rm) {
77 #pragma omp parallel for num_threads(m_nthreads) schedule(runtime) 78 for (IndexF i = first; i < last; i += step) {
void parallelFor(IndexF first, IndexL last, IndexS step, const Func &f, RM &rm)
typename Impl::template RMType< Impl, Rest... > RestType
std::function< Type()> FuncType
int getNumThreads() const
std::vector< Type * > m_values
void setNumThreads(int nthreads)
_OpenmpParallel(int nthreads)
std::result_of< F(Type &, Args...)>::type call(const F &to_call, Args &&...args)