130int main(
int argc,
char* argv[]) {
131 ippl::initialize(argc, argv);
133 gmsg =
new Inform(
"OPAL-X");
134 namespace fs = boost::filesystem;
136 H5SetVerbosityLevel(1);
140 static IpplTimings::TimerRef mainTimer = IpplTimings::getTimer(
"mainTimer");
141 IpplTimings::startTimer(mainTimer);
143 if (ippl::Comm->rank() == 0)
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);
155 if (ippl::Comm->rank() == 0) {
157 boost::system::error_code error_code;
159 std::cerr << error_code.message() << std::endl;
164 ippl::Comm->barrier();
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
237 }
else if (argStr == std::string(
"--version")) {
238 if (ippl::Comm->rank() == 0) {
242 }
else if (argStr == std::string(
"--version-full")) {
246 IpplInfo::printVersion();
247 std::string options =
248 (IpplInfo::compileOptions() + std::string(
" ")
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);
274 *ippl::Info << header << options << endl;
276 }
else if (argStr == std::string(
"--git-revision")) {
277 if (ippl::Comm->rank() == 0) {
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) {
315 *ippl::Info <<
"No input file provided!" << endl;
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;
354 if (ippl::Comm->rank() == 0) {
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()) {
377 *ippl::Error <<
"* ";
378 if (errormsg.gcount() == 1) {
379 *ippl::Error << closure;
380 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
381 *ippl::Error << buffer << closure.substr(errormsg.gcount() - 1);
383 *ippl::Error << buffer << endl;
385 errormsg.getline(buffer, 256);
390 "**********************************************************************"
393 "**********************************************************************"
405 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
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);
419 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
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);
433 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
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);
446 }
catch (IpplException& ex) {
447 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
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) {
461 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
462 errorMsg <<
"\n*** Error:\n";
463 errorMsg <<
" Sorry, virtual memory exhausted.\n" << ex.
what() << endl;
465 MPI_Abort(MPI_COMM_WORLD, -100);
466 }
catch (assertion& ex) {
467 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
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) {
481 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
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);
496 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
497 errorMsg <<
"\n*** Error:\n"
498 <<
" Unexpected exception caught.\n"
501 MPI_Abort(MPI_COMM_WORLD, -100);
507 IpplTimings::stopTimer(mainTimer);
509 IpplTimings::print();
515 ippl::Comm->barrier();
516 Fieldmap::clearDictionary();