Use proper doxygen tags in modular simulator
[gromacs.git] / api / include / gmxapi / context.h
blobc705d08a432d0d4015dee2d0d930b31451f2341a
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019,2020, 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 GMXAPI_CONTEXT_H
36 #define GMXAPI_CONTEXT_H
37 /*! \file
38 * \brief Declares classes representing execution context.
40 * \author M. Eric Irrgang <ericirrgang@gmail.com>
41 * \ingroup gmxapi
44 #include <memory>
45 #include <string>
46 #include <vector>
48 namespace gmxapi
51 class Workflow;
52 class Session;
54 /*!
55 * \brief Container for arguments passed to the simulation runner.
57 * This is part of an implementation that essentially wraps the command line
58 * implementation at a high level.
59 * \todo Modernize expression and handling of MD user options.
61 using MDArgs = std::vector<std::string>;
63 /*!
64 * \brief Context implementation abstract base class.
66 * Context Implementations depend on the execution environment, hardware resources, and
67 * possibly other factors, and so are not constructed directly but by helper functions.
68 * Their details are not exposed at the high level API.
69 * \ingroup gmxapi
71 class ContextImpl;
73 /*!
74 * \brief Execution context.
76 * The execution context represents computing resources and zero, one, or more
77 * workflows to execute. All API objects exist in some context, which determines
78 * how the API objects interact underneath the hood.
80 * A proxy can be configured with information needed to initialize a runtime
81 * environment capable of executing a work load, independently of defining the
82 * work.
83 * The actual execution
84 * environment is not necessarily instantiated / configured until the work is
85 * performed.
86 * Thus, construction of a Context object does not necessarily imply
87 * initialization of compute resources, but any active compute resources are
88 * appropriately deinitialized when the object is destroyed. However, to allow
89 * opportunities for exception handling, resources should be deinitialized when
90 * and as work is completed by the Runner.
92 * Ultimately, the class in this header file should just define an interface.
93 * Implementations for different execution environments will be provided by the
94 * library or extension code and documented separately,
95 * and it should be straight-forward to
96 * write extension code for other execution environments.
98 * \todo Further encapsulate resource state transitions with Session objects.
100 * \ingroup gmxapi
102 class Context
104 public:
106 * \brief Get a handle to a new default context object.
108 Context();
109 ~Context();
112 * \brief Nearly trivial copy
114 * \{
116 Context(const Context&) = default;
117 Context& operator=(const Context&) = default;
118 //! \}
121 * \brief Allow move
123 * \{
125 Context(Context&&) = default;
126 Context& operator=(Context&&) = default;
127 //! \}
130 * \brief Construct by wrapping an implementation object.
132 * \param impl Ownership of Context definition and resources.
134 explicit Context(std::shared_ptr<ContextImpl> impl);
137 * \brief Set the simulation runtime arguments for this instance.
139 * \param mdArgs User-provided runtime parameters (such as for `gmx mdrun`)
141 * This is awkwardly named and due for some evolution, since most of the mdrun CLI options
142 * pertain to the execution environment rather than the simulation parameters. For the first
143 * implementation, we just map user arguments to the equivalent command-line substrings.
145 void setMDArgs(const MDArgs& mdArgs);
148 * \brief Launch a workflow in the current context, if possible.
150 * \param work Configured workflow to instantiate.
151 * \return Ownership of a new session or nullptr if not possible.
153 std::shared_ptr<Session> launch(const Workflow& work);
155 private:
157 * \brief Private implementation
159 * Early implementation has not yet developed distinct handle classes
160 * for different levels of access to the Context. In this implementation,
161 * new Context handles to the same resources can be created (in library code)
162 * by constructing from a smart pointer to an implementation object.
164 * \todo Consider client requirements and ownership contracts.
165 * Whether/how API client might be required to create and hold a Context
166 * and/or Session object for the length of a process.
168 std::shared_ptr<ContextImpl> impl_;
171 } // end namespace gmxapi
173 #endif // header guard