Peano 4
Loading...
Searching...
No Matches
UserInterface.cpp
Go to the documentation of this file.
1#include "UserInterface.h"
2
5#include "tarch/mpi/Rank.h"
6
9
12
13#include "peano4/peano.h"
14
15namespace {
16 tarch::logging::Log _log( "swift2" );
17
19}
20
21
23 return ::enableDynamicLoadBalancing;
24}
25
26
31 "",
34 ));
38 "",
41 ));
45 "",
48 ));
49
53 "peano4",
56 ));
60 "peano4",
63 ));
67 "peano4",
70 ));
71
75 "tarch",
78 ));
82 "tarch",
85 ));
89 "tarch",
92 ));
93
97 "swift2",
100 ));
104 "swift2",
107 ));
111 "swift2",
114 ));
115
119 "toolbox",
122 ));
126 "toolbox",
129 ));
133 "toolbox",
136 ));
137}
138
139
140void swift2::printUsage(char** argv) {
141 std::cout << "Usage: ./" << argv[0] << " [options]" << std::endl <<
142"SWIFT 2 - an experimental rewrite of SPH With Inter-dependent Fine-grained Tasking \n\
143Original code: https://swift.dur.ac.uk/ \n\
144\n \
145Options: \n\
146 -h, --help Display help on commandline options. \n\
147 --threads no Specify how many threads to use (per rank). Option \n\
148 has no meaning if code base has not been \n\
149 translated with shared memory support. Not all \n\
150 runtimes allow you to set the thread count via the \n\
151 code. \n\
152 --gpus filter Specify which GPUs to use. Option has no meaning \n\
153 if code base has not been translated with gpu \n\
154 support. Pass in comma-separated list (3,4,9) to \n\
155 select which GPUs to use. If argument is empty, ExaHyPE \n\
156 may use all GPUs. If you want to use all GPUs, hand \n\
157 in all as argument. \n\
158 --log-filter-file file Specify which log filter file to use. Default file \n\
159 is exahype.log-filter \n\
160 --timeout t Set timeout. t is given in seconds and can be 0 to \n\
161 switch timeouts off. \n\
162 --threading-model t Set threading model. \n\
163 --dynamic-load-balancing [on|off] Disable or enable dynamic load balancing. Pass \n\
164 either on or off. The default is on. \n\
165\n\n\n\
166Supported threading models: " << tarch::multicore::orchestration::getListOfRealisations() << std::endl;
167}
168
169
170bool swift2::parseCommandLineArguments(int argc, char** argv) {
171 if (
172 (argc==2 and std::string(argv[1]).compare( "--help" )!=std::string::npos)
173 or
174 (argc==2 and std::string(argv[1]).compare( "-h" )!=std::string::npos)
175 or
176 (argc%2!=1)
177 ) {{
178 printUsage(argv);
179 return false;
180 }}
181
182 std::string logFilterFile = "swift2.log-filter";
184 std::set<int> gpuDevices;
185
186 for (int argument=1; argument<argc; argument+=2) {
187 std::string select = argv[argument];
188
189 if ( select.compare( "--threads" ) ==0 ) {
190 cores = std::atoi(argv[argument+1]);
191 logInfo( "parseCommandLineArguments(...)", "manually reset number of used cores to " << cores );
192 }
193 else if ( select.compare( "--gpus" ) ==0 ) {
194 std::string specifier = argv[argument+1];
195 std::string delimiter = ",";
196 if ( specifier.compare( "all" ) ==0 ) {
197 logInfo( "parseCommandLineArguments(...)", "enable all devices" );
198 }
199 else if (specifier.find( delimiter ) == std::string::npos) {
200 int gpu = std::atoi(specifier.c_str());
201 gpuDevices.insert(gpu);
202 logInfo( "parseCommandLineArguments(...)", "enable only GPU " << gpu );
203 }
204 else {
205 size_t pos = 0;
206 std::string token;
207 while ((pos = specifier.find(delimiter)) != std::string::npos) {
208 token = specifier.substr(0, pos);
209 int gpu = std::atoi(token.c_str());
210 gpuDevices.insert(gpu);
211 specifier.erase(0, pos + delimiter.length());
212 }
213
214 logInfo( "parseCommandLineArguments(...)", "manually set GPU filter with " << gpuDevices.size() << " devices enabled" );
215 }
216 }
217 else if ( select.compare( "--log-filter-file" ) == 0 ) {
218 logFilterFile = argv[argument+1];
219 }
220 else if ( select.compare( "--timeout" ) == 0 ) {
221 int timeout = std::atoi(argv[argument+1]);
223 logInfo( "parseCommandLineArguments(...)", "manually set timeout to " << timeout );
224 }
225 else if ( select.compare( "--threading-model" ) == 0 ) {
226 auto* realisation = tarch::multicore::orchestration::parseRealisation( argv[argument+1] );
227 if (realisation!=nullptr) {
229 }
230 else {
231 logError( "parseCommandLineArguments(...)", "was not able to set threading strategy " << argv[argument+1] );
232 return false;
233 }
234 }
235 else if ( select.compare( "--dynamic-load-balancing" ) == 0 ) {
236 std::string value = argv[argument+1];
237 if (value==std::string("on")) {
238 enableDynamicLoadBalancing = true;
239 }
240 else if (value==std::string("off")) {
241 enableDynamicLoadBalancing = false;
242 }
243 else {
244 logError( "parseCommandLineArguments(...)", "load balancing value has to be on or off. Value had been " << value );
245 return false;
246 }
247 }
248 else {
249 printUsage(argv);
250 return false;
251 }
252 }
253
256
258 logWarning( "main()", "no exahype.log-filter file found or file has been corrupted. Use default logging configuration" );
260 }
261
262 return true;
263}
264
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:440
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
static Device & getInstance()
void configure(const std::set< int > &devicesToUse={})
static bool parsePlainTextFile(const std::string &filename)
Tries to parse a simple text file where each line contains an entry.
void addFilterListEntry(const FilterListEntry &entry)
Add one filter list entry.
static LogFilter & getInstance()
Log Device.
Definition Log.h:516
void setDeadlockTimeOut(int valueInSeconds)
Set deadlock time out.
Definition Rank.cpp:565
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
static constexpr int UseDefaultNumberOfThreads
The default is what the system management typically gives you.
Definition Core.h:69
static Core & getInstance()
Definition Core.cpp:55
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:60
bool enableDynamicLoadBalancing()
Find out if user has enabled dynamic load balancing or not.
void setDefaultLogStatements()
bool parseCommandLineArguments(int argc, char **argv)
void printUsage(char **argv)
Strategy * parseRealisation(const std::string &realisation)
Parse the realisation string.
void setOrchestration(tarch::multicore::orchestration::Strategy *realisation)
Definition Tasks.cpp:159
tarch::logging::Log _log("examples::unittests")
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
static const std::string AlwaysOn
Definition LogFilter.h:39