[lammps-users] Redirecting lammps high-level output to a file in real time?

Hi all,
Does anyone know if it’s possible to print LAMMPS high-level output (that’d normally go to stdout if no -screen option is specified) to a file that can be read in real time so that one could check the status of the program while LAMMPS is running in the background? As far as I can tell, on my linux serial build (8 Oct), both -screen file and output redirection to a file only update when LAMMPS finishes, as is the case with the log file. Is there a way to change this behavior so that LAMMPS sends high-level output to a file while running, as it does when printing to stdout? I don’t think this is an issue of my build/my system, but I could be wrong.
Tyler Harvey

Hi all,

tyler,

Does anyone know if it's possible to print LAMMPS high-level output (that'd
normally go to stdout if no -screen option is specified) to a file that can
be read in real time so that one could check the status of the program while
LAMMPS is running in the background? As far as I can tell, on my linux
serial build (8 Oct), both -screen file and output redirection to a file
only update when LAMMPS finishes, as is the case with the log file. Is there
a way to change this behavior so that LAMMPS sends high-level output to a
file while running, as it does when printing to stdout? I don't think this
is an issue of my build/my system, but I could be wrong.

this is an issue of I/O buffering defaults. the stdio library that lammps
uses defaults to line buffered output on stdout and block buffered
(4kbyte or 8kbyte typically) output on file I/O.

you can use "thermo_modify flush yes" to have lammps insert a
call to fflush(2) after each thermo output block has been generated.

keep in mind that this can negatively effect you performance, as
the fflush() calls stall execution until data is committed from the
i/o buffer to the kernel.

cheers,
    axel.

Hey Axel,
That worked perfectly, thanks so much! Great to know that this behavior comes from the c++ library, too (and to know what it’s called).

John, just to clairfy–my trouble was that I was using output redirection to a file as you described, but I guess, based on what Axel’s said, the file only read 4 or 8 kb chunks from the output buffer at a time, which means that I had to wait quite a while before seeing each block of output in the file using a ‘tail -f output.file’ shell command, which isn’t very feasible for a quick check of the program’s status. But “thermo_modify flush yes” is a great, if speed-decreasing, fix.

Tyler

Essentially everything written to the screen is also written to
the log file, and it is flushed the same way, so looking at it
should be sufficient.

Steve