Peano 4
Loading...
Searching...
No Matches
toolbox::particles::SieveParticles< T > Class Template Reference

Utility class for all flavours of particle sets. More...

#include <SieveParticles.h>

Collaboration diagram for toolbox::particles::SieveParticles< T >:

Public Types

typedef T DoFType
 
typedef std::list< T * > ParticleList
 

Public Member Functions

void exchangeSieveListsGlobally ()
 Get all the global sieve data consistent.
 
void addParticleThatCanNotBeLiftedWithinItsTree (T *)
 Add a particle to the list of particles which cannot be lifted.
 
ParticleList getParticlesToBeSievedIntoVertex (const peano4::datamanagement::VertexMarker &marker, bool removeReturnedParticlesFromSet, bool onlyReturnParticlesThatWillBeLocal)
 Get particles that are to be sieved into one vertex.
 
bool hasParticlesToBeSievedIntoVertices () const
 Fine out how many particles still to sieve.
 
int getNumberOfParticlesThatHaveBeSievedIntoVertices () const
 hasParticlesToBeSievedIntoVertices() is equivalent to checking if this routine returns something greater than 0.
 

Static Private Member Functions

static void deleteParticles (ParticleList &list)
 

Private Attributes

ParticleList _particlesThatCanNotBeLiftedWithinTheirTree
 
ParticleList _particlesThatHaveToBeSieved
 Particles that should be sieved.
 

Static Private Attributes

static tarch::logging::Log _log
 
static int _SieveReductionTag
 Reduction tag.
 
static tarch::multicore::BooleanSemaphore _particlesThatCanNotBeLiftedWithinTheirTreeSemaphore
 This is for the assembly of the set of particles which require global (sieve) data exchange.
 
static tarch::multicore::BooleanSemaphore _particlesToBeSievedSemaphore
 

Detailed Description

template<typename T>
class toolbox::particles::SieveParticles< T >

Utility class for all flavours of particle sets.

Particle sets differ in the way they actually manage the particles. However, they all share common stats, operations, ... This is covered by this class. The class is used by toolbox.particles.ParticleSet which usually holds multiple of these classes for different purposes.

There's a problem here however: Most of these fields are static fields and hence cannot be modelled as static. If we have them static, they are tied to the base object, not the the particular particle type. However, the fact that we work with templates rides to our rescue. We can assume that this base class is instantiated per particle type. Therefore, all of its static fields are unique again. Along these discussions, this base class is more of an aspect rather than a real base class. The number of real functions and attributes is negligible.

An alternative implementation would make this a real class and let the actual particles sets holds a static attribute of this class. I think that would be a valid implementation, too.

Definition at line 47 of file SieveParticles.h.

Member Typedef Documentation

◆ DoFType

template<typename T >
typedef T toolbox::particles::SieveParticles< T >::DoFType

Definition at line 49 of file SieveParticles.h.

◆ ParticleList

template<typename T >
typedef std::list<T*> toolbox::particles::SieveParticles< T >::ParticleList

Definition at line 51 of file SieveParticles.h.

Member Function Documentation

◆ addParticleThatCanNotBeLiftedWithinItsTree()

template<typename T >
void toolbox::particles::SieveParticles< T >::addParticleThatCanNotBeLiftedWithinItsTree ( T * p)

Add a particle to the list of particles which cannot be lifted.

You hand over the pointer to the sieve list. That is, nothing is copied, but the responsibility for this object, from now on, resides with the sieve list. It will eventually delete the particle. Therefore you should not maintain any pointer to the particle anymore once you hand it over to the sieve list.

The routine is thread-safe. The object does not keep any kind of statistics. You have to maintain stats on your own if you need them. However, it only uses the lock, i.e. is thread-safe for originatingTree==GlobalSort.

Definition at line 139 of file SieveParticles.cpph.

◆ deleteParticles()

template<typename T >
void toolbox::particles::SieveParticles< T >::deleteParticles ( ParticleList & list)
staticprivate

Definition at line 27 of file SieveParticles.cpph.

◆ exchangeSieveListsGlobally()

template<typename T >
void toolbox::particles::SieveParticles< T >::exchangeSieveListsGlobally ( )

