39 #include <AMReX_ParallelDescriptor.H>
50 #include <gsl/gsl_errno.h>
52 #include <boost/system/error_code.hpp>
64 #ifdef DONT_DEFINE_IPPL_GMSG
75 void printStdoutHeader() {
77 std::string dateStr(simtimer.
date());
78 std::string timeStr(simtimer.
time());
79 std::string mySpace(
" ");
81 *gmsg << mySpace <<
" ____ _____ ___ " <<
endl;
82 *gmsg << mySpace <<
" / __ \\| __ \\ /\\ | | " <<
endl;
83 *gmsg << mySpace <<
" | | | | |__) / \\ | |" <<
endl;
84 *gmsg << mySpace <<
" | | | | ___/ /\\ \\ | |" <<
endl ;
85 *gmsg << mySpace <<
" | |__| | | / ____ \\| |____" <<
endl;
86 *gmsg << mySpace <<
" \\____/|_| /_/ \\_\\______|" <<
endl;
89 std::string copyRight =
"(c) PSI, http://amas.web.psi.ch";
91 <<
"This is OPAL (Object Oriented Parallel Accelerator Library) Version " <<
OPAL_PROJECT_VERSION <<
"\n"
92 << std::setw(37 + gitRevision.length() / 2) << std::right << gitRevision <<
"\n\n" << endl
93 << std::setw(37 + copyRight.length() / 2) << std::right << copyRight <<
"\n\n" << endl
94 <<
"The optimiser (former opt-Pilot) is integrated " << endl
97 *gmsg <<
"Please send cookies, goodies or other motivations (wine and beer ... ) \nto the OPAL developers " <<
PACKAGE_BUGREPORT <<
"\n" <<
endl;
98 *gmsg <<
"Time: " << timeStr <<
" date: " << dateStr <<
"\n" <<
endl;
102 ::printStdoutHeader();
105 INFOMSG(
"Usage: opal [<option> <option> ...]\n");
106 INFOMSG(
" The possible values for <option> are:\n");
107 INFOMSG(
" --version : Print the version of opal.\n");
108 INFOMSG(
" --version-full : Print the version of opal with additional informations.\n");
109 INFOMSG(
" --git-revision : Print the revision hash of the repository.\n");
110 INFOMSG(
" --input <fname> : Specifies the input file <fname>.\n");
111 INFOMSG(
" --restart <n> : Performes a restart from step <n>.\n");
112 INFOMSG(
" --restartfn <fname> : Uses the file <fname> to restart from.\n");
114 INFOMSG(
" --noInitAMR : Disable initialization of AMR\n");
117 INFOMSG(
" --help-command <command> : Display the help for the command <command>\n");
118 INFOMSG(
" --help : Display this command-line summary.\n");
125 std::string noamr =
"noInitAMR";
127 for (
int i = 0; i < argc; ++i) {
128 std::string sargv = std::string(argv[i]);
129 if ( sargv.find(noamr) != std::string::npos ) {
137 int opalMain(
int argc,
char *argv[]);
139 int main(
int argc,
char *argv[]) {
142 new Ippl(argc, argv);
143 gmsg =
new Inform(
"OPAL");
150 namespace fs = std::filesystem;
160 H5SetVerbosityLevel(1);
172 std::cout.precision(16);
173 std::cout.setf(std::ios::scientific, std::ios::floatfield);
174 std::cerr.precision(16);
175 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
189 std::error_code error_code;
191 std::cerr << error_code.message() <<
std::endl;
198 std::cerr <<
"unable to create directory; aborting" <<
std::endl;
209 char *startup = getenv(
"HOME");
210 std::filesystem::path p = strncat(startup,
"/init.opal", 20);
211 if (startup !=
nullptr && is_regular_file(p)) {
220 ERRORMSG(
"Could not open startup file '" << startup <<
"'\n"
221 <<
"Note: this is not mandatory for an OPAL simulation!\n");
225 *gmsg <<
"Reading startup file '" << startup <<
"'" <<
endl;
227 *gmsg <<
"Finished reading startup file." <<
endl;
232 <<
"Couldn't find startup file '" << startup <<
"'\n"
233 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
240 int inputFileArgument = -1;
242 std::string restartFileName;
244 for(
int ii = 1; ii < argc; ++ ii) {
245 std::string argStr = std::string(argv[ii]);
246 if (argStr == std::string(
"-h") ||
247 argStr == std::string(
"-help") ||
248 argStr == std::string(
"--help")) {
251 }
else if (argStr == std::string(
"--help-command")) {
256 ::printStdoutHeader();
261 *gmsg <<
"\nOpalParser::printHelp(): Unknown object \""
262 << cmdName <<
"\".\n" <<
endl;
266 object->printHelp(std::cout);
268 }
else if (argStr == std::string(
"--version")) {
273 }
else if (argStr == std::string(
"--version-full")) {
274 ::printStdoutHeader();
281 std::set<std::string> uniqOptions;
282 while (options.length() > 0) {
283 size_t n = options.find_first_of(
' ');
285 options = options.substr(n + 1);
286 n = options.find_first_of(
' ');
289 uniqOptions.insert(options.substr(0, n));
290 options = options.substr(n + 1);
292 for (
auto it: uniqOptions) {
296 std::string header(
"Compile-time options: ");
297 while (options.length() > 58) {
298 std::string line = options.substr(0, 58);
299 size_t n = line.find_last_of(
' ');
300 INFOMSG(header << line.substr(0, n) <<
"\n");
302 header = std::string(22,
' ');
303 options = options.substr(n + 1);
307 }
else if (argStr == std::string(
"--git-revision")) {
312 }
else if (argStr == std::string(
"--input")) {
314 inputFileArgument = ii;
316 }
else if (argStr == std::string(
"-restart") ||
317 argStr == std::string(
"--restart")) {
321 }
else if (argStr == std::string(
"-restartfn") ||
322 argStr == std::string(
"--restartfn")) {
323 restartFileName = std::string(argv[++ ii]);
325 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
328 if (inputFileArgument == -1 &&
329 (ii == 1 || ii + 1 == argc) &&
330 argv[ii][0] !=
'-') {
331 inputFileArgument = ii;
334 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" <<
endl);
341 ::printStdoutHeader();
342 if (inputFileArgument == -1) {
347 fname = std::string(argv[inputFileArgument]);
348 if (!fs::exists(fname)) {
349 INFOMSG(
"Input file '" << fname <<
"' doesn't exist!" <<
endl);
356 if (restartFileName.empty()) {
359 if (!fs::exists(restartFileName)) {
360 INFOMSG(
"Restart file '" << restartFileName <<
"' doesn't exist!" <<
endl);
372 *gmsg <<
"Input file '" << fname <<
"' not found." <<
endl;
376 *gmsg <<
"* Reading input stream '" << fname <<
"'" <<
endl;
378 *gmsg <<
"* End of input stream '" << fname <<
"'" <<
endl;
382 std::ifstream errormsg(
"errormsg.txt");
383 if(errormsg.good()) {
385 std::string closure(
" *\n");
387 <<
"* **********************************************************************************\n"
388 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
389 <<
"* **********************************************************************************"
391 errormsg.getline(buffer, 256);
392 while(errormsg.good()) {
394 if(errormsg.gcount() == 1) {
396 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
397 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
401 errormsg.getline(buffer, 256);
404 <<
"* **********************************************************************************\n"
405 <<
"* **********************************************************************************"
415 errorMsg <<
"\n*** User error detected by function \""
416 << ex.
where() <<
"\"\n";
418 std::string what = ex.
what();
419 size_t pos = what.find_first_of(
'\n');
421 errorMsg <<
" " << what.substr(0, pos) <<
endl;
422 what = what.substr(pos + 1, std::string::npos);
423 pos = what.find_first_of(
'\n');
424 }
while (pos != std::string::npos);
425 errorMsg <<
" " << what <<
endl;
427 MPI_Abort(MPI_COMM_WORLD, -100);
430 errorMsg <<
"\n*** User error detected by function \""
431 << 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 errorMsg <<
"\n*** Error detected by function \""
447 << ex.
where() <<
"\"\n";
448 std::string what = ex.
what();
449 size_t pos = what.find_first_of(
'\n');
451 errorMsg <<
" " << what.substr(0, pos) <<
endl;
452 what = what.substr(pos + 1, std::string::npos);
453 pos = what.find_first_of(
'\n');
454 }
while (pos != std::string::npos);
455 errorMsg <<
" " << what <<
endl;
457 MPI_Abort(MPI_COMM_WORLD, -100);
461 errorMsg <<
"\n*** Error detected by function \""
462 << ex.
where() <<
"\"\n";
463 std::string what = ex.
what();
464 size_t pos = what.find_first_of(
'\n');
466 errorMsg <<
" " << what.substr(0, pos) <<
endl;
467 what = what.substr(pos + 1, std::string::npos);
468 pos = what.find_first_of(
'\n');
469 }
while (pos != std::string::npos);
470 errorMsg <<
" " << what <<
endl;
472 MPI_Abort(MPI_COMM_WORLD, -100);
473 }
catch(std::bad_alloc &ex) {
475 errorMsg <<
"\n*** Error:\n";
476 errorMsg <<
" Sorry, virtual memory exhausted.\n"
480 MPI_Abort(MPI_COMM_WORLD, -100);
483 errorMsg <<
"\n*** Runtime-error ******************\n";
484 std::string what = ex.
what();
485 size_t pos = what.find_first_of(
'\n');
487 errorMsg <<
" " << what.substr(0, pos) <<
endl;
488 what = what.substr(pos + 1, std::string::npos);
489 pos = what.find_first_of(
'\n');
490 }
while (pos != std::string::npos);
491 errorMsg <<
" " << what <<
endl;
493 errorMsg <<
"\n************************************\n" <<
endl;
494 throw std::runtime_error(
"in Parser");
499 <<
" Internal OPAL error: \n";
500 std::string what = ex.what();
501 size_t pos = what.find_first_of(
'\n');
503 errorMsg <<
" " << what.substr(0, pos) <<
endl;
504 what = what.substr(pos + 1, std::string::npos);
505 pos = what.find_first_of(
'\n');
506 }
while (pos != std::string::npos);
507 errorMsg <<
" " << what <<
endl;
509 MPI_Abort(MPI_COMM_WORLD, -100);
512 errorMsg <<
"\n*** Error:\n"
513 <<
" Unexpected exception caught.\n" <<
endl;
515 MPI_Abort(MPI_COMM_WORLD, -100);
533 amrex::Finalize(
true);
The global OPAL structure.
static OpalData * getInstance()
static void clearDictionary()
The base class for all OPAL objects.
int main(int argc, char *argv[])
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
#define OPAL_PROJECT_VERSION
static const char * compileOptions()
virtual const std::string & what() const
Return the message string for the exception.
virtual void printHelp(std::ostream &) const
Print help.
static MPI_Comm getComm()
The abstract base class for all exceptions in CLASSIC.
std::string getGitRevision()
static void deleteInstance()
void setRestartStep(int s)
store the location where to restart
bool inRestartRun()
true if we do a restart run
virtual const char * what()
std::string toUpper(const std::string &str)
Inform & endl(Inform &inf)
Timing::TimerRef TimerRef
void setRestartRun(const bool &value=true)
set OPAL in restart mode
static void startTimer(TimerRef t)
void configure()
Configure all commands.
virtual const std::string & where() const
Return the name of the method or function which detected the exception.
virtual const std::string & where() const
static Communicate * Comm
The base class for all OPAL exceptions.
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
virtual const char * what() const
void handleGSLErrors(const char *reason, const char *file, int, int)
int opalMain(int argc, char *argv[])
The default parser for OPAL-9.
static void printVersion(void)
static void setEcho(bool flag)
Set echo flag.
void storeArguments(int argc, char *argv[])
#define PACKAGE_BUGREPORT
Inform & level5(Inform &inf)
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special exception
virtual const char * where() const
std::string time() const
Return time.
static void setGlobalTruncOrder(int order)
Set the global truncation order.
std::string getInputBasename()
get input file name without extension
b mention the algorithm in the References section The appropriate citation is
std::string date() const
Return date.
static TimerRef getTimer(const char *nm)
Object * find(const std::string &name)
Find entry.
#define OPAL_COMPILE_OPTIONS
void storeInputFn(const std::string &fn)
store opals input filename
static void stopTimer(TimerRef t)
virtual void run() const
Read current stream.
virtual const char * what() const
bool checkInitAmrFlag(int argc, char *argv[])
A stream of input tokens.
void setRestartFileName(std::string s)
store opals restart h5 format filename