MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
Environment Class Reference

Environment for the program. More...

#include <environment.h>

Collaboration diagram for Environment:
[legend]

Public Member Functions

 Environment (int, char **)
 
 ~Environment ()
 Destructor. More...
 
MInt run ()
 Runs the Environment, makes the Application run. More...
 
MInt end ()
 Ends the Environment. More...
 

Static Public Attributes

static MInt m_argc
 Reads the name of the property-file and creates a new Application. More...
 
static MChar ** m_argv
 

Private Member Functions

void parseCommandline ()
 Reads out the options that where used by the program call. More...
 

Static Private Member Functions

static void printStartupInformation ()
 Print startup summary of MAIA. More...
 

Private Attributes

ApplicationmApplication
 
ScratchmScratch
 
MString m_propertyFileInput = "properties.toml"
 

Detailed Description

Date
begin: 03.01.20 change 00.00.00

Definition at line 21 of file environment.h.

Constructor & Destructor Documentation

◆ Environment()

Environment::Environment ( int  ,
char **   
)

◆ ~Environment()

Environment::~Environment ( )

Definition at line 142 of file environment.cpp.

142 {
144 delete mScratch;
145 if(mApplication != nullptr) delete mApplication;
146}
Application * mApplication
Definition: environment.h:33
Scratch * mScratch
Definition: environment.h:34
static MString printSelf()
Returns a string summing up the scratch state information and all scratch space elements information.
Definition: scratch.cpp:106
InfoOutFile m_log

Member Function Documentation

◆ end()

MInt Environment::end ( )

Definition at line 179 of file environment.cpp.

179 {
180 TRACE();
181
182#ifdef MAIA_WRITE_ACCESS_PROPERTIES_FILE
184#endif
185 return 0;
186}
static void writePropertiesHumanReadable()
Write the properties into a text file.
Definition: context.cpp:600

◆ parseCommandline()

void Environment::parseCommandline ( )
private

Definition at line 190 of file environment.cpp.

190 {
191 TRACE();
192
193#if defined(MAIA_MS_COMPILER) || defined(_SX)
194#pragma message("WARNING: Not implemented!")
195#else
196 opterr = 0;
197 while(true) {
198 int c = 0;
199 DIR* directory = nullptr;
200 string inputDirectory;
201 string outputDirectory;
202 int option_index = 0;
203 static option long_options[] = {
204 {"debug", 1, 0, 'd'}, {"help", 0, 0, 'h'}, {"input", 1, 0, 'i'}, {"output", 1, 0, 'o'},
205 {"version", 0, 0, 'v'}, {"compiler", 0, 0, 'c'}, {"build-type", 0, 0, 'b'}, {0, 0, 0, 0}};
206
207 c = getopt_long(m_argc, m_argv, "d:hi:o:p:vcb", long_options, &option_index);
208 if(c == -1) {
209 break;
210 }
211
212 switch(c) {
213 case 0:
214 cout << "option " << long_options[option_index].name << endl;
215 if(optarg != nullptr) cout << "with arg " << optarg << endl;
216 cout << endl;
217 break;
218
219 case 'd':
220 if(atoi(optarg) < 2 * MDebug::m_maxLevel && atoi(optarg) >= MDebug::m_minLevel) {
221 SET_DEBUG_LEVEL((MDebugLevel)atoi(optarg));
222 if(globalDomainId() == 0) {
223 cout << "SET DEBUG LEVEL TO: " << atoi(optarg) << endl;
224 }
225 m_log << "SET DEBUG LEVEL TO: " << atoi(optarg) << endl;
226 DEBUG("Environment::parseCommandline: option -d " << atoi(optarg), MAIA_DEBUG_IO);
227 } else {
228 cerr << "Error: debug level out of range!" << endl;
229 cerr << "Specified debug level is " << atoi(optarg) << ", but must be in the range of " << endl;
230 cerr << 2 * MDebug::m_minLevel << " <= debug level <= " << 2 * MDebug::m_maxLevel << endl;
231 cerr << "Debug level is unchanged" << endl;
232 return;
233 }
234 break;
235
236 case 'h':
237 cout << "usage: " << m_argv[0] << " [-h] [-b] [-c] [--debug LEVEL] [--input DIRECTORY] "
238 << "[--output DIRECTORY] [-v] [PROPERTY_FILE]" << endl
239 << endl
240 << "positional arguments:" << endl
241 << " PROPERTY_FILE name of property file to use (default: '" << m_propertyFileInput << "')\n"
242 << endl
243 << "optional arguments:\n"
244 << " -b, --build-type show build type that was used\n"
245 << " -c, --compiler show used compiler\n"
246 << " -d, --debug LEVEL use specified debug level\n"
247 << " -h, --help this help screen\n"
248 << " -i, --input DIRECTORY specified directory is used for all "
249 "input files\n"
250 << " -o, --output DIRECTORY specified directory is used for all "
251 "output files\n"
252 << " -v, --version show MAIA version\n"
253 << endl;
254 m_log.close();
255 maia_res.close();
256 MPI_Finalize();
257 exit(0);
258 break;
259
260 case 'i':
261 directory = opendir(optarg);
262 if(directory != nullptr) {
263 closedir(directory);
264 inputDirectory.append(optarg);
265 DEBUG("Environment::parseCommandline: option -i " << optarg, MAIA_DEBUG_IO);
266 } else {
267 stringstream errorMessage;
268 errorMessage << " error opening inputDirectory \"" << optarg << "\"!" << endl;
269 mTerm(1, AT_, errorMessage.str());
270 }
271 break;
272
273 case 'o':
274 directory = opendir(optarg);
275 if(directory != nullptr) {
276 closedir(directory);
277 outputDirectory.append(optarg);
278 DEBUG("Environment::parseCommandline: option -o " << optarg, MAIA_DEBUG_IO);
279 } else {
280 stringstream errorMessage;
281 errorMessage << "Error opening outputDirectory \"" << optarg << "\"!";
282 mTerm(1, AT_, errorMessage.str());
283 }
284 break;
285
286 case 'v':
287// Show version and quit
288#ifndef MAIA_VERSION_STRING
289#define MAIA_VERSION_STRING unknown
290#endif
291 cout << XSTRINGIFY(MAIA_VERSION_STRING) << endl;
292 m_log.close();
293 maia_res.close();
294 MPI_Finalize();
295 exit(0);
296 break;
297
298 case 'c':
299// Show used compiler and quit
300#ifndef MAIA_COMPILER_STRING
301#define MAIA_COMPILER_STRING unknown
302#endif
303 cout << XSTRINGIFY(MAIA_COMPILER_STRING) << endl;
304 m_log.close();
305 maia_res.close();
306 MPI_Finalize();
307 exit(0);
308 break;
309
310 case 'b':
311// Show used build type and quit
312#ifndef MAIA_BUILD_TYPE_STRING
313#define MAIA_BUILD_TYPE_STRING unknown
314#endif
315 cout << XSTRINGIFY(MAIA_BUILD_TYPE_STRING) << endl;
316 m_log.close();
317 maia_res.close();
318 MPI_Finalize();
319 exit(0);
320 break;
321
322 case '?':
323 break;
324
325 default:
326 cerr << "Environment::parseCommandline: Error getopt returned "
327 "unkown option code \""
328 << c << "\"" << endl;
329 }
330 }
331
332 // Obtain command line argument for property file
333 if(optind < m_argc) {
334 m_propertyFileInput = m_argv[optind];
335 }
336 // On domain 0, check if file is readable
337 if(globalDomainId() == 0 && !ifstream(m_propertyFileInput)) {
338 TERMM(1, "property file '" + m_propertyFileInput + "' not readable");
339 }
340#endif
341}
static MChar ** m_argv
Definition: environment.h:29
MString m_propertyFileInput
Definition: environment.h:38
static MInt m_argc
Reads the name of the property-file and creates a new Application.
Definition: environment.h:28
void close(MBool forceClose=false)
Pass the close call to the respective internal buffer.
Definition: infoout.cpp:1011
static const MInt m_minLevel
Definition: debug.h:191
static const MInt m_maxLevel
Definition: debug.h:192
enum { MAIA_DEBUG_ASSERTION=1, MAIA_DEBUG_IO=2, MAIA_DEBUG_ALLOCATION=4, MAIA_DEBUG_TRACE=8, MAIA_DEBUG_TRACE_IN=16, MAIA_DEBUG_TRACE_OUT=32, MAIA_DEBUG_LEVEL1=64, MAIA_DEBUG_LEVEL2=128, MAIA_DEBUG_LEVEL3=256, MAIA_DEBUG_LEVEL4=512, MAIA_DEBUG_LEVEL5=1024, MAIA_DEBUG_USER1=2048, MAIA_DEBUG_USER2=4096, MAIA_DEBUG_USER3=8192, MAIA_DEBUG_USER4=16384, MAIA_DEBUG_USER5=32768 } MDebugLevel
This enum holds the error levels of the DEBUG class.
Definition: debug.h:131
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
MInt globalDomainId()
Return global domain id.
InfoOutFile maia_res

◆ printStartupInformation()

void Environment::printStartupInformation ( )
staticprivate
Author
Michael Schlottke-Lakemper (mic) mic@a.nosp@m.ia.r.nosp@m.wth-a.nosp@m.ache.nosp@m.n.de
Date
2016-09-19

This method prints some information to stdout that may be useful for debugging purposes later (and to identify which stdout logs belong to which MAIA run).

Definition at line 352 of file environment.cpp.

