Peano
Loading...
Searching...
No Matches
UserInterface.cpp
Go to the documentation of this file.
1#include "UserInterface.h"
2
6#include "tarch/mpi/Rank.h"
7
10
11#include "peano4/peano.h"
12
13namespace {
14 tarch::logging::Log _log( "swift2" );
15
17}
18
19
21 return ::enableDynamicLoadBalancing;
22}
23
24
30 "",
33 ));
37 "",
40 ));
44 "",
47 ));
48
52 "peano4",
55 ));
59 "peano4",
62 ));
66 "peano4",
69 ));
70
74 "tarch",
77 ));
81 "tarch",
84 ));
88 "tarch",
91 ));
92
96 "swift2",
99 ));
103 "swift2",
106 ));
110 "swift2",
113 ));
114
118 "toolbox",
121 ));
125 "toolbox",
128 ));
132 "toolbox",
135 ));
136}
137
138
139void swift2::printUsage(char** argv) {
140 std::cout << "Usage: ./" << argv[0] << " [options]" << std::endl <<
141"SWIFT 2 - an experimental rewrite of SPH With Inter-dependent Fine-grained Tasking \n\
142Original code: https://swift.dur.ac.uk/ \n\
143\n \
144Options: \n\
145 -h, --help Display help on commandline options. \n\
146 --threads no Specify how many threads to use (per rank). Option \n\
147 has no meaning if code base has not been \n\
148 translated with shared memory support. Not all \n\
149 runtimes allow you to set the thread count via the \n\
150 code. \n\
151 --gpus filter Specify which GPUs to use. Option has no meaning \n\
152 if code base has not been translated with gpu \n\
153 support. Pass in comma-separated list (3,4,9) to \n\
154 select which GPUs to use. If argument is empty, ExaHyPE \n\
155 may use all GPUs. If you want to use all GPUs, hand \n\
156 in all as argument. \n\
157 --log-filter-file file Specify which log filter file to use. Default file \n\
158 is exahype.log-filter \n\
159 --timeout t Set timeout. t is given in seconds and can be 0 to \n\
160 switch timeouts off. \n\
161 --threading-model t Set threading model. \n\
162 --dynamic-load-balancing [on|off] Disable or enable dynamic load balancing. Pass \n\
163 either on or off. The default is on. \n\
164\n\n\n\
165" << std::endl;
166}
167
168
169bool swift2::parseCommandLineArguments(int argc, char** argv) {
170 if (
171 (argc==2 and std::string(argv[1]).compare( "--help" )!=std::string::npos)
172 or
173 (argc==2 and std::string(argv[1]).compare( "-h" )!=std::string::npos)
174 or
175 (argc%2!=1)
176 ) {{
177 printUsage(argv);
178 return false;
179 }}
180
181 std::string logFilterFile = "swift2.log-filter";
183 std::set<int> gpuDevices;
184
185 for (int argument=1; argument<argc; argument+=2) {
186 std::string select = argv[argument];
187
188 if ( select.compare( "--threads" ) ==0 ) {
189 cores = std::atoi(argv[argument+1]);
190 logInfo( "parseCommandLineArguments(...)", "manually reset number of used cores to " << cores );
191 }
192 else if ( select.compare( "--gpus" ) ==0 ) {
193 std::string specifier = argv[argument+1];
194 std::string delimiter = ",";
195 if ( specifier.compare( "all" ) ==0 ) {
196 logInfo( "parseCommandLineArguments(...)", "enable all devices" );
197 }
198 else if (specifier.find( delimiter ) == std::string::npos) {
199 int gpu = std::atoi(specifier.c_str());
200 gpuDevices.insert(gpu);
201 logInfo( "parseCommandLineArguments(...)", "enable only GPU " << gpu );
202 }
203 else {
204 size_t pos = 0;
205 std::string token;
206 while ((pos = specifier.find(delimiter)) != std::string::npos) {
207 token = specifier.substr(0, pos);
208 int gpu = std::atoi(token.c_str());
209 gpuDevices.insert(gpu);
210 specifier.erase(0, pos + delimiter.length());
211 }
212
213 logInfo( "parseCommandLineArguments(...)", "manually set GPU filter with " << gpuDevices.size() << " devices enabled" );
214 }
215 }
216 else if ( select.compare( "--log-filter-file" ) == 0 ) {
217 logFilterFile = argv[argument+1];
218 }
219 else if ( select.compare( "--timeout" ) == 0 ) {
220 int timeout = std::atoi(argv[argument+1]);
222 logInfo( "parseCommandLineArguments(...)", "manually set timeout to " << timeout );
223 }
224 else if ( select.compare( "--dynamic-load-balancing" ) == 0 ) {
225 std::string value = argv[argument+1];
226 if (value==std::string("on")) {
227 enableDynamicLoadBalancing = true;
228 }
229 else if (value==std::string("off")) {
230 enableDynamicLoadBalancing = false;
231 }
232 else {
233 logError( "parseCommandLineArguments(...)", "load balancing value has to be on or off. Value had been " << value );
234 return false;
235 }
236 }
237 else {
238 printUsage(argv);
239 return false;
240 }
241 }
242
245
247 logWarning( "main()", "no exahype.log-filter file found or file has been corrupted. Use default logging configuration" );
249 }
250
251 return true;
252}
253
#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:566
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
static constexpr int UseDefaultNumberOfThreads
The default is what the system management typically gives you.
Definition Core.h:69
static Core & getInstance()
Definition Core.cpp:56
void configure(int numberOfThreads=UseDefaultNumberOfThreads)
Configure the whole node, i.e.
Definition Core.cpp:61
tarch::logging::Log _log("exahype2::fv")
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)
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