make communicator protected and use accessor instead. simplify
This commit is contained in:
@ -279,8 +279,7 @@ void Error::done(int status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
return the last error message reported by LAMMPS (only used if
|
return the last error message reported by LAMMPS
|
||||||
compiled with -DLAMMPS_EXCEPTIONS)
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
std::string Error::get_last_error() const
|
std::string Error::get_last_error() const
|
||||||
@ -289,8 +288,7 @@ std::string Error::get_last_error() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
return the type of the last error reported by LAMMPS (only used if
|
return the type of the last error reported by LAMMPS
|
||||||
compiled with -DLAMMPS_EXCEPTIONS)
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
ErrorType Error::get_last_error_type() const
|
ErrorType Error::get_last_error_type() const
|
||||||
@ -300,10 +298,9 @@ ErrorType Error::get_last_error_type() const
|
|||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
set the last error message and error type
|
set the last error message and error type
|
||||||
(only used if compiled with -DLAMMPS_EXCEPTIONS)
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void Error::set_last_error(const std::string &msg, ErrorType type)
|
void Error::set_last_error(const char *msg, ErrorType type)
|
||||||
{
|
{
|
||||||
last_error_message = msg;
|
last_error_message = msg;
|
||||||
last_error_type = type;
|
last_error_type = type;
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class Error : protected Pointers {
|
|||||||
|
|
||||||
std::string get_last_error() const;
|
std::string get_last_error() const;
|
||||||
ErrorType get_last_error_type() const;
|
ErrorType get_last_error_type() const;
|
||||||
void set_last_error(const std::string &msg, ErrorType type = ERROR_NORMAL);
|
void set_last_error(const char *msg, ErrorType type = ERROR_NORMAL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string last_error_message;
|
std::string last_error_message;
|
||||||
|
|||||||
@ -22,21 +22,23 @@ namespace LAMMPS_NS {
|
|||||||
|
|
||||||
class LAMMPSException : public std::exception {
|
class LAMMPSException : public std::exception {
|
||||||
public:
|
public:
|
||||||
std::string message;
|
|
||||||
|
|
||||||
LAMMPSException(const std::string &msg) : message(msg) {}
|
LAMMPSException(const std::string &msg) : message(msg) {}
|
||||||
|
|
||||||
const char *what() const noexcept override { return message.c_str(); }
|
const char *what() const noexcept override { return message.c_str(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LAMMPSAbortException : public LAMMPSException {
|
class LAMMPSAbortException : public LAMMPSException {
|
||||||
public:
|
public:
|
||||||
MPI_Comm universe;
|
|
||||||
|
|
||||||
LAMMPSAbortException(const std::string &msg, MPI_Comm _universe) :
|
LAMMPSAbortException(const std::string &msg, MPI_Comm _universe) :
|
||||||
LAMMPSException(msg), universe(_universe)
|
LAMMPSException(msg), universe(_universe)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
MPI_Comm get_universe() const { return universe; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MPI_Comm universe;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ErrorType { ERROR_NONE = 0, ERROR_NORMAL = 1, ERROR_ABORT = 2 };
|
enum ErrorType { ERROR_NONE = 0, ERROR_NORMAL = 1, ERROR_ABORT = 2 };
|
||||||
|
|||||||
@ -97,15 +97,15 @@ static void ptr_argument_warning()
|
|||||||
#define END_CAPTURE \
|
#define END_CAPTURE \
|
||||||
catch(LAMMPSAbortException &ae) { \
|
catch(LAMMPSAbortException &ae) { \
|
||||||
int nprocs = 0; \
|
int nprocs = 0; \
|
||||||
MPI_Comm_size(ae.universe, &nprocs ); \
|
MPI_Comm_size(ae.get_universe(), &nprocs ); \
|
||||||
\
|
\
|
||||||
if (nprocs > 1) { \
|
if (nprocs > 1) { \
|
||||||
error->set_last_error(ae.message, ERROR_ABORT); \
|
error->set_last_error(ae.what(), ERROR_ABORT); \
|
||||||
} else { \
|
} else { \
|
||||||
error->set_last_error(ae.message, ERROR_NORMAL); \
|
error->set_last_error(ae.what(), ERROR_NORMAL); \
|
||||||
} \
|
} \
|
||||||
} catch(LAMMPSException &e) { \
|
} catch(LAMMPSException &e) { \
|
||||||
error->set_last_error(e.message, ERROR_NORMAL); \
|
error->set_last_error(e.what(), ERROR_NORMAL); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
@ -172,7 +172,7 @@ void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr)
|
|||||||
lmp = new LAMMPS(argc, argv, comm);
|
lmp = new LAMMPS(argc, argv, comm);
|
||||||
if (ptr) *ptr = (void *) lmp;
|
if (ptr) *ptr = (void *) lmp;
|
||||||
} catch(LAMMPSException &e) {
|
} catch(LAMMPSException &e) {
|
||||||
fprintf(stderr, "LAMMPS Exception: %s\n", e.message);
|
fprintf(stderr, "LAMMPS Exception: %s\n", e.what());
|
||||||
if (ptr) *ptr = nullptr;
|
if (ptr) *ptr = nullptr;
|
||||||
} catch (fmt::format_error &fe) {
|
} catch (fmt::format_error &fe) {
|
||||||
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
fprintf(stderr, "fmt::format_error: %s\n", fe.what());
|
||||||
|
|||||||
@ -78,7 +78,7 @@ int main(int argc, char **argv)
|
|||||||
delete lammps;
|
delete lammps;
|
||||||
} catch (LAMMPSAbortException &ae) {
|
} catch (LAMMPSAbortException &ae) {
|
||||||
finalize();
|
finalize();
|
||||||
MPI_Abort(ae.universe, 1);
|
MPI_Abort(ae.get_universe(), 1);
|
||||||
} catch (LAMMPSException &) {
|
} catch (LAMMPSException &) {
|
||||||
finalize();
|
finalize();
|
||||||
MPI_Barrier(lammps_comm);
|
MPI_Barrier(lammps_comm);
|
||||||
|
|||||||
Reference in New Issue
Block a user