Peano 4
Loading...
Searching...
No Matches
tarch::services::ServiceRepository Class Reference

Service Repository. More...

#include <ServiceRepository.h>

Inheritance diagram for tarch::services::ServiceRepository:
Collaboration diagram for tarch::services::ServiceRepository:

Data Structures

struct  ServiceEntry
 

Public Member Functions

virtual ~ServiceRepository ()
 
void addService (Service *const service, const std::string &name)
 Add a new service.
 
bool hasService (Service *service) const
 This routine is thread-safe.
 
void removeService (Service *const service)
 This routine is thread-safe, i.e.
 
virtual void receiveDanglingMessages () override
 Answer to MPI Messages.
 
std::string getListOfRegisteredServices () const
 
void init ()
 Maybe the only service that you don't have to init and shutdown.
 
virtual void shutdown () override
 
- Public Member Functions inherited from tarch::services::Service
virtual ~Service ()
 

Static Public Member Functions

static ServiceRepositorygetInstance ()
 

Private Types

typedef std::vector< ServiceEntryServiceContainer
 

Private Member Functions

 ServiceRepository ()
 

Private Attributes

ServiceContainer _services
 
tarch::multicore::RecursiveSemaphore _receiveDanglingMessagesSemaphore
 

Static Private Attributes

static tarch::services::ServiceRepository _singleton
 

Additional Inherited Members

- Protected Attributes inherited from tarch::services::Service
tarch::multicore::RecursiveSemaphore _receiveDanglingMessagesSemaphore
 Recursive semaphores.
 

Detailed Description

Service Repository.

See the interface Service for a detailed description. The registry is a service itself, but it does not register as a service.

Author
Tobias Weinzierl

Definition at line 27 of file ServiceRepository.h.

Member Typedef Documentation

◆ ServiceContainer

Definition at line 34 of file ServiceRepository.h.

Constructor & Destructor Documentation

◆ ServiceRepository()

tarch::services::ServiceRepository::ServiceRepository ( )
private

Definition at line 18 of file ServiceRepository.cpp.

◆ ~ServiceRepository()

tarch::services::ServiceRepository::~ServiceRepository ( )
virtual

Definition at line 23 of file ServiceRepository.cpp.

Member Function Documentation

◆ addService()

void tarch::services::ServiceRepository::addService ( Service *const service,
const std::string & name )

Add a new service.

This routine is thread-safe, i.e. it blocks other addService() calls as well as receiveDanglingMessages().

Parameters
servicePointer to service
nameName of service (mandatory, not empty)

Definition at line 41 of file ServiceRepository.cpp.

References tarch::services::ServiceRepository::ServiceEntry::_name, tarch::services::ServiceRepository::ServiceEntry::_service, and assertion2.

Referenced by tarch::mpi::BooleanSemaphore::BooleanSemaphoreService::init(), peano4::parallel::SpacetreeSet::init(), and exahype2::RefinementControlService::RefinementControlService().

Here is the caller graph for this function:

◆ getInstance()

tarch::services::ServiceRepository & tarch::services::ServiceRepository::getInstance ( )
static

Definition at line 36 of file ServiceRepository.cpp.

