detect missing initialization and run it instead of crashing with a non-descript segfault
This commit is contained in:
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
enum{SUM,SUMSQ,MINN,MAXX,AVE,AVESQ}; // also in ReduceRegion
|
enum{SUM,SUMSQ,MINN,MAXX,AVE,AVESQ}; // also in ComputeReduceRegion
|
||||||
enum{X,V,F,COMPUTE,FIX,VARIABLE};
|
enum{UNKNOWN=-1,X,V,F,COMPUTE,FIX,VARIABLE};
|
||||||
enum{PERATOM,LOCAL};
|
enum{PERATOM,LOCAL};
|
||||||
|
|
||||||
#define INVOKED_VECTOR 2
|
#define INVOKED_VECTOR 2
|
||||||
@ -92,6 +92,10 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
flavor = new int[nargnew];
|
flavor = new int[nargnew];
|
||||||
ids = new char*[nargnew];
|
ids = new char*[nargnew];
|
||||||
value2index = new int[nargnew];
|
value2index = new int[nargnew];
|
||||||
|
for (int i=0; i < nargnew; ++i) {
|
||||||
|
which[i] = argindex[i] = flavor[i] = value2index[i] = UNKNOWN;
|
||||||
|
ids[i] = NULL;
|
||||||
|
}
|
||||||
nvalues = 0;
|
nvalues = 0;
|
||||||
|
|
||||||
iarg = 0;
|
iarg = 0;
|
||||||
@ -345,7 +349,7 @@ void ComputeReduce::init()
|
|||||||
error->all(FLERR,"Variable name for compute reduce does not exist");
|
error->all(FLERR,"Variable name for compute reduce does not exist");
|
||||||
value2index[m] = ivariable;
|
value2index[m] = ivariable;
|
||||||
|
|
||||||
} else value2index[m] = -1;
|
} else value2index[m] = UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set index and check validity of region
|
// set index and check validity of region
|
||||||
@ -468,8 +472,16 @@ double ComputeReduce::compute_one(int m, int flag)
|
|||||||
|
|
||||||
index = -1;
|
index = -1;
|
||||||
int vidx = value2index[m];
|
int vidx = value2index[m];
|
||||||
int aidx = argindex[m];
|
|
||||||
|
|
||||||
|
// initialization in case it has not yet been run, e.g. when
|
||||||
|
// the compute was invoked right after it has been created
|
||||||
|
|
||||||
|
if (vidx == UNKNOWN) {
|
||||||
|
init();
|
||||||
|
vidx = value2index[m];
|
||||||
|
}
|
||||||
|
|
||||||
|
int aidx = argindex[m];
|
||||||
int *mask = atom->mask;
|
int *mask = atom->mask;
|
||||||
int nlocal = atom->nlocal;
|
int nlocal = atom->nlocal;
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
enum{SUM,MINN,MAXX};
|
enum{SUM,MINN,MAXX};
|
||||||
enum{COMPUTE,FIX,VARIABLE};
|
enum{UNKNOWN=-1,COMPUTE,FIX,VARIABLE};
|
||||||
|
|
||||||
#define INVOKED_PERATOM 8
|
#define INVOKED_PERATOM 8
|
||||||
|
|
||||||
@ -74,6 +74,10 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
argindex = new int[nargnew];
|
argindex = new int[nargnew];
|
||||||
ids = new char*[nargnew];
|
ids = new char*[nargnew];
|
||||||
value2index = new int[nargnew];
|
value2index = new int[nargnew];
|
||||||
|
for (int i=0; i < nargnew; ++i) {
|
||||||
|
which[i] = argindex[i] = value2index[i] = UNKNOWN;
|
||||||
|
ids[i] = NULL;
|
||||||
|
}
|
||||||
nvalues = 0;
|
nvalues = 0;
|
||||||
|
|
||||||
iarg = 0;
|
iarg = 0;
|
||||||
@ -354,10 +358,19 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride)
|
|||||||
int *mask = atom->mask;
|
int *mask = atom->mask;
|
||||||
int nlocal = atom->nlocal;
|
int nlocal = atom->nlocal;
|
||||||
|
|
||||||
int index;
|
int index = -1;
|
||||||
|
int vidx = value2index[m];
|
||||||
|
|
||||||
|
// initialization in case it has not yet been run, e.g. when
|
||||||
|
// the compute was invoked right after it has been created
|
||||||
|
|
||||||
|
if (vidx == UNKNOWN) {
|
||||||
|
init();
|
||||||
|
vidx = value2index[m];
|
||||||
|
}
|
||||||
|
|
||||||
if (which[m] == COMPUTE) {
|
if (which[m] == COMPUTE) {
|
||||||
Compute *compute = modify->compute[value2index[m]];
|
Compute *compute = modify->compute[vidx];
|
||||||
|
|
||||||
if (!(compute->invoked_flag & INVOKED_PERATOM)) {
|
if (!(compute->invoked_flag & INVOKED_PERATOM)) {
|
||||||
compute->compute_peratom();
|
compute->compute_peratom();
|
||||||
@ -386,7 +399,7 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride)
|
|||||||
// access fix fields, check if fix frequency is a match
|
// access fix fields, check if fix frequency is a match
|
||||||
|
|
||||||
} else if (which[m] == FIX) {
|
} else if (which[m] == FIX) {
|
||||||
Fix *fix = modify->fix[value2index[m]];
|
Fix *fix = modify->fix[vidx];
|
||||||
if (update->ntimestep % fix->peratom_freq)
|
if (update->ntimestep % fix->peratom_freq)
|
||||||
error->all(FLERR,"Fix used in compute reduce/chunk not "
|
error->all(FLERR,"Fix used in compute reduce/chunk not "
|
||||||
"computed at compatible time");
|
"computed at compatible time");
|
||||||
@ -419,7 +432,7 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride)
|
|||||||
memory->create(varatom,maxatom,"reduce/chunk:varatom");
|
memory->create(varatom,maxatom,"reduce/chunk:varatom");
|
||||||
}
|
}
|
||||||
|
|
||||||
input->variable->compute_atom(value2index[m],igroup,varatom,1,0);
|
input->variable->compute_atom(vidx,igroup,varatom,1,0);
|
||||||
for (int i = 0; i < nlocal; i++) {
|
for (int i = 0; i < nlocal; i++) {
|
||||||
if (!(mask[i] & groupbit)) continue;
|
if (!(mask[i] & groupbit)) continue;
|
||||||
index = ichunk[i]-1;
|
index = ichunk[i]-1;
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
enum{SUM,SUMSQ,MINN,MAXX,AVE,AVESQ}; // also in ComputeReduce
|
enum{SUM,SUMSQ,MINN,MAXX,AVE,AVESQ}; // also in ComputeReduce
|
||||||
enum{X,V,F,COMPUTE,FIX,VARIABLE};
|
enum{UNKNOWN=-1,X,V,F,COMPUTE,FIX,VARIABLE};
|
||||||
enum{PERATOM,LOCAL};
|
enum{PERATOM,LOCAL};
|
||||||
|
|
||||||
#define INVOKED_VECTOR 2
|
#define INVOKED_VECTOR 2
|
||||||
@ -70,6 +70,15 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
|||||||
int nlocal = atom->nlocal;
|
int nlocal = atom->nlocal;
|
||||||
|
|
||||||
int n = value2index[m];
|
int n = value2index[m];
|
||||||
|
|
||||||
|
// initialization in case it has not yet been run,
|
||||||
|
// e.g. when invoked
|
||||||
|
if (n == UNKNOWN) {
|
||||||
|
init();
|
||||||
|
n = value2index[m];
|
||||||
|
}
|
||||||
|
|
||||||
|
int aidx = argindex[m];
|
||||||
int j = argindex[m];
|
int j = argindex[m];
|
||||||
|
|
||||||
double one = 0.0;
|
double one = 0.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user