Split lines with many copyright years
[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, 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 "multisimtest.h"
51
52 namespace gmx
53 {
54 namespace test
55 {
56
57 /* This test ensures mdrun can run multi-simulations.  It runs one
58  * simulation per MPI rank.
59  *
60  * TODO Preferably, we could test that mdrun correctly refuses to run
61  * multi-simulation unless compiled with real MPI with more than one
62  * rank available. However, if we just call mdrun blindly, those cases
63  * trigger an error that is currently fatal to mdrun and also to the
64  * test binary. So, in the meantime we must not test those cases. If
65  * there is no MPI, we disable the test, so that there is a reminder
66  * that it is disabled. There's no elegant way to conditionally
67  * disable a test at run time, so currently there is no feedback if
68  * only one rank is available. However, the test harness knows to run
69  * this test with more than one rank.
70  *
71  * Strictly, this test does not need to be parameterized, but
72  * conditionally disabling it with respect to GMX_LIB_MPI is easier if
73  * it is parameterized. */
74 TEST_P(MultiSimTest, ExitsNormally)
75 {
76     runExitsNormallyTest();
77 }
78
79 TEST_P(MultiSimTest, ExitsNormallyWithDifferentNumbersOfStepsPerSimulation)
80 {
81     if (size_ <= 1)
82     {
83         /* Can't test multi-sim without multiple ranks. */
84         return;
85     }
86     SimulationRunner runner(&fileManager_);
87     runner.useTopGroAndNdxFromDatabase("spc2");
88
89     const char* pcoupl = GetParam();
90     // Do some different small numbers of steps in each simulation
91     int numSteps = rank_ % 4;
92     organizeMdpFile(&runner, pcoupl, numSteps);
93     /* Call grompp on every rank - the standard callGrompp() only runs
94        grompp on rank 0. */
95     EXPECT_EQ(0, runner.callGromppOnThisRank());
96
97     ASSERT_EQ(0, runner.callMdrun(*mdrunCaller_));
98 }
99
100 /* Note, not all preprocessor implementations nest macro expansions
101    the same way / at all, if we would try to duplicate less code. */
102 #if GMX_LIB_MPI
103 INSTANTIATE_TEST_CASE_P(InNvt, MultiSimTest, ::testing::Values("pcoupl = no"));
104 #else
105 // Test needs real MPI to run
106 INSTANTIATE_TEST_CASE_P(DISABLED_InNvt, MultiSimTest, ::testing::Values("pcoupl = no"));
107 #endif
108
109 //! Convenience typedef
110 typedef MultiSimTest MultiSimTerminationTest;
111
112 TEST_F(MultiSimTerminationTest, WritesCheckpointAfterMaxhTerminationAndThenRestarts)
113 {
114     runMaxhTest();
115 }
116
117 } // namespace test
118 } // namespace gmx