implement 'dump_modify maxfiles' feature as discussed

This commit is contained in:
Axel Kohlmeyer
2018-05-10 23:25:26 -04:00
parent 724ade0af3
commit 7780d92823
3 changed files with 64 additions and 1 deletions

View File

@ -15,7 +15,7 @@ dump_modify dump-ID keyword values ... :pre
dump-ID = ID of dump to modify :ulb,l dump-ID = ID of dump to modify :ulb,l
one or more keyword/value pairs may be appended :l one or more keyword/value pairs may be appended :l
these keywords apply to various dump styles :l these keywords apply to various dump styles :l
keyword = {append} or {at} or {buffer} or {delay} or {element} or {every} or {fileper} or {first} or {flush} or {format} or {image} or {label} or {nfile} or {pad} or {precision} or {region} or {scale} or {sort} or {thresh} or {unwrap} :l keyword = {append} or {at} or {buffer} or {delay} or {element} or {every} or {fileper} or {first} or {flush} or {format} or {image} or {label} or {maxfiles} or {nfile} or {pad} or {precision} or {region} or {scale} or {sort} or {thresh} or {unwrap} :l
{append} arg = {yes} or {no} {append} arg = {yes} or {no}
{at} arg = N {at} arg = N
N = index of frame written upon first dump N = index of frame written upon first dump
@ -37,6 +37,8 @@ keyword = {append} or {at} or {buffer} or {delay} or {element} or {every} or {fi
{image} arg = {yes} or {no} {image} arg = {yes} or {no}
{label} arg = string {label} arg = string
string = character string (e.g. BONDS) to use in header of dump local file string = character string (e.g. BONDS) to use in header of dump local file
{maxfiles} arg = maxf
maxf = retain at most {maxf} files when writing one file per timestepq
{nfile} arg = Nf {nfile} arg = Nf
Nf = write this many files, one from each of Nf processors Nf = write this many files, one from each of Nf processors
{pad} arg = Nchar = # of characters to convert timestep to {pad} arg = Nchar = # of characters to convert timestep to
@ -364,6 +366,15 @@ e.g. BONDS or ANGLES.
:line :line
The {maxfiles} keyword applies only to dumps with a '*' wildcard included
in the dump file name, i.e. when writing one file per frame. The number
following the keyword determines the maximum number of files being written.
If this number is reached, the olders dump file from the current sequence
is deleted before a new dump file is written. A {maxfiles} value of -1
or 0 indicates that all files are retained.
:line
The {nfile} or {fileper} keywords can be used in conjunction with the The {nfile} or {fileper} keywords can be used in conjunction with the
"%" wildcard character in the specified dump file name, for all dump "%" wildcard character in the specified dump file name, for all dump
styles except the {dcd}, {image}, {movie}, {xtc}, and {xyz} styles styles except the {dcd}, {image}, {movie}, {xtc}, and {xyz} styles
@ -901,6 +912,7 @@ flush = yes
format = %d and %g for each integer or floating point value format = %d and %g for each integer or floating point value
image = no image = no
label = ENTRIES label = ENTRIES
maxifiles = -1
nfile = 1 nfile = 1
pad = 0 pad = 0
pbc = no pbc = no

View File

@ -91,6 +91,11 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
pbcflag = 0; pbcflag = 0;
delay_flag = 0; delay_flag = 0;
maxfiles = -1;
numfiles = 0;
fileidx = 0;
nameslist = NULL;
maxbuf = maxids = maxsort = maxproc = 0; maxbuf = maxids = maxsort = maxproc = 0;
buf = bufsort = NULL; buf = bufsort = NULL;
ids = idsort = NULL; ids = idsort = NULL;
@ -187,6 +192,13 @@ Dump::~Dump()
if (multiproc) MPI_Comm_free(&clustercomm); if (multiproc) MPI_Comm_free(&clustercomm);
// delete storage for caching file names
if (maxfiles > 0) {
for (int idx=0; idx < numfiles; ++idx)
delete[] nameslist[idx];
delete[] nameslist;
}
// XTC style sets fp to NULL since it closes file in its destructor // XTC style sets fp to NULL since it closes file in its destructor
if (multifile == 0 && fp != NULL) { if (multifile == 0 && fp != NULL) {
@ -549,6 +561,19 @@ void Dump::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1); sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
} }
*ptr = '*'; *ptr = '*';
if (maxfiles > 0) {
if (numfiles < maxfiles) {
nameslist[numfiles] = new char[strlen(filecurrent)+1];
strcpy(nameslist[numfiles],filecurrent);
++numfiles;
} else {
remove(nameslist[fileidx]);
delete[] nameslist[fileidx];
nameslist[fileidx] = new char[strlen(filecurrent)+1];
strcpy(nameslist[fileidx],filecurrent);
fileidx = (fileidx + 1) % maxfiles;
}
}
} }
// each proc with filewriter = 1 opens a file // each proc with filewriter = 1 opens a file
@ -1003,6 +1028,27 @@ void Dump::modify_params(int narg, char **arg)
iarg += n; iarg += n;
} }
} else if (strcmp(arg[iarg],"maxfiles") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (!multifile)
error->all(FLERR,"Cannot use dump_modify maxfiles "
"without * in dump file name");
// wipe out existing storage
if (maxfiles > 0) {
for (int idx=0; idx < numfiles; ++idx)
delete[] nameslist[idx];
delete[] nameslist;
}
maxfiles = force->inumeric(FLERR,arg[iarg+1]);
if (maxfiles == 0) error->all(FLERR,"Illegal dump_modify command");
if (maxfiles > 0) {
nameslist = new char*[maxfiles];
numfiles = 0;
for (int idx=0; idx < maxfiles; ++idx)
nameslist[idx] = NULL;
fileidx = 0;
}
iarg += 2;
} else if (strcmp(arg[iarg],"nfile") == 0) { } else if (strcmp(arg[iarg],"nfile") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command"); if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (!multiproc) if (!multiproc)

View File

@ -105,6 +105,11 @@ class Dump : protected Pointers {
double boxzlo,boxzhi; double boxzlo,boxzhi;
double boxxy,boxxz,boxyz; double boxxy,boxxz,boxyz;
int maxfiles; // max number of files created, -1 == infinite
int numfiles; // number of files in names list
int fileidx; // index of file in names list
char **nameslist; // list of history file names
bigint ntotal; // total # of per-atom lines in snapshot bigint ntotal; // total # of per-atom lines in snapshot
int reorderflag; // 1 if OK to reorder instead of sort int reorderflag; // 1 if OK to reorder instead of sort
int ntotal_reorder; // # of atoms that must be in snapshot int ntotal_reorder; // # of atoms that must be in snapshot