diff --git a/src/fix_neigh_history.cpp b/src/fix_neigh_history.cpp index 7413b590a7..613716c9a4 100644 --- a/src/fix_neigh_history.cpp +++ b/src/fix_neigh_history.cpp @@ -351,7 +351,9 @@ void FixNeighHistory::pre_exchange_newton() // 1st loop over neighbor list // calculate npartner for owned+ghost atoms - for (i = 0; i < nall_neigh; i++) npartner[i] = 0; + // Ensure npartner is zeroed across all atoms, nall_neigh can be less than nall + // when writing restarts when comm calls are made but modify->post_neighbor() isn't + for (i = 0; i < MAX(nall_neigh, atom->nall); i++) npartner[i] = 0; tagint *tag = atom->tag; NeighList *list = pair->list; @@ -406,7 +408,7 @@ void FixNeighHistory::pre_exchange_newton() // store partner IDs and values for owned+ghost atoms // re-zero npartner to use as counter - for (i = 0; i < nall_neigh; i++) npartner[i] = 0; + for (i = 0; i < MAX(nall_neigh, atom->nall); i++) npartner[i] = 0; for (ii = 0; ii < inum; ii++) { i = ilist[ii];