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
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -1274,16 +1274,18 @@ double FixHyperLocal::compute_vector(int i)
  if (i == 3) return 1.0*allbonds/atom->natoms;

  if (i == 4) {
    int nlocal = atom->nlocal;
    int nbonds = 0;   // BIGINT?
    const int nlocal = atom->nlocal;
    bigint nbonds = 0;
    for (int j = 0; j < nlocal; j++)
      nbonds += numbond[j];
    int allbonds;
    MPI_Allreduce(&nbonds,&allbonds,1,MPI_INT,MPI_SUM,world);
    int allneigh;   // BIGINT?
    MPI_Allreduce(&list->ipage->ndatum,&allneigh,1,MPI_INT,MPI_SUM,world);
    double neighsperatom = allneigh/atom->natoms; 
    double bondsperatom = 0.5*allbonds/atom->natoms;
    bigint allbonds;
    MPI_Allreduce(&nbonds,&allbonds,1,MPI_LMP_BIGINT,MPI_SUM,world);
    bigint allneigh,thisneigh;
    thisneigh = list->ipage->ndatum;
    MPI_Allreduce(&thisneigh,&allneigh,1,MPI_LMP_BIGINT,MPI_SUM,world);
    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;
  }