Get all the global sieve data consistent.

Has to be called after the traversal has finished on each rank by the main, i.e. do not call it within the action sets. You may not call this routine more than once per rank per traversal. The core purpose of this routine is to get the global sieve data all consistent: If a tree cannot resort its local particles, and, hence, cannot even synchronise with its neighbours as particles moved too fast, it dumps the particle into the global sieve list. After the traversal, all ranks (and eventually trees) should see the same global sieve list and start to sieve particles into their respective domain.

Algorithmic steps

  • Delete all the sieve particles which have not been sieved. We note that only particles within the domain are taken from the sieve set and inserted into the mesh. For particles close to domain boundaries, we create copies and insert these copies. The preimage consequently has to be deleted at one point, i.e. here in this routine.
  • Inform all other ranks about my number of local particles that I could not sort on the local rank.
  • Per other rank:
    • Find out how many particles will be received from this partner.
    • Send out my own copy of particles with an unblocking send.
    • Receive the guys from the neighbour. We can append these received data directly to our local data. We will use these local buffers to send out stuff to other neighbours, but as we append, we will only send out the first few particles which really stem from the local node.
    • Wrap up the unblocking send via a wait. It is important that we allow the rank to handle other (unexpected) message while we wait for the particle exchange to terminate. This is possible, as we use a tag of its own for the global particle exchange. Without a wait for unexpected messages, it could for example be that another rank requires a tree booking due to load balancing, and we cannot serve the tree request in our rank, as we are already stuck in the global particle exchange.
  • We roll over the globally lifted particles into the sieve set for the next mesh traversal.
  • Remove duplicates from the sieve list. The sieve list might contain redundant particles for those guys which ended up exactly on the boundary between two trees. Such guys are considered to be local in multiple subdomains and hence might also end up redundantly within the sieve list.
  • Clear the container _particlesThatCanNotBeLiftedWithinTheirTree which will be used in the future to gather the newly sieved particles.

Definition at line 36 of file SieveParticles.cpph.

References tarch::mpi::Rank::getCommunicator(), tarch::mpi::Rank::getInstance(), tarch::services::ServiceRepository::getInstance(), tarch::mpi::Rank::getNumberOfRanks(), tarch::mpi::Rank::getRank(), tarch::mpi::IntegerMessage::getValue(), logDebug, tarch::mpi::IntegerMessage::receiveAndPollDanglingMessages(), tarch::services::ServiceRepository::receiveDanglingMessages(), tarch::mpi::IntegerMessage::sendAndPollDanglingMessages(), tarch::mpi::Rank::setDeadlockTimeOutTimeStamp(), tarch::mpi::Rank::setDeadlockWarningTimeStamp(), tarch::mpi::Rank::triggerDeadlockTimeOut(), and tarch::mpi::Rank::writeTimeOutWarning().

Here is the call graph for this function:

◆ getNumberOfParticlesThatHaveBeSievedIntoVertices()

template<typename T >
int toolbox::particles::SieveParticles< T >::getNumberOfParticlesThatHaveBeSievedIntoVertices ( ) const

hasParticlesToBeSievedIntoVertices() is equivalent to checking if this routine returns something greater than 0.

Definition at line 145 of file SieveParticles.cpph.

◆ getParticlesToBeSievedIntoVertex()

template<typename T >
toolbox::particles::SieveParticles< T >::ParticleList toolbox::particles::SieveParticles< T >::getParticlesToBeSievedIntoVertex ( const peano4::datamanagement::VertexMarker & marker,
bool removeReturnedParticlesFromSet,
bool onlyReturnParticlesThatWillBeLocal )

Get particles that are to be sieved into one vertex.

Takes the current particle set and finds those particles which can be sieved into current vertex. The operation alters the object state of particleList, as it returns the particles that are to be sieved and removes them from the current set.

In line with peano4.toolbox.particles.Particle, we do not alter the parallel state. That's the job of whoever calls this routine. Most action sets (notably our sorting action sets) will invoke the boundary merger and this merger will then take care of the parallel flag.

All the particles in the result set are assigned the correct mesh size h of the corresponding mesh into which we sieve it. So this attribute is changed.

