Peano
Loading...
Searching...
No Matches
tarch::Enumerator Class Reference

Simple rank-global enumerator. More...

#include <Enumerator.h>

Collaboration diagram for tarch::Enumerator:

Public Member Functions

 Enumerator (int max=std::numeric_limits< int >::max() -2)
 
void reset ()
 Complete reset, which basically eliminates all the active numbers.
 
void setMax (int max)
 
int getNumber ()
 Return unique number.
 
void releaseNumber (int value)
 Free a number.
 
int size () const
 Number of numbers handed out so far.
 
std::string toString () const
 

Static Public Attributes

static constexpr int NoNumber = -1
 

Private Attributes

tarch::multicore::BooleanSemaphore _semaphore
 
std::set< int > _activeNumbers
 
int _max
 
int _lastNumberHandedOut
 

Static Private Attributes

static tarch::logging::Log _log
 

Detailed Description

Simple rank-global enumerator.

Very simple utility class to build up a global set of numbers on a rank. Is used in various places to create task numbers for example or to enumerate all vertices and cells properly.

The object is thread-safe, i.e. all modifiers are protected via a semaphore.

It ensures that no number is handed out twice, by maintaining a set of _activeNumbers.

Definition at line 28 of file Enumerator.h.

Constructor & Destructor Documentation

◆ Enumerator()

tarch::Enumerator::Enumerator ( int  max = std::numeric_limits< int >::max() -2)

Member Function Documentation

◆ getNumber()

int tarch::Enumerator::getNumber ( )

Return unique number.

Returns a unique non-zero number which is not yet used anywhere else on this rank. The number is positive or zero.

◆ releaseNumber()

void tarch::Enumerator::releaseNumber ( int  value)

Free a number.

number has to be the result of a previous getNumber() call. We had the situation where enclave task numbers became really big as we just increment _lastNumberHandedOut in getNumber(). So what I do is that I reduce _lastNumberHandedOut by half if value is too big. This way, we at least scan only half of the overall number range that we might have at our disposal.

Parameters
valueThe number that we want to release. If you pass in NoNumber, then nothing happens.

◆ reset()

void tarch::Enumerator::reset ( )

Complete reset, which basically eliminates all the active numbers.

◆ setMax()

void tarch::Enumerator::setMax ( int  max)

◆ size()

int tarch::Enumerator::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::Enumerator::toString ( ) const

Field Documentation

◆ _activeNumbers

std::set<int> tarch::Enumerator::_activeNumbers
private

Definition at line 75 of file Enumerator.h.

◆ _lastNumberHandedOut

int tarch::Enumerator::_lastNumberHandedOut
private

Definition at line 77 of file Enumerator.h.

◆ _log

tarch::logging::Log tarch::Enumerator::_log
staticprivate

Definition at line 72 of file Enumerator.h.

◆ _max

int tarch::Enumerator::_max
private

Definition at line 76 of file Enumerator.h.

◆ _semaphore

tarch::multicore::BooleanSemaphore tarch::Enumerator::_semaphore
private

Definition at line 74 of file Enumerator.h.

◆ NoNumber

constexpr int tarch::Enumerator::NoNumber = -1
staticconstexpr

Definition at line 30 of file Enumerator.h.


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