44 #include <AMReX_ParallelDescriptor.H>
49 #include "boost/smart_ptr.hpp"
74 #include <gsl/gsl_errno.h>
76 #include <boost/filesystem.hpp>
77 #include <boost/algorithm/string/predicate.hpp>
84 void errorHandlerGSL(
const char *reason,
94 std::string noamr =
"noInitAMR";
96 for (
int i = 0; i < argc; ++i) {
97 std::string sargv = std::string(argv[i]);
98 if ( sargv.find(noamr) != std::string::npos ) {
107 int main(
int argc,
char *argv[]) {
109 gmsg =
new Inform(
"OPAL");
111 namespace fs = boost::filesystem;
123 std::string dateStr(simtimer.
date());
124 std::string timeStr(simtimer.
time());
126 H5SetVerbosityLevel(1);
128 gsl_set_error_handler(&errorHandlerGSL);
134 std::string mySpace(
" ");
138 hmsg << mySpace <<
" ____ _____ ___ " <<
endl;
139 hmsg << mySpace <<
" / __ \\| __ \\ /\\ | | " <<
endl;
140 hmsg << mySpace <<
" | | | | |__) / \\ | |" <<
endl;
141 hmsg << mySpace <<
" | | | | ___/ /\\ \\ | |" <<
endl ;
142 hmsg << mySpace <<
" | |__| | | / ____ \\| |____" <<
endl;
143 hmsg << mySpace <<
" \\____/|_| /_/ \\_\\______|" <<
endl;
147 std::string copyRight =
"(c) PSI, http://amas.web.psi.ch";
149 <<
"This is OPAL (Object Oriented Parallel Accelerator Library) Version " <<
OPAL_PROJECT_VERSION <<
"\n"
150 << std::setw(37 + gitRevision.length() / 2) << std::right << gitRevision <<
"\n\n" << endl
151 << std::setw(37 + copyRight.length() / 2) << std::right << copyRight <<
"\n\n" << endl
152 <<
"The optimiser (former opt-Pilot) is integrated " << endl
156 *gmsg <<
"OPAL compiled with DKS (Dynamic Kernel Scheduler) Version "
159 *gmsg <<
" GPU present" << endl <<
endl;
161 *gmsg <<
" GPU not present" << endl <<
endl;
164 *gmsg <<
"Please send cookies, goodies or other motivations (wine and beer ... ) \nto the OPAL developers " <<
PACKAGE_BUGREPORT <<
"\n" <<
endl;
165 *gmsg <<
"Time: " << timeStr <<
" date: " << dateStr <<
"\n" <<
endl;
172 if (!fs::exists(
"data")) {
173 boost::system::error_code error_code;
174 if (!fs::create_directory(
"data", error_code)) {
175 std::cerr << error_code.message() <<
std::endl;
181 if (!fs::is_directory(
"data")) {
182 std::cerr <<
"unable to create directory; aborting" <<
std::endl;
189 std::cout.precision(16);
190 std::cout.setf(std::ios::scientific, std::ios::floatfield);
191 std::cerr.precision(16);
192 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
208 char *startup = getenv(
"HOME");
209 boost::filesystem::path p = strncat(startup,
"/init.opal", 20);
210 if (startup != NULL && is_regular_file(p)) {
219 ERRORMSG(
"Could not open startup file \"" << startup <<
"\".\n"
220 <<
"Note: this is not mandatory for an OPAL simulation!\n");
224 *gmsg <<
"Reading startup file \"" << startup <<
"\"." <<
endl;
226 *gmsg <<
"Finished reading startup file." <<
endl;
230 *gmsg <<
"Couldn't find startup file \"" << startup <<
"\".\n"
231 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
240 std::string restartFileName;
242 for(
int ii = 1; ii < argc; ++ ii) {
243 std::string argStr = std::string(argv[ii]);
245 if (argStr == std::string(
"--input")) {
250 }
else if (argStr == std::string(
"-restart") ||
251 argStr == std::string(
"--restart")) {
256 }
else if (argStr == std::string(
"-restartfn") ||
257 argStr == std::string(
"--restartfn")) {
258 restartFileName = std::string(argv[++ ii]);
260 }
else if (argStr == std::string(
"-version") ||
261 argStr == std::string(
"--version")) {
268 std::set<std::string> uniqOptions;
269 while (options.length() > 0) {
270 size_t n = options.find_first_of(
' ');
272 options = options.substr(n + 1);
273 n = options.find_first_of(
' ');
276 uniqOptions.insert(options.substr(0, n));
277 options = options.substr(n + 1);
279 for (
auto it: uniqOptions) {
283 std::string header(
"Compile-time options: ");
284 while (options.length() > 58) {
285 std::string line = options.substr(0, 58);
286 size_t n = line.find_last_of(
' ');
287 INFOMSG(header << line.substr(0, n) <<
"\n");
289 header = std::string(22,
' ');
290 options = options.substr(n + 1);
292 INFOMSG(header << options << endl);
294 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
296 }
else if (argStr == std::string(
"-help") ||
297 argStr == std::string(
"--help")) {
299 INFOMSG(
" --version : Print a brief version summary.\n");
300 INFOMSG(
" --input <fname> : Specifies the input file <fname>.\n");
301 INFOMSG(
" --restart <n> : Performes a restart from step <n>.\n");
302 INFOMSG(
" --restartfn <fname> : Uses the file <fname> to restart from.\n");
303 INFOMSG(
" --help : Display this command-line summary.\n");
308 (ii == 1 || ii + 1 == argc) &&
309 argv[ii][0] !=
'-') {
313 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" << endl);
315 INFOMSG(
" --version : Print a brief version summary.\n");
316 INFOMSG(
" --input <fname> : Specifies the input file <fname>.\n");
317 INFOMSG(
" --restart <n> : Performes a restart from step <n>.\n");
318 INFOMSG(
" --restartfn <fname> : Uses the file <fname> to restart from.\n");
319 INFOMSG(
" --help : Display this command-line summary.\n");
327 INFOMSG(
"No input file provided!" << endl);
331 fname = std::string(argv[arg]);
332 if (!fs::exists(fname)) {
333 INFOMSG(
"Input file \"" << fname <<
"\" doesn't exist!" << endl);
340 if (restartFileName ==
"")
342 if (!fs::exists(restartFileName)) {
343 INFOMSG(
"Restart file \"" << restartFileName <<
"\" doesn't exist!" << endl);
355 *gmsg <<
"Input file \"" << fname <<
"\" not found." <<
endl;
359 *gmsg <<
"* Reading input stream \"" << fname <<
"\"." <<
endl;
361 *gmsg <<
"* End of input stream \"" << fname <<
"\"." <<
endl;
366 std::ifstream errormsg(
"errormsg.txt");
367 if(errormsg.good()) {
369 std::string closure(
" *\n");
371 <<
"* **********************************************************************************\n"
372 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
373 <<
"* **********************************************************************************"
375 errormsg.getline(buffer, 256);
376 while(errormsg.good()) {
378 if(errormsg.gcount() == 1) {
380 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
381 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
385 errormsg.getline(buffer, 256);
388 <<
"* **********************************************************************************\n"
389 <<
"* **********************************************************************************"
399 errorMsg <<
"\n*** User error detected by function \""
400 << ex.
where() <<
"\"\n";
402 std::string what = ex.
what();
403 size_t pos = what.find_first_of(
'\n');
405 errorMsg <<
" " << what.substr(0, pos) <<
endl;
406 what = what.substr(pos + 1, std::string::npos);
407 pos = what.find_first_of(
'\n');
408 }
while (pos != std::string::npos);
409 errorMsg <<
" " << what <<
endl;
411 MPI_Abort(MPI_COMM_WORLD, -100);
414 errorMsg <<
"\n*** User error detected by function \""
415 << ex.
where() <<
"\"\n";
417 std::string what = ex.
what();
418 size_t pos = what.find_first_of(
'\n');
420 errorMsg <<
" " << what.substr(0, pos) <<
endl;
421 what = what.substr(pos + 1, std::string::npos);
422 pos = what.find_first_of(
'\n');
423 }
while (pos != std::string::npos);
424 errorMsg <<
" " << what <<
endl;
426 MPI_Abort(MPI_COMM_WORLD, -100);
430 std::stringstream msg;
431 errorMsg <<
"\n*** Error detected by function \""
432 << ex.
where() <<
"\"\n";
433 std::string what = ex.
what();
434 size_t pos = what.find_first_of(
'\n');
436 errorMsg <<
" " << what.substr(0, pos) <<
endl;
437 what = what.substr(pos + 1, std::string::npos);
438 pos = what.find_first_of(
'\n');
439 }
while (pos != std::string::npos);
440 errorMsg <<
" " << what <<
endl;
442 MPI_Abort(MPI_COMM_WORLD, -100);
446 std::stringstream msg;
447 errorMsg <<
"\n*** Error detected by function \""
448 << ex.
where() <<
"\"\n";
449 std::string what = ex.
what();
450 size_t pos = what.find_first_of(
'\n');
452 errorMsg <<
" " << what.substr(0, pos) <<
endl;
453 what = what.substr(pos + 1, std::string::npos);
454 pos = what.find_first_of(
'\n');
455 }
while (pos != std::string::npos);
456 errorMsg <<
" " << what <<
endl;
458 MPI_Abort(MPI_COMM_WORLD, -100);
459 }
catch(std::bad_alloc &ex) {
461 errorMsg <<
"\n*** Error:\n";
462 errorMsg <<
" Sorry, virtual memory exhausted.\n"
466 MPI_Abort(MPI_COMM_WORLD, -100);
469 errorMsg <<
"\n*** Runtime-error ******************\n";
470 std::string what = ex.
what();
471 size_t pos = what.find_first_of(
'\n');
473 errorMsg <<
" " << what.substr(0, pos) <<
endl;
474 what = what.substr(pos + 1, std::string::npos);
475 pos = what.find_first_of(
'\n');
476 }
while (pos != std::string::npos);
477 errorMsg <<
" " << what <<
endl;
479 errorMsg <<
"\n************************************\n" <<
endl;
480 throw std::runtime_error(
"in Parser");
481 }
catch(std::exception &ex) {
485 <<
" Internal OPAL error: \n";
486 std::string what = ex.what();
487 size_t pos = what.find_first_of(
'\n');
489 errorMsg <<
" " << what.substr(0, pos) <<
endl;
490 what = what.substr(pos + 1, std::string::npos);
491 pos = what.find_first_of(
'\n');
492 }
while (pos != std::string::npos);
493 errorMsg <<
" " << what <<
endl;
495 MPI_Abort(MPI_COMM_WORLD, -100);
498 errorMsg <<
"\n*** Error:\n"
499 <<
" Unexpected exception caught.\n" <<
endl;
501 MPI_Abort(MPI_COMM_WORLD, -100);
519 amrex::Finalize(
true);
static void deleteInstance()
The global OPAL structure.
A stream of input tokens.
static void clearDictionary()
void setRestartRun(const bool &value=true)
set OPAL in restart mode
The base class for all OPAL exceptions.
bool inRestartRun()
true if we do a restart run
void storeInputFn(const std::string &fn)
store opals input filename
The default parser for OPAL-9.
virtual const char * where() const
The abstract base class for all exceptions in CLASSIC.
std::string date() const
Return date.
virtual const std::string & where() const
static OpalData * getInstance()
static void printVersion(bool=false)
static void startTimer(TimerRef t)
#define OPAL_PROJECT_VERSION
virtual const std::string & what() const
Return the message string for the exception.
static MPI_Comm getComm()
void configure()
Configure all commands.
#define OPAL_COMPILE_OPTIONS
virtual void run() const
Read current stream.
static void printHelp(char **argv)
static void setEcho(bool flag)
Set echo flag.
A stream of input tokens.
static const char * compileOptions()
std::string time() const
Return time.
int main(int argc, char *argv[])
#define PACKAGE_BUGREPORT
static void setGlobalTruncOrder(int order)
Set the global truncation order.
void storeArguments(int argc, char *argv[])
void setRestartFileName(std::string s)
store opals restart h5 format filename
std::string getGitRevision()
virtual const char * what() const
virtual const char * what() const
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
std::string getInputBasename()
get input file name without extension
static Communicate * Comm
bool checkInitAmrFlag(int argc, char *argv[])
Inform & endl(Inform &inf)
void setRestartStep(int s)
store the location where to restart
virtual const std::string & where() const
Return the name of the method or function which detected the exception.