diff --git a/doc/src/Commands_input.rst b/doc/src/Commands_input.rst index 3313474686..595b8ffa2c 100644 --- a/doc/src/Commands_input.rst +++ b/doc/src/Commands_input.rst @@ -1,55 +1,75 @@ LAMMPS input scripts ==================== -LAMMPS executes by reading commands from a input script (text file), -one line at a time. When the input script ends, LAMMPS exits. Each -command causes LAMMPS to take some action. It may set an internal -variable, read in a file, or run a simulation. Most commands have -default settings, which means you only need to use the command if you -wish to change the default. +LAMMPS executes calculations by reading commands from a input script (text file), one +line at a time. When the input script ends, LAMMPS exits. This is different +from programs that read and process the entire input before starting a calculation. + +Each command causes LAMMPS to take some immediate action without regard +for any commands that may be processed later. Commands may set an +internal variable, read in a file, or run a simulation. These actions +can be grouped into three categories: + +a) commands that change a global setting (examples: timestep, newton, + echo, log, thermo, restart), +b) commands that add, modify, remove, or replace "styles" that are + executed during a "run" (examples: pair_style, fix, compute, dump, + thermo_style, pair_modify), and +c) commands that execute a "run" or perform some other computation or + operation (examples: print, run, minimize, temper, write_dump, rerun, + read_data, read_restart) + +Commands in category a) have default settings, which means you only +need to use the command if you wish to change the defaults. In many cases, the ordering of commands in an input script is not -important. However the following rules apply: +important, but can have consequences when the global state is changed +between commands in the c) category. The following rules apply: (1) LAMMPS does not read your entire input script and then perform a -simulation with all the settings. Rather, the input script is read -one line at a time and each command takes effect when it is read. -Thus this sequence of commands: + simulation with all the settings. Rather, the input script is read + one line at a time and each command takes effect when it is read. + Thus this sequence of commands: -.. code-block:: LAMMPS + .. code-block:: LAMMPS - timestep 0.5 - run 100 - run 100 + timestep 0.5 + run 100 + run 100 -does something different than this sequence: + does something different than this sequence: -.. code-block:: LAMMPS + .. code-block:: LAMMPS - run 100 - timestep 0.5 - run 100 + run 100 + timestep 0.5 + run 100 -In the first case, the specified timestep (0.5 fs) is used for two -simulations of 100 timesteps each. In the second case, the default -timestep (1.0 fs) is used for the first 100 step simulation and a 0.5 fs -timestep is used for the second one. + In the first case, the specified timestep (0.5 fs) is used for two + simulations of 100 timesteps each. In the second case, the default + timestep (1.0 fs) is used for the first 100 step simulation and a + 0.5 fs timestep is used for the second one. (2) Some commands are only valid when they follow other commands. For -example you cannot set the temperature of a group of atoms until atoms -have been defined and a group command is used to define which atoms -belong to the group. + example you cannot set the temperature of a group of atoms until + atoms have been defined and a group command is used to define which + atoms belong to the group. (3) Sometimes command B will use values that can be set by command A. -This means command A must precede command B in the input script if it -is to have the desired effect. For example, the -:doc:`read_data ` command initializes the system by setting -up the simulation box and assigning atoms to processors. If default -values are not desired, the :doc:`processors ` and -:doc:`boundary ` commands need to be used before read_data to -tell LAMMPS how to map processors to the simulation box. + This means command A must precede command B in the input script if + it is to have the desired effect. For example, the :doc:`read_data + ` command initializes the system by setting up the + simulation box and assigning atoms to processors. If default values + are not desired, the :doc:`processors ` and + :doc:`boundary ` commands need to be used before read_data + to tell LAMMPS how to map processors to the simulation box. Many input script errors are detected by LAMMPS and an ERROR or WARNING message is printed. The :doc:`Errors ` page gives more information on what errors mean. The documentation for each command lists restrictions on how the command can be used. + +You can use the :ref:`-skiprun ` command line flag +to have LAMMPS skip the execution of any "run", "minimize", or similar +commands to check the entire input for correct syntax to avoid crashes +on typos or syntax errors in long runs. diff --git a/doc/src/Run_options.rst b/doc/src/Run_options.rst index c4004c87e0..b07c9b2529 100644 --- a/doc/src/Run_options.rst +++ b/doc/src/Run_options.rst @@ -2,7 +2,7 @@ Command-line options ==================== At run time, LAMMPS recognizes several optional command-line switches -which may be used in any order. Either the full word or a one-or-two +which may be used in any order. Either the full word or a one or two letter abbreviation can be used: * :ref:`-e or -echo ` @@ -22,6 +22,7 @@ letter abbreviation can be used: * :ref:`-r2data or -restart2data ` * :ref:`-r2dump or -restart2dump ` * :ref:`-sc or -screen ` +* :ref:`-sr or skiprun ` * :ref:`-sf or -suffix ` * :ref:`-v or -var ` @@ -532,6 +533,20 @@ partition screen files file.N. ---------- +.. _skiprun: + +**-skiprun** + +Insert the command :doc:`timer timerout 0 every 1 ` at the +beginning of an input file or after a :doc:`clear ` command. +This has the effect that the entire LAMMPS input script is processed +without executing actual runs or minimizations (their main loops are +skipped). This can be helpful and convenient to test input scripts for +long running calculations to avoid having them crash after a long time +due to a typo or syntax error. + +---------- + .. _suffix: **-suffix style args** diff --git a/src/lammps.cpp b/src/lammps.cpp index 270b3c0584..e3e8f4c181 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -126,6 +126,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : cslib = nullptr; cscomm = 0; + skipflag = 0; + screen = nullptr; logfile = nullptr; infile = nullptr; @@ -391,6 +393,11 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : screenflag = iarg + 1; iarg += 2; + } else if (strcmp(arg[iarg],"-skiprun") == 0 || + strcmp(arg[iarg],"-sr") == 0) { + skipflag = 1; + ++iarg; + } else if (strcmp(arg[iarg],"-suffix") == 0 || strcmp(arg[iarg],"-sf") == 0) { if (iarg+2 > narg) @@ -462,9 +469,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : else { universe->uscreen = fopen(arg[screenflag],"w"); if (universe->uscreen == nullptr) - error->universe_one(FLERR,fmt::format("Cannot open universe screen " - "file {}: {}",arg[screenflag], - utils::getsyserror())); + error->universe_one(FLERR,fmt::format("Cannot open universe screen file {}: {}", + arg[screenflag],utils::getsyserror())); } if (logflag == 0) { if (helpflag == 0) { @@ -478,9 +484,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : else { universe->ulogfile = fopen(arg[logflag],"w"); if (universe->ulogfile == nullptr) - error->universe_one(FLERR,fmt::format("Cannot open universe log " - "file {}: {}",arg[logflag], - utils::getsyserror())); + error->universe_one(FLERR,fmt::format("Cannot open universe log file {}: {}", + arg[logflag],utils::getsyserror())); } } @@ -505,8 +510,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->one(FLERR,"Cannot open input script {}: {}",arg[inflag], utils::getsyserror()); } if ((universe->me == 0) && !helpflag) @@ -530,16 +534,14 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : str = fmt::format("screen.{}",universe->iworld); screen = fopen(str.c_str(),"w"); if (screen == nullptr) - error->one(FLERR,"Cannot open screen file {}: {}", - str,utils::getsyserror()); + error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror()); } else if (strcmp(arg[screenflag],"none") == 0) { screen = nullptr; } else { str = fmt::format("{}.{}",arg[screenflag],universe->iworld); screen = fopen(str.c_str(),"w"); if (screen == nullptr) - error->one(FLERR,"Cannot open screen file {}: {}", - arg[screenflag],utils::getsyserror()); + error->one(FLERR,"Cannot open screen file {}: {}",arg[screenflag],utils::getsyserror()); } } else if (strcmp(arg[partscreenflag],"none") == 0) { screen = nullptr; @@ -547,8 +549,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : str = fmt::format("{}.{}",arg[partscreenflag],universe->iworld); screen = fopen(str.c_str(),"w"); if (screen == nullptr) - error->one(FLERR,"Cannot open screen file {}: {}", - str,utils::getsyserror()); + error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror()); } if (partlogflag == 0) { @@ -556,16 +557,14 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : str = fmt::format("log.lammps.{}",universe->iworld); logfile = fopen(str.c_str(),"w"); if (logfile == nullptr) - error->one(FLERR,"Cannot open logfile {}: {}", - str, utils::getsyserror()); + error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror()); } else if (strcmp(arg[logflag],"none") == 0) { logfile = nullptr; } else { str = fmt::format("{}.{}",arg[logflag],universe->iworld); logfile = fopen(str.c_str(),"w"); if (logfile == nullptr) - error->one(FLERR,"Cannot open logfile {}: {}", - str, utils::getsyserror()); + error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror()); } } else if (strcmp(arg[partlogflag],"none") == 0) { logfile = nullptr; @@ -573,15 +572,13 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : str = fmt::format("{}.{}",arg[partlogflag],universe->iworld); logfile = fopen(str.c_str(),"w"); if (logfile == nullptr) - error->one(FLERR,"Cannot open logfile {}: {}", - str, utils::getsyserror()); + error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror()); } if (strcmp(arg[inflag], "none") != 0) { infile = fopen(arg[inflag],"r"); if (infile == nullptr) - error->one(FLERR,"Cannot open input script {}: {}", - arg[inflag], utils::getsyserror()); + error->one(FLERR,"Cannot open input script {}: {}",arg[inflag], utils::getsyserror()); } } @@ -615,12 +612,10 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : int mpisize; MPI_Type_size(MPI_LMP_TAGINT,&mpisize); if (mpisize != sizeof(tagint)) - error->all(FLERR,"MPI_LMP_TAGINT and tagint in " - "lmptype.h are not compatible"); + error->all(FLERR,"MPI_LMP_TAGINT and tagint in lmptype.h are not compatible"); MPI_Type_size(MPI_LMP_BIGINT,&mpisize); if (mpisize != sizeof(bigint)) - error->all(FLERR,"MPI_LMP_BIGINT and bigint in " - "lmptype.h are not compatible"); + error->all(FLERR,"MPI_LMP_BIGINT and bigint in lmptype.h are not compatible"); #ifdef LAMMPS_SMALLBIG if (sizeof(smallint) != 4 || sizeof(imageint) != 4 || @@ -837,6 +832,8 @@ void LAMMPS::create() void LAMMPS::post_create() { + if (skipflag) input->one("timer timeout 0 every 1"); + // default package command triggered by "-k on" if (kokkos && kokkos->kokkos_exists) input->one("package kokkos"); diff --git a/src/lammps.h b/src/lammps.h index 74ae47e9a2..71b731204c 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -22,52 +22,52 @@ namespace LAMMPS_NS { class LAMMPS { public: // ptrs to fundamental LAMMPS classes - class Memory *memory; // memory allocation functions - class Error *error; // error handling - class Universe *universe; // universe of processors - class Input *input; // input script processing - // ptrs to top-level LAMMPS-specific classes - class Atom *atom; // atom-based quantities - class Update *update; // integrators/minimizers - class Neighbor *neighbor; // neighbor lists - class Comm *comm; // inter-processor communication - class Domain *domain; // simulation box - class Force *force; // inter-particle forces - class Modify *modify; // fixes and computes - class Group *group; // groups of atoms - class Output *output; // thermo/dump/restart - class Timer *timer; // CPU timing info + class Memory *memory; // memory allocation functions + class Error *error; // error handling + class Universe *universe; // universe of processors + class Input *input; // input script processing + // ptrs to top-level LAMMPS-specific classes + class Atom *atom; // atom-based quantities + class Update *update; // integrators/minimizers + class Neighbor *neighbor; // neighbor lists + class Comm *comm; // inter-processor communication + class Domain *domain; // simulation box + class Force *force; // inter-particle forces + class Modify *modify; // fixes and computes + class Group *group; // groups of atoms + class Output *output; // thermo/dump/restart + class Timer *timer; // CPU timing info + // + class KokkosLMP *kokkos; // KOKKOS accelerator class + class AtomKokkos *atomKK; // KOKKOS version of Atom class + class MemoryKokkos *memoryKK; // KOKKOS version of Memory class + class Python *python; // Python interface + class CiteMe *citeme; // handle citation info const char *version; // LAMMPS version string = date int num_ver; // numeric version id derived from *version* // that is constructed so that will be greater // for newer versions in numeric or string // value comparisons - - MPI_Comm world; // MPI communicator - FILE *infile; // infile - FILE *screen; // screen output - FILE *logfile; // logfile - - double initclock; // wall clock at instantiation + // + MPI_Comm world; // MPI communicator + FILE *infile; // infile + FILE *screen; // screen output + FILE *logfile; // logfile + // + double initclock; // wall clock at instantiation + int skiprunflag; // 1 inserts timer command to skip run and minimize loops char *suffix, *suffix2, *suffixp; // suffixes to add to input script style names int suffix_enable; // 1 if suffixes are enabled, 0 if disabled char *exename; // pointer to argv[0] + // char ***packargs; // arguments for cmdline package commands int num_package; // number of cmdline package commands - - int clientserver; // 0 = neither, 1 = client, 2 = server - void *cslib; // client/server messaging via CSlib - MPI_Comm cscomm; // MPI comm for client+server in mpi/one mode - - class KokkosLMP *kokkos; // KOKKOS accelerator class - class AtomKokkos *atomKK; // KOKKOS version of Atom class - class MemoryKokkos *memoryKK; // KOKKOS version of Memory class - - class Python *python; // Python interface - - class CiteMe *citeme; // handle citation info + // + int clientserver; // 0 = neither, 1 = client, 2 = server + void *cslib; // client/server messaging via CSlib + MPI_Comm cscomm; // MPI comm for client+server in mpi/one mode const char *match_style(const char *style, const char *name); static const char *installed_packages[];