70 static unsigned ncores() {
return std::thread::hardware_concurrency(); }
90 template <
typename... Args>
99 template <
typename RetT,
typename FuncT,
typename... Args>
100 std::future<RetT>
async(FuncT&& func, Args&&... args)
103 typedef task_type* task_pointer;
105 task_pointer _ptask =
106 new task_type(std::forward<FuncT>(func), std::forward<Args>(args)...);
107 std::future<RetT> _f = _ptask->get_future();
112 template <
typename RetT,
typename FuncT>
113 std::future<RetT>
async(FuncT&& func)
116 typedef task_type* task_pointer;
118 task_pointer _ptask =
new task_type(std::forward<FuncT>(func));
119 std::future<RetT> _f = _ptask->get_future();
124 template <
typename FuncT,
typename... Args>
125 auto async(FuncT&& func, Args... args)
126 -> std::future<
decay_t<
decltype(func(args...))>>
128 using RetT =
decay_t<
decltype(func(args...))>;
132 new task_type(std::forward<FuncT>(func), std::forward<Args>(args)...);
133 auto _f = _ptask->get_future();
143 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
147 return tg.
wrap(std::forward<FuncT>(func), std::forward<Args>(args)...);
150 template <
typename RetT,
typename ArgT,
typename FuncT>
153 return tg.
wrap(std::forward<FuncT>(func));
160 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
163 tg.
exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
166 template <
typename RetT,
typename ArgT,
typename FuncT>
169 tg.
exec(std::forward<FuncT>(func));
172 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
175 tg.
exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
178 template <
typename RetT,
typename ArgT,
typename FuncT>
181 tg.
exec(std::forward<FuncT>(func));
186 template <
typename FuncT,
typename... Args>
189 tg.
exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
192 template <
typename FuncT>
195 tg.
exec(std::forward<FuncT>(func));
199#if defined(PTL_USE_TBB)
203 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
207 return tg.
wrap(std::forward<FuncT>(func), std::forward<Args>(args)...);
210 template <
typename RetT,
typename ArgT,
typename FuncT>
211 Task<RetT, ArgT>*
wrap(TBBTaskGroup<RetT, ArgT>& tg, FuncT&& func)
213 return tg.wrap(std::forward<FuncT>(func));
219 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
220 void exec(TBBTaskGroup<RetT, ArgT>& tg, FuncT&& func, Args&&... args)
222 tg.exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
225 template <
typename RetT,
typename ArgT,
typename FuncT>
226 void exec(TBBTaskGroup<RetT, ArgT>& tg, FuncT&& func)
228 tg.exec(std::forward<FuncT>(func));
249PTL::TaskManager::fgInstance()
251 static thread_local TaskManager* _instance =
nullptr;
262 auto nthreads = std::thread::hardware_concurrency();
263 std::cout <<
"Allocating mad::TaskManager with " << nthreads <<
" thread(s)..."
292 if(fgInstance() ==
this)
293 fgInstance() =
nullptr;
The task class is supplied to thread_pool.
task_type< Args... > * wrap(Func &&func, Args... args)
void exec(Func &&func, Args... args)
ThreadPool::size_type size_type
ThreadPool * thread_pool() const
TaskManager(this_type &&)=default
void rexec(TaskGroup< void, void > &tg, FuncT &&func, Args &&... args)
void rexec(TaskGroup< void, void > &tg, FuncT &&func)
void exec(Task< Args... > *_task)
TaskManager(ThreadPool *)
Task< RetT, ArgT, Args... > * wrap(TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
this_type & operator=(const this_type &)=delete
void rexec(TaskGroup< RetT, ArgT > &tg, FuncT &&func)
static TaskManager * GetInstanceIfExists()
static TaskManager * GetInstance()
get the singleton pointer
this_type & operator=(this_type &&)=default
Task< RetT, ArgT > * wrap(TaskGroup< RetT, ArgT > &tg, FuncT &&func)
void rexec(TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
auto async(FuncT &&func, Args... args) -> std::future< decay_t< decltype(func(args...))> >
std::future< RetT > async(FuncT &&func, Args &&... args)
void exec(TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
void exec(TaskGroup< RetT, ArgT > &tg, FuncT &&func)
std::future< RetT > async(FuncT &&func)
TaskManager(const this_type &)=delete
static TaskRunManager * GetMasterRunManager(bool useTBB=false)
The task class is supplied to thread_pool.
size_type add_task(task_pointer task, int bin=-1)
size_type destroy_threadpool()
typename std::decay< T >::type decay_t