Mantid
|
ThreadSchedulerMutexes : Version of a ThreadSchedulerLargestCost that also makes sure to not try to schedule two tasks with the same mutex at the same time. More...
#include <ThreadSchedulerMutexes.h>
Public Member Functions | |
void | clear () override |
Empty out the queue. More... | |
bool | empty () override |
void | finished (Task *task, size_t threadnum) override |
Signal to the scheduler that a task is complete. More... | |
std::shared_ptr< Task > | pop (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... | |
ThreadSchedulerMutexes ()=default | |
~ThreadSchedulerMutexes () override | |
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< Task > | pop (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 Types | |
using | InnerMap = std::multimap< double, std::shared_ptr< Task > > |
Map to tasks, sorted by cost. More... | |
using | SuperMap = std::map< std::shared_ptr< std::mutex >, InnerMap > |
Map to maps, sorted by Mutex*. More... | |
Protected Attributes | |
std::set< std::shared_ptr< std::mutex > > | m_mutexes |
Vector of currently used mutexes. More... | |
SuperMap | m_supermap |
A super map; first key = a Mutex * Inside it: second key = the 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... | |
ThreadSchedulerMutexes : Version of a ThreadSchedulerLargestCost that also makes sure to not try to schedule two tasks with the same mutex at the same time.
This scheduler also sorts by largest cost so as to optimize allocation that way.
NOTE: The performance of "pop"ping a task is much slower if you have a very large number of different mutexes; this scheduler is better suited if you only have a few (e.g. one for DiskIO, and NULL for calculations). Popping a task scales with the N^2 where N is the number of different mutexes.
Definition at line 36 of file ThreadSchedulerMutexes.h.
|
protected |
Map to tasks, sorted by cost.
Definition at line 165 of file ThreadSchedulerMutexes.h.
|
protected |
Map to maps, sorted by Mutex*.
Definition at line 167 of file ThreadSchedulerMutexes.h.
|
default |
|
inlineoverride |
Definition at line 40 of file ThreadSchedulerMutexes.h.
|
inlineoverridevirtual |
Empty out the queue.
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 150 of file ThreadSchedulerMutexes.h.
|
inlineoverridevirtual |
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 139 of file ThreadSchedulerMutexes.h.
|
inlineoverridevirtual |
Signal to the scheduler that a task is complete.
task | :: the Task that was completed. |
threadnum | :: unused argument |
Reimplemented from Mantid::Kernel::ThreadScheduler.
Definition at line 116 of file ThreadSchedulerMutexes.h.
References Mantid::Kernel::Task::getMutex(), and UNUSED_ARG.
|
inlineoverridevirtual |
Retrieves the next Task to execute.
threadnum | :: ID of the calling thread. |
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 53 of file ThreadSchedulerMutexes.h.
References UNUSED_ARG.
|
inlineoverridevirtual |
Add a Task to the queue.
newTask | :: Task to add to queue |
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 43 of file ThreadSchedulerMutexes.h.
|
inlineoverridevirtual |
Returns the size of the queue.
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 127 of file ThreadSchedulerMutexes.h.
|
protected |
Vector of currently used mutexes.
Definition at line 174 of file ThreadSchedulerMutexes.h.
|
protected |
A super map; first key = a Mutex * Inside it: second key = the cost.
Definition at line 171 of file ThreadSchedulerMutexes.h.