48#include <gsl/gsl_errno.h>
50#include <boost/filesystem.hpp>
51#include <boost/system/error_code.hpp>
61 std::string dateStr(simtimer.
date());
62 std::string timeStr(simtimer.
time());
63 std::string mySpace(
" ");
65 *
gmsg << mySpace <<
" ____ _____ _ __ __" <<
endl;
78 std::string copyRight =
"(c) PSI, http://amas.web.psi.ch";
80 <<
"This is OPAL-X (Object Oriented Parallel Accelerator Library) Version "
82 << std::setw(37 + gitRevision.length() / 2) << std::right << gitRevision <<
"\n\n"
84 << std::setw(37 + copyRight.length() / 2) << std::right << copyRight <<
"\n\n"
86 <<
"This is the performance portable version of OPAL" <<
endl
89 *
gmsg <<
"Please send cookies, goodies or other motivations (wine and beer ... ) \nto the "
93 *
gmsg <<
"Time: " << timeStr <<
" date: " << dateStr <<
"\n" <<
endl;
96 *
gmsg <<
"* Host: " << Kokkos::HostSpace::execution_space::name() <<
endl;
99#ifdef KOKKOS_ENABLE_CUDA
100 *
gmsg <<
"* Device: " << Kokkos::Cuda::name() <<
endl <<
endl;
101#elif defined(KOKKOS_ENABLE_HIP)
102 *
gmsg <<
"* Device: " << Kokkos::Experimental::HIP::name() <<
endl <<
endl;
103#elif defined(KOKKOS_ENABLE_OPENMP)
104 *
gmsg <<
"* Device: " << Kokkos::OpenMP::name() <<
endl <<
endl;
114 *
ippl::Info <<
"Usage: opal [<option> <option> ...]\n";
115 *
ippl::Info <<
" The possible values for <option> are:\n";
116 *
ippl::Info <<
" --version : Print the version of opal.\n";
117 *
ippl::Info <<
" --version-full : Print the version of opal with additional "
119 *
ippl::Info <<
" --git-revision : Print the revision hash of the repository.\n";
120 *
ippl::Info <<
" --input <fname> : Specifies the input file <fname>.\n";
121 *
ippl::Info <<
" --restart <n> : Performes a restart from step <n>.\n";
122 *
ippl::Info <<
" --restartfn <fname> : Uses the file <fname> to restart from.\n";
124 *
ippl::Info <<
" --help-command <command> : Display the help for the command <command>\n";
125 *
ippl::Info <<
" --help : Display this command-line summary.\n";
130int main(
int argc,
char* argv[]) {
134 namespace fs = boost::filesystem;
136 H5SetVerbosityLevel(1);
144 remove(
"errormsg.txt");
148 std::cout.precision(16);
149 std::cout.setf(std::ios::scientific, std::ios::floatfield);
150 std::cerr.precision(16);
151 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
157 boost::system::error_code error_code;
159 std::cerr << error_code.message() <<
std::endl;
166 std::cerr <<
"unable to create directory; aborting" <<
std::endl;
174 *
gmsg <<
"configure done argc= " << argc <<
endl;
179 char* startup = getenv(
"HOME");
180 boost::filesystem::path p = strncat(startup,
"/init.opal", 20);
181 if (startup !=
nullptr && is_regular_file(p)) {
189 *
ippl::Error <<
"Could not open startup file '" << startup <<
"'\n"
190 <<
"Note: this is not mandatory for an OPAL simulation!\n";
194 *
gmsg <<
"Reading startup file '" << startup <<
"'" <<
endl;
197 *
gmsg <<
"Finished reading startup file." <<
endl;
201 *
gmsg <<
level5 <<
"Couldn't find startup file '" << startup <<
"'\n"
202 <<
"Note: this is not mandatory for an OPAL simulation!\n"
210 int inputFileArgument = -1;
212 std::string restartFileName;
213 for (
int ii = 1; ii < argc; ++ii) {
214 std::string argStr = std::string(argv[ii]);
215 if (argStr == std::string(
"-h") || argStr == std::string(
"-help")
216 || argStr == std::string(
"--help")) {
219 }
else if (argStr == std::string(
"--help-command")) {
229 *
gmsg <<
"\nOpalParser::printHelp(): Unknown object \"" << cmdName
235 object->printHelp(std::cout);
237 }
else if (argStr == std::string(
"--version")) {
242 }
else if (argStr == std::string(
"--version-full")) {
247 std::string options =
250 std::set<std::string> uniqOptions;
251 while (options.length() > 0) {
252 size_t n = options.find_first_of(
' ');
254 options = options.substr(n + 1);
255 n = options.find_first_of(
' ');
258 uniqOptions.insert(options.substr(0, n));
259 options = options.substr(n + 1);
261 for (
auto it : uniqOptions) {
265 std::string header(
"Compile-time options: ");
266 while (options.length() > 58) {
267 std::string line = options.substr(0, 58);
268 size_t n = line.find_last_of(
' ');
269 *
ippl::Info << header << line.substr(0, n) <<
"\n";
271 header = std::string(22,
' ');
272 options = options.substr(n + 1);
276 }
else if (argStr == std::string(
"--git-revision")) {
281 }
else if (argStr == std::string(
"--input")) {
283 inputFileArgument = ii;
286 argStr == std::string(
"-restart") || argStr == std::string(
"--restart")) {
291 argStr == std::string(
"-restartfn") || argStr == std::string(
"--restartfn")) {
292 restartFileName = std::string(argv[++ii]);
294 }
else if (argStr == std::string(
"--info")) {
297 }
else if (argStr == std::string(
"--overallocate")) {
301 if (inputFileArgument == -1 && (ii == 1 || ii + 1 == argc)
302 && argv[ii][0] !=
'-') {
303 inputFileArgument = ii;
306 *
gmsg <<
"Unknown argument \"" << argStr <<
"\"" <<
endl;
314 if (inputFileArgument == -1) {
319 fname = std::string(argv[inputFileArgument]);
320 if (!fs::exists(fname)) {
321 *
ippl::Info <<
"Input file '" << fname <<
"' doesn't exist!" <<
endl;
328 if (restartFileName.empty()) {
331 if (!fs::exists(restartFileName)) {
332 *
ippl::Info <<
"Restart file '" << restartFileName <<
"' doesn't exist!"
345 *
gmsg <<
"Input file '" << fname <<
"' not found." <<
endl;
349 *
gmsg <<
"* Reading input stream '" << fname <<
"'" <<
endl;
351 *
gmsg <<
"* End of input stream '" << fname <<
"'" <<
endl;
355 std::ifstream errormsg(
"errormsg.txt");
356 if (errormsg.good()) {
365 "***********************************************************************"
368 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S "
369 "*********************\n"
371 "***********************************************************************"
375 errormsg.getline(buffer, 256);
376 while (errormsg.good()) {
378 if (errormsg.gcount() == 1) {
380 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
381 *
ippl::Error << buffer << closure.substr(errormsg.gcount() - 1);
385 errormsg.getline(buffer, 256);
390 "**********************************************************************"
393 "**********************************************************************"
406 errorMsg <<
"\n*** User error detected by function \"" << ex.
where() <<
"\"\n";
408 std::string what = ex.
what();
409 size_t pos = what.find_first_of(
'\n');
411 errorMsg <<
" " << what.substr(0, pos) <<
endl;
412 what = what.substr(pos + 1, std::string::npos);
413 pos = what.find_first_of(
'\n');
414 }
while (pos != std::string::npos);
415 errorMsg <<
" " << what <<
endl;
417 MPI_Abort(MPI_COMM_WORLD, -100);
420 errorMsg <<
"\n*** User error detected by function \"" << ex.
where() <<
"\"\n";
422 std::string what = ex.
what();
423 size_t pos = what.find_first_of(
'\n');
425 errorMsg <<
" " << what.substr(0, pos) <<
endl;
426 what = what.substr(pos + 1, std::string::npos);
427 pos = what.find_first_of(
'\n');
428 }
while (pos != std::string::npos);
429 errorMsg <<
" " << what <<
endl;
431 MPI_Abort(MPI_COMM_WORLD, -100);
435 errorMsg <<
"\n*** Error detected by function \"" << ex.
where() <<
"\"\n";
436 std::string what = ex.
what();
437 size_t pos = what.find_first_of(
'\n');
439 errorMsg <<
" " << what.substr(0, pos) <<
endl;
440 what = what.substr(pos + 1, std::string::npos);
441 pos = what.find_first_of(
'\n');
442 }
while (pos != std::string::npos);
443 errorMsg <<
" " << what <<
endl;
445 MPI_Abort(MPI_COMM_WORLD, -100);
449 errorMsg <<
"\n*** Error detected by function \"" << ex.
where() <<
"\"\n";
450 std::string what = ex.
what();
451 size_t pos = what.find_first_of(
'\n');
453 errorMsg <<
" " << what.substr(0, pos) <<
endl;
454 what = what.substr(pos + 1, std::string::npos);
455 pos = what.find_first_of(
'\n');
456 }
while (pos != std::string::npos);
457 errorMsg <<
" " << what <<
endl;
459 MPI_Abort(MPI_COMM_WORLD, -100);
460 }
catch (std::bad_alloc& ex) {
462 errorMsg <<
"\n*** Error:\n";
463 errorMsg <<
" Sorry, virtual memory exhausted.\n" << ex.
what() <<
endl;
465 MPI_Abort(MPI_COMM_WORLD, -100);
468 errorMsg <<
"\n*** Runtime-error ******************\n";
469 std::string what = ex.
what();
470 size_t pos = what.find_first_of(
'\n');
472 errorMsg <<
" " << what.substr(0, pos) <<
endl;
473 what = what.substr(pos + 1, std::string::npos);
474 pos = what.find_first_of(
'\n');
475 }
while (pos != std::string::npos);
476 errorMsg <<
" " << what <<
endl;
478 errorMsg <<
"\n************************************\n" <<
endl;
479 throw std::runtime_error(
"in Parser");
480 }
catch (std::exception& ex) {
484 <<
" Internal OPAL error: \n";
485 std::string what = ex.
what();
486 size_t pos = what.find_first_of(
'\n');
488 errorMsg <<
" " << what.substr(0, pos) <<
endl;
489 what = what.substr(pos + 1, std::string::npos);
490 pos = what.find_first_of(
'\n');
491 }
while (pos != std::string::npos);
492 errorMsg <<
" " << what <<
endl;
494 MPI_Abort(MPI_COMM_WORLD, -100);
497 errorMsg <<
"\n*** Error:\n"
498 <<
" Unexpected exception caught.\n"
501 MPI_Abort(MPI_COMM_WORLD, -100);
#define OPAL_COMPILE_OPTIONS
#define PACKAGE_BUGREPORT
#define OPAL_PROJECT_VERSION
int main(int argc, char *argv[])
void handleGSLErrors(const char *reason, const char *file, int, int)
Inform & endl(Inform &inf)
Inform & level5(Inform &inf)
void configure()
Configure all commands.
std::string toUpper(const std::string &str)
std::string getGitRevision()
void initialize(int &argc, char *argv[], MPI_Comm comm)
std::unique_ptr< Inform > Info
std::unique_ptr< Inform > Error
std::unique_ptr< mpi::Communicator > Comm
void abort(const char *msg, int errorcode)
The base class for all OPAL objects.
The global OPAL structure.
void storeInputFn(const std::string &fn)
store opals input filename
std::string getInputBasename()
get input file name without extension
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Object * find(const std::string &name)
Find entry.
void setRestartFileName(std::string s)
store opals restart h5 format filename
static OpalData * getInstance()
void storeArguments(int argc, char *argv[])
void setRestartStep(int s)
store the location where to restart
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
bool inRestartRun()
true if we do a restart run
static void clearDictionary()
A stream of input tokens.
static void setEcho(bool flag)
Set echo flag.
The default parser for OPAL-9.
virtual void run() const
Read current stream.
The abstract base class for all exceptions in CLASSIC.
virtual const std::string & what() const
Return the message string for the exception.
virtual const std::string & where() const
Return the name of the method or function which detected the exception.
The base class for all OPAL exceptions.
std::string date() const
Return date.
std::string time() const
Return time.
static void printVersion(void)
static const char * compileOptions()
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)