pcrd = &pull->coord[coord_ind];
- get_pull_coord_distance(pull, coord_ind, pbc);
-
+ /* Update the reference value before computing the distance,
+ * since it is used in the distance computation with periodic pulling.
+ */
update_pull_coord_reference_value(pcrd, coord_ind, t);
+ get_pull_coord_distance(pull, coord_ind, pbc);
+
/* Determine the deviation */
dev = pcrd->value - pcrd->value_ref;
calc_pull_coord_vector_force(pcrd);
/* Add the forces for this coordinate to the total virial and force */
- if (forceWithVirial->computeVirial_)
+ if (forceWithVirial->computeVirial_ && pull->comm.isMasterRank)
{
matrix virial = { { 0 } };
add_virial_coord(virial, pcrd);
ga2la = nullptr;
}
- /* We always make the master node participate, such that it can do i/o
- * and to simplify MC type extensions people might have.
+ /* We always make the master node participate, such that it can do i/o,
+ * add the virial and to simplify MC type extensions people might have.
*/
- bMustParticipate = (comm->bParticipateAll || dd == nullptr || DDMASTER(dd));
+ bMustParticipate = (comm->bParticipateAll || comm->isMasterRank);
for (g = 0; g < pull->ngroup; g++)
{
make_local_pull_group(ga2la, &pull->group[g],
0, md->homenr);
+ GMX_ASSERT(bMustParticipate || dd != nullptr, "Either all ranks (including this rank) participate, or we use DD and need to have access to dd here");
+
/* We should participate if we have pull or pbc atoms */
if (!bMustParticipate &&
(pull->group[g].nat_loc > 0 ||
comm = &pull->comm;
#if GMX_MPI
- /* Use a sub-communicator when we have more than 32 ranks */
+ /* Use a sub-communicator when we have more than 32 ranks, but not
+ * when we have an external pull potential, since then the external
+ * potential provider expects each rank to have the coordinate.
+ */
comm->bParticipateAll = (cr == nullptr || !DOMAINDECOMP(cr) ||
cr->dd->nnodes <= 32 ||
+ pull->numCoordinatesWithExternalPotential > 0 ||
getenv("GMX_PULL_PARTICIPATE_ALL") != nullptr);
/* This sub-commicator is not used with comm->bParticipateAll,
* so we can always initialize it to NULL.
*/
comm->mpi_comm_com = MPI_COMM_NULL;
comm->nparticipate = 0;
+ comm->isMasterRank = (cr == nullptr || MASTER(cr));
#else
/* No MPI: 1 rank: all ranks pull */
comm->bParticipateAll = TRUE;
+ comm->isMasterRank = true;
#endif
comm->bParticipate = comm->bParticipateAll;
comm->setup_count = 0;