From e58743de9046654223d94d8a344ca352aed7e4e0 Mon Sep 17 00:00:00 2001 From: Joseph Barker Date: Fri, 27 Feb 2026 12:55:45 +0000 Subject: [PATCH] Fix NVE Spin hang When running on more than one processor and when atoms belong to different fix groups the nve/spin fix would hang and not integrate. The issue is caused only in the case that sectoring is true (e.g. MPI with more than one processor) and a sector contains some atoms with the nve/spin fix and some without. There are while loops that become infinite because `i' never gets changed because `mask[i] & groupbit' keeps evaluating as false. This is fixed by advancing `i' even if we don't need to integrate some spins. --- src/SPIN/fix_nve_spin.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/SPIN/fix_nve_spin.cpp b/src/SPIN/fix_nve_spin.cpp index 8670cd21675..8422cd98653 100644 --- a/src/SPIN/fix_nve_spin.cpp +++ b/src/SPIN/fix_nve_spin.cpp @@ -349,22 +349,24 @@ void FixNVESpin::initial_integrate(int /*vflag*/) comm->forward_comm(); int i = stack_foot[j]; while (i >= 0) { + const int next = forward_stacks[i]; if (mask[i] & groupbit) { ComputeInteractionsSpin(i); AdvanceSingleSpin(i); - i = forward_stacks[i]; } + i = next; } } for (int j = nsectors-1; j >= 0; j--) { // advance quarter s for nlocal comm->forward_comm(); int i = stack_head[j]; while (i >= 0) { + const int next = backward_stacks[i]; if (mask[i] & groupbit) { ComputeInteractionsSpin(i); AdvanceSingleSpin(i); - i = backward_stacks[i]; } + i = next; } } } else { // serial seq. update @@ -402,22 +404,24 @@ void FixNVESpin::initial_integrate(int /*vflag*/) comm->forward_comm(); int i = stack_foot[j]; while (i >= 0) { + const int next = forward_stacks[i]; if (mask[i] & groupbit) { ComputeInteractionsSpin(i); AdvanceSingleSpin(i); - i = forward_stacks[i]; } + i = next; } } for (int j = nsectors-1; j >= 0; j--) { // advance quarter s for nlocal comm->forward_comm(); int i = stack_head[j]; while (i >= 0) { + const int next = backward_stacks[i]; if (mask[i] & groupbit) { ComputeInteractionsSpin(i); AdvanceSingleSpin(i); - i = backward_stacks[i]; } + i = next; } } } else { // serial seq. update