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
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
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
271
297
302
308
311
313
318 static bool isStorageStackNumber(int number);
319
326
334
340 void setNextProgramStep( int number );
341
343
355 void init();
356
418 void shutdown();
419
420 enum class ExchangeMode {
428 };
429
430 static std::string toString( ExchangeMode mode );
431
432 typedef std::pair<int, MPI_Comm> GridDataExchangeMetaInformation;
433
445 GridDataExchangeMetaInformation getGridDataExchangeMetaInformation( int sendingTreeId, int receivingTreeId, ExchangeMode exchange ) const;
446
451 static std::string getSemanticsForTag( int tag );
452};
453
Node is Peano's abstraction for the hybrid of MPI/threads.
Definition Node.h:36
static void shutdownMPIDatatypes()
Node()
The standard constructor assigns the attributes default values and checks whether the program is comp...
static int getInputStackNumberForVerticalDataExchange(int id)
Get the input stack where a tree writes all of its vertical data to/from when it exchanges informatio...
void shutdown()
Shutdown the node.
static tarch::logging::Log _log
Logging device.
Definition Node.h:51
std::map< int, TreeEntry > _treeEntries
Definition Node.h:73
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/...
void init()
Init the parallel environment.
int reserveId(int rank, int forTreeId)
This operation is not const as it does some internal bookkeeping.
static std::bitset< 2 *Dimensions > getPeriodicBoundaryNumber(const tarch::la::Vector< TwoPowerD, int > &flags)
Analyse to which of the 2d faces it is adjacent.
static int getTreeNumberTiedToExchangeStackNumber(int number)
Gives you back the id of a communication partner, i.e.
static std::string toString(ExchangeMode mode)
tarch::multicore::BooleanSemaphore _semaphore
Definition Node.h:55
int getLocalTreeId(int treeId) const
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...
static int getPeriodicBoundaryExchangeInputStackNumberForOutputStack(int outputStackNumber)
Hand in an output stack number of a face and you get back the input stack number.
int getRank(int treeId) const
You hand in a tree number and the node tells you on which rank such a tree is hosted.
static constexpr int Terminate
Definition Node.h:38
int _rankOrchestrationTag
Definition Node.h:71
virtual ~Node()
The standard destructor calls MPI_Finalize().
int getCurrentProgramStep() const
void deregisterId(int id)
Only the SpacetreeSet should call this operation.
void registerId(int id, int masterId)
The operation is not thread-safe as we call it only internally, i.e.
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
@ VerticalData
Vertical data is data running from the master to the worker and the other way round.
static bool isGlobalMaster(int treeId)
Is this the global master?
std::pair< int, MPI_Comm > GridDataExchangeMetaInformation
Definition Node.h:432
static bool isVerticalDataExchangeOutputStackNumber(int number)
static bool isPeriodicBoundaryExchangeOutputStackNumber(int number)
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...
static std::string getSemanticsForTag(int tag)
I use this for debugging.
static bool isVerticalDataExchangeInputStackNumber(int number)
Node(const Node &node)=delete
The copy constructor is private.
static Node & getInstance()
This operation returns the singleton instance.
void setNextProgramStep(int number)
The user tells the set which program step to use, i.e.
static void initMPIDatatypes()
I originally wanted to embed these guys into the singleton's constructor.
static bool isHorizontalDataExchangeOutputStackNumber(int number)
See getOutputStackNumberOfBoundaryExchange().
MPI_Comm _dataExchangeCommunicators[MaxSpacetreesPerRank]
Definition Node.h:67
static int getOutputStackNumberForVerticalDataExchange(int id)
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.
int getNumberOfRegisteredTrees() const
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 getOutputStackForPeriodicBoundaryExchange(int faceNumber)
Identify output stack for periodic boundary data written by face.
static int mapPeriodicBoundaryExchangeOutputStackOntoInputStack(int outputStack)
static bool isStorageStackNumber(int number)
There are communication stacks and storage stacks.
static PeriodicBoundaryStackIdentifier getPeriodicBoundaryExchangeInputStackNumberForOutputStack(PeriodicBoundaryStackIdentifier outputStackIdentifier)
static Node _singleton
Definition Node.h:53
static int getInputStackNumberForHorizontalDataExchange(int id)
Counterpart of getOutputStackNumberOfBoundaryExchange(int)
static bool isHorizontalDataExchangeInputStackNumber(int number)
static constexpr int UndefProgramStep
Value for _currentProgramStep.
Definition Node.h:44
static std::string toString(const std::set< PeriodicBoundaryStackIdentifier > &data)
int getId(int rank, int localTreeId) const
Peano maps grid instance threads + mpi ranks onto global IDs through this routine.
I test the mapping of vertex adjacency data onto stack numbers here.
Definition NodeTest.h:21
Log Device.
Definition Log.h:517
The parallel namespace is Peano's core abstracts from both MPI and multicore parallelisation.
Simple vector class.
Definition Vector.h:159