Preparation for de-duplicating mdrun setup
[gromacs.git] / src / gromacs / mdrun / simulationcontext.h
blobf80033113c9843ec7ebc384db2f1971ac8c68b23
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 #ifndef GROMACS_SIMULATIONCONTEXT_H
36 #define GROMACS_SIMULATIONCONTEXT_H
38 /*! \libinternal
39 * \file
40 * \brief Provide ways for client code to own simulation resources.
42 * For `gmx mdrun` to be implemented as a client program, public API needs to
43 * provide a way to create and manipulate the SimulationContext.
45 * \author M. Eric Irrgang <ericirrgang@gmail.com>
46 * \ingroup module_mdrun
47 * \inlibraryapi
50 #include <memory>
52 #include "gromacs/hardware/hw_info.h"
54 struct t_filenm;
55 struct t_commrec;
56 struct gmx_output_env_t;
58 namespace gmx
61 /*! \cond libapi
62 * \libinternal
63 * \brief Simulation environment and configuration.
65 * SimulationContext allows a simulation module (\relates gmx::mdrun) to retrieve
66 * runtime parameters and resources from client code. The client retains ownership
67 * of the context and its resources, with exceptions as noted.
69 * The public interface of SimulationContext is not yet well-specified.
70 * Client code can create an instance with gmx::createSimulationContext()
72 * \todo This class should also handle aspects of simulation
73 * environment such as working directory and environment variables.
75 * \ingroup module_mdrun
76 * \inlibraryapi
78 * \internal
79 * This is a minimal placeholder for a more complete implementation.
80 * Interfaces for different API levels are not yet final, but also depend on
81 * additional development of t_commrec and other resources.
82 * \todo Impose sensible access restrictions.
83 * Either the SimulationContext should be passed to the Mdrunner as logically constant or
84 * a separate handle class can provide access to resources that have been
85 * allocated by (negotiated with) the client for the current simulation
86 * (or simulation segment).
87 * Non-const accessors to shared resources need to be associated with update
88 * signals that the simulation components (modules and runner) can subscribe to.
90 * Also reference https://redmine.gromacs.org/issues/2587
92 class SimulationContext final
94 public:
95 /*!
96 * \brief Object must be initialized with non-default constructor.
98 SimulationContext() = delete;
101 * \brief Initializate with borrowed values.
103 * \param communicationRecord non-owning communication record handle.
105 * Client code is responsible for cleaning up communicationRecord after
106 * SimulationContext is destroyed.
108 * \internal
109 * SimulationContext should be the owner of these objects and these implementation
110 * details are subject to change as ownership semantics are clarified in future
111 * development.
113 explicit SimulationContext(t_commrec* communicationRecord);
116 * \brief Non-owning communicator handle.
118 * Communication record is allocated, initialized, and finalized by
119 * client code without clearly transferring ownership.
121 * \todo Context should own communicator.
123 t_commrec* communicationRecord_;
125 //! \endcond
127 /*! \cond libapi
128 * \brief Get ownership of a new SimulationContext object.
130 * A client must share ownership of some resources and transfer ownership of
131 * other resources to create or configure the context. The simulation may in
132 * turn consume or borrow some resources from the context. This is a new
133 * framework that will evolve in the contexts of
134 * https://redmine.gromacs.org/issues/2375
135 * https://redmine.gromacs.org/issues/2587
136 * https://redmine.gromacs.org/issues/2605
138 * Ownership is returned as a smart pointer because ownership or reference may need to
139 * be transferred through higher level code or maintained as a heap object,
140 * and there is not yet a public interface, wrapper, or separate handle object.
142 * This call signature sets all parameters processed by the command-line client
143 * code. Additional call signatures can allow implementation-specified default
144 * values or newer initialization interfaces.
146 * \param simulationCommunicator Handle to communication data structure.
148 * \ingroup module_mdrun
150 SimulationContext createSimulationContext(t_commrec* simulationCommunicator);
151 //! \endcond
153 } // end namespace gmx
155 #endif //GROMACS_SIMULATIONCONTEXT_H