diff --git a/src/error.cpp b/src/error.cpp index 741ff4f2dd..946cc19fd6 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -119,13 +119,18 @@ void Error::all(const std::string &file, int line, int failed, const std::string { MPI_Barrier(world); + // must get rank from communicator since "comm" instance may not yet exist + + int me = 0; + MPI_Comm_rank(world, &me); + std::string lastcmd = "(unknown)"; std::string mesg = "ERROR: " + str + fmt::format(" ({}:{})\n", truncpath(file), line); // add text about the input following the error message if (failed > NOLASTLINE) mesg += utils::point_to_error(input, failed); - if (comm->me == 0) utils::logmesg(lmp,mesg); + if (me == 0) utils::logmesg(lmp,mesg); utils::flush_buffers(lmp); // allow commands if an exception was caught in a run @@ -150,8 +155,12 @@ void Error::one(const std::string &file, int line, int failed, const std::string { std::string lastcmd = "(unknown)"; - std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", comm->me, str, - truncpath(file), line); + // must get rank from communicator since "comm" instance may not yet exist + + int me = 0; + MPI_Comm_rank(world, &me); + + std::string mesg = fmt::format("ERROR on proc {}: {} ({}:{})\n", me, str, truncpath(file), line); if (failed > NOPOINTER) mesg += utils::point_to_error(input, failed); utils::logmesg(lmp,mesg); diff --git a/src/lammps.cpp b/src/lammps.cpp index f8a1c9950c..0a289fe006 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -562,7 +562,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : else if (strcmp(arg[inflag], "none") == 0) infile = stdin; else infile = fopen(arg[inflag],"r"); if (infile == nullptr) - error->one(FLERR,"Cannot open input script {}: {}", arg[inflag], utils::getsyserror()); + error->all(FLERR,"Cannot open input script {}: {}", arg[inflag], utils::getsyserror()); if (!helpflag) utils::logmesg(this,"LAMMPS ({}{})\n", version, update_string);