Peano
Loading...
Searching...
No Matches
tarch::multicore::TaskEnumerator Class Reference

Rank-global enumerator for tasks. More...

#include <TaskEnumerator.h>

Inheritance diagram for tarch::multicore::TaskEnumerator:
Collaboration diagram for tarch::multicore::TaskEnumerator:

Public Member Functions

 TaskEnumerator ()
 
void reset ()
 
int getNumber ()
 Get a new task number.
 
void releaseNumber (int value)
 Release a task number.
 
int size () const
 Number of numbers handed out so far.
 
std::string toString () const
 

Static Public Attributes

static constexpr int NoNumber = -1
 

Static Private Member Functions

static tarch::multicore::MultiReadSingleWriteSemaphore & _enumeratorSequenceSemaphore ()
 We use a method instead of a member variable so that thhe static semaphore is is guaranteed to be initialised before we use it.
 

Private Attributes

int _enumeratorNumber
 Number of enumerator that's tied to this instance.
 

Static Private Attributes

static std::vector< tarch::Enumerator * > _enumerator
 
static tarch::logging::Log _log
 

Detailed Description

Rank-global enumerator for tasks.

The "problem" with tasks is that we often have different solvers running in parallel which all need their own task numbers. And these should, obviously, not conflict. The present enumerator tackles this problem:

The class is a wrapper layer around a set of enumerators. It is aware of the maximum number of tasks that our system can handle. Every time you construct an instance of this class, it coordinates internally with all the other instances of this class and ensures that each instance only hands out numbers from its specific range.

If you had, for example, only numbers from 0 up to 10000-1, and you create two instances of tarch::multicore::TaskEnumerator, then the first instance would only hand out numbers from 0 to 5000-1, and the second one only from 5000 to 10000-1. They ensure that there is no conflict.

The actual task number administration is thread-safe, as we rely internally on tarch::Enumerator instances on the heap. However, the creation of these heap objects can lead to race conditions. Therefore, we protect this access explicitly with a semaphore allowing for multiple reads but only one write.

Definition at line 41 of file TaskEnumerator.h.

Constructor & Destructor Documentation

◆ TaskEnumerator()

tarch::multicore::TaskEnumerator::TaskEnumerator ( )

Member Function Documentation

◆ _enumeratorSequenceSemaphore()

static tarch::multicore::MultiReadSingleWriteSemaphore & tarch::multicore::TaskEnumerator::_enumeratorSequenceSemaphore ( )
staticprivate

We use a method instead of a member variable so that thhe static semaphore is is guaranteed to be initialised before we use it.

Without this we fall victim to the static initialisation order fiasco.

◆ getNumber()

int tarch::multicore::TaskEnumerator::getNumber ( )

Get a new task number.

Returns a unique non-zero number which is not yet used anywhere else on this rank. The function delegates the call to an instance of tarch::Enumerator::getNumber(). Consequently, it is thread-safe.

Returns
Non-zero number or tarch::Enumerator::NoNumber if there's no number left.

◆ releaseNumber()

void tarch::multicore::TaskEnumerator::releaseNumber ( int  value)

Release a task number.

Free a number again. number has to be the result of a previous getNumber() call. Is thread-safe.

◆ reset()

void tarch::multicore::TaskEnumerator::reset ( )

◆ size()

int tarch::multicore::TaskEnumerator::size ( ) const

Number of numbers handed out so far.

Referenced by tarch.plotter.api.input.Patch.Patch::__repr__().

Here is the caller graph for this function:

◆ toString()

std::string tarch::multicore::TaskEnumerator::toString ( ) const

Field Documentation

◆ _enumerator

std::vector< tarch::Enumerator* > tarch::multicore::TaskEnumerator::_enumerator
staticprivate

Definition at line 82 of file TaskEnumerator.h.

◆ _enumeratorNumber

int tarch::multicore::TaskEnumerator::_enumeratorNumber
private

Number of enumerator that's tied to this instance.

The value serves as index to access _enumerator.

Logically, this attribute is a const attribute. We however cannot make it const, as the constructor first of all has to lock the array _enumerator, then it can determine what the value of _enumeratorNumber number is.

Definition at line 95 of file TaskEnumerator.h.

◆ _log

tarch::logging::Log tarch::multicore::TaskEnumerator::_log
staticprivate

Definition at line 83 of file TaskEnumerator.h.

◆ NoNumber

constexpr int tarch::multicore::TaskEnumerator::NoNumber = -1
staticconstexpr

Definition at line 43 of file TaskEnumerator.h.


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