68 static
unsigned ncores() {
return std::thread::hardware_concurrency(); }
95 template <
typename... Args>
99 throw std::runtime_error(
"Nullptr to thread-pool");
106 template <
typename RetT,
typename FuncT,
typename... Args>
112 throw std::runtime_error(
"Nullptr to thread-pool");
114 auto _ptask = std::make_shared<task_type>(std::forward<FuncT>(func),
115 std::forward<Args>(args)...);
120 template <
typename RetT,
typename FuncT>
121 std::shared_ptr<PackagedTask<RetT>>
async(FuncT&& func)
126 throw std::runtime_error(
"Nullptr to thread-pool");
128 auto _ptask = std::make_shared<task_type>(std::forward<FuncT>(func));
133 template <
typename FuncT,
typename... Args>
134 auto async(FuncT&& func, Args... args)
137 using RetT =
decay_t<
decltype(func(args...))>;
141 throw std::runtime_error(
"Nullptr to thread-pool");
143 auto _ptask = std::make_shared<task_type>(std::forward<FuncT>(func),
144 std::forward<Args>(args)...);
154 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
156 FuncT&& func, Args&&... args)
158 return tg.
wrap(std::forward<FuncT>(func), std::forward<Args>(args)...);
161 template <
typename RetT,
typename ArgT,
typename FuncT>
164 return tg.
wrap(std::forward<FuncT>(func));
171 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
174 tg.
exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
177 template <
typename RetT,
typename ArgT,
typename FuncT>
180 tg.
exec(std::forward<FuncT>(func));
183 template <
typename RetT,
typename ArgT,
typename FuncT,
typename... Args>
186 tg.
exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
189 template <
typename RetT,
typename ArgT,
typename FuncT>
192 tg.
exec(std::forward<FuncT>(func));
197 template <
typename FuncT,
typename... Args>
200 tg.
exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
203 template <
typename FuncT>
206 tg.
exec(std::forward<FuncT>(func));
213 bool m_is_finalized =
false;
227PTL::TaskManager::fgInstance()
229 static thread_local TaskManager* _instance =
nullptr;
240 auto nthreads = std::thread::hardware_concurrency();
241 std::cout <<
"Allocating mad::TaskManager with " << nthreads <<
" thread(s)..."
260, m_is_finalized(!_manage_pool)
271 if(fgInstance() ==
this)
272 fgInstance() =
nullptr;
The task class is supplied to thread_pool.
std::shared_ptr< task_type< Args... > > wrap(Func func, Args... args)
enable_if_t< std::is_void< Up >::value, void > exec(Func func, Args... args)
ThreadPool * thread_pool() const
std::shared_ptr< PackagedTask< RetT > > async(FuncT &&func)
virtual ~TaskManager() noexcept(false)
void rexec(TaskGroup< void, void > &tg, FuncT &&func, Args &&... args)
void rexec(TaskGroup< void, void > &tg, FuncT &&func)
void exec(Task< Args... > *_task)
void rexec(TaskGroup< RetT, ArgT > &tg, FuncT &&func)
static TaskManager * GetInstanceIfExists()
static TaskManager * GetInstance()
get the singleton pointer
std::shared_ptr< Task< RetT, ArgT > > wrap(TaskGroup< RetT, ArgT > &tg, FuncT &&func)
ThreadPool::size_type size_type
void rexec(TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
TaskManager(ThreadPool *, bool _manage_pool=true)
std::shared_ptr< Task< RetT, ArgT, Args... > > wrap(TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
void exec(TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
void exec(TaskGroup< RetT, ArgT > &tg, FuncT &&func)
auto async(FuncT &&func, Args... args) -> std::shared_ptr< PackagedTask< decay_t< decltype(func(args...))>, Args... > >
std::shared_ptr< PackagedTask< RetT, Args... > > async(FuncT &&func, Args &&... args)
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