Merge pull request #3115 from rbberger/pylammps_update

PyLammps update
This commit is contained in:
Axel Kohlmeyer
2022-02-07 15:09:10 -05:00
committed by GitHub
15 changed files with 341 additions and 103 deletions

View File

@ -213,8 +213,7 @@ void Error::one(const std::string &file, int line, const std::string &str)
throw LAMMPSAbortException(mesg, world);
#else
if (screen) fflush(screen);
if (logfile) fflush(logfile);
utils::flush_buffers(lmp);
KokkosLMP::finalize();
MPI_Abort(world,1);
exit(1); // to trick "smart" compilers into believing this does not return

View File

@ -5439,6 +5439,21 @@ void lammps_fix_external_set_vector(void *handle, const char *id, int idx, doubl
/* ---------------------------------------------------------------------- */
/** Flush output buffers
\verbatim embed:rst
This function can be used to force output to be written to screen and logfiles
to simplify capturing output from LAMMPS library calls.
\endverbatim
*
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
*/
void lammps_flush_buffers(void *handle) {
utils::flush_buffers((LAMMPS *) handle);
}
/* ---------------------------------------------------------------------- */
/** Free memory buffer allocated by LAMMPS.
*
\verbatim embed:rst

View File

@ -246,6 +246,8 @@ void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double
void lammps_fix_external_set_vector_length(void *handle, const char *id, int len);
void lammps_fix_external_set_vector(void *handle, const char *id, int idx, double val);
void lammps_flush_buffers(void *ptr);
void lammps_free(void *ptr);
int lammps_is_running(void *handle);

View File

@ -375,8 +375,7 @@ void Thermo::compute(int flag)
if (me == 0) {
utils::logmesg(lmp,line);
if (screen && flushflag) fflush(screen);
if (logfile && flushflag) fflush(logfile);
if (flushflag) utils::flush_buffers(lmp);
}
// set to 1, so that subsequent invocations of CPU time will be non-zero

View File

@ -24,6 +24,7 @@
#include "text_file_reader.h"
#include "tokenizer.h"
#include "update.h"
#include "universe.h"
#include <algorithm>
#include <cctype>
@ -138,6 +139,14 @@ void utils::fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format, fmt::format_ar
}
}
void utils::flush_buffers(LAMMPS *lmp)
{
if (lmp->screen) fflush(lmp->screen);
if (lmp->logfile) fflush(lmp->logfile);
if (lmp->universe->uscreen) fflush(lmp->universe->uscreen);
if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile);
}
/* define this here, so we won't have to include the headers
everywhere and utils.h will more likely be included anyway. */

View File

@ -74,6 +74,14 @@ namespace utils {
void logmesg(LAMMPS *lmp, const std::string &mesg);
/*! Flush output buffers
*
* This function calls fflush on screen and logfile FILE pointers
* if available
*/
void flush_buffers(LAMMPS *lmp);
/*! Return a string representing the current system error status
*
* This is a wrapper around calling strerror(errno).