Peano 4
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include "MyObserver.h"
2
3#include "tarch/logging/Log.h"
8#include "tarch/mpi/Rank.h"
9
10#include "peano4/peano.h"
14
15
16tarch::logging::Log _log("examples::grid");
17
18
19std::bitset<Dimensions> periodicBC = 0;
20
21#include "peano4/UnitTests.h"
22#include "tarch/UnitTests.h"
23
24
25void runTests() {
26 int unitTestsErrors = 0;
27 tarch::tests::TestCase* tests = nullptr;
28
29 tests = tarch::getUnitTests();
30 tests->run();
31 unitTestsErrors += tests->getNumberOfErrors();
32 delete tests;
33
34 tests = peano4::getUnitTests();
35 tests->run();
36 unitTestsErrors += tests->getNumberOfErrors();
37 delete tests;
38
39 if (unitTestsErrors != 0) {
40 logError("main()", "unit tests failed. Quit.");
42 }
43}
44
45
46
47void runSerial() {
48 examples::grid::MyObserver emptyObserver;
49
51#if Dimensions==2
52 {0.0, 0.0},
53 {1.0, 1.0},
54#else
55 {0.0, 0.0, 0.0},
56 {1.0, 1.0, 1.0},
57#endif
59 );
60
61
62 // You wouldn't do this usually. We always work against the set.
64#if Dimensions==2
65 {0.0, 0.0},
66 {1.0, 1.0}
67#else
68 {0.0, 0.0, 0.0},
69 {1.0, 1.0, 1.0}
70#endif
71 );
72
73
76
77 #if PeanoDebug>0
78 emptyObserver.beginTraversalOnRank(false);
79 #endif
80 spacetree.traverse( emptyObserver );
81 #if PeanoDebug>0
82 emptyObserver.endTraversalOnRank(false);
83 #endif
84
85 logInfo( "runSerial(...)", "grid statistics = " << spacetree.getGridStatistics().toString() );
86 }
87
88
89 peano4::grid::TraversalVTKPlotter plotterObserver( "grid-serial" );
90 spacetree.traverse( plotterObserver );
91
93}
94
95
97 static int phase = 0;
98
99 int targetRank = (phase+1) % tarch::mpi::Rank::getInstance().getNumberOfRanks();
100
101 if (phase==0) {
102 const int spacetreeOfInterest = 0;
103
105 if (
107 and
108 peano4::parallel::SpacetreeSet::getInstance().split(0,peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()/3,targetRank)
109 and
110 peano4::parallel::SpacetreeSet::getInstance().split(0,peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()/3,targetRank)
111 ) {
112 logInfo( "updateDomainDecomposition()", "split rank 0 into 1 and 2 -> success" );
113 phase++;
114 }
115 }
116 else phase++;
117 }
118 else if (
119 phase==1
120 and
121 peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()>=ThreePowerD*2
122 ) {
123 const int spacetreeOfInterest = 1;
124
125 if ( peano4::parallel::SpacetreeSet::getInstance().isLocalSpacetree(spacetreeOfInterest) ) {
126 if ( not peano4::parallel::SpacetreeSet::getInstance().split(1,peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()/3/3,targetRank) ) {
127 logInfo( "updateDomainDecomposition()", "split rank 1 -> failed" );
128 phase++;
129 }
130 else {
131 logInfo( "updateDomainDecomposition()", "split rank 1 -> success" );
132 }
133 }
134 else phase++;
135 }
136 else if (
137 phase==2
138 and
139 peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()>=ThreePowerD*4
140 ) {
141 const int spacetreeOfInterest = periodicBC==0 ? 1 : 0;
142 if ( peano4::parallel::SpacetreeSet::getInstance().isLocalSpacetree(spacetreeOfInterest) ) {
144 spacetreeOfInterest,
145 peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()/3/3/3,targetRank)
146 ) {
147 phase++;
148 }
149 }
150 else phase++;
151 }
152 else if (
153 phase==3
154 and
155 peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()>=ThreePowerD*6
156 ) {
157 const int spacetreeOfInterest = 2;
158 if ( peano4::parallel::SpacetreeSet::getInstance().isLocalSpacetree(spacetreeOfInterest) ) {
159 if ( not peano4::parallel::SpacetreeSet::getInstance().split(2,peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()/3/3/3/3,targetRank) ) {
160 phase++;
161 }
162 }
163 else phase++;
164 }
165 else if (
166 phase==4
167 and
168 peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()>=ThreePowerD*8
169 ) {
170 const int spacetreeOfInterest = 2;
171 if ( peano4::parallel::SpacetreeSet::getInstance().isLocalSpacetree(spacetreeOfInterest) ) {
172 if ( not peano4::parallel::SpacetreeSet::getInstance().split(spacetreeOfInterest,peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()/3/3/3/3/3,targetRank) ) {
173 phase++;
174 }
175 }
176 else phase++;
177 }
178 else if (
179 phase==5
180 and
181 peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().getNumberOfLocalUnrefinedCells()>=ThreePowerD*10
182 ) {
183 const int spacetreeOfInterest = 1;
184 if ( peano4::parallel::SpacetreeSet::getInstance().isLocalSpacetree(spacetreeOfInterest) ) {
185 if ( not peano4::parallel::SpacetreeSet::getInstance().split(1,10,targetRank) ) {
186 phase++;
187 }
188 }
189 else phase++;
190 }
191}
192
193
196#if Dimensions==2
197 {0.0, 0.0},
198 {1.0, 1.0},
199#else
200 {0.0, 0.0, 0.0},
201 {1.0, 1.0, 1.0},
202#endif
204 );
205
206 examples::grid::MyObserver emptyObserver;
207
208 if (tarch::mpi::Rank::getInstance().isGlobalMaster() ) {
212 #if PeanoDebug>0
213 emptyObserver.beginTraversalOnRank(true);
214 #endif
216 #if PeanoDebug>0
217 emptyObserver.endTraversalOnRank(true);
218 #endif
219
220 logInfo( "runParallel(...)", "grid statistics = " << peano4::parallel::SpacetreeSet::getInstance().getGridStatistics().toString() );
221
223 }
224
225 logInfo( "runParallel(...)", "terminated successfully" );
226 }
227 else { // not the global master
228 while (peano4::parallel::Node::getInstance().continueToRun()) {
229 assertionEquals( peano4::parallel::Node::getInstance().getCurrentProgramStep(), 14 );
230
232
233 #if PeanoDebug>0
234 emptyObserver.beginTraversalOnRank(true);
235 #endif
237 #if PeanoDebug>0
238 emptyObserver.endTraversalOnRank(true);
239 #endif
240 }
241 }
242
244}
245
246
247int main(int argc, char** argv) {
248 const int ExitCodeSuccess = 0;
249 const int ExitCodeUnitTestsFailed = 1;
250
253
256 ));
259 ));
262 ));
265 ));
268 ));
271 ));
273
275
276 runTests();
277
278 if (argc==2) {
279 periodicBC = std::atoi( argv[1] );
280 }
281 else {
282 srand( time(NULL) );
283 periodicBC = 0;
284 for (int i=0; i<Dimensions; i++) {
285 periodicBC[i] = rand() < RAND_MAX / 5;
286 }
287 logInfo( "main(...)", "use a random periodic boundary condition choice: " << periodicBC );
288 }
289
290 #if defined(Parallel) or defined(SharedMemoryParallelisation)
291 runParallel();
292 #else
293 runSerial();
294 #endif
295
297
298 return 0;
299}
#define assertionEquals(lhs, rhs)
#define ThreePowerD
Definition Globals.h:24
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
void runSerial()
Definition main.cpp:47
int main(int argc, char **argv)
Main routine of the SPH code.
Definition main.cpp:247
std::bitset< Dimensions > periodicBC
Definition main.cpp:19
void runTests()
Definition main.cpp:25
void runParallel()
Definition main.cpp:194
tarch::logging::Log _log("examples::grid")
void updateDomainDecomposition()
Definition main.cpp:96
static constexpr int GridRefinementIterations
Definition MyObserver.h:28
static constexpr int StationaryIterations
Definition MyObserver.h:29
Represents one tree.
Definition Spacetree.h:40
Observer which pipes the automaton transitions into a VTK file.
void setNextProgramStep(int number)
The user tells the set which program step to use, i.e.
Definition Node.cpp:441
static Node & getInstance()
This operation returns the singleton instance.
Definition Node.cpp:108
bool split(int treeId, const peano4::SplitInstruction &instruction, int targetRank)
Split a local tree.
peano4::grid::GridStatistics getGridStatistics() const
Return statistics object for primary spacetree.
static SpacetreeSet & getInstance()
bool isLocalSpacetree(int treeId) const
Codes hold one spacetree set per rank.
void traverse(peano4::grid::TraversalObserver &observer)
Invoke traverse on all spacetrees in parallel.
void closeOutputStreamAndReopenNewOne()
The command line logger can pipe debug data into an output file instead of piping everything to the t...
static CommandLineLogger & getInstance()
void setOutputFile(const std::string &outputLogFileName)
Is redundant, as you could use setLogFormat() instead.
void addFilterListEntry(const FilterListEntry &entry)
Add one filter list entry.
static LogFilter & getInstance()
Log Device.
Definition Log.h:516
int getNumberOfRanks() const
Definition Rank.cpp:551
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
static void abort(int errorCode)
A proper abort in an MPI context has to use MPI_Abort.
Definition Rank.cpp:591
static Core & getInstance()
Definition Core.cpp:55
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:60
Represents one test case.
Definition TestCase.h:57
std::string toString(Filter filter)
Definition convert.cpp:170
tarch::tests::TestCase * getUnitTests()
Please destroy after usage.
Definition UnitTests.cpp:11
void shutdownSingletons()
The very first thing I have to do is to shut down Node.
Definition peano.cpp:155
void fillLookupTables()
Fill Lookup Tables.
Definition peano.cpp:92
int initParallelEnvironment(int *argc, char ***argv)
Init Parallel Environment.
Definition peano.cpp:106
void initSingletons(const tarch::la::Vector< Dimensions, double > &offset, const tarch::la::Vector< Dimensions, double > &width, const std::bitset< Dimensions > &periodicBC=0)
Fire up all the singletons.
Definition peano.cpp:138
void shutdownParallelEnvironment()
Shutdown all the parallel environment, i.e.
Definition peano.cpp:132
tarch::tests::TestCase * getUnitTests()
Please destroy after usage.
Definition UnitTests.cpp:17
Represents one entry of the filter list.
Definition LogFilter.h:30
static const std::string TargetTrace
Definition LogFilter.h:36
static const std::string TargetDebug
Definition LogFilter.h:35
static const std::string TargetInfo
Definition LogFilter.h:34