Peano
Loading...
Searching...
No Matches
peano4::stacks::STDVectorStack< T > Class Template Reference

Default stack implementation using std::vector. More...

#include <STDVectorStack.h>

Inheritance diagram for peano4::stacks::STDVectorStack< T >:
Collaboration diagram for peano4::stacks::STDVectorStack< T >:

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.
 
STDVectorStackoperator= (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.
 
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.
 

Detailed Description

template<class T>
class peano4::stacks::STDVectorStack< T >

Default stack implementation using std::vector.

Visibility

The fields are protected, as there are subclasses. They usually differ "only" in the way they organise the data exchange between parallel entities.

Signature of hosted objects

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

class MyClass {
public:
enum ObjectConstruction {
NoData
};
MyClass( ObjectConstruction );
};

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.

Constructor & Destructor Documentation

◆ STDVectorStack() [1/2]

template<class T >
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.

See also
EventStack::EventStack()

Definition at line 111 of file STDVectorStack.h.

◆ ~STDVectorStack()

template<class T >
peano4::stacks::STDVectorStack< T >::~STDVectorStack ( )
default

◆ STDVectorStack() [2/2]

template<class T >
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.

Member Function Documentation

◆ clear()

template<class T >
void peano4::stacks::STDVectorStack< T >::clear ( )

◆ clone()

template<class T >
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().

Here is the call graph for this function:

◆ empty()

template<class T >
bool peano4::stacks::STDVectorStack< T >::empty ( ) const

◆ operator=()

template<class T >
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.

◆ pop()

template<class T >
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.

◆ popBlock()

template<class T >
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.

Returns
Pointer to block. Your are responsible to delete this view afterwards.

Definition at line 350 of file STDVectorStack.h.

References peano4::stacks::STDVectorStack< T >::_currentElement, and assertion.

◆ push()

template<class T >
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.

◆ pushBlock()

template<class T >
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.

Parameters
numberOfElementsSize of the view

Definition at line 372 of file STDVectorStack.h.

References peano4::stacks::STDVectorStack< T >::_currentElement, peano4::stacks::STDVectorStack< T >::_data, and assertion.

◆ reverse()

template<class T >
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.

◆ sendingOrReceiving()

template<class T >
int peano4::stacks::STDVectorStack< T >::sendingOrReceiving ( ) const

I need this one to find out whether I'm waiting for data.

Returns
A negative value if we don't send or receive anymore. Otherwise, we return the rank of the communication partner.

Definition at line 518 of file STDVectorStack.h.

References peano4::stacks::STDVectorStack< T >::_ioMode, peano4::stacks::STDVectorStack< T >::_ioRank, and peano4::stacks::None.

◆ size()

◆ startReceive() [1/3]

◆ startReceive() [2/3]

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().

Here is the call graph for this function:

◆ startReceive() [3/3]

void peano4::stacks::STDVectorStack< double >::startReceive ( peano4::grid::TraversalObserver::SendReceiveContext ,
int rank,
int tag,
MPI_Comm comm,
int numberOfElements )

◆ startSend() [1/3]

template<class T >
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().

Here is the call graph for this function:

◆ startSend() [2/3]

Definition at line 4 of file STDVectorStack.cpp.

References assertion, logError, and tarch::mpi::MPIReturnValueToString().

Here is the call graph for this function:

◆ startSend() [3/3]

◆ top() [1/2]

template<class T >
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.

◆ top() [2/2]

template<class T >
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.

◆ toString()

◆ tryToFinishSendOrReceive()

template<class T >
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.

Returns
finished send/receive already.

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().

Here is the call graph for this function:

Field Documentation

◆ _currentElement

◆ _data

template<class T >
std::vector< T > peano4::stacks::STDVectorStack< T >::_data
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().

◆ _ioMode

◆ _ioMPIRequest

◆ _ioRank

◆ _ioTag

◆ _log

template<class T >
tarch::logging::Log peano4::stacks::STDVectorStack< T >::_log
staticprotected

Logging device.

Definition at line 81 of file STDVectorStack.h.


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