Peano
Loading...
Searching...
No Matches
Node.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
6#include "tarch/logging/Log.h"
9
10
11#include "TreeEntry.h"
12
13
14#include <set>
15#include <queue>
16#include <map>
17
18
19namespace peano4 {
20 namespace parallel {
21 class Node;
22
23 namespace tests {
24 class NodeTest;
25 }
26 }
27}
28
29
37 public:
38 static constexpr int Terminate = -2;
39 static constexpr int MaxSpacetreesPerRank = 1024;
40
44 static constexpr int UndefProgramStep = -1;
45 private:
47
52
54
56
62 static constexpr int StacksPerCommunicationPartner = 4;
63
64 #if !defined(Parallel)
65 typedef int MPI_Comm;
66 #endif
68
70
72
73 std::map< int, TreeEntry > _treeEntries;
74
80 Node();
81
85 Node( const Node& node ) = delete;
86
92 int getId(int rank, int localTreeId) const;
93
100 void registerId(int id, int masterId);
101
113 static std::bitset<2*Dimensions> getPeriodicBoundaryNumber(const tarch::la::Vector<TwoPowerD,int>& flags);
114 public:
118 int getLocalTreeId(int treeId) const;
119 int getGlobalTreeId(int treeId) const;
120
127 static void initMPIDatatypes();
128 static void shutdownMPIDatatypes();
129
136 static Node& getInstance();
137
141 virtual ~Node();
142
146 static bool isGlobalMaster(int treeId);
147
151 int getNumberOfRegisteredTrees() const;
152
168 int reserveId(int rank, int forTreeId);
169
175 int getRank(int treeId) const;
176
181 void deregisterId(int id);
182
188
196
201
216 typedef std::pair<int, int > PeriodicBoundaryStackIdentifier;
217
244 static std::set< PeriodicBoundaryStackIdentifier > getOutputStacksForPeriodicBoundaryExchange(const tarch::la::Vector<TwoPowerD,int>& flags);
245
246 static std::string toString( const std::set< PeriodicBoundaryStackIdentifier >& data );
247
270 static int getOutputStackForPeriodicBoundaryExchange(int faceNumber);
271
295 static int getPeriodicBoundaryExchangeInputStackNumberForOutputStack(int outputStackNumber);
297
302
306 static bool isHorizontalDataExchangeOutputStackNumber(int number);
307 static bool isHorizontalDataExchangeInputStackNumber(int number);
308
309 static bool isVerticalDataExchangeOutputStackNumber(int number);
310 static bool isVerticalDataExchangeInputStackNumber(int number);
311
312 static bool isPeriodicBoundaryExchangeOutputStackNumber(int number);
313
318 static bool isStorageStackNumber(int number);
319
325 static int getTreeNumberTiedToExchangeStackNumber(int number);
326
333 bool continueToRun();
334
340 void setNextProgramStep( int number );
341
342 int getCurrentProgramStep() const;
343
344 void init();
345
368 void shutdown();
369
370 enum class ExchangeMode {
378 };
379
380 static std::string toString( ExchangeMode mode );
381
382 typedef std::pair<int, MPI_Comm> GridDataExchangeMetaInformation;
383
395 GridDataExchangeMetaInformation getGridDataExchangeMetaInformation( int sendingTreeId, int receivingTreeId, ExchangeMode exchange ) const;
396
401 static std::string getSemanticsForTag( int tag );
402};
403
Node is Peano's abstraction for the hybrid of MPI/threads.
Definition Node.h:36
static void shutdownMPIDatatypes()
Definition Node.cpp:44
static std::bitset< 2 *Dimensions > getPeriodicBoundaryNumber(const tarch::la::Vector< TwoPowerD, int > &flags)
Analyse to which of the 2d faces it is adjacent.
Definition Node.cpp:231
static int getOutputStackForPeriodicBoundaryExchange(int faceNumber)
Identify output stack for periodic boundary data written by face.
Definition Node.cpp:250
Node()
The standard constructor assigns the attributes default values and checks whether the program is comp...
Definition Node.cpp:61
void shutdown()
The shutdown is invoked by peano4::shutdownSingletons()
Definition Node.cpp:452
static int getTreeNumberTiedToExchangeStackNumber(int number)
Gives you back the id of a communication partner, i.e.
Definition Node.cpp:413
static tarch::logging::Log _log
Logging device.
Definition Node.h:51
std::map< int, TreeEntry > _treeEntries
Definition Node.h:73
static bool isPeriodicBoundaryExchangeOutputStackNumber(int number)
Definition Node.cpp:377
static constexpr int MaxSpacetreesPerRank
Definition Node.h:39
bool continueToRun()
You should call this operation only on the ranks >0 to find out whether you should do more iteration/...
Definition Node.cpp:418
int reserveId(int rank, int forTreeId)
This operation is not const as it does some internal bookkeeping.
Definition Node.cpp:137
static bool isHorizontalDataExchangeInputStackNumber(int number)
Definition Node.cpp:393
static int getOutputStackNumberForHorizontalDataExchange(int id)
Hand in a spacetree id and get back the number that we should use to send something to this tree.
Definition Node.cpp:211
tarch::multicore::BooleanSemaphore _semaphore
Definition Node.h:55
int getLocalTreeId(int treeId) const
Definition Node.cpp:125
static int mapPeriodicBoundaryExchangeOutputStackOntoInputStack(int outputStack)
Definition Node.cpp:203
int getRank(int treeId) const
You hand in a tree number and the node tells you on which rank such a tree is hosted.
Definition Node.cpp:119
static int getInputStackNumberForHorizontalDataExchange(int id)
Counterpart of getOutputStackNumberOfBoundaryExchange(int)
Definition Node.cpp:216
static constexpr int Terminate
Definition Node.h:38
int _rankOrchestrationTag
Definition Node.h:71
int getCurrentProgramStep() const
Definition Node.cpp:447
void deregisterId(int id)
Only the SpacetreeSet should call this operation.
Definition Node.cpp:188
void registerId(int id, int masterId)
The operation is not thread-safe as we call it only internally, i.e.
Definition Node.cpp:164
static void initMPIDatatypes()
I originally wanted to embed these guys into the singleton's constructor.
Definition Node.cpp:27
std::pair< int, int > PeriodicBoundaryStackIdentifier
A periodic boundary stack is basically a stack (an integer), but I do augment it by a bitset which id...
Definition Node.h:216
int getGlobalTreeId(int treeId) const
Definition Node.cpp:131
static bool isVerticalDataExchangeOutputStackNumber(int number)
Definition Node.cpp:401
@ VerticalData
Vertical data is data running from the master to the worker and the other way round.
static bool isHorizontalDataExchangeOutputStackNumber(int number)
See getOutputStackNumberOfBoundaryExchange().
Definition Node.cpp:385
std::pair< int, MPI_Comm > GridDataExchangeMetaInformation
Definition Node.h:382
Node(const Node &node)=delete
The copy constructor is private.
static std::string toString(const std::set< PeriodicBoundaryStackIdentifier > &data)
Definition Node.cpp:262
void setNextProgramStep(int number)
The user tells the set which program step to use, i.e.
Definition Node.cpp:441
static int getOutputStackNumberForVerticalDataExchange(int id)
Definition Node.cpp:221
static Node _singleton
Definition Node.h:53
MPI_Comm _dataExchangeCommunicators[MaxSpacetreesPerRank]
Definition Node.h:67
int getNumberOfRegisteredTrees() const
Definition Node.cpp:183
virtual ~Node()
The standard destructor calls MPI_Finalize().
Definition Node.cpp:65
static std::set< PeriodicBoundaryStackIdentifier > getOutputStacksForPeriodicBoundaryExchange(const tarch::la::Vector< TwoPowerD, int > &flags)
You hand in a the flags of a vertex and you get the boundary stack identifiers including their direct...
Definition Node.cpp:282
static constexpr int StacksPerCommunicationPartner
We need one stack for outgoing data, one for incoming data, and we distinguish horizontal and vertica...
Definition Node.h:62
static int getPeriodicBoundaryExchangeInputStackNumberForOutputStack(int outputStackNumber)
Hand in an output stack number of a face and you get back the input stack number.
Definition Node.cpp:355
static bool isVerticalDataExchangeInputStackNumber(int number)
Definition Node.cpp:407
static std::string getSemanticsForTag(int tag)
I use this for debugging.
Definition Node.cpp:497
static bool isGlobalMaster(int treeId)
Is this the global master?
Definition Node.cpp:103
static bool isStorageStackNumber(int number)
There are communication stacks and storage stacks.
Definition Node.cpp:198
GridDataExchangeMetaInformation getGridDataExchangeMetaInformation(int sendingTreeId, int receivingTreeId, ExchangeMode exchange) const
I use two tags per spacetree per rank: one for boundary data (horizontal) and one for up-down and syn...
Definition Node.cpp:476
static int getInputStackNumberForVerticalDataExchange(int id)
Get the input stack where a tree writes all of its vertical data to/from when it exchanges informatio...
Definition Node.cpp:226
static constexpr int UndefProgramStep
Value for _currentProgramStep.
Definition Node.h:44
int getId(int rank, int localTreeId) const
Peano maps grid instance threads + mpi ranks onto global IDs through this routine.
Definition Node.cpp:113
static Node & getInstance()
This operation returns the singleton instance.
Definition Node.cpp:108
I test the mapping of vertex adjacency data onto stack numbers here.
Definition NodeTest.h:21
Log Device.
Definition Log.h:516
The parallel namespace is Peano's core abstracts from both MPI and multicore parallelisation.
Simple vector class.
Definition Vector.h:150