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

Stack over objects, where some of the properties per object are realised through smart pointers. More...

#include <STDVectorStackOverObjectsWithSmartPointers.h>

Collaboration diagram for peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >:

Data Structures

class  PopBlockStackView
 This class represents a whole block of the tree. More...
 
class  PushBlockStackView
 

Public Member Functions

 STDVectorStackOverObjectsWithSmartPointers ()
 
 STDVectorStackOverObjectsWithSmartPointers (const STDVectorStackOverObjectsWithSmartPointers< T > &)
 
STDVectorStackOverObjectsWithSmartPointers< T > & operator= (const STDVectorStackOverObjectsWithSmartPointers< T > &stack)
 One is allowed to copy a stack but it has to be empty.
 
void clone (const STDVectorStackOverObjectsWithSmartPointers< 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)
 Start the actual send process.
 
void startReceive (peano4::grid::TraversalObserver::SendReceiveContext context, int rank, int tag, MPI_Comm comm, int numberOfElements)
 Trigger a receive.
 
bool tryToFinishSendOrReceive ()
 Finish a send or receive if it is still pending.
 
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
 

Private Types

using FlattenedContainer = std::vector< typename T::FlattenedType >
 

Private Attributes

std::vector< T > _data
 This is the attribute holding all the temporary stacks.
 
FlattenedContainer _flattenedData
 We cannot send out _data, as each element in _data hosts at least one smart pointer.
 
IOMode _ioMode
 
int _ioRank
 
int _ioTag
 
MPI_Request * _ioMPIRequest
 

Static Private Attributes

static tarch::logging::Log _log
 Logging device.
 

Detailed Description

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

Stack over objects, where some of the properties per object are realised through smart pointers.

This class is similar to the other smart pointer class, but it differs in two ways:

  1. It does not assume that there's only a smart pointer. Instead, it assumes that the manage objects on the stack all are modelled as C++ classes and some of the vectors are realised through tarch::la::SmartPointerVector.
  2. This particular class assumes that each smart pointer's memory region is known at compile time, i.e. it does not support dynamic size vectors.

Realisation

The class can be seen as a plain wrapper around std::vector. Pop and push operations actually make the std::vector increase and decrease.

Parameters
TDaStGen object that hosts a pointer which is backed up by a smart pointer, i.e. deleted as soon as noone needs it anymore. T has to provide a clone() operation but it also has to introduce a flattened variant of its own that we can use for MPI data exchange and copying.

Definition at line 52 of file STDVectorStackOverObjectsWithSmartPointers.h.

Member Typedef Documentation

◆ FlattenedContainer

template<class T >
using peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::FlattenedContainer = std::vector<typename T::FlattenedType>
private

Definition at line 64 of file STDVectorStackOverObjectsWithSmartPointers.h.

Constructor & Destructor Documentation

◆ STDVectorStackOverObjectsWithSmartPointers() [1/2]

template<class T >
peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::STDVectorStackOverObjectsWithSmartPointers ( )

◆ STDVectorStackOverObjectsWithSmartPointers() [2/2]

template<class T >
peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::STDVectorStackOverObjectsWithSmartPointers ( const STDVectorStackOverObjectsWithSmartPointers< T > &  )

Member Function Documentation

◆ clear()

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

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

Here is the caller graph for this function:

◆ clone()

Clone data into the current object on which clone() is called.

This operation overwrites the baseclass version. If we called the plain base class version, we would end up with a shallow copy. However, we want a semi-shallow copy: We replicate the meta data, and then we call the clone() of the actual vector over pointers. It is up to this routine if we craete a shallow copy or not.

Read the class documentation why I think that the clone() on the subvectors should create a deep copy. It is the section on intra-node parallelisation.

This operation has to use the default constructor of T to resize, as we want the destination data structure to be able to host the target data. So it has to issue all the news if required.

◆ empty()

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

◆ operator=()

◆ pop()

Pops element from a stack.

I have to be careful how and why I use std::move here, as we employ smart pointers. I found that a move after the return confuses the reference counting, and eventually leads to memory leaks.

◆ popBlock()

template<class T >
PopBlockStackView peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< 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.

Parameters
numberOfElementsSize of the view

◆ push()

template<class T >
void peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::push ( const T &  element)

Pushes element to a stack.

◆ pushBlock()

template<class T >
PushBlockStackView peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::pushBlock ( int  numberOfElements)

Push a block on the output stack.

Parameters
numberOfElementsSize of the view

◆ reverse()

template<class T >
void peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< 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.

◆ sendingOrReceiving()

template<class T >
int peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< 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.

◆ size()

◆ startReceive()

template<class T >
void peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::startReceive ( peano4::grid::TraversalObserver::SendReceiveContext  context,
int  rank,
int  tag,
MPI_Comm  comm,
int  numberOfElements 
)

Trigger a receive.

This is the counterpart of startSend() and hence pretty similar. We clear _data and we resize _flattenedData so that latter can take the incoming data. We know that we need that incoming data eventually within _data, but we are not there yet. After that, we issue a non-blocking receive and return.

