Skip to content
Snippets Groups Projects
Commit c49c35e4 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

avoid tuncation error through integer division and promote to use "bigint"...

avoid tuncation error through integer division and promote to use "bigint" instead of "int" to avoid overflows for large systems
parent 1597e78d
No related branches found
No related tags found
No related merge requests found
...@@ -44,9 +44,9 @@ enum{IGNORE,WARN,ERROR}; ...@@ -44,9 +44,9 @@ enum{IGNORE,WARN,ERROR};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixHyperLocal::FixHyperLocal(LAMMPS *lmp, int narg, char **arg) : FixHyperLocal::FixHyperLocal(LAMMPS *lmp, int narg, char **arg) :
FixHyper(lmp, narg, arg), old2now(NULL), xold(NULL), tagold(NULL), FixHyper(lmp, narg, arg), old2now(NULL), xold(NULL), tagold(NULL),
bonds(NULL), numbond(NULL), maxstrain(NULL), maxstrain_region(NULL), bonds(NULL), numbond(NULL), maxstrain(NULL), maxstrain_region(NULL),
maxstrain_bondindex(NULL), biasflag(NULL), boost(NULL), maxstrain_bondindex(NULL), biasflag(NULL), boost(NULL),
histo(NULL), allhisto(NULL) histo(NULL), allhisto(NULL)
{ {
// error checks // error checks
...@@ -1274,16 +1274,18 @@ double FixHyperLocal::compute_vector(int i) ...@@ -1274,16 +1274,18 @@ double FixHyperLocal::compute_vector(int i)
if (i == 3) return 1.0*allbonds/atom->natoms; if (i == 3) return 1.0*allbonds/atom->natoms;
if (i == 4) { if (i == 4) {
int nlocal = atom->nlocal; const int nlocal = atom->nlocal;
int nbonds = 0; // BIGINT? bigint nbonds = 0;
for (int j = 0; j < nlocal; j++) for (int j = 0; j < nlocal; j++)
nbonds += numbond[j]; nbonds += numbond[j];
int allbonds; bigint allbonds;
MPI_Allreduce(&nbonds,&allbonds,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&nbonds,&allbonds,1,MPI_LMP_BIGINT,MPI_SUM,world);
int allneigh; // BIGINT? bigint allneigh,thisneigh;
MPI_Allreduce(&list->ipage->ndatum,&allneigh,1,MPI_INT,MPI_SUM,world); thisneigh = list->ipage->ndatum;
double neighsperatom = allneigh/atom->natoms; MPI_Allreduce(&thisneigh,&allneigh,1,MPI_LMP_BIGINT,MPI_SUM,world);
double bondsperatom = 0.5*allbonds/atom->natoms; const double natoms = atom->natoms;
const double neighsperatom = static_cast<double>(allneigh)/natoms;
const double bondsperatom = 0.5*static_cast<double>(allbonds)/natoms;
return neighsperatom * bondsperatom; return neighsperatom * bondsperatom;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment