Hello,
I’ve noticed that pair styles that make use of a full neighbor list
(e.g. Tersoff) use the following lines to skip half of it:
// two-body interactions from full neighbor list, skip half of them
if (itag > jtag) {
if ((itag+jtag) 2 == 0) continue;
} else if (itag < jtag) {
if ((itag+jtag) 2 == 1) continue;
} else { //itag==jtag -> they are the same particle (j is a ghost)
if (x[j][2] < ztmp ) continue;
if (x[j][2] == ztmp && x[j][1] < ytmp ) continue;
if (x[j][2] == ztmp && x[j][1] == ytmp && x[j][0] < xtmp) continue;
}
There are two things unclear to me:
- the advantage of using the if…else-if with the “% 2” instead of a simple
if (itag > jtag) continue;
load balancing.
consider a system with only two adjacent subdomains and without periodic boundaries:
for each you have the index in the range [0,nlocal), and j in the range [0,nlocal+nghost).
while the range [0,nlocal) are atoms with different tags between the two subdomains,
the range [nlocal, nlocal+nghost) are atoms that are local on one subdomain and ghosts on the other.
you also want to evenly split these pairs between the two subdomains, so that when running in parallel
both subdomains have to do about the same amount of work. specifically at the beginning of a run and for solids where there is no diffusion,
chances are high that the tags are sorted by location and thus all or most of the tags of the atoms in the first
subdomain would be smaller than the tags of the atoms in the second. please keep in mind that this construct is used for pair styles that require newton for pairs to be on.
if you have periodic boundaries and more subdomains, things are a bit more complex, but the principle remains the same.
- the reason of the “else” condition: why would we want the interaction
of an atom with a ghost of itself?
periodic boundary conditions.
Due to using domain distribution for MPI parallelization, you need a copy of (some) atoms from the neighboring sub-domain, AKA ghost atoms.
if there is only one subdomain those ghost atoms are copies of the same subdomain (from the other “side” of the box).
if the (communication) cutoff is large compared to the size of the subdomain, there may even be multiple copies. because of how LAMMPS is doing this, it is not subject to minimum image conventions (and you don’t see those applied when using the neighbor list). the only exception I know is pair style list (which does not use a neighborlist at all and is built to handle interactions of pairs with very large distances). if you have the same tag for a pair of atoms, you need to find a different way to get the even split (and consistently so) thus you decide based on the z coordinates, if those are the same then on the y coordinates, and if those are the same, too, on the x coordinates. all 3 coordinates cannot be the same as that would mean the particles are on top of each other, but that could only happen if both were local; if one is a ghost it has to be different in at least one of x, y, or z.
HTH,
axel.