Newer
Older

Christian Godenschwager
committed
//======================================================================================================================
//

Christoph Schwarzmeier
committed
// This file is part of waLBerla. waLBerla is free software: you can

Christian Godenschwager
committed
// redistribute it and/or modify it under the terms of the GNU General Public

Christoph Schwarzmeier
committed
// License as published by the Free Software Foundation, either version 3 of

Christian Godenschwager
committed
// the License, or (at your option) any later version.

Christoph Schwarzmeier
committed
//
// 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

Christian Godenschwager
committed
// for more details.

Christoph Schwarzmeier
committed
//

Christian Godenschwager
committed
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
// 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?" );
}

Christoph Schwarzmeier
committed
Sweep selectedSweep;
size_t numSweeps = s.sweep.get(selectedSweep, selectors + bi->getState());
// ensure that no more than one sweep has been added to a single SweepAdder object
if (numSweeps == size_t(0)) {

Christoph Schwarzmeier
committed
} else {
if (numSweeps > size_t(1)) {
WALBERLA_ABORT("Only one sweep must be added to a single SweepAdder object. This error might be caused "
"by e.g. \"timeloop.add() << Sweep(A) << Sweep(B);\".")
}
}

Christian Godenschwager
committed
WALBERLA_LOG_PROGRESS_SECTION()
{
std::string sweepName;
s.sweep.getUnique( selectors + bi->getState(), sweepName );
WALBERLA_LOG_PROGRESS("Running sweep \"" << sweepName << "\" on block " << bi->getId() );
}

Christoph Schwarzmeier
committed
(selectedSweep.function_)( bi.get() );

Christian Godenschwager
committed
}
// 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 possibilities in selectable object

Christian Godenschwager
committed
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 )
{

Christoph Schwarzmeier
committed
Sweep selectedSweep;

Christian Godenschwager
committed
std::string sweepName;

Christoph Schwarzmeier
committed
size_t numSweeps = s.sweep.get(selectedSweep, sweepName, selectors + bi->getState());

Christian Godenschwager
committed

Christoph Schwarzmeier
committed
// ensure that no more than one sweep has been added to a single SweepAdder object
if (numSweeps == size_t(0)) {

Christoph Schwarzmeier
committed
} else {
if (numSweeps > size_t(1)) {
WALBERLA_ABORT("Only one sweep must be added to a single SweepAdder object. This error might be caused "
"by e.g. \"timeloop.add() << Sweep(A) << Sweep(B);\".")
}
}

Christian Godenschwager
committed
WALBERLA_LOG_PROGRESS("Running sweep \"" << sweepName << "\" on block " << bi->getId() );
// loop over all blocks
timing[sweepName].start();

Christoph Schwarzmeier
committed
(selectedSweep.function_)( bi.get() );

Christian Godenschwager
committed
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