MADNESS
0.10.1
|
A singleton pool of threads for dynamic execution of tasks. More...
#include <thread.h>
Public Member Functions | |
ThreadPool (const ThreadPool &)=delete | |
ThreadPool (ThreadPool &&)=delete | |
~ThreadPool () | |
Destructor. More... | |
void | flush_prebuf () |
void | operator= (const ThreadPool &)=delete |
void | operator= (ThreadPool &&)=delete |
template<typename opT > | |
void | scan (opT &op) |
Static Public Member Functions | |
static void | add (const std::vector< PoolTaskInterface * > &tasks) |
Add a vector of tasks to the pool. More... | |
static void | add (PoolTaskInterface *task) |
Add a new task to the pool. More... | |
template<typename Probe > | |
static void | await (const Probe &probe, bool dowork=true, bool sleep=false) |
Gracefully wait for a condition to become true, executing any tasks in the queue. More... | |
static void | begin (int nthread=-1) |
Please invoke while in a single-threaded environment. More... | |
static int | default_nthread () |
Get the number of threads from the environment. More... | |
static void | end () |
static const DQStats & | get_stats () |
Returns queue statistics. More... | |
static const ThreadPoolThread * | get_threads () |
static ThreadPool * | instance () |
Return a pointer to the only instance, constructing as necessary. More... | |
static std::size_t | queue_size () |
Returns the number of tasks in the queue. More... | |
static bool | run_task () |
An otherwise idle thread can all this to run a task. More... | |
static void | set_wait_policy (WaitPolicy policy, int sleep_duration_in_microseconds=0) |
static std::size_t | size () |
Returns the number of threads in the pool. More... | |
Static Public Attributes | |
static std::unique_ptr< tbb::task_arena > | tbb_arena = nullptr |
static std::unique_ptr< tbb::global_control > | tbb_control = nullptr |
Private Member Functions | |
ThreadPool (int nthread=-1) | |
The constructor is private to enforce the singleton model. More... | |
bool | run_task (bool wait, ThreadPoolThread *this_thread) |
Run the next task. More... | |
bool | run_tasks (bool wait, ThreadPoolThread *const this_thread) |
void | thread_main (ThreadPoolThread *const thread) |
Static Private Member Functions | |
static void * | pool_thread_main (void *v) |
Forwards the thread to bound member function. More... | |
Private Attributes | |
volatile bool | finish |
Set to true when time to stop. More... | |
ThreadPoolThread | main_thread |
Placeholder for main thread tls. More... | |
AtomicInt | nfinished |
Thread pool exit counter. More... | |
int | nthreads |
Number of threads. More... | |
DQueue< PoolTaskInterface * > | queue |
Queue of tasks. More... | |
ThreadPoolThread * | threads |
Array of threads. More... | |
Static Private Attributes | |
static double | await_timeout = 900.0 |
Waiter timeout. More... | |
static ThreadPool * | instance_ptr = 0 |
Singleton pointer. More... | |
static const int | nmax = 128 |
Number of task a worker thread will pop from the task queue. More... | |
Friends | |
class | WorldTaskQueue |
A singleton pool of threads for dynamic execution of tasks.
|
delete |
Referenced by begin().
|
delete |
|
private |
The constructor is private to enforce the singleton model.
[in] | nthread | Description needed. |
References SafeMPI::COMM_WORLD, default_nthread(), SafeMPI::Intracomm::Get_size(), instance_ptr, MADNESS_ASSERT, MADNESS_EXCEPTION, main_thread, nfinished, nthreads, pool_thread_main(), madness::ThreadBase::set_pool_thread_index(), madness::Thread::start(), tbb_arena, tbb_control, madness::ThreadBase::thread_key, and threads.
|
inline |
Destructor.
References threads.
|
inlinestatic |
Add a vector of tasks to the pool.
[in] | tasks | Vector of tasks to add to the pool. |
References add(), and MADNESS_EXCEPTION.
|
inlinestatic |
Add a new task to the pool.
[in,out] | task | Description needed. |
References instance(), MADNESS_EXCEPTION, queue, task(), and tbb_arena.
Referenced by add(), end(), main(), and madness::TaskInterface::Submit::notify().
|
inlinestatic |
Gracefully wait for a condition to become true, executing any tasks in the queue.
Probe should be an object that, when called, returns the status.
Probe | Type of the probe. |
[in] | probe | The probe. |
[in] | dowork | Do work while waiting - default is true |
[in] | sleep | Sleep instead of spin while waiting (e.g., to avoid pounding on MPI) - default is false |
References await_timeout, bufsize, madness::cpu_time(), current_time, madness::myusleep(), madness::MutexWaiter::reset(), run_task(), and madness::MutexWaiter::wait().
Referenced by madness::World::await(), and madness::WorldTaskQueue::fence().
|
static |
Please invoke while in a single-threaded environment.
[in] | nthread | The number of threads. |
References ThreadPool(), await_timeout, SafeMPI::COMM_WORLD, SafeMPI::Intracomm::Get_rank(), madness::ThreadBase::init_thread_key(), instance_ptr, madness::profiling::TaskProfiler::output_file_name_, madness::quiet(), and size().
|
static |
Get the number of threads from the environment.
References MADNESS_EXCEPTION, madness::ThreadBase::num_hw_processors(), and shift.
Referenced by ThreadPool().
|
static |
References add(), madness::ThreadBase::delete_thread_key(), finish, flush_prebuf(), instance(), instance_ptr, main_thread, nfinished, nthreads, madness::ThreadPoolThread::profiler(), and madness::profiling::TaskProfiler::write_to_file().
|
inline |
References queue.
Referenced by end(), and madness::RMI::RmiTask::process_some().
|
static |
Returns queue statistics.
References instance(), and queue.
Referenced by madness::print_stats().
|
inlinestatic |
Access the pool thread array
size()
References instance(), and threads.
|
inlinestatic |
Return a pointer to the only instance, constructing as necessary.
References instance_ptr, and MADNESS_EXCEPTION.
Referenced by add(), end(), get_stats(), get_threads(), pool_thread_main(), madness::RMI::RmiTask::process_some(), queue_size(), run_task(), set_wait_policy(), and size().
|
delete |
|
delete |
|
staticprivate |
Forwards the thread to bound member function.
[in] | v | Description needed. |
References instance(), thread_main(), and v.
Referenced by ThreadPool().
|
inlinestatic |
Returns the number of tasks in the queue.
References instance(), and queue.
|
inlinestatic |
An otherwise idle thread can all this to run a task.
References instance(), run_tasks(), and madness::ThreadBase::this_thread().
Referenced by await(), and thread_main().
|
inlineprivate |
Run the next task.
[in] | wait | Block of true. |
[in,out] | this_thread | Description needed. |
References madness::profiling::TaskEventList::event(), MADNESS_EXCEPTION, madness::profiling::TaskProfiler::new_list(), madness::ThreadPoolThread::profiler(), and queue.
|
inlineprivate |
[in] | wait | Description needed. |
[in,out] | this_thread | Description needed. |
References madness::profiling::TaskEventList::event(), MADNESS_EXCEPTION, madness::profiling::TaskProfiler::new_list(), nmax, madness::ThreadPoolThread::profiler(), queue, and madness::PoolTaskInterface::set_event().
Referenced by run_task(), and thread_main().
|
inline |
|
inlinestatic |
References instance(), and queue.
Referenced by madness::threadpool_wait_policy().
|
inlinestatic |
Returns the number of threads in the pool.
References instance(), and nthreads.
Referenced by madness::CubicInterpolationTable< T >::CubicInterpolationTable(), begin(), madness::RMI::RmiTask::huge_msg_handler(), main(), madness::print_stats(), madness::archive::ArchiveStoreImpl< ParallelOutputArchive< VectorOutputArchive >, WorldContainer< keyT, valueT > >::store(), test2(), test_multi(), and madness::profiling::TaskProfiler::write_to_file().
|
private |
[in,out] | thread | Description needed. |
References madness::ThreadBinder::bind(), madness::binder, finish, nfinished, PROFILE_MEMBER_FUNC, madness::ThreadPoolThread::profiler(), run_task(), run_tasks(), and madness::profiling::TaskProfiler::write_to_file().
Referenced by pool_thread_main().
|
friend |
|
staticprivate |
|
private |
Set to true when time to stop.
Referenced by end(), and thread_main().
|
staticprivate |
Singleton pointer.
Referenced by ThreadPool(), begin(), end(), and instance().
|
private |
Placeholder for main thread tls.
Referenced by ThreadPool(), and end().
|
private |
Thread pool exit counter.
Referenced by ThreadPool(), end(), and thread_main().
|
staticprivate |
Number of task a worker thread will pop from the task queue.
Referenced by run_tasks().
|
private |
Number of threads.
Referenced by ThreadPool(), end(), and size().
|
private |
Queue of tasks.
Referenced by add(), flush_prebuf(), get_stats(), queue_size(), run_task(), run_tasks(), scan(), and set_wait_policy().
|
static |
Referenced by ThreadPool(), add(), and madness::RMI::begin().
|
static |
Referenced by ThreadPool().
|
private |
Array of threads.
Referenced by ThreadPool(), ~ThreadPool(), and get_threads().