Referenced by tarch::mpi::BooleanSemaphore::BooleanSemaphoreService::acquireLock(), swift2::ParticleSpecies::allReduce(), toolbox::particles::SieveParticles< T >::exchangeSieveListsGlobally(), applications::exahype2::euler::sphericalaccretion::MassAccumulator::finishAccumulation(), peano4::parallel::SpacetreeSet::finishAllOutstandingSendsAndReceives(), applications::exahype2::euler::sphericalaccretion::SSInfall::finishTimeStep(), exahype2::RefinementControlService::freeAllPendingSendRequests(), tarch::mpi::BooleanSemaphore::BooleanSemaphoreService::init(), peano4::parallel::SpacetreeSet::init(), peano4::initSingletons(), peano4::datamanagement::CellMarker::receiveAndPollDanglingMessages(), peano4::grid::AutomatonState::receiveAndPollDanglingMessages(), peano4::grid::GridControlEvent::receiveAndPollDanglingMessages(), peano4::grid::GridStatistics::receiveAndPollDanglingMessages(), peano4::grid::GridTraversalEvent::receiveAndPollDanglingMessages(), peano4::grid::GridVertex::receiveAndPollDanglingMessages(), peano4::parallel::StartTraversalMessage::receiveAndPollDanglingMessages(), peano4::parallel::TreeEntry::receiveAndPollDanglingMessages(), peano4::parallel::TreeManagementMessage::receiveAndPollDanglingMessages(), tarch::mpi::DoubleMessage::receiveAndPollDanglingMessages(), tarch::mpi::IntegerMessage::receiveAndPollDanglingMessages(), tarch::mpi::StringMessage::receiveAndPollDanglingMessages(), toolbox::particles::ParticleSet< T >::reduceParticleStateStatistics(), toolbox::particles::ParticleSet< T >::reduceReassignmentStatistics(), exahype2::RefinementControlService::RefinementControlService(), peano4::datamanagement::CellMarker::sendAndPollDanglingMessages(), peano4::grid::AutomatonState::sendAndPollDanglingMessages(), peano4::grid::GridControlEvent::sendAndPollDanglingMessages(), peano4::grid::GridStatistics::sendAndPollDanglingMessages(), peano4::grid::GridTraversalEvent::sendAndPollDanglingMessages(), peano4::grid::GridVertex::sendAndPollDanglingMessages(), peano4::parallel::StartTraversalMessage::sendAndPollDanglingMessages(), peano4::parallel::TreeEntry::sendAndPollDanglingMessages(), peano4::parallel::TreeManagementMessage::sendAndPollDanglingMessages(), tarch::mpi::DoubleMessage::sendAndPollDanglingMessages(), tarch::mpi::IntegerMessage::sendAndPollDanglingMessages(), tarch::mpi::StringMessage::sendAndPollDanglingMessages(), peano4::parallel::Node::shutdown(), peano4::parallel::SpacetreeSet::shutdown(), tarch::mpi::BooleanSemaphore::BooleanSemaphoreService::shutdown(), peano4::shutdownSingletons(), peano4::parallel::SpacetreeSet::traverse(), and exahype2::RefinementControlService::~RefinementControlService().

Here is the caller graph for this function:

◆ getListOfRegisteredServices()

std::string tarch::services::ServiceRepository::getListOfRegisteredServices ( ) const
Returns
List of registered services separated by whitespaces

Definition at line 101 of file ServiceRepository.cpp.

◆ hasService()

bool tarch::services::ServiceRepository::hasService ( Service * service) const

This routine is thread-safe.

Definition at line 66 of file ServiceRepository.cpp.

◆ init()

void tarch::services::ServiceRepository::init ( )

Maybe the only service that you don't have to init and shutdown.

Definition at line 28 of file ServiceRepository.cpp.

Referenced by peano4::initSingletons().

Here is the caller graph for this function:

◆ receiveDanglingMessages()

void tarch::services::ServiceRepository::receiveDanglingMessages ( )
overridevirtual

Answer to MPI Messages.

Tell all registered services to answer to MPI messages that are still pending in the MPI queues.

MPI tuning

I once had an implementation that checks via Iprobe whether to call the receiveDanglingMessages() of all registered services. Without that probe, my ExaHyPE 2 code did crash. Today, I think this has been a bug in the way how parts of the code handled the requests, so I could remove the snippet again.

Starvation

From a theory point of view, it makes sense nevertheless to allow codes to do something else while receiveDanglingMessages() is called. If this routine is called, the system basically flags that there's a lack of MPI progression or poor load balancing, so the routine indeed should give a user code to do something meaningful meanwhile.

I thought it would be an excellent idea to process some tasks therefore. With a lot of tasks, this is a poor idea. Potentially p-1 threads hit the task queue (if one thread is doing I/O for example) and then they all block each other and no MPI progress is made, as very few tasks call the actual MPI routines. So I removed that line to process a task, and this has made the system much more stable.

Receive dangling message in multithreaded environment

It is important that you never ever call receiveDanglingMessages() of a service directly. Instead, you always should go to the repository. The reasons reads as follows: Most services do not protect their receiveDanglingMessages() with an additional semaphore. So two threads might hit it and both thus issue an Iprobe. Let there be one MPI message in the queue. Both probes return a true and, hence, both threads issue a receive. Unfortunately, only one of them succeeds. We could have solved that with new MPI features, but we also solve it in the old-fashioned way if you only issue receives through the repository, as the repository invokes the services, but it first blocks all other threads through a semaphore.