Thread safety

This routine is not static, i.e. we assume it works on a thread-local list of particles. This thread-local list is typically constructed as deep copy of the global sieve list. getSievedParticlesForNextGridTraversal() provides these deep copy semantics. Since we work with a copy of the global particles per thread, there's no need to add semaphores. We are inherently thread-safe. However, we have to delete all left-over particles which have not been sieved by a local thread. As the list had been a deep copy, we'd otherwise create a memory leak.

See also
getSievedParticlesForNextGridTraversal() for the deep copy and the roll-over of particles that cannot be lifted into particles that have to be sieved.
toolbox::particles::sieveParticle() for the sieve logic.
deleteParticles() for the deletion of deep copies.
Parameters
originatingTreeNumber of tree (positive integer) or GlobalSort. It indicates where the particles should come from, i.e. are they form a specific tree or some particles that we have to sort globally.
removeReturnedParticlesFromSetIf this field is set, we remove the particles from the underlying set before we return them. That is, the underlying set on which we call getParticlesToBeSievedIntoVertex() shrinks monotonously. If you set it to false, the particles will reside within the set, but the set will eventually delete them, as it updates its content globally. Therefore, you should not use the returned particles directly but rather create copies.

Definition at line 157 of file SieveParticles.cpph.

References logDebug, toolbox::particles::particleAssignedToVertexWillBeLocal(), and toolbox::particles::sieveParticle().

Here is the call graph for this function:

◆ hasParticlesToBeSievedIntoVertices()

template<typename T >
bool toolbox::particles::SieveParticles< T >::hasParticlesToBeSievedIntoVertices ( ) const

Fine out how many particles still to sieve.

If you ask how many particles we have to sieve, you will receive the ones that have not been sieved so far. Therefore, this routine can not be used for any statistics after a grid sweep to find out how many sieves have been done.

Definition at line 151 of file SieveParticles.cpph.

Field Documentation

◆ _log

template<typename T >
tarch::logging::Log toolbox::particles::SieveParticles< T >::_log
staticprivate

Definition at line 194 of file SieveParticles.h.

◆ _particlesThatCanNotBeLiftedWithinTheirTree

template<typename T >
ParticleList toolbox::particles::SieveParticles< T >::_particlesThatCanNotBeLiftedWithinTheirTree
private

Definition at line 213 of file SieveParticles.h.

◆ _particlesThatCanNotBeLiftedWithinTheirTreeSemaphore

template<typename T >
tarch::multicore::BooleanSemaphore toolbox::particles::SieveParticles< T >::_particlesThatCanNotBeLiftedWithinTheirTreeSemaphore
staticprivate

This is for the assembly of the set of particles which require global (sieve) data exchange.

When we later on sieve the particles into their target vertices, we need another semaphore of its own.

Definition at line 210 of file SieveParticles.h.

◆ _particlesThatHaveToBeSieved

template<typename T >
ParticleList toolbox::particles::SieveParticles< T >::_particlesThatHaveToBeSieved
private

Particles that should be sieved.

This is a set of particles which should be sieved in the next traversal. However, nobody takes particles directly from this list. Instead, tasks will work with their own clones of this list.

See also
getSievedParticlesForNextGridTraversal()

The list is populated by finishedTraversal().

Definition at line 226 of file SieveParticles.h.

◆ _particlesToBeSievedSemaphore

template<typename T >
tarch::multicore::BooleanSemaphore toolbox::particles::SieveParticles< T >::_particlesToBeSievedSemaphore
staticprivate

Definition at line 211 of file SieveParticles.h.

◆ _SieveReductionTag

template<typename T >
int toolbox::particles::SieveParticles< T >::_SieveReductionTag
staticprivate
Initial value:
"toolbox::particles::"
"SieveParticles<T>::_"
"SieveReductionTag"
)
static int reserveFreeTag(const std::string &fullQualifiedMessageName, int numberOfTags=1)
Return a Free Tag.
Definition Rank.cpp:39

Reduction tag.

We one of these per subclass, i.e. I cannot move it to the superclass

Definition at line 203 of file SieveParticles.h.


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