MADNESS  version 0.9
Public Member Functions | Static Public Member Functions | Friends | List of all members
madness::ThreadPool Class Reference

A singleton pool of threads for dynamic execution of tasks. More...

#include <worldthread.h>

Public Member Functions

template<typename opT >
void scan (opT &op)
 
 ~ThreadPool ()
 

Static Public Member Functions

static void begin (int nthread=-1)
 Please invoke while in single threaded environment. More...
 
static void end ()
 
static void add (PoolTaskInterface *task)
 Add a new task to the pool. More...
 
static void add (const std::vector< PoolTaskInterface * > &tasks)
 Add a vector of tasks to the pool. More...
 
static bool run_task ()
 An otherwise idle thread can all this to run a task. More...
 
static std::size_t size ()
 Returns number of threads in the pool. More...
 
static std::size_t queue_size ()
 Returns number of tasks in the queue. More...
 
static const DQStatsget_stats ()
 Returns queue statistics. More...
 
template<typename Probe >
static void await (const Probe &probe, bool dowork=true)
 Gracefully wait for a condition to become true ... executes tasks if any in queue. More...
 

Friends

class WorldTaskQueue
 

Detailed Description

A singleton pool of threads for dynamic execution of tasks.

YOU MUST INSTANTIATE THE POOL WHILE RUNNING WITH JUST ONE THREAD

Constructor & Destructor Documentation

madness::ThreadPool::~ThreadPool ( )
inline

Member Function Documentation

static void madness::ThreadPool::add ( PoolTaskInterface task)
inlinestatic
static void madness::ThreadPool::add ( const std::vector< PoolTaskInterface * > &  tasks)
inlinestatic

Add a vector of tasks to the pool.

References add(), and MADNESS_EXCEPTION.

template<typename Probe >
static void madness::ThreadPool::await ( const Probe &  probe,
bool  dowork = true 
)
inlinestatic

Gracefully wait for a condition to become true ... executes tasks if any in queue.

Probe should be an object that when called returns the status.

References madness::MutexWaiter::reset(), run_task(), and madness::MutexWaiter::wait().

Referenced by madness::World::await(), and madness::WorldTaskQueue::fence().

void madness::ThreadPool::begin ( int  nthread = -1)
static

Please invoke while in single threaded environment.

References SafeMPI::COMM_WORLD, SafeMPI::Intracomm::Get_rank(), size(), and mpfr::trunc().

Referenced by madness::initialize(), and main().

void madness::ThreadPool::end ( )
static

References add().

Referenced by madness::finalize().

const DQStats & madness::ThreadPool::get_stats ( )
static

Returns queue statistics.

Referenced by madness::print_stats().

static std::size_t madness::ThreadPool::queue_size ( )
inlinestatic

Returns number of tasks in the queue.

static bool madness::ThreadPool::run_task ( )
inlinestatic

An otherwise idle thread can all this to run a task.

Returns true if one was run

References madness::ThreadBase::this_thread().

Referenced by await().

template<typename opT >
void madness::ThreadPool::scan ( opT &  op)
inline
static std::size_t madness::ThreadPool::size ( )
inlinestatic

Returns number of threads in the pool.

Referenced by begin(), madness::initialize(), and madness::print_stats().

Friends And Related Function Documentation

friend class WorldTaskQueue
friend

The documentation for this class was generated from the following files: