Peano
Loading...
Searching...
No Matches
SpacetreeSet.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include "tarch/logging/Log.h"
6
8
12
13#include "peano4/maps/maps.h"
14#include "peano4/grid/grid.h"
15
17
18#include <list>
19#include <map>
20#include <set>
21
22namespace peano4 {
23 namespace grid {
24 class Spacetree;
25 class TraversalObserver;
26 struct GridStatistics;
27 struct AutomatonState;
28 }
29
30 namespace parallel {
31 class SpacetreeSet;
32 }
33}
34
42 private:
44
46
47 std::vector<peano4::parallel::TreeManagementMessage> _unansweredMessages;
48
56 private:
61
62 public:
63 TraverseTask( peano4::grid::Spacetree& tree, SpacetreeSet& set, peano4::grid::TraversalObserver& observer, bool invertTreeTraversalDirectionBeforeWeStart );
64
69 virtual bool run() override;
70 };
71
72 public:
146 template <class Container>
147 static void exchangeAllHorizontalDataExchangeStacks( Container& stackContainer, int spacetreeId, bool symmetricDataCardinality );
148
158 template <class Container>
159 static void exchangeAllPeriodicBoundaryDataStacks( Container& stackContainer, int spacetreeId );
160
174 template <class Container>
176 Container& stackContainer,
177 int spacetreeId, int parentId
178 );
179
180 template <class Container>
181 static void deleteAllStacks(
182 Container& stackContainer,
183 int spacetreeId
184 );
185
195 template <class Container>
196 static void finishAllOutstandingSendsAndReceives( Container& stackContainer, int spacetreeId );
197
285 template <class Container>
286 static void streamDataFromSplittingTreeToNewTree( Container& stackContainer, int master, int worker );
287
288 template <class Container>
289 static void streamDataFromJoiningTreeToMasterTree( Container& stackContainer, int master, int worker );
290
291 private:
296
301
306
307 static std::string toString( SpacetreeSetState state );
308
317
324
328 std::list< peano4::grid::Spacetree > _spacetrees;
329
336
347 std::map< int, peano4::grid::TraversalObserver* > _clonedObserver;
348
350
351 const peano4::grid::Spacetree& getSpacetree(int id) const;
352
356 int getAnswerTag( int targetSpacetreeId ) const;
357
374
380 void deleteAllStacks( peano4::grid::TraversalObserver& observer, int spacetreeId );
381
432
443 void createNewTrees();
444
449
478 void addSpacetree( int masterId, int newTreeId );
479
501 int spacetreeId, int parentId,
502 const std::set<int>& joiningIds
503 );
504
517
526 std::set<int> getLocalTreesMergingWithWorkers() const;
527
538
539 SpacetreeSet();
540 SpacetreeSet(const SpacetreeSet& ) = delete;
542
543 public:
549
550 static SpacetreeSet& getInstance();
551
552
629 void answerQuestions();
630
640 virtual void receiveDanglingMessages() override;
641
646 void init(
649 const std::bitset<Dimensions>& periodicBC = 0
650 );
651
652 virtual void shutdown() override;
653
686
691
693
716 bool split(int treeId, const peano4::SplitInstruction& instruction, int targetRank);
717
722 bool isLocalSpacetree(int treeId) const;
723
727 std::set<int> getLocalSpacetrees() const;
728};
729
730#include "SpacetreeSet.cpph"
AutomatonState state
std::bitset< Dimensions > periodicBC
Definition main.cpp:19
Represents one tree.
Definition Spacetree.h:40
Each task triggers the traversal of one specific spacetree.
virtual bool run() override
I create the copy of the observer, run the traversal on my local tree _spacetree and finally destroy ...
peano4::grid::TraversalObserver & _observer
TraverseTask(peano4::grid::Spacetree &tree, SpacetreeSet &set, peano4::grid::TraversalObserver &observer, bool invertTreeTraversalDirectionBeforeWeStart)
The spacetree set has to be a singleton, as it is reponsible to accept requests for new trees from re...
void exchangeVerticalDataBetweenTrees(peano4::grid::TraversalObserver &observer)
void addSpacetree(int masterId, int newTreeId)
Adds a new spacetree to the set.
void createNewTrees()
This operation should be called pretty close towards the end of a traversal.
std::map< int, peano4::grid::TraversalObserver * > _clonedObserver
I create/clone one observer per local tree.
static void streamDataFromSplittingTreeToNewTree(Container &stackContainer, int master, int worker)
Copies (streams) data from the master to the worker.
static void exchangeAllPeriodicBoundaryDataStacks(Container &stackContainer, int spacetreeId)
Exchange periodic BC data.
SpacetreeSet & operator=(const SpacetreeSet &)=delete
peano4::grid::Spacetree & getSpacetree(int id)
static void deleteAllStacks(Container &stackContainer, int spacetreeId)
SpacetreeSet(const SpacetreeSet &)=delete
void streamLocalVertexInformationToMasterThroughVerticalStacks(int spacetreeId, int parentId, const std::set< int > &joiningIds)
Whenever we join two partitions, we have to stream data from the worker to the master.
std::set< int > getLocalTreesMergingWithWorkers() const
I need this routine for technical reasons: Prior to the sweep of trees, I have to identify all of tho...
SpacetreeSetState _state
The state identifies what the set is doing right now.
int getAnswerTag(int targetSpacetreeId) const
bool split(int treeId, const peano4::SplitInstruction &instruction, int targetRank)
Split a local tree.
int _requestMessageTag
I use this tag to identify messages send from one tree to another rank.
static std::string toString(SpacetreeSetState state)
void createObserverCloneIfRequired(peano4::grid::TraversalObserver &observer, int treeId)
Quick lookup whether an observer clone for this tree id does already exist.
int _answerMessageTag
Never use this tag directly.
virtual void receiveDanglingMessages() override
We poll the tree management messages.
void answerQuestions()
Run through the set of unanswered questions and, well, answer them.
peano4::grid::GridStatistics getGridStatistics() const
Return statistics object for primary spacetree.
std::list< peano4::grid::Spacetree > _spacetrees
These are the local spacetrees.
void init(const tarch::la::Vector< Dimensions, double > &offset, const tarch::la::Vector< Dimensions, double > &width, const std::bitset< Dimensions > &periodicBC=0)
void exchangeHorizontalDataBetweenTrees(peano4::grid::TraversalObserver &observer)
void cleanUpTrees(peano4::grid::TraversalObserver &observer)
static SpacetreeSet & getInstance()
std::set< int > getLocalSpacetrees() const
static void exchangeAllVerticalDataExchangeStacks(Container &stackContainer, int spacetreeId, int parentId)
static tarch::logging::Log _log
Logging device.
virtual void shutdown() override
static SpacetreeSet _singleton
static void finishAllOutstandingSendsAndReceives(Container &stackContainer, int spacetreeId)
This routine finishes all the sends and receives that are still active, i.e.
~SpacetreeSet()
As the setis a singleton and a service, it has to deregister itself.
static tarch::multicore::BooleanSemaphore _semaphore
Semaphore to protect container holding all the local trees.
static void exchangeAllHorizontalDataExchangeStacks(Container &stackContainer, int spacetreeId, bool symmetricDataCardinality)
Realise domain boundary exchange (over multiple scales)
bool isLocalSpacetree(int treeId) const
Codes hold one spacetree set per rank.
void streamDataFromSplittingTreesToNewTrees(peano4::grid::TraversalObserver &observer)
Copy the data from a splitting tree onto its new workers.
void traverse(peano4::grid::TraversalObserver &observer)
Invoke traverse on all spacetrees in parallel.
static void streamDataFromJoiningTreeToMasterTree(Container &stackContainer, int master, int worker)
std::vector< peano4::parallel::TreeManagementMessage > _unansweredMessages
Log Device.
Definition Log.h:516
Abstract super class for a job.
Definition Task.h:21
Service Interface.
Definition Service.h:87
The parallel namespace is Peano's core abstracts from both MPI and multicore parallelisation.
Instruction to split.
Definition grid.h:34
Simple vector class.
Definition Vector.h:134