352 {
353 // Define buffer size
354 const MInt bufferSize = 1024;
355
356 // Get current hostname
357 array<char, bufferSize> host_{};
358 gethostname(&host_[0], bufferSize - 1);
359 host_[bufferSize - 1] = '\0';
360 const MString host(&host_[0]);
361
362 // Get current username
363 MString user = "(unknown user)";
364#if defined(MAIA_MS_COMPILER)
365 constexpr MInt INFO_BUFFER_SIZE = 32767;
366 TCHAR infoBuf[INFO_BUFFER_SIZE];
367 DWORD bufCharCount = INFO_BUFFER_SIZE;
368 if(GetUserName(infoBuf, &bufCharCount)) {
369 user = infoBuf;
370 }
371#else
372 passwd* p;
373 p = getpwuid(getuid());
374 if(p) {
375 user = MString(p->pw_name);
376 }
377#endif
378
379 // Get current directory
380 array<char, bufferSize> dir_{};
381#if defined(MAIA_MS_COMPILER)
382 _getcwd(&dir_[0], bufferSize - 1);
383#else
384 if(getcwd(&dir_[0], bufferSize - 1) == nullptr) {
385 TERM(-1);
386 }
387#endif
388 dir_[bufferSize - 1] = '\0';
389 const MString dir(&dir_[0]);
390
391 // Get current execution command and command line arguments
392 const MString executable(m_argv[0]);
393 stringstream ss;
394 if(m_argc > 1) {
395 ss << MString(m_argv[0]);
396 for(MInt n = 1; n < m_argc; n++) {
397 ss << " " << MString(m_argv[n]);
398 }
399 } else {
400 ss << "(none)";
401 }
402 const MString args(ss.str());
403
404 // Create start timestamp
405 array<char, bufferSize> dateString_{};
406 time_t rawTime = 0;
407
408 // Get the current time and write it to rawTime
409 time(&rawTime);
410
411 // Convert to time struct
412 tm* timeInfo = localtime(&rawTime);
413
414 // Format time to string and save to buffer
415 strftime(&dateString_[0], bufferSize, "%Y-%m-%d %H:%M:%S", timeInfo);
416
417 // Store date as real string
418 const MString dateString(&dateString_[0]);
419
420 // Print startup information
421 cout << " _____ ______ ________ ___ ________ \n"
422 " ____|\\ _ \\ _ \\ |\\ __ \\ |\\ \\ |\\ __ \\ ___ \n"
423 " ___\\ \\ \\\\\\__\\ \\ \\\\ \\ \\|\\ \\\\ \\ \\\\ \\ \\|\\ \\ ___ \n"
424 " ___\\ \\ \\\\|__| \\ \\\\ \\ __ \\\\ \\ \\\\ \\ __ \\ ___ \n"
425 " ___\\ \\ \\ \\ \\ \\\\ \\ \\ \\ \\\\ \\ \\\\ \\ \\ \\ \\ ___ \n"
426 " ___\\ \\__\\ \\ \\__\\\\ \\__\\ \\__\\\\ \\__\\\\ \\__\\ \\__\\ ___ \n"
427 " ___\\|__| \\|__| \\|__|\\|__| \\|__| \\|__|\\|__| ____ \n"
428 "\n";
429 cout << "Start time: " << dateString << "\n"
430 << "Number of ranks: " << globalNoDomains() << "\n"
431#ifdef _OPENMP
432 << "Number of OMP threads: " << omp_get_max_threads() << "\n"
433#endif
434 << "Host (of rank 0): " << host << "\n"
435 << "Working directory: " << dir << "\n"
436 << "User: " << user << "\n"
437 << "Executable: " << executable << "\n"
438 << "Command line args: " << args << "\n"
439 << endl;
440}
MInt globalNoDomains()
Return global number of domains.
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
constexpr std::underlying_type< FcCell >::type p(const FcCell property)
Converts property name to underlying integer value.

◆ run()

MInt Environment::run ( )

Definition at line 149 of file environment.cpp.

149 {
150 Profile runProfile("Environment::run");
151
154
155 TRACE();
156
157 MBool flowSolver = false;
158 flowSolver = Context::getBasicProperty<MBool>("flowSolver", AT_, &flowSolver);
159
160 // Return here if flow solver is not enabled.
161 if(!flowSolver) {
162 return 0;
163 }
164
165 MInt nDim = read_nDim();
166
167 if(nDim == 2) {
168 mApplication->run<2>();
169 } else if(nDim == 3) {
170 mApplication->run<3>();
171 } else {
172 mTerm(1, AT_, "Invalid value of nDim!");
173 }
174
175 return 0;
176}
static void communicateProperties()
Communicates properties to check if default falues match.
Definition: context.cpp:773
static void initializationProcessFinished()
Sets flag to forbide property access.
Definition: context.cpp:745
This class collects all function timings and produces a profiling for certain areas of the code.
Definition: timer.h:679
bool MBool
Definition: maiatypes.h:58

Member Data Documentation

◆ m_argc

MInt Environment::m_argc
static

Definition at line 28 of file environment.h.

◆ m_argv

MChar ** Environment::m_argv
static

Definition at line 29 of file environment.h.

◆ m_propertyFileInput

MString Environment::m_propertyFileInput = "properties.toml"
private

Definition at line 38 of file environment.h.

◆ mApplication

Application* Environment::mApplication
private

Definition at line 33 of file environment.h.

◆ mScratch

Scratch* Environment::mScratch
private

Definition at line 34 of file environment.h.


The documentation for this class was generated from the following files: