Parallelization over several GPU nodes

GROMACS version: 2020 or 2021
GROMACS modification: No
Hello,
I am trying to run 4 different gromacs simulations simultaneously on two nodes each with 2 gpus. All of this should be done in a single slurm job because this calculation is a part of a bigger algorithm. I would like to assing each of the four simulations a single GPU. How should I run this? Like this:
gmx mdrun -gpu_id 0
gmx mdrun -gpu_id 1
gmx mdrun -gpu_id 2
gmx mdrun -gpu_id 3
Or like this?
gmx mdrun -gpu_id 0
gmx mdrun -gpu_id 1
gmx mdrun -gpu_id 0
gmx mdrun -gpu_id 1
Thank you very much for your help!
Best,
Sergio

You could use the multidir functionality for that. For that you would make 4 directories, say, dirA, dirB, dirC, dirD, put a different topol.tpr in each of them, and then start the multi-simulation with something like

srun -N 4 --tasks-per-node=2 gmx_mpi mdrun -s topol -multidir dirA dirB dirC dirD

Then, mdrun would automatically assign one simulation per GPU and also do the pinning of the CPU threads correctly for you.

See
https://manual.gromacs.org/current/user-guide/mdrun-features.html

Best,
Carsten

Thank you very much for the suggestion Karsten. Unfortunatelly the simulation method I am implementing is not programmed for multidir, although maybe it is a good option for the future. I have sort figured out that doing:
gmx mdrun -gpu_id 0
gmx mdrun -gpu_id 1
gmx mdrun -gpu_id 0
gmx mdrun -gpu_id 1
seems to work out alright.
Thanks!
Sergio