2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014,2015,2016,2018 by the GROMACS development team.
5 * Copyright (c) 2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
39 * Tests for the mdrun multi-simulation functionality
41 * \author Mark Abraham <mark.j.abraham@gmail.com>
42 * \ingroup module_mdrun_integration_tests
46 #include "multisimtest.h"
53 #include <gtest/gtest.h>
55 #include "gromacs/utility/basenetwork.h"
56 #include "gromacs/utility/path.h"
57 #include "gromacs/utility/real.h"
58 #include "gromacs/utility/stringutil.h"
60 #include "testutils/cmdlinetest.h"
62 #include "moduletest.h"
63 #include "terminationhelper.h"
70 MultiSimTest::MultiSimTest() :
71 size_(gmx_node_num()),
72 rank_(gmx_node_rank()),
73 mdrunCaller_(new CommandLine)
76 const char* directoryNameFormat = "sim_%d";
78 // Modify the file manager to have a temporary directory unique to
79 // each simulation. No need to have a mutex on this, nobody else
80 // can access the fileManager_ yet because we only just
82 std::string originalTempDirectory = fileManager_.getOutputTempDirectory();
83 std::string newTempDirectory =
84 Path::join(originalTempDirectory, formatString(directoryNameFormat, rank_));
85 Directory::create(newTempDirectory);
86 fileManager_.setOutputTempDirectory(newTempDirectory);
88 mdrunCaller_->append("mdrun");
89 mdrunCaller_->addOption("-multidir");
90 for (int i = 0; i != size_; ++i)
92 mdrunCaller_->append(Path::join(originalTempDirectory, formatString(directoryNameFormat, i)));
96 void MultiSimTest::organizeMdpFile(SimulationRunner* runner, const char* controlVariable, int numSteps)
98 const real baseTemperature = 298;
99 const real basePressure = 1;
100 std::string mdpFileContents = formatString(
103 "nstcalcenergy = 1\n"
104 "tcoupl = v-rescale\n"
108 // pressure coupling (if active)
111 "compressibility = 4.5e-5\n"
112 // velocity generation
115 // control variable specification
118 baseTemperature + 0.0001 * rank_,
119 basePressure * std::pow(1.01, rank_),
120 /* Set things up so that the initial KE decreases with
121 increasing replica number, so that the (identical)
122 starting PE decreases on the first step more for the
123 replicas with higher number, which will tend to force
124 replica exchange to occur. */
125 std::max(baseTemperature - 10 * rank_, real(0)),
127 runner->useStringAsMdpFile(mdpFileContents);
130 void MultiSimTest::runExitsNormallyTest()
134 /* Can't test multi-sim without multiple ranks. */
138 SimulationRunner runner(&fileManager_);
139 runner.useTopGroAndNdxFromDatabase("spc2");
141 const char* pcoupl = GetParam();
142 organizeMdpFile(&runner, pcoupl);
143 /* Call grompp on every rank - the standard callGrompp() only runs
145 EXPECT_EQ(0, runner.callGromppOnThisRank());
147 ASSERT_EQ(0, runner.callMdrun(*mdrunCaller_));
150 void MultiSimTest::runMaxhTest()
154 /* Can't test replica exchange without multiple ranks. */
158 SimulationRunner runner(&fileManager_);
159 runner.useTopGroAndNdxFromDatabase("spc2");
161 TerminationHelper helper(&fileManager_, mdrunCaller_.get(), &runner);
162 // Make sure -maxh has a chance to propagate
164 organizeMdpFile(&runner, "pcoupl = no", numSteps);
165 /* Call grompp on every rank - the standard callGrompp() only runs
167 EXPECT_EQ(0, runner.callGromppOnThisRank());
169 helper.runFirstMdrun(runner.cptFileName_);
170 helper.runSecondMdrun();