469711e65727297a1dc85a2e2dc0cfb46b1a384c
[alexxy/gromacs.git] / src / programs / mdrun / tests / multisim.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2013,2014,2015,2016,2018 by the GROMACS development team.
5  * Copyright (c) 2019,2020,2021, 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.
9  *
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.
14  *
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.
19  *
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.
24  *
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.
32  *
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.
35  */
36
37 /*! \internal \file
38  * \brief
39  * Tests for the mdrun multi-simulation functionality
40  *
41  * \author Mark Abraham <mark.j.abraham@gmail.com>
42  * \ingroup module_mdrun_integration_tests
43  */
44 #include "gmxpre.h"
45
46 #include "config.h"
47
48 #include <gtest/gtest.h>
49
50 #include "gromacs/mdtypes/md_enums.h"
51
52 #include "multisimtest.h"
53
54 namespace gmx
55 {
56 namespace test
57 {
58
59 /* This test ensures mdrun can run multi-simulations.  It runs one
60  * simulation per MPI rank.
61  *
62  * TODO Preferably, we could test that mdrun correctly refuses to run
63  * multi-simulation unless compiled with real MPI with more than one
64  * rank available. However, if we just call mdrun blindly, those cases
65  * trigger an error that is currently fatal to mdrun and also to the
66  * test binary. So, in the meantime we must not test those cases. If
67  * there is no MPI, we disable the test, so that there is a reminder
68  * that it is disabled. There's no elegant way to conditionally
69  * disable a test at run time, so currently there is no feedback if
70  * only one rank is available. However, the test harness knows to run
71  * this test with more than one rank. */
72 TEST_P(MultiSimTest, ExitsNormally)
73 {
74     runExitsNormallyTest();
75 }
76
77 TEST_P(MultiSimTest, ExitsNormallyWithDifferentNumbersOfStepsPerSimulation)
78 {
79     if (!mpiSetupValid())
80     {
81         // MPI setup is not suitable for multi-sim
82         return;
83     }
84     SimulationRunner runner(&fileManager_);
85     runner.useTopGroAndNdxFromDatabase("spc2");
86
87     // Do some different small numbers of steps in each simulation
88     int numSteps = simulationNumber_ % 4;
89     runGrompp(&runner, numSteps);
90
91     ASSERT_EQ(0, runner.callMdrun(*mdrunCaller_));
92 }
93
94 /* Note, not all preprocessor implementations nest macro expansions
95    the same way / at all, if we would try to duplicate less code. */
96 #if GMX_LIB_MPI
97 INSTANTIATE_TEST_CASE_P(InNvt,
98                         MultiSimTest,
99                         ::testing::Combine(::testing::Values(NumRanksPerSimulation(1),
100                                                              NumRanksPerSimulation(2)),
101                                            ::testing::Values(IntegrationAlgorithm::MD),
102                                            ::testing::Values(TemperatureCoupling::VRescale),
103                                            ::testing::Values(PressureCoupling::No)));
104 #else
105 // Test needs real MPI to run
106 INSTANTIATE_TEST_CASE_P(DISABLED_InNvt,
107                         MultiSimTest,
108                         ::testing::Combine(::testing::Values(NumRanksPerSimulation(1),
109                                                              NumRanksPerSimulation(2)),
110                                            ::testing::Values(IntegrationAlgorithm::MD),
111                                            ::testing::Values(TemperatureCoupling::VRescale),
112                                            ::testing::Values(PressureCoupling::No)));
113 #endif
114
115 //! Convenience typedef
116 typedef MultiSimTest MultiSimTerminationTest;
117
118 TEST_P(MultiSimTerminationTest, WritesCheckpointAfterMaxhTerminationAndThenRestarts)
119 {
120     runMaxhTest();
121 }
122
123 INSTANTIATE_TEST_CASE_P(InNvt,
124                         MultiSimTerminationTest,
125                         ::testing::Combine(::testing::Values(NumRanksPerSimulation(1),
126                                                              NumRanksPerSimulation(2)),
127                                            ::testing::Values(IntegrationAlgorithm::MD),
128                                            ::testing::Values(TemperatureCoupling::VRescale),
129                                            ::testing::Values(PressureCoupling::No)));
130
131 } // namespace test
132 } // namespace gmx