Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'dump_modify maxfiles' feature #907

Merged
merged 6 commits into from May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion doc/src/dump_modify.txt
Expand Up @@ -15,7 +15,7 @@ dump_modify dump-ID keyword values ... :pre
dump-ID = ID of dump to modify :ulb,l
one or more keyword/value pairs may be appended :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}
{at} arg = N
N = index of frame written upon first dump
Expand All @@ -37,6 +37,8 @@ keyword = {append} or {at} or {buffer} or {delay} or {element} or {every} or {fi
{image} arg = {yes} or {no}
{label} arg = string
string = character string (e.g. BONDS) to use in header of dump local file
{maxfiles} arg = Fmax
Fmax = keep only the most recent {Fmax} snapshots (one snapshot per file)
{nfile} arg = Nf
Nf = write this many files, one from each of Nf processors
{pad} arg = Nchar = # of characters to convert timestep to
Expand Down Expand Up @@ -364,6 +366,20 @@ e.g. BONDS or ANGLES.

:line

The {maxfiles} keyword can only be used when a '*' wildcard is
included in the dump file name, i.e. when writing a new file(s) for
each snapshot. The specified {Fmax} is how many snapshots will be
kept. Once this number is reached, the file(s) containing the oldest
snapshot is deleted before a new dump file is written. If the
specified {Fmax} <= 0, then all files are retained.

This can be useful for debugging, especially if you don't know on what
timestep something bad will happen, e.g. when LAMMPS will exit with an
error. You can dump every timestep, and limit the number of dump
files produced, even if you run for 1000s of steps.

:line

The {nfile} or {fileper} keywords can be used in conjunction with the
"%" wildcard character in the specified dump file name, for all dump
styles except the {dcd}, {image}, {movie}, {xtc}, and {xyz} styles
Expand Down Expand Up @@ -901,6 +917,7 @@ flush = yes
format = %d and %g for each integer or floating point value
image = no
label = ENTRIES
maxifiles = -1
nfile = 1
pad = 0
pbc = no
Expand Down
10 changes: 10 additions & 0 deletions lib/atc/Function.cpp
@@ -1,4 +1,6 @@
#ifndef _WIN32
#include <alloca.h>
#endif
#include "Function.h"
#include "ATC_Error.h"
#include "LammpsInterface.h"
Expand Down Expand Up @@ -59,7 +61,11 @@ namespace ATC {
{
string type = args[0];
int narg = nargs -1;
#ifdef _WIN32
double *dargs = (double *) _alloca(sizeof(double) * narg);
#endif
double *dargs = (double *) alloca(sizeof(double) * narg);
#endif
for (int i = 0; i < narg; ++i) dargs[i] = atof(args[i+1]);

return function(type, narg, dargs);
Expand Down Expand Up @@ -193,7 +199,11 @@ XT_Function_Mgr * XT_Function_Mgr::myInstance_ = NULL;
{
string type = args[0];
int narg = nargs -1;
#ifdef _WIN32
double *dargs = (double *) _alloca(sizeof(double) * narg);
#else
double *dargs = (double *) alloca(sizeof(double) * narg);
#endif
for (int i = 0; i < narg; ++i) dargs[i] = atof(args[i+1]);

return function(type, narg, dargs);
Expand Down
13 changes: 13 additions & 0 deletions src/COMPRESS/dump_atom_gz.cpp
Expand Up @@ -71,6 +71,19 @@ void DumpAtomGZ::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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
Expand Down
13 changes: 13 additions & 0 deletions src/COMPRESS/dump_cfg_gz.cpp
Expand Up @@ -75,6 +75,19 @@ void DumpCFGGZ::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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
Expand Down
13 changes: 13 additions & 0 deletions src/COMPRESS/dump_custom_gz.cpp
Expand Up @@ -73,6 +73,19 @@ void DumpCustomGZ::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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
Expand Down
13 changes: 13 additions & 0 deletions src/COMPRESS/dump_xyz_gz.cpp
Expand Up @@ -73,6 +73,19 @@ void DumpXYZGZ::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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
Expand Down
13 changes: 13 additions & 0 deletions src/MPIIO/dump_atom_mpiio.cpp
Expand Up @@ -77,6 +77,19 @@ void DumpAtomMPIIO::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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;
}
}
}

if (append_flag) { // append open
Expand Down
13 changes: 13 additions & 0 deletions src/MPIIO/dump_cfg_mpiio.cpp
Expand Up @@ -96,6 +96,19 @@ void DumpCFGMPIIO::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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;
}
}
}

if (append_flag) { // append open
Expand Down
13 changes: 13 additions & 0 deletions src/MPIIO/dump_custom_mpiio.cpp
Expand Up @@ -98,6 +98,19 @@ void DumpCustomMPIIO::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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;
}
}
}

if (append_flag) { // append open
Expand Down
13 changes: 13 additions & 0 deletions src/MPIIO/dump_xyz_mpiio.cpp
Expand Up @@ -98,6 +98,19 @@ void DumpXYZMPIIO::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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;
}
}
}

if (append_flag) { // append open
Expand Down
47 changes: 47 additions & 0 deletions src/dump.cpp
Expand Up @@ -91,6 +91,11 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
pbcflag = 0;
delay_flag = 0;

maxfiles = -1;
numfiles = 0;
fileidx = 0;
nameslist = NULL;

maxbuf = maxids = maxsort = maxproc = 0;
buf = bufsort = NULL;
ids = idsort = NULL;
Expand Down Expand Up @@ -187,6 +192,14 @@ Dump::~Dump()

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

if (multifile == 0 && fp != NULL) {
Expand Down Expand Up @@ -549,6 +562,19 @@ void Dump::openfile()
sprintf(filecurrent,pad,filestar,update->ntimestep,ptr+1);
}
*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
Expand Down Expand Up @@ -1003,6 +1029,27 @@ void Dump::modify_params(int narg, char **arg)
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) {
if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command");
if (!multiproc)
Expand Down
5 changes: 5 additions & 0 deletions src/dump.h
Expand Up @@ -105,6 +105,11 @@ class Dump : protected Pointers {
double boxzlo,boxzhi;
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
int reorderflag; // 1 if OK to reorder instead of sort
int ntotal_reorder; // # of atoms that must be in snapshot
Expand Down
4 changes: 2 additions & 2 deletions src/dump_custom.cpp
Expand Up @@ -60,7 +60,7 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
earg(NULL), vtype(NULL), vformat(NULL), columns(NULL), choose(NULL),
dchoose(NULL), clist(NULL), field2index(NULL), argindex(NULL), id_compute(NULL),
compute(NULL), id_fix(NULL), fix(NULL), id_variable(NULL), variable(NULL),
vbuf(NULL), id_custom(NULL), flag_custom(NULL), typenames(NULL),
vbuf(NULL), id_custom(NULL), flag_custom(NULL), typenames(NULL),
pack_choice(NULL)
{
if (narg == 5) error->all(FLERR,"No dump custom arguments specified");
Expand Down Expand Up @@ -1676,7 +1676,7 @@ int DumpCustom::modify_param(int narg, char **arg)

if (strcmp(arg[0],"refresh") == 0) {
if (narg < 2) error->all(FLERR,"Illegal dump_modify command");
if (strncmp(arg[1],"c_",2) != 0)
if (strncmp(arg[1],"c_",2) != 0)
error->all(FLERR,"Illegal dump_modify command");
if (refreshflag) error->all(FLERR,"Dump modify can only have one refresh");

Expand Down