diff --git a/src/finish.cpp b/src/finish.cpp index f3dbc83498..1543e66a34 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -479,62 +479,25 @@ void Finish::end(int flag) mesg += "\n"; } - // find a non-skip neighbor list containing half pairwise interactions - // count neighbors in that list for stats purposes - // allow it to be Kokkos neigh list as well - - for (m = 0; m < neighbor->old_nrequest; m++) - if (neighbor->old_requests[m]->half && - neighbor->old_requests[m]->skip == 0 && - neighbor->lists[m] && neighbor->lists[m]->numneigh) break; - - nneigh = 0; - if (m < neighbor->old_nrequest) { - if (!neighbor->lists[m]->kokkos) { - int inum = neighbor->lists[m]->inum; - int *ilist = neighbor->lists[m]->ilist; - int *numneigh = neighbor->lists[m]->numneigh; - for (i = 0; i < inum; i++) - nneigh += numneigh[ilist[i]]; - } else if (lmp->kokkos) nneigh = lmp->kokkos->neigh_count(m); + tmp = neighbor->get_nneigh_half(); + if (tmp > 0) { + stats(1,&tmp,&ave,&max,&min,10,histo); + if (me == 0) { + mesg += fmt::format("Neighs: {:11.6} ave {:11.6g} max {:11.6g} min\n",ave,max,min); + mesg += "Histogram:"; + for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); + mesg += "\n"; + } } - tmp = nneigh; - stats(1,&tmp,&ave,&max,&min,10,histo); - if (me == 0) { - mesg += fmt::format("Neighs: {:11.6} ave {:11.6g} max {:11.6g} min\n",ave,max,min); - mesg += "Histogram:"; - for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); - mesg += "\n"; - } - - // find a non-skip neighbor list containing full pairwise interactions - // count neighbors in that list for stats purposes - // allow it to be Kokkos neigh list as well - - for (m = 0; m < neighbor->old_nrequest; m++) - if (neighbor->old_requests[m]->full && - neighbor->old_requests[m]->skip == 0) break; - - nneighfull = 0; - if (m < neighbor->old_nrequest) { - if (!neighbor->lists[m]->kokkos && neighbor->lists[m]->numneigh) { - int inum = neighbor->lists[m]->inum; - int *ilist = neighbor->lists[m]->ilist; - int *numneigh = neighbor->lists[m]->numneigh; - for (i = 0; i < inum; i++) - nneighfull += numneigh[ilist[i]]; - } else if (lmp->kokkos) - nneighfull = lmp->kokkos->neigh_count(m); - - tmp = nneighfull; + tmp = neighbor->get_nneigh_full(); + if (tmp > 0) { stats(1,&tmp,&ave,&max,&min,10,histo); if (me == 0) { mesg += fmt::format("FullNghs: {:11.6} ave {:11.6g} max {:11.6g} min\n",ave,max,min); mesg += "Histogram:"; for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); mesg += "\n"; - } } if (me == 0) utils::logmesg(lmp,mesg); @@ -594,7 +557,7 @@ void Finish::end(int flag) } /* ---------------------------------------------------------------------- */ - +// FIXME: should use bigint here. void Finish::stats(int n, double *data, double *pave, double *pmax, double *pmin, int nhisto, int *histo) diff --git a/src/imbalance_neigh.cpp b/src/imbalance_neigh.cpp index 0a1c2a87cc..e821610b91 100644 --- a/src/imbalance_neigh.cpp +++ b/src/imbalance_neigh.cpp @@ -61,19 +61,12 @@ void ImbalanceNeigh::compute(double *weight) } } - // find suitable neighbor list - // can only use certain conventional neighbor lists - // NOTE: why not full list, if half does not exist? + bigint neighsum = neighbor->get_nneigh_half(); + if (neighsum == 0) neighsum = neighbor->get_nneigh_full(); - for (req = 0; req < neighbor->old_nrequest; ++req) { - if (neighbor->old_requests[req]->half && neighbor->old_requests[req]->skip == 0 && - neighbor->lists[req] && neighbor->lists[req]->numneigh) - break; - } - - if (req >= neighbor->old_nrequest || neighbor->ago < 0) { + if ((neighsum == 0) || (neighbor->ago < 0)) { if (comm->me == 0 && !did_warn) - error->warning(FLERR, "Balance weight neigh skipped b/c no list found"); + error->warning(FLERR, "Balance weight neigh skipped b/c no suitable list found"); did_warn = 1; return; } @@ -81,15 +74,8 @@ void ImbalanceNeigh::compute(double *weight) // neighsum = total neigh count for atoms on this proc // localwt = weight assigned to each owned atom - NeighList *list = neighbor->lists[req]; - const int inum = list->inum; - const int *const ilist = list->ilist; - const int *const numneigh = list->numneigh; - int nlocal = atom->nlocal; - - bigint neighsum = 0; - for (int i = 0; i < inum; ++i) neighsum += numneigh[ilist[i]]; double localwt = 0.0; + const int nlocal = atom->nlocal; if (nlocal) localwt = 1.0 * neighsum / nlocal; if (nlocal && localwt <= 0.0) error->one(FLERR, "Balance weight <= 0.0"); diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 8de67961ae..708300fc4a 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -29,6 +29,7 @@ #include "fix.h" #include "force.h" #include "group.h" +#include "kokkos.h" #include "memory.h" #include "modify.h" #include "nbin.h" @@ -2772,6 +2773,59 @@ void Neighbor::build_collection(int istart) } } + +/* ---------------------------------------------------------------------- + for neighbor list statistics in Finish class +------------------------------------------------------------------------- */ + +bigint Neighbor::get_nneigh_full() +{ + // find a non-skip neighbor list containing full pairwise interactions + // count neighbors in that list for stats purposes + // allow it to be Kokkos neigh list as well + + int m; + for (m = 0; m < old_nrequest; m++) + if (old_requests[m]->full && !old_requests[m]->skip) break; + + bigint nneighfull = 0; + if (m < old_nrequest) { + if (!lists[m]->kokkos && lists[m]->numneigh) { + int inum = neighbor->lists[m]->inum; + int *ilist = neighbor->lists[m]->ilist; + int *numneigh = neighbor->lists[m]->numneigh; + for (int i = 0; i < inum; i++) + nneighfull += numneigh[ilist[i]]; + } else if (lmp->kokkos) + nneighfull = lmp->kokkos->neigh_count(m); + } + return nneighfull; +} + +bigint Neighbor::get_nneigh_half() +{ + // find a non-skip neighbor list containing half pairwise interactions + // count neighbors in that list for stats purposes + // allow it to be Kokkos neigh list as well + + int m; + for (m = 0; m < old_nrequest; m++) + if (old_requests[m]->half && !old_requests[m]->skip) break; + + bigint nneighhalf = 0; + if (m < old_nrequest) { + if (!lists[m]->kokkos && lists[m]->numneigh) { + int inum = neighbor->lists[m]->inum; + int *ilist = neighbor->lists[m]->ilist; + int *numneigh = neighbor->lists[m]->numneigh; + for (int i = 0; i < inum; i++) + nneighhalf += numneigh[ilist[i]]; + } else if (lmp->kokkos) + nneighhalf = lmp->kokkos->neigh_count(m); + } + return nneighhalf; +} + /* ---------------------------------------------------------------------- return # of bytes of allocated memory ------------------------------------------------------------------------- */ diff --git a/src/neighbor.h b/src/neighbor.h index ba26260442..2feafe1bce 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -159,6 +159,8 @@ class Neighbor : protected Pointers { int any_full(); // Check if any old requests had full neighbor lists void build_collection(int); // build peratom collection array starting at the given index + bigint get_nneigh_full(); // return number of neighbors in a regular full neighbor list + bigint get_nneigh_half(); // return number of neighbors in a regular half neighbor list double memory_usage(); bigint last_setup_bins; // step of last neighbor::setup_bins() call