Peano
Loading...
Searching...
No Matches
peano4::maps::STDStackMap< T > Class Template Reference

#include <STDStackMap.h>

Collaboration diagram for peano4::maps::STDStackMap< T >:

Public Member Functions

 ~STDStackMap ()
 
bool empty (int treeId, int stackId) const
 
T * getForPush (int treeId, int stackId)
 Get the stack belonging to a tree.
 
T * getForPush (const StackKey &key)
 
T * getForPop (int treeId, int stackId)
 
T * getForPop (const StackKey &key)
 
void clear ()
 Clear the whole stack map.
 
void clear (int spacetree)
 With this clear, I have to manually delete all stacks.
 
std::string toString () const
 
std::set< StackKeygetKeys ()
 This one should be const, but I might need a semaphore, so I have to omit the const qualifier.
 
void garbageCollection (int spacetree)
 Invoke garbage collection.
 
bool holdsStack (int treeId, int stackId) const
 For debugging/assertions.
 
bool holdsStack (const StackKey &key) const
 

Private Member Functions

void createStack (const StackKey &key)
 This routine is not thread-safe, i.e.
 

Private Attributes

std::map< StackKey, T * > _data
 
tarch::multicore::BooleanSemaphore _semaphore
 Semaphore to protect _data.
 

Static Private Attributes

static tarch::logging::Log _log
 

Detailed Description

template<typename T>
class peano4::maps::STDStackMap< T >

Definition at line 21 of file STDStackMap.h.

Constructor & Destructor Documentation

◆ ~STDStackMap()

template<typename T >
peano4::maps::STDStackMap< T >::~STDStackMap ( )

Definition at line 227 of file STDStackMap.h.

References assertionMsg.

Member Function Documentation

◆ clear() [1/2]

template<typename T >
void peano4::maps::STDStackMap< T >::clear ( )

Clear the whole stack map.

A normal C++ code might deploy this into the destructor, but I had weird seg faults when I did so.

My explanation is that this map is also used in some library functions and that they are typically global variables. The order in which stuff is destroyed is thus non-deterministic (in the way that it is left to the linker). So I rather shutdown stuff explicitly.

Definition at line 217 of file STDStackMap.h.

Referenced by peano4.output.Makefile.Makefile::__init__().

Here is the caller graph for this function:

◆ clear() [2/2]

template<typename T >
void peano4::maps::STDStackMap< T >::clear ( int spacetree)

With this clear, I have to manually delete all stacks.

It is not enough to call clear(). Clear() usually only resets the size to zero, and we then wait for the garbage collection to free the actual memory. This garbage collection however usually leaves all in/out (lets call them storage) stacks intact, as it knows that we'll gonna use them in the next sweep - an assumption that's invalid if we delete a tree and consequently invoke clear(int).

Definition at line 254 of file STDStackMap.h.

References peano4::parallel::Node::getInstance(), peano4::parallel::Node::getLocalTreeId(), and logDebug.

Referenced by peano4.output.Makefile.Makefile::__init__().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createStack()

template<typename T >
void peano4::maps::STDStackMap< T >::createStack ( const StackKey & key)
private

This routine is not thread-safe, i.e.

if you need it thread-safe then you have to wrap it into a semaphore manually.

Definition at line 133 of file STDStackMap.h.

◆ empty()

template<typename T >
bool peano4::maps::STDStackMap< T >::empty ( int treeId,
int stackId ) const

Definition at line 146 of file STDStackMap.h.

◆ garbageCollection()

template<typename T >
void peano4::maps::STDStackMap< T >::garbageCollection ( int spacetree)

Invoke garbage collection.

The standard stack in C++ has a clear operation. However, it does not actively free memory. Indeed, the C++ standard leaves it up to the STL implementation to decide whether to free or not. Most don't. As a consequence, the memory hunger of Peano applications could rise dramatically - in particular throughout forks when whole spacetrees are (temporarily) replicated.

The only way around the lack of a proper free is the total elimination of a vector (via a delete) and the recreation. We do thus rely on this mechanism though we only apply it to communication stacks. All the temporary stacks and in/out stacks are never erased.

Definition at line 233 of file STDStackMap.h.

References peano4::parallel::Node::getInstance(), peano4::parallel::Node::getLocalTreeId(), peano4::parallel::Node::isStorageStackNumber(), and logDebug.

Here is the call graph for this function:

◆ getForPop() [1/2]

template<typename T >
T * peano4::maps::STDStackMap< T >::getForPop ( const StackKey & key)

Definition at line 173 of file STDStackMap.h.

References assertion.

◆ getForPop() [2/2]

template<typename T >
T * peano4::maps::STDStackMap< T >::getForPop ( int treeId,
int stackId )
See also
getForPush(int,int)
Returns
A stack of type T.

Definition at line 167 of file STDStackMap.h.

◆ getForPush() [1/2]

template<typename T >
T * peano4::maps::STDStackMap< T >::getForPush ( const StackKey & key)

Definition at line 159 of file STDStackMap.h.

◆ getForPush() [2/2]

template<typename T >
T * peano4::maps::STDStackMap< T >::getForPush ( int treeId,
int stackId )

Get the stack belonging to a tree.

There are two versions of the routine: one for pushes, one for pops. I distinguish the two, as the push variant might create new stacks lazily whereas the pop knowns a priori that the requested stack does exist.

Implementation details

We nevertheless have to be careful with pops. In the vanilla version, pops cannot create new stacks. But we use one global map for all stacks of all spacetrees hosted by this rank. So concurrent pushes can create new stacks on-the-fly. So we need some thread-saving mechanisms.

Returns
A stack of type T. It is a pointer and this routine realises a lazy creation, i.e. might create the result upon demand.

Definition at line 153 of file STDStackMap.h.

◆ getKeys()

template<typename T >
std::set< peano4::maps::StackKey > peano4::maps::STDStackMap< T >::getKeys ( )

This one should be const, but I might need a semaphore, so I have to omit the const qualifier.

Definition at line 194 of file STDStackMap.h.

◆ holdsStack() [1/2]

template<typename T >
bool peano4::maps::STDStackMap< T >::holdsStack ( const StackKey & key) const

Definition at line 211 of file STDStackMap.h.

◆ holdsStack() [2/2]

template<typename T >
bool peano4::maps::STDStackMap< T >::holdsStack ( int treeId,
int stackId ) const

For debugging/assertions.

Definition at line 205 of file STDStackMap.h.

◆ toString()

template<typename T >
std::string peano4::maps::STDStackMap< T >::toString ( ) const

Definition at line 181 of file STDStackMap.h.

Field Documentation

◆ _data

◆ _log

template<typename T >
tarch::logging::Log peano4::maps::STDStackMap< T >::_log
staticprivate

Definition at line 23 of file STDStackMap.h.

◆ _semaphore

template<typename T >
tarch::multicore::BooleanSemaphore peano4::maps::STDStackMap< T >::_semaphore
private

Semaphore to protect _data.

Definition at line 30 of file STDStackMap.h.


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