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

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>

Inheritance diagram for Mantid::Kernel::ThreadSchedulerMutexes:
Mantid::Kernel::ThreadScheduler

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< 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...
 
 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< 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 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...
 

Detailed Description

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.

Author
Janik Zikovsky
Date
2011-02-25 16:39:43.233991

Definition at line 36 of file ThreadSchedulerMutexes.h.

Member Typedef Documentation

◆ InnerMap

using Mantid::Kernel::ThreadSchedulerMutexes::InnerMap = std::multimap<double, std::shared_ptr<Task> >
protected

Map to tasks, sorted by cost.

Definition at line 165 of file ThreadSchedulerMutexes.h.

◆ SuperMap

using Mantid::Kernel::ThreadSchedulerMutexes::SuperMap = std::map<std::shared_ptr<std::mutex>, InnerMap>
protected

Map to maps, sorted by Mutex*.

Definition at line 167 of file ThreadSchedulerMutexes.h.

Constructor & Destructor Documentation

◆ ThreadSchedulerMutexes()

Mantid::Kernel::ThreadSchedulerMutexes::ThreadSchedulerMutexes ( )
default

◆ ~ThreadSchedulerMutexes()

Mantid::Kernel::ThreadSchedulerMutexes::~ThreadSchedulerMutexes ( )
inlineoverride

Definition at line 40 of file ThreadSchedulerMutexes.h.

Member Function Documentation

◆ clear()

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

Empty out the queue.

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 150 of file ThreadSchedulerMutexes.h.

◆ empty()

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

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 139 of file ThreadSchedulerMutexes.h.

◆ finished()

void Mantid::Kernel::ThreadSchedulerMutexes::finished ( Task task,
size_t  threadnum 
)
inlineoverridevirtual

Signal to the scheduler that a task is complete.

Parameters
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.

◆ pop()

std::shared_ptr< Task > Mantid::Kernel::ThreadSchedulerMutexes::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 53 of file ThreadSchedulerMutexes.h.

References UNUSED_ARG.

◆ push()

void Mantid::Kernel::ThreadSchedulerMutexes::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 43 of file ThreadSchedulerMutexes.h.

◆ size()

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

Returns the size of the queue.

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 127 of file ThreadSchedulerMutexes.h.

Member Data Documentation

◆ m_mutexes

std::set<std::shared_ptr<std::mutex> > Mantid::Kernel::ThreadSchedulerMutexes::m_mutexes
protected

Vector of currently used mutexes.

Definition at line 174 of file ThreadSchedulerMutexes.h.

◆ m_supermap

SuperMap Mantid::Kernel::ThreadSchedulerMutexes::m_supermap
protected

A super map; first key = a Mutex * Inside it: second key = the cost.

Definition at line 171 of file ThreadSchedulerMutexes.h.


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