add -nonbuf / -nb command line flag to disable buffering for screen and logfile
This commit is contained in:
@ -196,6 +196,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
int citelogfile = CiteMe::VERBOSE;
|
||||
char *citefile = nullptr;
|
||||
int helpflag = 0;
|
||||
int nonbufflag = 0;
|
||||
|
||||
suffix = suffix2 = suffixp = nullptr;
|
||||
suffix_enable = 0;
|
||||
@ -298,6 +299,11 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
citeflag = 0;
|
||||
iarg++;
|
||||
|
||||
} else if (strcmp(arg[iarg],"-nonbuf") == 0 ||
|
||||
strcmp(arg[iarg],"-nb") == 0) {
|
||||
nonbufflag = 1;
|
||||
iarg++;
|
||||
|
||||
} else if (strcmp(arg[iarg],"-package") == 0 ||
|
||||
strcmp(arg[iarg],"-pk") == 0) {
|
||||
if (iarg+2 > narg)
|
||||
@ -520,7 +526,6 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
utils::flush_buffers(this);
|
||||
}
|
||||
|
||||
|
||||
// universe is one or more worlds, as setup by partition switch
|
||||
// split universe communicator into separate world communicators
|
||||
// set world screen, logfile, communicator, infile
|
||||
@ -540,6 +545,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
screen = fopen(str.c_str(),"w");
|
||||
if (screen == nullptr)
|
||||
error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror());
|
||||
setvbuf(screen, NULL, _IONBF, 0);
|
||||
} else if (strcmp(arg[screenflag],"none") == 0) {
|
||||
screen = nullptr;
|
||||
} else {
|
||||
@ -563,6 +569,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
logfile = fopen(str.c_str(),"w");
|
||||
if (logfile == nullptr)
|
||||
error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror());
|
||||
setbuf(logfile, NULL);
|
||||
} else if (strcmp(arg[logflag],"none") == 0) {
|
||||
logfile = nullptr;
|
||||
} else {
|
||||
@ -587,6 +594,15 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
|
||||
}
|
||||
}
|
||||
|
||||
// make all screen and logfile output unbuffered for debugging crashes
|
||||
|
||||
if (nonbufflag) {
|
||||
if (universe->uscreen) setbuf(universe->uscreen, nullptr);
|
||||
if (universe->ulogfile) setbuf(universe->ulogfile, nullptr);
|
||||
if (screen) setbuf(screen, nullptr);
|
||||
if (logfile) setbuf(logfile, nullptr);
|
||||
}
|
||||
|
||||
// screen and logfile messages for universe and world
|
||||
|
||||
if ((universe->me == 0) && (!helpflag)) {
|
||||
|
||||
Reference in New Issue
Block a user