Merge remote-tracking branch 'github/read-dump-parallel' into collected-post-stable-patches

# Conflicts:
#	src/read_dump.cpp
This commit is contained in:
Axel Kohlmeyer 2018-12-03 15:28:34 -05:00
commit 22f99be57e
11 changed files with 2167 additions and 325 deletions

View File

@ -22,7 +22,8 @@ field = {x} or {y} or {z} or {vx} or {vy} or {vz} or {q} or {ix} or {iy} or {iz}
{ix},{iy},{iz} = image flags in each dimension
{fx},{fy},{fz} = force components :pre
zero or more keyword/value pairs may be appended :l
keyword = {box} or {replace} or {purge} or {trim} or {add} or {label} or {scaled} or {wrapped} or {format} :l
keyword = {nfile} or {box} or {replace} or {purge} or {trim} or {add} or {label} or {scaled} or {wrapped} or {format} :l
{nfile} value = Nfiles = how many parallel dump files exist
{box} value = {yes} or {no} = replace simulation box with dump box
{replace} value = {yes} or {no} = overwrite atoms with dump atoms
{purge} value = {yes} or {no} = delete all atoms before adding dump atoms
@ -85,9 +86,18 @@ command, after the dump snapshot is read.
If the dump filename specified as {file} ends with ".gz", the dump
file is read in gzipped format. You cannot (yet) read a dump file
that was written in binary format with a ".bin" suffix, or to multiple
files via the "%" option in the dump file name. See the
"dump"_dump.html command for details.
that was written in binary format with a ".bin" suffix.
You can read dump files that were written (in parallel) to multiple
files via the "%" wild-card character in the dump file name. If any
specified dump file name contains a "%", they must all contain it.
See the "dump"_dump.html command for details.
The "%" wild-card character is only supported by the {native} format
for dump files, described next.
If reading parallel dump files, you must also use the {nfile} keyword
to tell LAMMPS how many parallel files exist, via its specified
{Nfiles} value.
The format of the dump file is selected through the {format} keyword.
If specified, it must be the last keyword used, since all remaining

View File

