2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
39 * \brief This file defines functions for inter-rank signalling by mdrun.
41 * This handles details of responding to termination conditions,
42 * coordinating checkpoints, and coordinating multi-simulations.
44 * \author Berk Hess <hess@kth.se>
45 * \author Mark Abraham <mark.j.abraham@gmail.com>
46 * \ingroup module_mdlib
51 #include "mdrun_signalling.h"
55 #include "gromacs/gmxlib/network.h"
56 #include "gromacs/mdlib/md_support.h"
57 #include "gromacs/mdtypes/commrec.h"
58 #include "gromacs/mdtypes/inputrec.h"
59 #include "gromacs/utility/arrayref.h"
60 #include "gromacs/utility/fatalerror.h"
61 #include "gromacs/utility/real.h"
63 void init_global_signals(struct gmx_signalling_t *gs, const t_commrec *cr,
64 const t_inputrec *ir, int repl_ex_nst)
70 gs->nstms = multisim_nstsimsync(cr, ir, repl_ex_nst);
73 fprintf(debug, "Syncing simulations for checkpointing and termination every %d steps\n", gs->nstms);
81 for (i = 0; i < eglsNR; i++)
89 prepareSignalBuffer(struct gmx_signalling_t *gs)
93 gmx::ArrayRef<signed char> sig(gs->sig);
94 gmx::ArrayRef<real> temp(gs->mpiBuffer);
96 std::copy(sig.begin(), sig.end(), temp.begin());
102 return gmx::EmptyArrayRef();
107 handleSignals(struct gmx_signalling_t *gs,
111 /* Is the signal in one simulation independent of other simulations? */
112 bool bIsSignalLocal[eglsNR] = { false, false, true };
119 if (MULTISIM(cr) && bInterSimGS)
123 /* Communicate the signals between the simulations */
124 gmx_sum_sim(eglsNR, gs->mpiBuffer, cr->ms);
126 /* Communicate the signals from the master to the others */
127 gmx_bcast(eglsNR*sizeof(gs->mpiBuffer[0]), gs->mpiBuffer, cr);
129 for (int i = 0; i < eglsNR; i++)
131 if (bInterSimGS || bIsSignalLocal[i])
133 /* Set the communicated signal only when it is non-zero,
134 * since signals might not be processed at each MD step.
136 signed char gsi = (gs->mpiBuffer[i] >= 0.0 ?
137 static_cast<signed char>(gs->mpiBuffer[i] + 0.5) :
138 static_cast<signed char>(gs->mpiBuffer[i] - 0.5));
143 /* Turn off the local signal */