Newer
Older

Christian Godenschwager
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//======================================================================================================================
//
// This file is part of waLBerla. waLBerla is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// waLBerla is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file SweepTimeloop.cpp
//! \ingroup timeloop
//! \author Martin Bauer <martin.bauer@fau.de>
//
//======================================================================================================================
#include "SweepTimeloop.h"
#include "core/Abort.h"
namespace walberla {
namespace timeloop {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////// Execution of Timeloop ////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SweepTimeloop::doTimeStep(const Set<SUID> &selectors)
{
removeForDeletionMarkedSweeps();
//iterate over all registered sweeps
for( auto sweepIt = sweeps_.begin(); sweepIt != sweeps_.end(); ++sweepIt )
{
SweepAdder & s = * ( sweepIt->second );
//select and execute before functions
for( size_t j=0; j < s.beforeFuncs.size(); ++j )
executeSelectable(s.beforeFuncs[j].selectableFunc_,selectors,"Pre-Sweep Function");
// Loop over all blocks
for( BlockStorage::iterator bi = blockStorage_.begin(); bi != blockStorage_.end(); ++bi )
{
if( s.sweep.empty() )
{
WALBERLA_ABORT("Selecting Sweep " << sweepIt->first << ": " <<
"No sweep has been registered! Did you only register a BeforeFunction or AfterFunction?" );
}
Sweep * selectedSweep = s.sweep.getUnique( selectors + bi->getState() );

Christian Godenschwager
committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
WALBERLA_LOG_PROGRESS_SECTION()
{
std::string sweepName;
s.sweep.getUnique( selectors + bi->getState(), sweepName );
WALBERLA_LOG_PROGRESS("Running sweep \"" << sweepName << "\" on block " << bi->getId() );
}
(selectedSweep->function_)( bi.get() );
}
// select and execute after functions
for( size_t j=0; j < s.afterFuncs.size(); ++j )
executeSelectable(s.afterFuncs[j].selectableFunc_,selectors,"Post-Sweep Function");
}
}
void SweepTimeloop::doTimeStep(const Set<SUID> &selectors, WcTimingPool &timing)
{
removeForDeletionMarkedSweeps();
// On first run we extract all possible names of sweeps, independent of selectors
// to register timer for them. Since all timingPools have to have the same entries on
// all processes otherwise a timingPool.reduce() does not work
// see test SweepTimeloopTimerReduction.cpp
if ( firstRun_ || timing.empty() )
{
for( auto sweepIt = sweeps_.begin(); sweepIt != sweeps_.end(); ++sweepIt )
{
SweepAdder & s = * ( sweepIt->second );
// loop over all possibilites in selectable object
for( auto it = s.sweep.begin(); it != s.sweep.end(); ++it )
timing.registerTimer( it.identifier() );
}
firstRun_ = false;
}
//iterate over all registered sweeps
for( auto sweepIt = sweeps_.begin(); sweepIt != sweeps_.end(); ++sweepIt )
{
SweepAdder & s = * ( sweepIt->second );
//select and execute before functions
for( size_t j=0; j < s.beforeFuncs.size(); ++j )
executeSelectable( s.beforeFuncs[j].selectableFunc_, selectors, "Pre-Sweep Function", timing );
for( BlockStorage::iterator bi = blockStorage_.begin(); bi != blockStorage_.end(); ++bi )
{
std::string sweepName;
Sweep * selectedSweep = s.sweep.getUnique( selectors + bi->getState(), sweepName );
if( !selectedSweep )

Christian Godenschwager
committed
WALBERLA_LOG_PROGRESS("Running sweep \"" << sweepName << "\" on block " << bi->getId() );
// loop over all blocks
timing[sweepName].start();
(selectedSweep->function_)( bi.get() );
timing[sweepName].end();
}
// select and execute after functions
for( size_t j=0; j < s.afterFuncs.size(); ++j )
executeSelectable(s.afterFuncs[j].selectableFunc_,selectors,"Post-Sweep Function", timing );
}
}
} // namespace timeloop
} // namespace walberla