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
57
58
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//======================================================================================================================
//
// 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 TimeloopAndSweepRegister.cpp
//! \ingroup timeloop
//! \author Martin Bauer <martin.bauer@fau.de>
//! \brief test cases that test the registering of Sweeps at timeloop
//
//======================================================================================================================
#include "timeloop/SweepTimeloop.h"
#include "core/DataTypes.h"
#include "core/debug/TestSubsystem.h"
#include "core/logging/Logging.h"
#include <string>
#include <vector>
using namespace std;
using namespace walberla;
class GeneralSweep
{
public:
GeneralSweep(const string & name, vector<string> & vec)
: myName(name), outVec(vec)
{}
void operator() (IBlock * ){
outVec.push_back(myName);
}
private:
string myName;
vector<string> & outVec;
};
class GeneralFunction
{
public:
GeneralFunction(const string & name, vector<string> & vec)
: myName(name), outVec(vec)
{}
void operator() (){
outVec.push_back(myName);
}
private:
string myName;
vector<string> & outVec;
};
int main()
{
debug::enterTestMode();
vector<string> expectedSequence;
vector<string> sequence;
SUID cpuSelect("CPU");
SUID gpuSelect("GPU");
SUID srtSelect("SRT");
SUID mrtSelect("MRT");
//FIXME put a real test in here
shared_ptr<SweepTimeloop> tl = make_shared<SweepTimeloop>(shared_ptr<BlockStorage>(),100);
typedef SweepTimeloop::SweepHandle SH;
SH sweep1 = tl->addSweep( GeneralSweep("CPU1",sequence), cpuSelect);
tl->addSweep(sweep1, GeneralSweep("GPU1",sequence), gpuSelect);
SH sweep2 = tl->addSweep( GeneralSweep("CPU2",sequence), cpuSelect);
tl->addSweep(sweep2, GeneralSweep("GPU2",sequence), gpuSelect);
tl->addFuncBeforeSweep(sweep1,GeneralFunction("Pre1",sequence));
tl->addFuncAfterSweep (sweep1,GeneralFunction("Post1",sequence));
tl->addFuncBeforeSweep(sweep2,GeneralFunction("Pre2",sequence));
tl->addFuncAfterSweep (sweep2,GeneralFunction("Post2",sequence));
typedef Timeloop::FctHandle FH;
FH preTs = tl->addFuncBeforeTimeStep( GeneralFunction("PreTimestepCPU",sequence),cpuSelect,srtSelect);
tl->addFuncBeforeTimeStep(preTs, GeneralFunction("PreTimestepGPU",sequence),gpuSelect,srtSelect);
FH postTs = tl->addFuncAfterTimeStep ( GeneralFunction("PostTimestepCPU",sequence),cpuSelect,mrtSelect);
tl->addFuncAfterTimeStep (postTs,GeneralFunction("PostTimestepGPU",sequence),gpuSelect,mrtSelect);
//---------- First Run - CPU Selector ---------------------------------------------
expectedSequence.push_back("PreTimestepCPU");
expectedSequence.push_back("Pre1");
expectedSequence.push_back("CPU1");
expectedSequence.push_back("Post1");
expectedSequence.push_back("Pre2");
expectedSequence.push_back("CPU2");
expectedSequence.push_back("Post2");
expectedSequence.push_back("PostTimestepCPU");
tl->singleStep(cpuSelect);
WALBERLA_CHECK_EQUAL(expectedSequence.size(), sequence.size());
WALBERLA_CHECK( equal(expectedSequence.begin(),expectedSequence.end(), sequence.begin() ) );
expectedSequence.clear();
sequence.clear();
// ------------ Second Run - GPU Selector -------------------------------------------
expectedSequence.push_back("PreTimestepGPU");
expectedSequence.push_back("Pre1");
expectedSequence.push_back("GPU1");
expectedSequence.push_back("Post1");
expectedSequence.push_back("Pre2");
expectedSequence.push_back("GPU2");
expectedSequence.push_back("Post2");
expectedSequence.push_back("PostTimestepGPU");
tl->singleStep(gpuSelect);
WALBERLA_CHECK_EQUAL(expectedSequence.size(), sequence.size());
WALBERLA_CHECK( equal(expectedSequence.begin(),expectedSequence.end(), sequence.begin() ) );
expectedSequence.clear();
sequence.clear();
// ------------ Second Run - GPU and SRT -------------------------------------------
expectedSequence.push_back("Pre1");
expectedSequence.push_back("GPU1");
expectedSequence.push_back("Post1");
expectedSequence.push_back("Pre2");
expectedSequence.push_back("GPU2");
expectedSequence.push_back("Post2");
expectedSequence.push_back("PostTimestepGPU");
tl->singleStep(gpuSelect + srtSelect);
WALBERLA_CHECK_EQUAL(expectedSequence.size(), sequence.size());
WALBERLA_CHECK( equal(expectedSequence.begin(),expectedSequence.end(), sequence.begin() ) );
expectedSequence.clear();
sequence.clear();
return 0;
}