@ -89,12 +89,23 @@ this auxiliary information should be defined in the usual way, e.g. in
a data file read in by a "read_data"_read_data.html command, before
using the rerun command.
Also note that the frequency of thermodynamic or dump output from the
rerun simulation will depend on settings made in the rerun script, the
same as for output from any LAMMPS simulation. See further info below
as to what that means if the timesteps for snapshots read from dump
files do not match the specified output frequency.
:line
If more than one dump file is specified, the dump files are read one
after the other. It is assumed that snapshot timesteps will be in
ascending order. If a snapshot is encountered that is not in
ascending order, it will cause the rerun command to complete.
ascending order, it will skip the snapshot until it reads one that is.
This allows skipping of a duplicate snapshot (same timestep),
e.g. that appeared at the end of one file and beginning of the next.
However if you specify a series of dump files in an incorrect order
(with respect to the timesteps they contain), you may skip large
numbers of snapshots
The {first}, {last}, {every}, {skip} keywords determine which
snapshots are read from the dump file(s). Snapshots are skipped until
@ -177,12 +188,12 @@ a timestep it expects to be, LAMMPS will flag an error.
The various forms of LAMMPS output, as defined by the
"thermo_style"_thermo_style.html, "thermo"_thermo.html,
"dump"_dump.html, and "restart"_restart.html commands occur on
specific timesteps. If successive dump snapshots skip those
timesteps, then no output will be produced. E.g. if you request
thermodynamic output every 100 steps, but the dump file snapshots are
every 1000 steps, then you will only see thermodynamic output every
1000 steps.
"dump"_dump.html, and "restart"_restart.html commands occur with
specified frequency, e.g. every N steps. If the timestep for a dump
snapshot is not a multiple of N, then it will be read and processed,
but no output will be produced. If you want output for every dump
snapshot, you can simply use N=1 for an output frequency, e.g. for
thermodyanmic output or new dump file output.
:line

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ CommandStyle(read_dump,ReadDump)
#ifndef LMP_READ_DUMP_H
#define LMP_READ_DUMP_H
#include <mpi.h>
#include <cstdio>
#include "pointers.h"
@ -43,15 +44,26 @@ class ReadDump : protected Pointers {
private:
int me,nprocs;
FILE *fp;
int dimension;
char **files; // list of input dump files to process
int nfile; // # of dump files to process (each may be parallel)
int currentfile; // current open file (0 to nfile-1)
MPI_Comm clustercomm; // comm for proc cluster that reads/shares a file
int me_cluster,nprocs_cluster; // proc ID and count for my read cluster
int multiproc; // 0 = each dump file is a single file
// 1 = each dump file is parallel (multiple files)
int multiproc_nfile; // number of parallel files in one dump file
int nreader; // # of parallel dump files read by my cluster
int firstfile; // index of 1st dump file my cluster reads
// (0 to multiproc_nfile-1)
int filereader; // 1 if this proc reads from a dump file(s)
int dimension; // same as in Domain
int triclinic;
int nfile; // # of dump files to process
char **files; // list of file names
int currentfile; // currently open file
int boxflag; // overwrite simulation with dump file box params
int replaceflag,addflag; // flags for processing dump snapshot atoms
int trimflag,purgeflag;
@ -59,10 +71,13 @@ private:
int wrapflag; // user 0/1 if dump file coords are unwrapped/wrapped
char *readerstyle; // style of dump files to read
int nnew; // # of dump file atoms this proc owns
int nfield; // # of fields to extract from dump file
int *fieldtype; // type of each field = X,VY,IZ,etc
char **fieldlabel; // user specified label for field
double **fields; // per-atom field values
int maxnew; // allocation size of fields array
double **buf; // read buffer
int scaled; // 0/1 if dump file coords are unscaled/scaled
int wrapped; // 0/1 if dump file coords are unwrapped/wrapped
@ -71,20 +86,26 @@ private:
double xlo,xhi,ylo,yhi,zlo,zhi,xy,xz,yz; // dump snapshot box params
double xprd,yprd,zprd;
bigint nsnapatoms; // # of atoms in dump file shapshot
bigint *nsnapatoms; // # of atoms in one snapshot from
// one (parallel) dump file
// nreader-length vector b/c a reader proc
// may read from multiple parallel dump files
int npurge,nreplace,ntrim,nadd; // stats on processed atoms
int addproc; // proc that should add next atom
int yindex,zindex; // field index for Y,Z coords
int *uflag; // set to 1 if snapshot atom matches owned atom
int *ucflag,*ucflag_all; // set to 1 if snapshot chunk atom was processed
class Reader **readers; // class that reads a dump file
// nreader-length list of readers if proc reads
// from multiple parallel dump files
class Reader *reader; // class that reads dump file
void read_atoms();
void process_atoms();
void migrate_old_atoms();
void migrate_new_atoms();
void migrate_atoms_by_coords();
void setup_multiproc();
int whichtype(char *);
void process_atoms(int);
void delete_atoms();
double xfield(int, int);
double yfield(int, int);

1011
src/read_dump2.cpp Normal file

File diff suppressed because it is too large Load Diff

172
src/read_dump2.h Normal file
View File

@ -0,0 +1,172 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
Contributed by Timothy Sirk
------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS
CommandStyle(read_dump2,ReadDump2)
#else
#ifndef LMP_READ_DUMP2_H
#define LMP_READ_DUMP2_H
#include <cstdio>
#include "pointers.h"
namespace LAMMPS_NS {
class ReadDump2 : protected Pointers {
public:
ReadDump2(class LAMMPS *);
~ReadDump2();
void command(int, char **);
void store_files(int, char **);
void setup_reader(int, char **);
bigint seek(bigint, int);
void header(int);
bigint next(bigint, bigint, int, int);
void atoms();
int fields_and_keywords(int, char **);
private:
int me,nprocs;
FILE *fp;
int dimension;
int triclinic;
int nfile; // # of dump files to process
char **files; // list of file names
int currentfile; // currently open file
int boxflag; // overwrite simulation with dump file box params
int replaceflag,addflag; // flags for processing dump snapshot atoms
int trimflag,purgeflag;
int scaleflag; // user 0/1 if dump file coords are unscaled/scaled
int wrapflag; // user 0/1 if dump file coords are unwrapped/wrapped
char *readerstyle; // style of dump files to read
int nfield; // # of fields to extract from dump file
int *fieldtype; // type of each field = X,VY,IZ,etc
char **fieldlabel; // user specified label for field
double **fields; // per-atom field values
int scaled; // 0/1 if dump file coords are unscaled/scaled
int wrapped; // 0/1 if dump file coords are unwrapped/wrapped
double box[3][3]; // dump file box parameters
double xlo,xhi,ylo,yhi,zlo,zhi,xy,xz,yz; // dump snapshot box params
double xprd,yprd,zprd;
bigint nsnapatoms; // # of atoms in dump file shapshot
int npurge,nreplace,ntrim,nadd; // stats on processed atoms
int addproc; // proc that should add next atom
int yindex,zindex; // field index for Y,Z coords
int *uflag; // set to 1 if snapshot atom matches owned atom
int *ucflag,*ucflag_all; // set to 1 if snapshot chunk atom was processed
class Reader *reader; // class that reads dump file
int whichtype(char *);
void process_atoms(int);
void delete_atoms();
double xfield(int, int);
double yfield(int, int);
double zfield(int, int);
};
}
#endif
#endif
/* ERROR/WARNING messages:
E: Read_dump command before simulation box is defined
The read_dump command cannot be used before a read_data, read_restart,
or create_box command.
E: Illegal ... command
Self-explanatory. Check the input script syntax and compare to the
documentation for the command. You can use -echo screen as a
command-line option when running LAMMPS to see the offending line.
E: Dump file does not contain requested snapshot
Self-explanatory.
E: Unknown dump reader style
The choice of dump reader style via the format keyword is unknown.
E: No box information in dump, must use 'box no'
UNDOCUMENTED
E: Read_dump triclinic status does not match simulation
Both the dump snapshot and the current LAMMPS simulation must
be using either an orthogonal or triclinic box.
E: Read_dump field not found in dump file
Self-explanatory.
E: Read_dump xyz fields do not have consistent scaling/wrapping
Self-explanatory.
E: All read_dump x,y,z fields must be specified for scaled, triclinic coords
For triclinic boxes and scaled coordinates you must specify all 3 of
the x,y,z fields, else LAMMPS cannot reconstruct the unscaled
coordinates.
E: Too many total atoms
See the setting for bigint in the src/lmptype.h file.
E: Read dump of atom property that isn't allocated
Self-explanatory.
E: Duplicate fields in read_dump command
Self-explanatory.
E: If read_dump purges it cannot replace or trim
These operations are not compatible. See the read_dump doc
page for details.
E: Read_dump cannot use 'add keep' without atom IDs
UNDOCUMENTED
E: Cannot add atoms if dump file does not store atom type
UNDOCUMENTED
U: No box information in dump. You have to use 'box no'
Self-explanatory.
*/

View File

@ -31,11 +31,13 @@ class ReadRestart : protected Pointers {
void command(int, char **);
private:
int me,nprocs,nprocs_file,multiproc_file;
int me,nprocs;
FILE *fp;
int multiproc; // 0 = proc 0 writes for all
// else # of procs writing files
int multiproc; // 0 = restart file is a single file
// 1 = restart file is parallel (multiple files)
int multiproc_file; // # of parallel files in restart
int nprocs_file; // total # of procs that wrote restart file
// MPI-IO values

View File

@ -18,6 +18,8 @@
using namespace LAMMPS_NS;
// only proc 0 calls methods of this class, except for constructor/destructor
/* ---------------------------------------------------------------------- */
Reader::Reader(LAMMPS *lmp) : Pointers(lmp)

View File

@ -57,7 +57,7 @@ void Rerun::command(int narg, char **arg)
if (nfile == 0 || nfile == narg) error->all(FLERR,"Illegal rerun command");
// parse optional args up until "dump"
// user MAXBIGINT -1 so Output can add 1 to it and still be a big int
// use MAXBIGINT -1 so Output can add 1 to it and still be a big int
bigint first = 0;
bigint last = MAXBIGINT - 1;

193
src/rerun2.cpp Normal file
View File

@ -0,0 +1,193 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include <cstdlib>
#include <cstring>
#include "rerun2.h"
#include "read_dump2.h"
#include "domain.h"
#include "update.h"
#include "integrate.h"
#include "modify.h"
#include "output.h"
#include "finish.h"
#include "timer.h"
#include "error.h"
#include "force.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
Rerun2::Rerun2(LAMMPS *lmp) : Pointers(lmp) {}
/* ---------------------------------------------------------------------- */
void Rerun2::command(int narg, char **arg)
{
if (domain->box_exist == 0)
error->all(FLERR,"Rerun command before simulation box is defined");
if (narg < 2) error->all(FLERR,"Illegal rerun command");
// list of dump files = args until a keyword
int iarg = 0;
while (iarg < narg) {
if (strcmp(arg[iarg],"first") == 0) break;
if (strcmp(arg[iarg],"last") == 0) break;
if (strcmp(arg[iarg],"every") == 0) break;
if (strcmp(arg[iarg],"skip") == 0) break;
if (strcmp(arg[iarg],"start") == 0) break;
if (strcmp(arg[iarg],"stop") == 0) break;
if (strcmp(arg[iarg],"dump") == 0) break;
iarg++;
}
int nfile = iarg;
if (nfile == 0 || nfile == narg) error->all(FLERR,"Illegal rerun command");
// parse optional args up until "dump"
// use MAXBIGINT -1 so Output can add 1 to it and still be a big int
bigint first = 0;
bigint last = MAXBIGINT - 1;
int nevery = 0;
int nskip = 1;
int startflag = 0;
int stopflag = 0;
bigint start = -1;
bigint stop = -1;
while (iarg < narg) {
if (strcmp(arg[iarg],"first") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command");
first = force->bnumeric(FLERR,arg[iarg+1]);
if (first < 0) error->all(FLERR,"Illegal rerun command");
iarg += 2;
} else if (strcmp(arg[iarg],"last") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command");
last = force->bnumeric(FLERR,arg[iarg+1]);
if (last < 0) error->all(FLERR,"Illegal rerun command");
iarg += 2;
} else if (strcmp(arg[iarg],"every") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command");
nevery = force->inumeric(FLERR,arg[iarg+1]);
if (nevery < 0) error->all(FLERR,"Illegal rerun command");
iarg += 2;
} else if (strcmp(arg[iarg],"skip") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command");
nskip = force->inumeric(FLERR,arg[iarg+1]);
if (nskip <= 0) error->all(FLERR,"Illegal rerun command");
iarg += 2;
} else if (strcmp(arg[iarg],"start") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command");
startflag = 1;
start = force->bnumeric(FLERR,arg[iarg+1]);
if (start < 0) error->all(FLERR,"Illegal rerun command");
iarg += 2;
} else if (strcmp(arg[iarg],"stop") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command");
stopflag = 1;
stop = force->bnumeric(FLERR,arg[iarg+1]);
if (stop < 0) error->all(FLERR,"Illegal rerun command");
iarg += 2;
} else if (strcmp(arg[iarg],"dump") == 0) {
break;
} else error->all(FLERR,"Illegal rerun command");
}
int nremain = narg - iarg - 1;
if (nremain <= 0) error->all(FLERR,"Illegal rerun command");
if (first > last) error->all(FLERR,"Illegal rerun command");
if (startflag && stopflag && start > stop)
error->all(FLERR,"Illegal rerun command");
// pass list of filenames to ReadDump
// along with post-"dump" args and post-"format" args
ReadDump2 *rd = new ReadDump2(lmp);
rd->store_files(nfile,arg);
if (nremain)
nremain = rd->fields_and_keywords(nremain,&arg[narg-nremain]);
else nremain = rd->fields_and_keywords(0,NULL);
if (nremain) rd->setup_reader(nremain,&arg[narg-nremain]);
else rd->setup_reader(0,NULL);
// perform the pseudo run
// invoke lmp->init() only once
// read all relevant snapshots
// use setup_minimal() since atoms are already owned by correct procs
// addstep_compute_all() insures energy/virial computed on every snapshot
update->whichflag = 1;
if (startflag) update->beginstep = update->firststep = start;
else update->beginstep = update->firststep = first;
if (stopflag) update->endstep = update->laststep = stop;
else update->endstep = update->laststep = last;
int firstflag = 1;
int ndump = 0;
lmp->init();
timer->init();
timer->barrier_start();
bigint ntimestep = rd->seek(first,0);
if (ntimestep < 0)
error->all(FLERR,"Rerun dump file does not contain requested snapshot");
while (1) {
ndump++;
rd->header(firstflag);
update->reset_timestep(ntimestep);
rd->atoms();
modify->init();
update->integrate->setup_minimal(1);
modify->end_of_step();
if (firstflag) output->setup();
else if (output->next) output->write(ntimestep);
firstflag = 0;
ntimestep = rd->next(ntimestep,last,nevery,nskip);
if (stopflag && ntimestep > stop)
error->all(FLERR,"Read rerun dump file timestep > specified stop");
if (ntimestep < 0) break;
}
// insure thermo output on last dump timestep
output->next_thermo = update->ntimestep;
output->write(update->ntimestep);
timer->barrier_stop();
update->integrate->cleanup();
// set update->nsteps to ndump for Finish stats to print
update->nsteps = ndump;
Finish finish(lmp);
finish.end(1);
update->whichflag = 0;
update->firststep = update->laststep = 0;
update->beginstep = update->endstep = 0;
// clean-up
delete rd;
}

59
src/rerun2.h Normal file
View File

@ -0,0 +1,59 @@
/* -*- c++ -*- ----------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef COMMAND_CLASS
CommandStyle(rerun2,Rerun2)
#else
#ifndef LMP_RERUN2_H
#define LMP_RERUN2_H
#include "pointers.h"
namespace LAMMPS_NS {
class Rerun2 : protected Pointers {
public:
Rerun2(class LAMMPS *);
void command(int, char **);
};
}
#endif
#endif
/* ERROR/WARNING messages:
E: Rerun command before simulation box is defined
The rerun command cannot be used before a read_data, read_restart, or
create_box command.
E: Illegal ... command
Self-explanatory. Check the input script syntax and compare to the
documentation for the command. You can use -echo screen as a
command-line option when running LAMMPS to see the offending line.
E: Rerun dump file does not contain requested snapshot
Self-explanatory.
E: Read rerun dump file timestep > specified stop
Self-explanatory.
*/