![]() |
Peano
|
Default stack implementation using std::vector. More...
#include <STDVectorStack.h>
Data Structures | |
class | PopBlockStackView |
This class represents a whole block of the tree. More... | |
class | PushBlockStackView |
Public Member Functions | |
STDVectorStack () | |
Constructor. | |
~STDVectorStack ()=default | |
STDVectorStack (const STDVectorStack< T > &stack) | |
One is allowed to clone/copy a stack, but it has to be empty. | |
STDVectorStack & | operator= (const STDVectorStack< T > &stack) |
One is allowed to copy a stack but it has to be empty. | |
void | clone (const STDVectorStack< T > &data) |
Clone data into the current object on which clone() is called. | |
T | pop () |
Pops element from a stack. | |
T & | top (int shift=0) |
Get top element or shiftth top element. | |
const T & | top (int shift=0) const |
Get top element or shiftth top element. | |
void | push (const T &element) |
Pushes element to a stack. | |
PopBlockStackView | popBlock (int numberOfElements) |
This operation grabs numberOfElements from the input stack en block and returns a view to it. | |
PushBlockStackView | pushBlock (int numberOfElements) |
Push a block on the output stack. | |
int | size () const |
bool | empty () const |
void | clear () |
void | startSend (peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm) |
Always pairs up with a finish... call. | |
void | startReceive (peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm, int numberOfElements) |
bool | tryToFinishSendOrReceive () |
If this routine is invoked on a stack which is neither sending or receiving, then it degenerates to nop. | |
int | sendingOrReceiving () const |
I need this one to find out whether I'm waiting for data. | |
void | reverse () |
Reversing a stream is something I need extremely rarely. | |
std::string | toString () const |
void | startSend (peano4::grid::TraversalObserver::SendReceiveContext, int rank, int tag, MPI_Comm comm) |
void | startReceive (peano4::grid::TraversalObserver::SendReceiveContext, int rank, int tag, MPI_Comm comm, int numberOfElements) |
void | startSend (peano4::grid::TraversalObserver::SendReceiveContext, int rank, int tag, MPI_Comm comm) |
void | startReceive (peano4::grid::TraversalObserver::SendReceiveContext, int rank, int tag, MPI_Comm comm, int numberOfElements) |
Protected Attributes | |
std::vector< T > | _data |
This is the attribute holding all the temporary stacks. | |
int | _currentElement |
Identifies top element of stack. | |
IOMode | _ioMode |
int | _ioRank |
int | _ioTag |
MPI_Request * | _ioMPIRequest |
Static Protected Attributes | |
static tarch::logging::Log | _log |
Logging device. | |
Default stack implementation using std::vector.
The fields are protected, as there are subclasses. They usually differ "only" in the way they organise the data exchange between parallel entities.
In principle, all we assume is that the hosted objects work internally like normal C++ objects with proper move/copy semantics. However, we expect them to provide one more constructor, which looks similar to
The enum here has no semantics of its own. It is simply there to allow us to specify a special constructor which should not allocate any data. A similar pattern is used within Intel's TBB to define special-semantics constructor.
If the object backs up some dynamic memory on the heap, the invocation of this special constructor means that the dynamic memory should not be allocated. We use this feature in the resize or clone() operations, where we know that any new entry will be overwritten later on by the assignment operator. All we do there is to provide space of the objects.
If your stored class does not manage dynamic memory, the modified constructor can delegate to the default constructor.
Definition at line 76 of file STDVectorStack.h.
peano4::stacks::STDVectorStack< T >::STDVectorStack | ( | ) |
Constructor.
There's not really a need to initialise _ioMode and _ioTag, but I do so to ensure that memory checkers don't yield wrong alarms.
Definition at line 111 of file STDVectorStack.h.
|
default |
peano4::stacks::STDVectorStack< T >::STDVectorStack | ( | const STDVectorStack< T > & | stack | ) |
One is allowed to clone/copy a stack, but it has to be empty.
Usually only when we cut the domain into pieces.
Definition at line 129 of file STDVectorStack.h.
References assertionMsg.
void peano4::stacks::STDVectorStack< T >::clear | ( | ) |
Definition at line 393 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement.
Referenced by peano4.output.Makefile.Makefile::__init__(), and peano4::stacks::STDVectorStack< T >::tryToFinishSendOrReceive().
void peano4::stacks::STDVectorStack< T >::clone | ( | const STDVectorStack< T > & | data | ) |
Clone data into the current object on which clone() is called.
Definition at line 156 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, assertionEquals1, and peano4::stacks::STDVectorStack< T >::toString().
bool peano4::stacks::STDVectorStack< T >::empty | ( | ) | const |
Definition at line 389 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement.
STDVectorStack & peano4::stacks::STDVectorStack< T >::operator= | ( | const STDVectorStack< T > & | stack | ) |
One is allowed to copy a stack but it has to be empty.
Definition at line 147 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, assertion, and assertionEquals.
T peano4::stacks::STDVectorStack< T >::pop | ( | ) |
Pops element from a stack.
I have played around with an implementation of this routine via moves, i.e. as
T pop() { assertion1(_currentElement>0,_currentElement); _currentElement--; return std::move( _data[_currentElement] ); }
I put the move into this routine to highlight that we are actually moving stuff out of the container. However, this move is not required and, according to the C++ standard, degenerates to the identify here. I'm also not sure if it preserved the semantics.
Definition at line 299 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, and assertion1.
PopBlockStackView peano4::stacks::STDVectorStack< T >::popBlock | ( | int | numberOfElements | ) |
This operation grabs numberOfElements from the input stack en block and returns a view to it.
Subsequent pops do not affect this block anymore, i.e. the stack is reduced immediately.
Definition at line 350 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, and assertion.
void peano4::stacks::STDVectorStack< T >::push | ( | const T & | element | ) |
Pushes element to a stack.
_currentElement always points to the next free element on the stack.
Definition at line 332 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, and assertion.
PushBlockStackView peano4::stacks::STDVectorStack< T >::pushBlock | ( | int | numberOfElements | ) |
Push a block on the output stack.
Pushing a block on the output stack basically means that we move the stack pointer by numberOfElements entries. A block write stems from a regular subgrid, i.e. the corresponding subgrid remains constant, but it might happen that other grid parts processed before have added new vertices. So, we might have to increase the stack size before we open the push view on the stack. Also, the swapping of the stacks might imply that the current output stack is not big enough - the input stack might be, but we are using two distinguished stack data structures.
numberOfElements | Size of the view |
Definition at line 372 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, and assertion.
void peano4::stacks::STDVectorStack< T >::reverse | ( | ) |
Reversing a stream is something I need extremely rarely.
The biggest application is the realisation of joins through peano4::parallel::SpacetreeSet::streamLocalVertexInformationToMasterThroughVerticalStacks(). Here, I need a streamed version of the tree to get the up-to-date data of the mesh in. However, I don't have streams. I have only stacks. So I map the stream idea to a stack.
Definition at line 529 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_data.
int peano4::stacks::STDVectorStack< T >::sendingOrReceiving | ( | ) | const |
I need this one to find out whether I'm waiting for data.
Definition at line 518 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_ioMode, peano4::stacks::STDVectorStack< T >::_ioRank, and peano4::stacks::None.
int peano4::stacks::STDVectorStack< T >::size | ( | ) | const |
Definition at line 385 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement.
Referenced by peano4.visualisation.input.Patch.Patch::__repr__(), kernel_impl.Enumerator::fetch(), kernel_impl.Enumerator::lower(), peano4::stacks::STDVectorStack< T >::tryToFinishSendOrReceive(), and kernel_impl.Enumerator::upper().
void peano4::stacks::STDVectorStack< T >::startReceive | ( | peano4::grid::TraversalObserver::SendReceiveContext | context, |
int | rank, | ||
int | tag, | ||
MPI_Comm | comm, | ||
int | numberOfElements ) |
Definition at line 434 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, peano4::stacks::STDVectorStack< T >::_ioMode, peano4::stacks::STDVectorStack< T >::_ioMPIRequest, peano4::stacks::STDVectorStack< T >::_ioRank, peano4::stacks::STDVectorStack< T >::_ioTag, assertion, assertion3, assertionEquals, logDebug, logError, peano4::stacks::MPIReceive, tarch::mpi::MPIReturnValueToString(), peano4::stacks::None, and peano4::stacks::STDVectorStack< T >::toString().
void peano4::stacks::STDVectorStack< double >::startReceive | ( | peano4::grid::TraversalObserver::SendReceiveContext | , |
int | rank, | ||
int | tag, | ||
MPI_Comm | comm, | ||
int | numberOfElements ) |
Definition at line 29 of file STDVectorStack.cpp.
References assertion, assertion3, logError, logTraceInWith3Arguments, logTraceOut, and tarch::mpi::MPIReturnValueToString().
void peano4::stacks::STDVectorStack< double >::startReceive | ( | peano4::grid::TraversalObserver::SendReceiveContext | , |
int | rank, | ||
int | tag, | ||
MPI_Comm | comm, | ||
int | numberOfElements ) |
void peano4::stacks::STDVectorStack< T >::startSend | ( | peano4::grid::TraversalObserver::SendReceiveContext | context, |
int | rank, | ||
int | tag, | ||
MPI_Comm | comm ) |
Always pairs up with a finish... call.
When we trigger the send, the code still might insert additional elements, i.e. starting does not mean all the data that is to be sent out is already in the container.
Definition at line 402 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, peano4::stacks::STDVectorStack< T >::_ioMode, peano4::stacks::STDVectorStack< T >::_ioMPIRequest, peano4::stacks::STDVectorStack< T >::_ioRank, peano4::stacks::STDVectorStack< T >::_ioTag, assertion, logDebug, logError, tarch::mpi::MPIReturnValueToString(), peano4::stacks::MPISend, peano4::stacks::None, and peano4::stacks::STDVectorStack< T >::toString().
void peano4::stacks::STDVectorStack< double >::startSend | ( | peano4::grid::TraversalObserver::SendReceiveContext | , |
int | rank, | ||
int | tag, | ||
MPI_Comm | comm ) |
Definition at line 4 of file STDVectorStack.cpp.
References assertion, logError, and tarch::mpi::MPIReturnValueToString().
void peano4::stacks::STDVectorStack< double >::startSend | ( | peano4::grid::TraversalObserver::SendReceiveContext | , |
int | rank, | ||
int | tag, | ||
MPI_Comm | comm ) |
T & peano4::stacks::STDVectorStack< T >::top | ( | int | shift = 0 | ) |
Get top element or shiftth top element.
We start to count with 0, i.e. a shift of 0 (default) really returns the top element. A shift of 3 returns the fourth element from the stack
Definition at line 310 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, assertion1, and assertion2.
const T & peano4::stacks::STDVectorStack< T >::top | ( | int | shift = 0 | ) | const |
Get top element or shiftth top element.
We start to count with 0, i.e. a shift of 0 (default) really returns the top element. A shift of 3 returns the fourth element from the stack
Definition at line 321 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, assertion1, and assertion2.
std::string peano4::stacks::STDVectorStack< T >::toString | ( | ) | const |
Definition at line 533 of file STDVectorStack.h.
Referenced by peano4::stacks::STDVectorStack< T >::clone(), peano4::stacks::STDVectorStack< T >::startReceive(), peano4::stacks::STDVectorStack< T >::startSend(), and peano4::stacks::STDVectorStack< T >::tryToFinishSendOrReceive().
bool peano4::stacks::STDVectorStack< T >::tryToFinishSendOrReceive | ( | ) |
If this routine is invoked on a stack which is neither sending or receiving, then it degenerates to nop.
If it is a receiving stack, then the routine waits until all of the data is literally in. If we invoke it on a sending stack, the code checks that the send is complete, i.e. the data is either received or at least somewhere in the network. After that, it releases the underlying stack, i.e. clears it. Once this operation has terminated, the stack's state will be IOMode::None.
Definition at line 483 of file STDVectorStack.h.
References peano4::stacks::STDVectorStack< T >::_ioMode, peano4::stacks::STDVectorStack< T >::_ioMPIRequest, peano4::stacks::STDVectorStack< T >::_ioRank, peano4::stacks::STDVectorStack< T >::_ioTag, assertion, peano4::stacks::STDVectorStack< T >::clear(), logDebug, logTraceInWith4Arguments, logTraceOutWith1Argument, peano4::stacks::MPIReceive, peano4::stacks::MPISend, peano4::stacks::None, peano4::stacks::STDVectorStack< T >::size(), and peano4::stacks::STDVectorStack< T >::toString().
|
protected |
Identifies top element of stack.
In C++ style, it points to the next new element on the stack, i.e. it is the same as the stack size. Initially, it is zero.
Definition at line 93 of file STDVectorStack.h.
Referenced by peano4::stacks::STDVectorStack< T >::clear(), peano4::stacks::STDVectorStack< T >::clone(), peano4::stacks::STDVectorStack< T >::empty(), peano4::stacks::STDVectorStack< T >::operator=(), peano4::stacks::STDVectorStack< T >::pop(), peano4::stacks::STDVectorStack< T >::popBlock(), peano4::stacks::STDVectorStack< T >::push(), peano4::stacks::STDVectorStack< T >::pushBlock(), peano4::stacks::STDVectorStack< T >::size(), peano4::stacks::STDVectorStack< T >::startReceive(), peano4::stacks::STDVectorStack< T >::startSend(), peano4::stacks::STDVectorStack< T >::top(), and peano4::stacks::STDVectorStack< T >::top().
|
protected |
This is the attribute holding all the temporary stacks.
Definition at line 86 of file STDVectorStack.h.
Referenced by peano4::stacks::STDVectorStack< T >::clone(), 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(), peano4.toolbox.particles.ParticleSet.AbstractParticleSetGenerator::get_stack_container(), peano4::stacks::STDVectorStack< T >::operator=(), peano4::stacks::STDVectorStack< T >::pop(), peano4::stacks::STDVectorStack< T >::push(), peano4::stacks::STDVectorStack< T >::pushBlock(), peano4::stacks::STDVectorStack< T >::reverse(), peano4::stacks::STDVectorStack< T >::startReceive(), peano4::stacks::STDVectorStack< T >::startSend(), peano4::stacks::STDVectorStack< T >::top(), and peano4::stacks::STDVectorStack< T >::top().
|
protected |
|
protected |
Definition at line 99 of file STDVectorStack.h.
Referenced by peano4::stacks::STDVectorStack< T >::startReceive(), peano4::stacks::STDVectorStack< T >::startSend(), and peano4::stacks::STDVectorStack< T >::tryToFinishSendOrReceive().
|
protected |
|
protected |
Definition at line 97 of file STDVectorStack.h.
Referenced by peano4::stacks::STDVectorStack< T >::startReceive(), peano4::stacks::STDVectorStack< T >::startSend(), and peano4::stacks::STDVectorStack< T >::tryToFinishSendOrReceive().
|
staticprotected |
Logging device.
Definition at line 81 of file STDVectorStack.h.