This routine is thread-safe compared to addService() and removeService().

Implements tarch::services::Service.

Definition at line 80 of file ServiceRepository.cpp.

References tarch::multicore::RecursiveLock::tryLock().

Referenced by tarch::mpi::BooleanSemaphore::BooleanSemaphoreService::acquireLock(), swift2::ParticleSpecies::allReduce(), toolbox::particles::SieveParticles< T >::exchangeSieveListsGlobally(), applications::exahype2::euler::sphericalaccretion::MassAccumulator::finishAccumulation(), peano4::parallel::SpacetreeSet::finishAllOutstandingSendsAndReceives(), applications::exahype2::euler::sphericalaccretion::SSInfall::finishTimeStep(), exahype2::RefinementControlService::freeAllPendingSendRequests(), peano4::datamanagement::CellMarker::receiveAndPollDanglingMessages(), peano4::grid::AutomatonState::receiveAndPollDanglingMessages(), peano4::grid::GridControlEvent::receiveAndPollDanglingMessages(), peano4::grid::GridStatistics::receiveAndPollDanglingMessages(), peano4::grid::GridTraversalEvent::receiveAndPollDanglingMessages(), peano4::grid::GridVertex::receiveAndPollDanglingMessages(), peano4::parallel::StartTraversalMessage::receiveAndPollDanglingMessages(), peano4::parallel::TreeEntry::receiveAndPollDanglingMessages(), peano4::parallel::TreeManagementMessage::receiveAndPollDanglingMessages(), tarch::mpi::DoubleMessage::receiveAndPollDanglingMessages(), tarch::mpi::IntegerMessage::receiveAndPollDanglingMessages(), tarch::mpi::StringMessage::receiveAndPollDanglingMessages(), toolbox::particles::ParticleSet< T >::reduceParticleStateStatistics(), toolbox::particles::ParticleSet< T >::reduceReassignmentStatistics(), peano4::datamanagement::CellMarker::sendAndPollDanglingMessages(), peano4::grid::AutomatonState::sendAndPollDanglingMessages(), peano4::grid::GridControlEvent::sendAndPollDanglingMessages(), peano4::grid::GridStatistics::sendAndPollDanglingMessages(), peano4::grid::GridTraversalEvent::sendAndPollDanglingMessages(), peano4::grid::GridVertex::sendAndPollDanglingMessages(), peano4::parallel::StartTraversalMessage::sendAndPollDanglingMessages(), peano4::parallel::TreeEntry::sendAndPollDanglingMessages(), peano4::parallel::TreeManagementMessage::sendAndPollDanglingMessages(), tarch::mpi::DoubleMessage::sendAndPollDanglingMessages(), tarch::mpi::IntegerMessage::sendAndPollDanglingMessages(), tarch::mpi::StringMessage::sendAndPollDanglingMessages(), peano4::parallel::Node::shutdown(), and peano4::parallel::SpacetreeSet::traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeService()

void tarch::services::ServiceRepository::removeService ( Service *const service)

This routine is thread-safe, i.e.

it blocks out receiveDanglingMessages() and all other routine which register or de-register services.

Definition at line 55 of file ServiceRepository.cpp.

Referenced by peano4::parallel::SpacetreeSet::shutdown(), tarch::mpi::BooleanSemaphore::BooleanSemaphoreService::shutdown(), and exahype2::RefinementControlService::~RefinementControlService().

Here is the caller graph for this function:

◆ shutdown()

void tarch::services::ServiceRepository::shutdown ( )
overridevirtual

Implements tarch::services::Service.

Definition at line 32 of file ServiceRepository.cpp.

Referenced by peano4::shutdownSingletons().

Here is the caller graph for this function:

Field Documentation

◆ _receiveDanglingMessagesSemaphore

tarch::multicore::RecursiveSemaphore tarch::services::ServiceRepository::_receiveDanglingMessagesSemaphore
private

Definition at line 38 of file ServiceRepository.h.

◆ _services

ServiceContainer tarch::services::ServiceRepository::_services
private

Definition at line 36 of file ServiceRepository.h.

◆ _singleton

tarch::services::ServiceRepository tarch::services::ServiceRepository::_singleton
staticprivate
See also
tarch::services::Serivce for a description how to realise singletons.

Definition at line 43 of file ServiceRepository.h.


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