![]() |
Peano
|
#include <STDStackMap.h>
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< StackKey > | getKeys () |
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 |
Definition at line 21 of file STDStackMap.h.
peano4::maps::STDStackMap< T >::~STDStackMap | ( | ) |
Definition at line 227 of file STDStackMap.h.
References assertionMsg.
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__().
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__().
|
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.
bool peano4::maps::STDStackMap< T >::empty | ( | int | treeId, |
int | stackId ) const |
Definition at line 146 of file STDStackMap.h.
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.
T * peano4::maps::STDStackMap< T >::getForPop | ( | const StackKey & | key | ) |
Definition at line 173 of file STDStackMap.h.
References assertion.
T * peano4::maps::STDStackMap< T >::getForPop | ( | int | treeId, |
int | stackId ) |
T * peano4::maps::STDStackMap< T >::getForPush | ( | const StackKey & | key | ) |
Definition at line 159 of file STDStackMap.h.
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.
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.
Definition at line 153 of file STDStackMap.h.
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.
bool peano4::maps::STDStackMap< T >::holdsStack | ( | const StackKey & | key | ) | const |
Definition at line 211 of file STDStackMap.h.
bool peano4::maps::STDStackMap< T >::holdsStack | ( | int | treeId, |
int | stackId ) const |
For debugging/assertions.
Definition at line 205 of file STDStackMap.h.
std::string peano4::maps::STDStackMap< T >::toString | ( | ) | const |
Definition at line 181 of file STDStackMap.h.
|
private |
Definition at line 25 of file STDStackMap.h.
Referenced by peano4.datamodel.DaStGen2.DaStGen2Generator::construct_output(), peano4.datamodel.DaStGen2.DaStGen2GeneratorForObjectsWithSmartPointers::construct_output(), peano4.toolbox.particles.ParticleSet.ParticleSetGenerator_ScatteredOnHeap_IndexByList::construct_output(), peano4.toolbox.particles.ParticleSet.ParticleSetGenerator_ScatteredOnHeap_IndexByVector::construct_output(), peano4.toolbox.particles.ParticleSet.ParticleSetGenerator_ContinuousPerVertex::construct_output(), peano4.toolbox.particles.ParticleSet.ParticleSetGenerator_GlobalContinuous::construct_output(), peano4.datamodel.DaStGen2.DaStGen2Generator::get_header_file_include(), peano4.datamodel.DaStGen2.DaStGen2GeneratorForObjectsWithSmartPointers::get_header_file_include(), peano4.toolbox.particles.ParticleSet.AbstractParticleSetGenerator::get_header_file_include(), peano4.datamodel.DaStGen2.DaStGen2Generator::get_stack_container(), peano4.datamodel.DaStGen2.DaStGen2GeneratorForObjectsWithSmartPointers::get_stack_container(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_stack_container(), and peano4.toolbox.particles.ParticleSet.AbstractParticleSetGenerator::get_stack_container().
|
staticprivate |
Definition at line 23 of file STDStackMap.h.
|
private |
Semaphore to protect _data.
Definition at line 30 of file STDStackMap.h.