limit the maximum number of iterations so the LAMMPS simulation will not stall

This commit is contained in:
Axel Kohlmeyer
2023-10-27 19:10:55 -04:00
parent 588be47b18
commit d35c271677
2 changed files with 15 additions and 4 deletions

View File

@ -29,6 +29,7 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
static constexpr int MAXLOOP = 100;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeClusterAtom::ComputeClusterAtom(LAMMPS *lmp, int narg, char **arg) : ComputeClusterAtom::ComputeClusterAtom(LAMMPS *lmp, int narg, char **arg) :
@ -136,9 +137,11 @@ void ComputeClusterAtom::compute_peratom()
int change, done, anychange; int change, done, anychange;
while (true) { int counter = 0;
// stop after MAXLOOP iterations
while (counter < MAXLOOP) {
comm->forward_comm(this); comm->forward_comm(this);
++counter;
change = 0; change = 0;
while (true) { while (true) {
done = 1; done = 1;
@ -177,6 +180,8 @@ void ComputeClusterAtom::compute_peratom()
MPI_Allreduce(&change, &anychange, 1, MPI_INT, MPI_MAX, world); MPI_Allreduce(&change, &anychange, 1, MPI_INT, MPI_MAX, world);
if (!anychange) break; if (!anychange) break;
} }
if ((comm->me == 0) && (counter >= MAXLOOP))
error->warning(FLERR, "Compute cluster/atom did not converge after {} iterations", MAXLOOP);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -31,7 +31,8 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
#define BIG 1.0e20 static constexpr double BIG = 1.0e20;
static constexpr int MAXLOOP = 100;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -145,8 +146,11 @@ void ComputeFragmentAtom::compute_peratom()
commflag = 1; commflag = 1;
while (true) { int counter = 0;
// stop after MAXLOOP iterations
while (counter < MAXLOOP) {
comm->forward_comm(this); comm->forward_comm(this);
++counter;
done = 1; done = 1;
// set markflag = 0 for all owned atoms, for new iteration // set markflag = 0 for all owned atoms, for new iteration
@ -223,6 +227,8 @@ void ComputeFragmentAtom::compute_peratom()
MPI_Allreduce(&done,&alldone,1,MPI_INT,MPI_MIN,world); MPI_Allreduce(&done,&alldone,1,MPI_INT,MPI_MIN,world);
if (alldone) break; if (alldone) break;
} }
if ((comm->me == 0) && (counter >= MAXLOOP))
error->warning(FLERR, "Compute fragment/atom did not converge after {} iterations", MAXLOOP);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */