135int main(
int argc,
char* argv[]) {
136 ippl::initialize(argc, argv);
138 gmsg =
new Inform(
"OPAL-X");
139 namespace fs = std::filesystem;
141 H5SetVerbosityLevel(1);
145 static IpplTimings::TimerRef mainTimer = IpplTimings::getTimer(
"mainTimer");
146 IpplTimings::startTimer(mainTimer);
148 if (ippl::Comm->rank() == 0) remove(
"errormsg.txt");
152 std::cout.precision(16);
153 std::cout.setf(std::ios::scientific, std::ios::floatfield);
154 std::cerr.precision(16);
155 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
159 if (ippl::Comm->rank() == 0) {
161 std::error_code error_code;
163 std::cerr << error_code.message() << std::endl;
168 ippl::Comm->barrier();
170 std::cerr <<
"unable to create directory; aborting" << std::endl;
182 char* startup = getenv(
"HOME");
183 std::filesystem::path p = strncat(startup,
"/init.opal", 20);
184 if (startup !=
nullptr && fs::is_regular_file(p)) {
192 *ippl::Error <<
"Could not open startup file '" << startup <<
"'\n"
193 <<
"Note: this is not mandatory for an OPAL simulation!\n";
197 *
gmsg <<
"Reading startup file '" << startup <<
"'" << endl;
199 *
gmsg <<
"Finished reading startup file." << endl;
203 *
gmsg << level5 <<
"Couldn't find startup file '" << startup <<
"'\n"
204 <<
"Note: this is not mandatory for an OPAL simulation!\n"
212 int inputFileArgument = -1;
214 std::string restartFileName;
215 for (
int ii = 1; ii < argc; ++ii) {
216 std::string argStr = std::string(argv[ii]);
217 if (argStr == std::string(
"-h") || argStr == std::string(
"-help")
218 || argStr == std::string(
"--help")) {
221 }
else if (argStr == std::string(
"--help-command")) {
231 *
gmsg <<
"\nOpalParser::printHelp(): Unknown object \"" << cmdName
237 object->printHelp(std::cout);
239 }
else if (argStr == std::string(
"--version")) {
240 if (ippl::Comm->rank() == 0) {
241 std::cout << buildinfo::project_version << std::endl;
244 }
else if (argStr == std::string(
"--version-full")) {
246 *ippl::Info <<
"OPAL Version " << buildinfo::project_version <<
", git rev. "
248 IpplInfo::printVersion();
249 std::string options =
250 (IpplInfo::compileOptions() + std::string(
" ")
251 + std::string(buildinfo::compile_options) + std::string(
" "));
252 std::set<std::string> uniqOptions;
253 while (options.length() > 0) {
254 size_t n = options.find_first_of(
' ');
256 options = options.substr(n + 1);
257 n = options.find_first_of(
' ');
260 uniqOptions.insert(options.substr(0, n));
261 options = options.substr(n + 1);
263 for (
auto it : uniqOptions) {
267 std::string header(
"Compile-time options: ");
268 while (options.length() > 58) {
269 std::string line = options.substr(0, 58);
270 size_t n = line.find_last_of(
' ');
271 *ippl::Info << header << line.substr(0, n) <<
"\n";
273 header = std::string(22,
' ');
274 options = options.substr(n + 1);
276 *ippl::Info << header << options << endl;
278 }
else if (argStr == std::string(
"--git-revision")) {
279 if (ippl::Comm->rank() == 0) {
283 }
else if (argStr == std::string(
"--input")) {
285 inputFileArgument = ii;
288 argStr == std::string(
"-restart") || argStr == std::string(
"--restart")) {
293 argStr == std::string(
"-restartfn")
294 || argStr == std::string(
"--restartfn")) {
295 restartFileName = std::string(argv[++ii]);
297 }
else if (argStr == std::string(
"--info")) {
300 }
else if (argStr == std::string(
"--overallocate")) {
304 if (inputFileArgument == -1 && (ii == 1 || ii + 1 == argc)
305 && argv[ii][0] !=
'-') {
306 inputFileArgument = ii;
309 *
gmsg <<
"Unknown argument \"" << argStr <<
"\"" << endl;
317 if (inputFileArgument == -1) {
318 *ippl::Info <<
"No input file provided!" << endl;
322 fname = std::string(argv[inputFileArgument]);
323 if (!fs::exists(fname)) {
324 *ippl::Info <<
"Input file '" << fname <<
"' doesn't exist!" << endl;
331 if (restartFileName.empty()) {
334 if (!fs::exists(restartFileName)) {
335 *ippl::Info <<
"Restart file '" << restartFileName <<
"' doesn't exist!"
348 *
gmsg <<
"Input file '" << fname <<
"' not found." << endl;
352 *
gmsg <<
"* Reading input stream '" << fname <<
"'" << endl;
354 *
gmsg <<
"* End of input stream '" << fname <<
"'" << endl;
357 if (ippl::Comm->rank() == 0) {
358 std::ifstream errormsg(
"errormsg.txt");
359 if (errormsg.good()) {
369 "*******************************************************************"
373 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S "
374 "*********************\n"
376 "*******************************************************************"
381 errormsg.getline(buffer, 256);
382 while (errormsg.good()) {
383 *ippl::Error <<
"* ";
384 if (errormsg.gcount() == 1) {
385 *ippl::Error << closure;
386 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
387 *ippl::Error << buffer << closure.substr(errormsg.gcount() - 1);
389 *ippl::Error << buffer << endl;
391 errormsg.getline(buffer, 256);
393 *ippl::Error <<
"* " << closure
395 "**************************************************************"
399 "**************************************************************"
408 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
409 errorMsg <<
"\n*** User error detected by function \"" << ex.
where() <<
"\"\n";
411 std::string what = ex.
what();
412 size_t pos = what.find_first_of(
'\n');
414 errorMsg <<
" " << what.substr(0, pos) << endl;
415 what = what.substr(pos + 1, std::string::npos);
416 pos = what.find_first_of(
'\n');
417 }
while (pos != std::string::npos);
418 errorMsg <<
" " << what << endl;
420 MPI_Abort(MPI_COMM_WORLD, -100);
421 }
catch (IpplException& ex) {
422 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
424 errorMsg <<
"\n*** Error detected by function \"" << ex.
where() <<
"\"\n";
425 std::string what = ex.
what();
426 size_t pos = what.find_first_of(
'\n');
428 errorMsg <<
" " << what.substr(0, pos) << endl;
429 what = what.substr(pos + 1, std::string::npos);
430 pos = what.find_first_of(
'\n');
431 }
while (pos != std::string::npos);
432 errorMsg <<
" " << what << endl;
434 MPI_Abort(MPI_COMM_WORLD, -100);
435 }
catch (std::bad_alloc& ex) {
436 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
437 errorMsg <<
"\n*** Error:\n";
438 errorMsg <<
" Sorry, virtual memory exhausted.\n" << ex.
what() << endl;
440 MPI_Abort(MPI_COMM_WORLD, -100);
441 }
catch (assertion& ex) {
442 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
443 errorMsg <<
"\n*** Runtime-error ******************\n";
444 std::string what = ex.
what();
445 size_t pos = what.find_first_of(
'\n');
447 errorMsg <<
" " << what.substr(0, pos) << endl;
448 what = what.substr(pos + 1, std::string::npos);
449 pos = what.find_first_of(
'\n');
450 }
while (pos != std::string::npos);
451 errorMsg <<
" " << what << endl;
453 errorMsg <<
"\n************************************\n" << endl;
454 throw std::runtime_error(
"in Parser");
455 }
catch (std::exception& ex) {
456 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
459 <<
" Internal OPAL error: \n";
460 std::string what = ex.
what();
461 size_t pos = what.find_first_of(
'\n');
463 errorMsg <<
" " << what.substr(0, pos) << endl;
464 what = what.substr(pos + 1, std::string::npos);
465 pos = what.find_first_of(
'\n');
466 }
while (pos != std::string::npos);
467 errorMsg <<
" " << what << endl;
469 MPI_Abort(MPI_COMM_WORLD, -100);
471 Inform errorMsg(
"Error", std::cerr, INFORM_ALL_NODES);
472 errorMsg <<
"\n*** Error:\n"
473 <<
" Unexpected exception caught.\n"
476 MPI_Abort(MPI_COMM_WORLD, -100);
482 IpplTimings::stopTimer(mainTimer);
484 IpplTimings::print();
487 std::string(
"timing.dat"),
490 ippl::Comm->barrier();
491 Fieldmap::clearDictionary();
int main(int argc, char *argv[])