move calculation of number of neighbors to Neighbor class

this allows reusing the code in the ImbalanceNeigh class
This commit is contained in:
Axel Kohlmeyer
2022-03-09 23:18:28 -05:00
parent 3ef02edb48
commit 26c0b9cf87
4 changed files with 73 additions and 68 deletions

View File

@ -479,27 +479,8 @@ 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 = nneigh;
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);
@ -507,34 +488,16 @@ void Finish::end(int flag)
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)

View File

@ -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");

View File

@ -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
------------------------------------------------------------------------- */

View File

@ -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