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,2016,2017,2018,2019, 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- and intra-simulation
40 * signalling by mdrun.
42 * This handles details of responding to termination conditions,
43 * coordinating checkpoints, and coordinating multi-simulations.
45 * \todo Move this to mdrunutility module alongside gathering
46 * multi-simulation communication infrastructure there.
48 * \author Berk Hess <hess@kth.se>
49 * \author Mark Abraham <mark.j.abraham@gmail.com>
50 * \ingroup module_mdlib
55 #include "simulationsignal.h"
59 #include "gromacs/gmxlib/network.h"
60 #include "gromacs/mdrunutility/multisim.h"
61 #include "gromacs/mdtypes/commrec.h"
62 #include "gromacs/utility/arrayref.h"
63 #include "gromacs/utility/gmxassert.h"
64 #include "gromacs/utility/real.h"
69 SimulationSignaller::SimulationSignaller(SimulationSignals *signals,
71 const gmx_multisim_t *ms,
74 : signals_(signals), cr_(cr), ms_(ms),
75 doInterSim_(doInterSim),
76 doIntraSim_(doInterSim || doIntraSim),
81 SimulationSignaller::getCommunicationBuffer()
85 std::transform(std::begin(*signals_), std::end(*signals_), std::begin(mpiBuffer_),
86 [](const SimulationSignals::value_type &s) { return s.sig; });
97 SimulationSignaller::signalInterSim()
103 // The situations that lead to doInterSim_ == true without a
104 // multi-simulation begin active should already have issued an
105 // error at mdrun time in release mode, so there's no need for a
106 // release-mode assertion.
107 GMX_ASSERT(isMultiSim(ms_), "Cannot do inter-simulation signalling without a multi-simulation");
110 // Communicate the signals between the simulations.
111 gmx_sum_sim(eglsNR, mpiBuffer_.data(), ms_);
113 // Communicate the signals from the master to the others.
114 gmx_bcast(eglsNR*sizeof(mpiBuffer_[0]), mpiBuffer_.data(), cr_);
117 void SimulationSignaller::setSignals()
124 SimulationSignals &s = *signals_;
125 for (size_t i = 0; i < s.size(); i++)
127 if (doInterSim_ || s[i].isLocal)
129 // Floating-point reduction of integer values is always
130 // exact, so we can use a simple cast.
131 signed char gsi = static_cast<signed char>(mpiBuffer_[i]);
133 /* Set the communicated signal only when it is non-zero,
134 * since a previously set signal might not have been
135 * handled immediately. */
140 // Turn off any local signal now that it has been processed.
146 void SimulationSignaller::finalizeSignals()