Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Mantid::Kernel::ThreadSchedulerLargestCost Class Reference

A Largest Cost Thread Scheduler. More...

#include <ThreadScheduler.h>

Inheritance diagram for Mantid::Kernel::ThreadSchedulerLargestCost:
Mantid::Kernel::ThreadScheduler

Public Member Functions

void clear () override
 Empty out the queue. More...
 
bool empty () override
 
std::shared_ptr< Taskpop (size_t threadnum) override
 Retrieves the next Task to execute. More...
 
void push (std::shared_ptr< Task > newTask) override
 Add a Task to the queue. More...
 
size_t size () override
 Returns the size of the queue. More...
 
 ThreadSchedulerLargestCost ()
 
 ~ThreadSchedulerLargestCost () override
 Destructor. More...
 
- Public Member Functions inherited from Mantid::Kernel::ThreadScheduler
virtual void abort (std::runtime_error exception)
 Signal to the scheduler that a task is complete. More...
 
virtual void clear ()=0
 Empty out the queue. More...
 
virtual bool empty ()=0
 Returns true if the queue is empty. More...
 
virtual void finished (Task *task, size_t threadnum)
 Signal to the scheduler that a task is complete. More...
 
bool getAborted ()
 Returns true if the execution was aborted. More...
 
std::runtime_error getAbortException ()
 Returns the exception that was caught, if any. More...
 
virtual std::shared_ptr< Taskpop (size_t threadnum)=0
 Retrieves the next Task to execute. More...
 
virtual void push (std::shared_ptr< Task > newTask)=0
 Add a Task to the queue. More...
 
virtual size_t size ()=0
 Returns the size of the queue. More...
 
 ThreadScheduler ()
 Constructor. More...
 
double totalCost ()
 Returns the total cost of all Task's in the queue. More...
 
double totalCostExecuted ()
 Returns the total cost of all Task's in the queue. More...
 
virtual ~ThreadScheduler ()=default
 Destructor. More...
 

Protected Attributes

std::multimap< double, std::shared_ptr< Task > > m_map
 A multimap keeps tasks sorted by the key (cost) More...
 
- Protected Attributes inherited from Mantid::Kernel::ThreadScheduler
bool m_aborted
 The run was aborted due to an exception. More...
 
std::runtime_error m_abortException
 The exception that aborted the run. More...
 
double m_cost
 Total cost of all tasks. More...
 
double m_costExecuted
 Accumulated cost of tasks that have been executed (popped) More...
 
std::mutex m_queueLock
 Mutex to prevent simultaneous access to the queue. More...
 

Detailed Description

A Largest Cost Thread Scheduler.

The scheduled tasks are run so that the most time-consuming (highest cost) taks are run first. This tends to optimize task allocation the best. http://en.wikipedia.org/wiki/Bin_packing_problem

Interally, it uses a multimap to keep elements sorted while inserting them.

Definition at line 228 of file ThreadScheduler.h.

Constructor & Destructor Documentation

◆ ThreadSchedulerLargestCost()

Mantid::Kernel::ThreadSchedulerLargestCost::ThreadSchedulerLargestCost ( )
inline

Definition at line 230 of file ThreadScheduler.h.

◆ ~ThreadSchedulerLargestCost()

Mantid::Kernel::ThreadSchedulerLargestCost::~ThreadSchedulerLargestCost ( )
inlineoverride

Destructor.

Definition at line 233 of file ThreadScheduler.h.

Member Function Documentation

◆ clear()

void Mantid::Kernel::ThreadSchedulerLargestCost::clear ( )
inlineoverridevirtual

Empty out the queue.

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 278 of file ThreadScheduler.h.

◆ empty()

bool Mantid::Kernel::ThreadSchedulerLargestCost::empty ( )
inlineoverridevirtual
Returns
true if the queue is empty

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 237 of file ThreadScheduler.h.

◆ pop()

std::shared_ptr< Task > Mantid::Kernel::ThreadSchedulerLargestCost::pop ( size_t  threadnum)
inlineoverridevirtual

Retrieves the next Task to execute.

Parameters
threadnum:: ID of the calling thread.
Returns
a Task pointer to execute.

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 252 of file ThreadScheduler.h.

References UNUSED_ARG.

◆ push()

void Mantid::Kernel::ThreadSchedulerLargestCost::push ( std::shared_ptr< Task newTask)
inlineoverridevirtual

Add a Task to the queue.

Parameters
newTask:: Task to add to queue

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 243 of file ThreadScheduler.h.

◆ size()

size_t Mantid::Kernel::ThreadSchedulerLargestCost::size ( )
inlineoverridevirtual

Returns the size of the queue.

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 270 of file ThreadScheduler.h.

Member Data Documentation

◆ m_map

std::multimap<double, std::shared_ptr<Task> > Mantid::Kernel::ThreadSchedulerLargestCost::m_map
protected

A multimap keeps tasks sorted by the key (cost)

Definition at line 289 of file ThreadScheduler.h.


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