See clone() for a description why we have to use resize() with the standard constructor here.

See also
startSend()

◆ startSend()

template<class T >
void peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::startSend ( peano4::grid::TraversalObserver::SendReceiveContext  context,
int  rank,
int  tag,
MPI_Comm  comm 
)

Start the actual send process.

Always pairs up with a tryToFinishSendOrReceive() call.

Gathering the data

We know that the data are potentially gathered all over the place on the heap subject to a smart pointer. So we first create a complete copy of all data in a container called _flattenedData. These copies are flattened data, i.e. are stored consecutively in memory.

Once we have created this flattened copy, we can delete the original data structure. We won't need it anymore. This is in line with other stacks which clear themselves after they have sent out data. See for example peano4::stacks::STDVectorStackOverSmartPointers<T>::startSend(). This clear() on the original data might not immediately lead to system frees, as other stacks might hold references to the same data on the heap.

The flattened data however has to stay there, as we only trigger a non-blocking send, i.e. the data might not have left the system yet. This flattened data are cleaned up within tryToFinishSendOrReceive().

◆ top() [1/2]

template<class T >
T & peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< 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

◆ top() [2/2]

template<class T >
const T & peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< 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

◆ toString()

template<class T >
std::string peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::toString ( ) const

◆ tryToFinishSendOrReceive()

template<class T >
bool peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::tryToFinishSendOrReceive ( )

Finish a send or receive if it is still pending.

If the stack is not in a sending or receiving state, we return immediately. Otherwise, we issue an MPI_Test to see if MPI tells us if it is done. If so, we can trigger the actual clean-up:

  • Delete the MPI Request object. We don't need it anymore.
  • Reset the IO mode to None. We are finished here.
  • If we have sent data: Clear the flattened data. It has gone out now, so there's no need for us to hold it anymore.
  • If we have received data:
    • Resize the actual _data array. This is where the incoming data has to end up eventually.
    • Copy the entries from the flattened collection over into _data one by one. For each entry, we have to unflatten the incoming data.
    • Free the flattened data. All is copied over, so we don't need it anymore.
Returns
Send or receive has completed successfully. We only return false if it is still pending and we weren't able to finish it up.

Field Documentation

◆ _data

template<class T >
std::vector<T> peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::_data
private

This is the attribute holding all the temporary stacks.

Definition at line 62 of file STDVectorStackOverObjectsWithSmartPointers.h.

Referenced by peano4.api.datamodel.DaStGen2.DaStGen2Generator::construct_output(), peano4.api.datamodel.DaStGen2.DaStGen2GeneratorForObjectsWithSmartPointers::construct_output(), peano4.api.toolbox.particles.ParticleSet.ParticleSetGenerator_ScatteredOnHeap_IndexByList::construct_output(), peano4.api.toolbox.particles.ParticleSet.ParticleSetGenerator_ScatteredOnHeap_IndexByVector::construct_output(), peano4.api.toolbox.particles.ParticleSet.ParticleSetGenerator_ContinuousPerVertex::construct_output(), peano4.api.toolbox.particles.ParticleSet.ParticleSetGenerator_GlobalContinuous::construct_output(), peano4.api.datamodel.DaStGen2.DaStGen2Generator::get_header_file_include(), peano4.api.datamodel.DaStGen2.DaStGen2GeneratorForObjectsWithSmartPointers::get_header_file_include(), peano4.api.toolbox.particles.ParticleSet.AbstractParticleSetGenerator::get_header_file_include(), peano4.api.datamodel.DaStGen2.DaStGen2Generator::get_stack_container(), peano4.api.datamodel.DaStGen2.DaStGen2GeneratorForObjectsWithSmartPointers::get_stack_container(), peano4.api.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_stack_container(), peano4.api.toolbox.particles.ParticleSet.AbstractParticleSetGenerator::get_stack_container(), peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::operator=(), and peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::PopBlockStackView::PopBlockStackView().

◆ _flattenedData

template<class T >
FlattenedContainer peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::_flattenedData
private

We cannot send out _data, as each element in _data hosts at least one smart pointer.

Definition at line 70 of file STDVectorStackOverObjectsWithSmartPointers.h.

◆ _ioMode

template<class T >
IOMode peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::_ioMode
private

Definition at line 72 of file STDVectorStackOverObjectsWithSmartPointers.h.

◆ _ioMPIRequest

template<class T >
MPI_Request* peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::_ioMPIRequest
private

Definition at line 77 of file STDVectorStackOverObjectsWithSmartPointers.h.

◆ _ioRank

template<class T >
int peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::_ioRank
private

Definition at line 73 of file STDVectorStackOverObjectsWithSmartPointers.h.

◆ _ioTag

template<class T >
int peano4::stacks::STDVectorStackOverObjectsWithSmartPointers< T >::_ioTag
private

Definition at line 74 of file STDVectorStackOverObjectsWithSmartPointers.h.

◆ _log

Logging device.

Definition at line 57 of file STDVectorStackOverObjectsWithSmartPointers.h.


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