2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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.
36 #ifndef GMXAPI_RESOURCEASSIGNMENT_H
37 #define GMXAPI_RESOURCEASSIGNMENT_H
40 * \brief Provide build-specific overloads for client-MPI-dependent stuff.
42 * Define the interfaces that a client must implement to generate MpiContextManager for the library.
43 * Client code should use the gmxapi_mpi.h template header to generate code supporting
44 * the required interface. (Client code should not need to include this header directly.)
46 * \note This is a generated header. Some definitions are determined when the GROMACS library
47 * build is configured.
49 * If the library is built with tMPI, CommHandle is empty and offerComm is not defined.
51 * If the library is built with an MPI library, CommHandle holds a native MPI_Comm object and
52 * the library-provided offerComm is used by the client MultiProcessingResources implementation
53 * to support passing a copy of the communicator.
55 * Note: The communicator is not `dup`ed in this call. If the library later duplicates
56 * the offered communicator, the library will be responsible for freeing the duplicate.
57 * However, the caller is responsible for keeping any MPI environment valid while the library is
58 * in use. For details, \see MpiContextManager.
60 * \author "M. Eric Irrgang <ericirrgang@gmail.com>"
66 // The interface in this header is determined when the GROMACS library build is configured.
67 #cmakedefine01 GMX_LIB_MPI
75 // Forward declaration for library resources.
76 // CommHandle is opaque to the public API, but allows extensions to implement
77 // required library interfaces by composing the behavior of helpers like offerComm().
78 // The abstraction is important because the library implementations depend on
79 // the options with which GROMACS was built.
83 * \brief Convey the resources that the client has directed the library to use within a Context.
85 * The object itself does not convey ownership of resources. However, the interfaces
86 * for declaring assigned resources must have well-specified (and documented)
87 * semantics for resource ownership. See assignResource().
88 * (Note: the initial implementation only allows for assignment of an MPI Communicator.)
90 * The library and client share this interface definition. The implementation is
91 * provided by client code with the aid of a template header.
92 * Client developers should refer instead to gmxapi_mpi.h.
94 class ResourceAssignment
97 virtual ~ResourceAssignment();
98 [[nodiscard]] virtual int size() const = 0;
99 [[nodiscard]] virtual int rank() const = 0;
100 virtual void applyCommunicator(class CommHandle* dst) const;
103 /*! \brief Offer the client communicator to the library.
105 * Helper function allowing clients to provide the MPI communicator for the library.
106 * \param src client-provided communicator.
107 * \param dst library recipient, abstracted to hide library MPI type details.
110 template<typename CommT>
111 void offerComm([[maybe_unused]] CommT src, [[maybe_unused]] CommHandle* dst)
113 // Default overload does nothing.
117 /*! \brief Offer the client communicator to the library.
119 * Helper function allowing clients to provide communicator to library.
120 * \param src communicator offered by client
121 * \param dst opaque pointer to library resource destination
123 * This function is only available in MPI-enabled GROMACS.
124 * Used indirectly in template helpers for client code to implement library interfaces.
125 * Clients should use the assignResource() higher level function in explicit code,
126 * which will evaluable appropriately for the target GROMACS library.
128 * \todo Provide a stub for docs even when not available.
130 void offerComm(MPI_Comm src, CommHandle* dst);
133 } // end namespace gmxapi
135 #endif // GMXAPI_RESOURCEASSIGNMENT_H