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"
16
18
19#include <list>
20#include <map>
21#include <set>
22
23namespace peano4 {
24 namespace grid {
25 class Spacetree;
26 class TraversalObserver;
27 struct GridStatistics;
28 struct AutomatonState;
29 }
30
31 namespace parallel {
32 class SpacetreeSet;
33 }
34}
35
43 private:
45
47
48 std::vector<peano4::parallel::TreeManagementMessage> _unansweredMessages;
49
57 private:
62
63 public:
64 TraverseTask( peano4::grid::Spacetree& tree, SpacetreeSet& set, peano4::grid::TraversalObserver& observer, bool invertTreeTraversalDirectionBeforeWeStart );
65
70 virtual void run() override;
71 };
72
73 public:
147 template <class Container>
148 static void exchangeAllHorizontalDataExchangeStacks( Container& stackContainer, int spacetreeId, bool symmetricDataCardinality );
149
159 template <class Container>
160 static void exchangeAllPeriodicBoundaryDataStacks( Container& stackContainer, int spacetreeId );
161
175 template <class Container>
177 Container& stackContainer,
178 int spacetreeId, int parentId
179 );
180
181 template <class Container>
182 static void deleteAllStacks(
183 Container& stackContainer,
184 int spacetreeId
185 );
186
196 template <class Container>
197 static void finishAllOutstandingSendsAndReceives( Container& stackContainer, int spacetreeId );
198
294 template <class Container>
295 static void streamDataFromSplittingTreeToNewTree( Container& stackContainer, int master, int worker );
296
297 template <class Container>
298 static void streamDataFromJoiningTreeToMasterTree( Container& stackContainer, int master, int worker );
299
300 private:
305
310
315
316 static std::string toString( SpacetreeSetState state );
317
326
333
337 std::list< peano4::grid::Spacetree > _spacetrees;
338
346
355
362
373 std::map< int, peano4::grid::TraversalObserver* > _clonedObserver;
374
376
378
382 int getAnswerTag( int targetSpacetreeId ) const;
383
400
406 void deleteAllStacks( peano4::grid::TraversalObserver& observer, int spacetreeId );
407
458
470
475
504 void addSpacetree( int masterId, int newTreeId );
505
527 int spacetreeId, int parentId,
528 const std::set<int>& joiningIds
529 );
530
546
555 std::set<int> getLocalTreesMergingWithWorkers() const;
556
567
569 SpacetreeSet(const SpacetreeSet& ) = delete;
571
572 public:
578
580
581
659
669 virtual void receiveDanglingMessages() override;
670
675 void init(
678 const std::bitset<Dimensions>& periodicBC = 0
679 );
680
681 virtual void shutdown() override;
682
715
735
743
779 bool split(int treeId, const peano4::SplitInstruction& instruction, int targetRank);
780
785 bool isLocalSpacetree(int treeId) const;
786
790 std::set<int> getLocalSpacetrees() const;
791};
792
793#include "SpacetreeSet.cpph"
Represents one tree.
Definition Spacetree.h:40
Each task triggers the traversal of one specific spacetree.
virtual void 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...
const peano4::grid::Spacetree & getSpacetree(int id) const
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.
SpacetreeSet & operator=(const SpacetreeSet &)=delete
peano4::grid::Spacetree & getSpacetree(int id)
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.
static void streamDataFromJoiningTreeToMasterTree(Container &stackContainer, int master, int worker)
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.
static void finishAllOutstandingSendsAndReceives(Container &stackContainer, int spacetreeId)
This routine finishes all the sends and receives that are still active, i.e.
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 void exchangeAllVerticalDataExchangeStacks(Container &stackContainer, int spacetreeId, int parentId)
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.
peano4::grid::GridStatistics sumUpLocalGridStatistics() const
Sum up the statistics of all local trees.
void answerQuestions()
Run through the set of unanswered questions and, well, answer them.
peano4::grid::GridStatistics getGridStatistics() const
Return the grid statistics of the whole mesh.
std::list< peano4::grid::Spacetree > _spacetrees
These are the local spacetrees.
static void exchangeAllPeriodicBoundaryDataStacks(Container &stackContainer, int spacetreeId)
Exchange periodic BC data.
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)
peano4::grid::GridStatistics getGridStatistics(int treeId) const
Return the statistics of one local tree.
void cleanUpTrees(peano4::grid::TraversalObserver &observer)
Clean up empty trees.
void deleteAllStacks(peano4::grid::TraversalObserver &observer, int spacetreeId)
I do this after a join/after I've removed an empty tree.
static SpacetreeSet & getInstance()
static std::string toString(SpacetreeSetState state)
static SpacetreeSet _singleton
static void deleteAllStacks(Container &stackContainer, int spacetreeId)
std::set< int > getLocalSpacetrees() const
virtual void receiveDanglingMessages() override
We poll the tree management messages.
static tarch::logging::Log _log
Logging device.
~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.
virtual void shutdown() override
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.
peano4::grid::GridStatistics _gridStatistics
Grid statistics over all trees on all ranks.
static void streamDataFromSplittingTreeToNewTree(Container &stackContainer, int master, int worker)
Copies (streams) data from the master to the worker.
std::vector< peano4::parallel::TreeManagementMessage > _unansweredMessages
Log Device.
Definition Log.h:517
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:159