remove -DLAMMPS_EXCEPTIONS and always enable the corresponding code paths

This commit is contained in:
Axel Kohlmeyer
2023-04-15 17:49:08 -04:00
parent e506dd738b
commit 0cd5ae5f2e
17 changed files with 58 additions and 208 deletions

View File

@ -18,10 +18,7 @@
#include "input.h"
#include "output.h"
#include "universe.h"
#if defined(LAMMPS_EXCEPTIONS)
#include "update.h"
#endif
using namespace LAMMPS_NS;
@ -40,10 +37,8 @@ static std::string truncpath(const std::string &path)
Error::Error(LAMMPS *lmp)
: Pointers(lmp), numwarn(0), maxwarn(100), allwarn(0)
{
#ifdef LAMMPS_EXCEPTIONS
last_error_message.clear();
last_error_type = ERROR_NONE;
#endif
}
/* ----------------------------------------------------------------------
@ -73,19 +68,11 @@ void Error::universe_all(const std::string &file, int line, const std::string &s
}
if (universe->ulogfile) fclose(universe->ulogfile);
#ifdef LAMMPS_EXCEPTIONS
// allow commands if an exception was caught in a run
// update may be a null pointer when catching command line errors
if (update) update->whichflag = 0;
throw LAMMPSException(mesg);
#else
KokkosLMP::finalize();
MPI_Finalize();
exit(1);
#endif
}
/* ----------------------------------------------------------------------
@ -99,19 +86,11 @@ void Error::universe_one(const std::string &file, int line, const std::string &s
universe->me,str,truncpath(file),line);
if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen);
#ifdef LAMMPS_EXCEPTIONS
// allow commands if an exception was caught in a run
// update may be a null pointer when catching command line errors
if (update) update->whichflag = 0;
throw LAMMPSAbortException(mesg, universe->uworld);
#else
KokkosLMP::finalize();
MPI_Abort(universe->uworld,1);
exit(1); // to trick "smart" compilers into believing this does not return
#endif
}
/* ----------------------------------------------------------------------
@ -155,31 +134,17 @@ void Error::all(const std::string &file, int line, const std::string &str)
utils::logmesg(lmp,mesg);
}
#ifdef LAMMPS_EXCEPTIONS
// allow commands if an exception was caught in a run
// update may be a null pointer when catching command line errors
if (update) update->whichflag = 0;
std::string msg = fmt::format("ERROR: {} ({}:{})\n",
str, truncpath(file), line);
std::string msg = fmt::format("ERROR: {} ({}:{})\n", str, truncpath(file), line);
if (universe->nworlds > 1) {
if (universe->nworlds > 1)
throw LAMMPSAbortException(msg, universe->uworld);
}
throw LAMMPSException(msg);
#else
if (output) delete output;
if (screen && screen != stdout) fclose(screen);
if (logfile) fclose(logfile);
KokkosLMP::finalize();
if (universe->nworlds > 1) MPI_Abort(universe->uworld,1);
MPI_Finalize();
exit(1);
#endif
else
throw LAMMPSException(msg);
}
/* ----------------------------------------------------------------------
@ -204,20 +169,11 @@ void Error::one(const std::string &file, int line, const std::string &str)
if (universe->uscreen)
fputs(mesg.c_str(),universe->uscreen);
#ifdef LAMMPS_EXCEPTIONS
// allow commands if an exception was caught in a run
// update may be a null pointer when catching command line errors
if (update) update->whichflag = 0;
throw LAMMPSAbortException(mesg, world);
#else
utils::flush_buffers(lmp);
KokkosLMP::finalize();
MPI_Abort(world,1);
exit(1); // to trick "smart" compilers into believing this does not return
#endif
}
/* ----------------------------------------------------------------------
@ -322,7 +278,6 @@ void Error::done(int status)
exit(status);
}
#ifdef LAMMPS_EXCEPTIONS
/* ----------------------------------------------------------------------
return the last error message reported by LAMMPS (only used if
compiled with -DLAMMPS_EXCEPTIONS)
@ -353,4 +308,3 @@ void Error::set_last_error(const std::string &msg, ErrorType type)
last_error_message = msg;
last_error_type = type;
}
#endif