avoid segfaults if a dump is created and followed by run pre no
This commit is contained in:
@ -283,6 +283,8 @@ void DumpAtomMPIIO::init_style()
|
|||||||
|
|
||||||
void DumpAtomMPIIO::write_header(bigint ndump)
|
void DumpAtomMPIIO::write_header(bigint ndump)
|
||||||
{
|
{
|
||||||
|
if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
(this->*header_choice)(ndump);
|
(this->*header_choice)(ndump);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -309,6 +309,8 @@ void DumpCustomMPIIO::init_style()
|
|||||||
|
|
||||||
void DumpCustomMPIIO::write_header(bigint ndump)
|
void DumpCustomMPIIO::write_header(bigint ndump)
|
||||||
{
|
{
|
||||||
|
if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
(this->*header_choice)(ndump);
|
(this->*header_choice)(ndump);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
src/dump.cpp
39
src/dump.cpp
@ -1,4 +1,4 @@
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||||
https://www.lammps.org/, Sandia National Laboratories
|
https://www.lammps.org/, Sandia National Laboratories
|
||||||
@ -41,14 +41,20 @@ Dump *Dump::dumpptr;
|
|||||||
#define BIG 1.0e20
|
#define BIG 1.0e20
|
||||||
#define EPSILON 1.0e-6
|
#define EPSILON 1.0e-6
|
||||||
|
|
||||||
enum{ASCEND,DESCEND};
|
enum { ASCEND, DESCEND };
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) :
|
||||||
|
Pointers(lmp), multiname(nullptr), refresh(nullptr), skipvar(nullptr), format(nullptr),
|
||||||
|
format_default(nullptr), format_line_user(nullptr), format_float_user(nullptr),
|
||||||
|
format_int_user(nullptr), format_bigint_user(nullptr), format_column_user(nullptr), fp(nullptr),
|
||||||
|
nameslist(nullptr), buf(nullptr), sbuf(nullptr), ids(nullptr), bufsort(nullptr),
|
||||||
|
idsort(nullptr), index(nullptr), proclist(nullptr), xpbc(nullptr), vpbc(nullptr),
|
||||||
|
imagepbc(nullptr), irregular(nullptr)
|
||||||
{
|
{
|
||||||
MPI_Comm_rank(world,&me);
|
MPI_Comm_rank(world, &me);
|
||||||
MPI_Comm_size(world,&nprocs);
|
MPI_Comm_size(world, &nprocs);
|
||||||
|
|
||||||
id = utils::strdup(arg[0]);
|
id = utils::strdup(arg[0]);
|
||||||
|
|
||||||
@ -64,17 +70,7 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
|||||||
first_flag = 0;
|
first_flag = 0;
|
||||||
flush_flag = 1;
|
flush_flag = 1;
|
||||||
|
|
||||||
format = nullptr;
|
|
||||||
format_default = nullptr;
|
|
||||||
|
|
||||||
format_line_user = nullptr;
|
|
||||||
format_float_user = nullptr;
|
|
||||||
format_int_user = nullptr;
|
|
||||||
format_bigint_user = nullptr;
|
|
||||||
format_column_user = nullptr;
|
|
||||||
|
|
||||||
refreshflag = 0;
|
refreshflag = 0;
|
||||||
refresh = nullptr;
|
|
||||||
|
|
||||||
clearstep = 0;
|
clearstep = 0;
|
||||||
sort_flag = 0;
|
sort_flag = 0;
|
||||||
@ -92,25 +88,15 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
|||||||
has_id = 1;
|
has_id = 1;
|
||||||
|
|
||||||
skipflag = 0;
|
skipflag = 0;
|
||||||
skipvar = nullptr;
|
|
||||||
|
|
||||||
maxfiles = -1;
|
maxfiles = -1;
|
||||||
numfiles = 0;
|
numfiles = 0;
|
||||||
fileidx = 0;
|
fileidx = 0;
|
||||||
nameslist = nullptr;
|
|
||||||
|
|
||||||
maxbuf = maxids = maxsort = maxproc = 0;
|
maxbuf = maxids = maxsort = maxproc = 0;
|
||||||
buf = bufsort = nullptr;
|
|
||||||
ids = idsort = nullptr;
|
|
||||||
index = proclist = nullptr;
|
|
||||||
irregular = nullptr;
|
|
||||||
|
|
||||||
maxsbuf = 0;
|
maxsbuf = 0;
|
||||||
sbuf = nullptr;
|
|
||||||
|
|
||||||
maxpbc = -1;
|
maxpbc = -1;
|
||||||
xpbc = vpbc = nullptr;
|
|
||||||
imagepbc = nullptr;
|
|
||||||
|
|
||||||
// parse filename for special syntax
|
// parse filename for special syntax
|
||||||
// if contains '%', write one file per proc and replace % with proc-ID
|
// if contains '%', write one file per proc and replace % with proc-ID
|
||||||
@ -120,18 +106,17 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp)
|
|||||||
// else if ends in .gz or other known extensions -> compressed text file
|
// else if ends in .gz or other known extensions -> compressed text file
|
||||||
// else ASCII text file
|
// else ASCII text file
|
||||||
|
|
||||||
fp = nullptr;
|
|
||||||
singlefile_opened = 0;
|
singlefile_opened = 0;
|
||||||
compressed = 0;
|
compressed = 0;
|
||||||
binary = 0;
|
binary = 0;
|
||||||
multifile = 0;
|
multifile = 0;
|
||||||
|
size_one = 0;
|
||||||
|
|
||||||
multiproc = 0;
|
multiproc = 0;
|
||||||
nclusterprocs = nprocs;
|
nclusterprocs = nprocs;
|
||||||
filewriter = 0;
|
filewriter = 0;
|
||||||
if (me == 0) filewriter = 1;
|
if (me == 0) filewriter = 1;
|
||||||
fileproc = 0;
|
fileproc = 0;
|
||||||
multiname = nullptr;
|
|
||||||
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
if ((ptr = strchr(filename,'%'))) {
|
if ((ptr = strchr(filename,'%'))) {
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// clang-format off
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||||
https://www.lammps.org/, Sandia National Laboratories
|
https://www.lammps.org/, Sandia National Laboratories
|
||||||
@ -29,8 +28,10 @@ using namespace LAMMPS_NS;
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
DumpAtom::DumpAtom(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg)
|
DumpAtom::DumpAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||||
|
Dump(lmp, narg, arg), header_choice(nullptr), pack_choice(nullptr)
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
if (narg != 5) error->all(FLERR,"Illegal dump atom command");
|
if (narg != 5) error->all(FLERR,"Illegal dump atom command");
|
||||||
|
|
||||||
scale_flag = 1;
|
scale_flag = 1;
|
||||||
@ -146,6 +147,8 @@ int DumpAtom::modify_param(int narg, char **arg)
|
|||||||
|
|
||||||
void DumpAtom::write_header(bigint ndump)
|
void DumpAtom::write_header(bigint ndump)
|
||||||
{
|
{
|
||||||
|
if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
if (multiproc) (this->*header_choice)(ndump);
|
if (multiproc) (this->*header_choice)(ndump);
|
||||||
else if (me == 0) (this->*header_choice)(ndump);
|
else if (me == 0) (this->*header_choice)(ndump);
|
||||||
}
|
}
|
||||||
@ -154,6 +157,8 @@ void DumpAtom::write_header(bigint ndump)
|
|||||||
|
|
||||||
void DumpAtom::pack(tagint *ids)
|
void DumpAtom::pack(tagint *ids)
|
||||||
{
|
{
|
||||||
|
if (!pack_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
(this->*pack_choice)(ids);
|
(this->*pack_choice)(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// clang-format off
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||||
https://www.lammps.org/, Sandia National Laboratories
|
https://www.lammps.org/, Sandia National Laboratories
|
||||||
@ -53,13 +52,14 @@ enum{LT,LE,GT,GE,EQ,NEQ,XOR};
|
|||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
|
DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
|
||||||
Dump(lmp, narg, arg), idregion(nullptr), thresh_array(nullptr), thresh_op(nullptr),
|
Dump(lmp, narg, arg), idregion(nullptr), thresh_array(nullptr), thresh_op(nullptr),
|
||||||
thresh_value(nullptr), thresh_last(nullptr), thresh_fix(nullptr), thresh_fixID(nullptr),
|
thresh_value(nullptr), thresh_last(nullptr), thresh_fix(nullptr), thresh_fixID(nullptr),
|
||||||
thresh_first(nullptr), earg(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr),
|
thresh_first(nullptr), earg(nullptr), vtype(nullptr), vformat(nullptr), columns(nullptr),
|
||||||
columns_default(nullptr), choose(nullptr), dchoose(nullptr), clist(nullptr),
|
columns_default(nullptr), choose(nullptr), dchoose(nullptr), clist(nullptr),
|
||||||
field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr), id_fix(nullptr),
|
field2index(nullptr), argindex(nullptr), id_compute(nullptr), compute(nullptr), id_fix(nullptr),
|
||||||
fix(nullptr), id_variable(nullptr), variable(nullptr), vbuf(nullptr), id_custom(nullptr),
|
fix(nullptr), id_variable(nullptr), variable(nullptr), vbuf(nullptr), id_custom(nullptr),
|
||||||
custom(nullptr), custom_flag(nullptr), typenames(nullptr), pack_choice(nullptr)
|
custom(nullptr), custom_flag(nullptr), typenames(nullptr), header_choice(nullptr),
|
||||||
|
pack_choice(nullptr)
|
||||||
{
|
{
|
||||||
if (narg == 5) error->all(FLERR,"No dump {} arguments specified", style);
|
if (narg == 5) error->all(FLERR,"No dump {} arguments specified", style);
|
||||||
|
|
||||||
@ -352,6 +352,8 @@ void DumpCustom::init_style()
|
|||||||
|
|
||||||
void DumpCustom::write_header(bigint ndump)
|
void DumpCustom::write_header(bigint ndump)
|
||||||
{
|
{
|
||||||
|
if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
if (multiproc) (this->*header_choice)(ndump);
|
if (multiproc) (this->*header_choice)(ndump);
|
||||||
else if (me == 0) (this->*header_choice)(ndump);
|
else if (me == 0) (this->*header_choice)(ndump);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -311,6 +311,8 @@ void DumpGrid::init_style()
|
|||||||
|
|
||||||
void DumpGrid::write_header(bigint ndump)
|
void DumpGrid::write_header(bigint ndump)
|
||||||
{
|
{
|
||||||
|
if (!header_choice) error->all(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
if (multiproc) (this->*header_choice)(ndump);
|
if (multiproc) (this->*header_choice)(ndump);
|
||||||
else if (me == 0) (this->*header_choice)(ndump);
|
else if (me == 0) (this->*header_choice)(ndump);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,6 +130,8 @@ int DumpXYZ::modify_param(int narg, char **arg)
|
|||||||
void DumpXYZ::write_header(bigint n)
|
void DumpXYZ::write_header(bigint n)
|
||||||
{
|
{
|
||||||
if (me == 0) {
|
if (me == 0) {
|
||||||
|
if (!fp) error->one(FLERR, "Must not use 'run pre no' after creating a new dump");
|
||||||
|
|
||||||
auto header = fmt::format("{}\n Atoms. Timestep: {}", n, update->ntimestep);
|
auto header = fmt::format("{}\n Atoms. Timestep: {}", n, update->ntimestep);
|
||||||
if (time_flag) header += fmt::format(" Time: {:.6f}", compute_time());
|
if (time_flag) header += fmt::format(" Time: {:.6f}", compute_time());
|
||||||
header += "\n";
|
header += "\n";
|
||||||
@ -177,9 +179,8 @@ int DumpXYZ::convert_string(int n, double *mybuf)
|
|||||||
memory->grow(sbuf,maxsbuf,"dump:sbuf");
|
memory->grow(sbuf,maxsbuf,"dump:sbuf");
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += sprintf(&sbuf[offset],format,
|
offset += sprintf(&sbuf[offset], format, typenames[static_cast<int> (mybuf[m+1])],
|
||||||
typenames[static_cast<int> (mybuf[m+1])],
|
mybuf[m+2], mybuf[m+3], mybuf[m+4]);
|
||||||
mybuf[m+2],mybuf[m+3],mybuf[m+4]);
|
|
||||||
m += size_one;
|
m += size_one;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user