Skip to content

GROMACS 2020-2024 patches: follow-up of #1505 (GPU buffer operations with 2020-2023, constraint virial with MTS, messages and CHANGES) - #1508

Merged
carlocamilloni merged 3 commits into
plumed:v2.9from
invemichele-peptone:gromacs-legacy-followup
Oct 15, 2026
Merged

carlocamilloni merged 3 commits into
plumed:v2.9from
invemichele-peptone:gromacs-legacy-followup

Conversation

@invemichele-peptone

@invemichele-peptone invemichele-peptone commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Description

Follow-up of #1505, which was merged while I was still running a last review. That review found two more bugs, one of them in a fix of #1505, plus some messages and CHANGES entries to correct. #1509 is the follow-up for v2.10; both can reach master with the merges of v2.10, as #1505 and #1506 did.

GPU force buffer operations, GROMACS 2020-2023 (the fix of #1505 did not work there)

#1505 made PLUMED count as force work on the CPU, through plumedswitch. In GROMACS 2020-2023, do_force() sets up that workload itself on the pair-search steps. But md.cpp sets plumedswitch to 0 while PLUMED runs after do_force(), which happens on the virial and energy steps. Step 0 is always both, so PLUMED's forces were still lost with GPU buffer ops, at least until the next pair search: in the whole run when every pair search is on a virial step, e.g. with the nstlist that mdrun picks on the GPU. A flag that is never switched off, plumedIsUsed, now decides it. GROMACS 2024 sets up the workload in md.cpp, before the switch, so it was already right.

Constraint virial with multiple time stepping, GROMACS 2021-2024

On the slow MTS steps when PLUMED runs after do_force(), it applies its forces to the combined MTS buffer, which the update uses. GROMACS computes the constraint virial from the normal buffer, and writes that one to the trajectory. So the constraint virial lacked the part of PLUMED's forces that the constraints pass on to the other atoms. The difference PLUMED made to the combined buffer is now added to the normal one too. With a bias on ENERGY, the slow forces in the normal buffer are then rescaled as in the combined one; this affects only the constraint virial, not the dynamics.

  • Restraint between two water oxygens, MTS (factor 2), ENERGY printed every 2 steps, against the GROMACS pull code: virial off by 2.7, -0.5 and 3.8 kJ/mol at step 0 (5.2 after 20 steps), and trajectory forces off by 2.6%; now 0 at step 0, as without MTS, and the same forces.

Messages, a comment and CHANGES

  • The error for shells also fires with flexible constraints, which use the same relaxation: it now says so. The thread-MPI error suggests -ntmpi 1.
  • A comment said that the forces on virtual sites are spread only in the energy path; they are spread whenever PLUMED runs after do_force().
  • CHANGES:
    • the double-counted virial was there also in the patches for GROMACS older than 2019 (I checked those for 2018 and 4.6);
    • after a stop request, mdrun runs one more step after the next communication of signals, and between simulations signals are communicated every 200 steps or more, not at least every 200 steps;
    • the shells entry mentions flexible constraints;
    • the MTS entry mentions the constraint virial.
Target release

I would like my code to appear in release v2.9

Type of contribution
  • changes to code or doc authored by PLUMED developers, or additions of code in the core or within the default modules
  • changes to a module not authored by you
  • new module contribution or edit of a module authored by you
Copyright
  • I agree to transfer the copyright of the code I have written to the PLUMED developers or to the author of the code I am modifying.
  • the module I added or modified contains a COPYRIGHT file with the correct license information. Code should be released under an open source license. I also used the command cd src && ./header.sh mymodulename in order to make sure the headers of the module are correct.
Tests
  • I added a new regtest or modified an existing regtest to validate my changes.
  • I verified that all regtests are passed successfully on GitHub Actions.

With the regression tests of plumed-testcenter/plumed-testcenter#95, which now also check the virial at step 0 within 0.1 kJ/mol and the forces with MTS:

  • GROMACS 2020.7, 2021.7, 2022.5, 2023.5 and 2024.3 patched with this branch, with its kernel: all tests pass. With the 2.10 kernel and the 2024.3 patch: all pass.
  • With v2.9 as it is now, pull-mts fails for 2021.7-2024.3 (5.2 kJ/mol).
  • The GPU test, on a GROMACS 2023.5 CUDA build: fails with v2.9 as it is now, and passes with this branch.
  • Patching a clean GROMACS tree gives exactly the files of this branch.

🤖 Generated with Claude Code

invemichele-peptone and others added 3 commits October 15, 2026 11:21
…t runs after do_force()

In GROMACS 2020-2023, do_force() sets up the domain workload on the pair-search
steps, and it read plumedswitch, which md.cpp sets to 0 while PLUMED runs after
do_force() (on the virial and energy steps, and in the HREX energy evaluation).
Step 0 is always such a step, so with GPU force buffer operations PLUMED's
forces could still be lost until the next pair search, or in the whole run when
every pair-search step computes the virial. A flag that is never switched off,
plumedIsUsed, now decides it. GROMACS 2024 sets up the workload in md.cpp,
before the switch, and was already right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…normal force buffer

On the slow MTS steps when PLUMED runs after do_force() (the virial and energy
steps), it applies its forces to the combined MTS buffer, which the update uses.
GROMACS computes the constraint virial from the normal buffer (and writes it to
the trajectory), which then lacked the part of PLUMED's forces that the
constraints pass on: e.g. 2.7, -0.5 and 3.8 kJ/mol on the virial of a restraint
between two water oxygens, against the GROMACS pull code. The difference PLUMED
made to the combined buffer is now added to the normal one too. With a bias on
ENERGY the slow forces in the normal buffer are then rescaled as in the combined
one, which only affects the constraint virial, not the dynamics.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ions to CHANGES

- The error for shells also fires with flexible constraints, which use the same
  relaxation: say so. The error for thread-MPI suggests -ntmpi 1.
- The forces on virtual sites are spread whenever PLUMED runs after do_force(),
  not only in the energy path.
- CHANGES: the virial was counted twice also with the patches for GROMACS older
  than 2019; after a stop request, mdrun runs one more step after the next
  communication of signals, which between simulations happens every 200 steps
  or more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants