Local and ghost atoms in one array

What is the reason for combining the local and ghost atoms in one array?

For example, if you wanted to send/receive local and ghost atoms in the same message, rather than breaking it up into exchange/borders. Is combining them into one array mostly for ease of use or are there also performance benefits to the approach that LAMMPS uses?

Thanks!

You don’t need to. Local atoms migrate only when updating the neighbor list and in between you only need to update some data of the ghost atoms (positions and when requested also velocities).

There are performance benefits when processing neighbor lists, e.g. in pair styles. This is usually the most performance critical step in a simulation.

I think it is both for convenience and performance.

As a practical example the loop for calculating pair forces looks like (in pseudo code):

for (i in ilist):
  for (j in jlist[i]):
   calculate_force(x[i], x[j]) ...

So for each local atom i that has a list of neighbours, go over each of its neighbours and calculate the force based on the positions of i and j. Now j is sometimes a local atom and sometimes a ghost atom, and if ghost atoms were on a different list altogether the code would have to decide when to look at the “local list” and when to look at the “ghost list”.

Instead of that you can just refer to (for example) x[j] for position of atom j, and it Just Works whether j is local or ghost. You can still loop over local atoms only by stopping at nlocal, loop over ghost atoms only by starting at nlocal, but also operate on full sets just by using the whole list.

1 Like