ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/communication.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24/** \file
25 * This file contains the asynchronous MPI communication.
26 *
27 * It is the header file for communication.cpp.
28 *
29 * The asynchronous MPI communication is used during the script
30 * evaluation. Except for the head node that interprets the interface
31 * script, all other nodes wait in @ref mpi_loop() for the head node to
32 * issue an action using @c MpiCallbacks::call(). @ref mpi_loop() immediately
33 * executes an @c MPI_Bcast and therefore waits for the head node to
34 * broadcast a command, which is done by @c MpiCallbacks::call(). The request
35 * consists of a callback function with an arbitrary number of arguments.
36 *
37 * To add new actions (e.g. to implement new interface functionality), do the
38 * following:
39 * - write the @c mpi_* function that is executed on the head node
40 * - write the @c mpi_*_local function that is executed on worker nodes
41 * - register the local function with one of the @c REGISTER_CALLBACK macros
42 *
43 * After this, your procedure is free to do anything. However, it has
44 * to be in (MPI) sync with what your new @c mpi_*_local does. This
45 * procedure is called immediately after the broadcast.
46 */
47
48#include "MpiCallbacks.hpp"
49
50#include <utils/Vector.hpp>
51
52#include <boost/mpi/communicator.hpp>
53#include <boost/mpi/environment.hpp>
54
55#include <memory>
56#include <utility>
57
58/** The number of this node. */
59extern int this_node;
60/** The communicator */
61extern boost::mpi::communicator comm_cart;
62#ifdef ESPRESSO_SHARED_MEMORY_PARALLELISM
63struct KokkosHandle;
64extern std::shared_ptr<KokkosHandle> kokkos_handle;
65#endif
66
68 std::shared_ptr<boost::mpi::environment> m_mpi_env;
69 std::shared_ptr<Communication::MpiCallbacks> m_callbacks;
70 bool m_is_mpi_gpu_aware;
71
72public:
75 std::shared_ptr<boost::mpi::environment> mpi_env);
77
78 auto &mpiCallbacks() const { return *m_callbacks; }
79 auto mpiCallbacksHandle() { return m_callbacks; }
80 auto get_mpi_env() const { return m_mpi_env; }
81 auto is_mpi_gpu_aware() const { return m_is_mpi_gpu_aware; }
82};
83
85 boost::mpi::communicator &comm;
87 /** @brief The MPI rank. */
89 /** @brief The MPI world size. */
90 int size;
91
93 void init_comm_cart();
95 /** @brief Calculate the node index in the Cartesian topology. */
97 /** @brief Set new Cartesian topology. */
98 void set_node_grid(Utils::Vector3i const &value);
99};
100
102extern std::unique_ptr<CommunicationEnvironment> communication_environment;
103
104namespace Communication {
105/**
106 * @brief Returns a reference to the global callback class instance.
107 */
109 return ::communication_environment->mpiCallbacks();
110}
111} // namespace Communication
112
113/** Process requests from head node. Worker nodes main loop. */
114void mpi_loop();
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
Vector implementation and trait types for boost qvm interoperability.
The interface of the MPI callback mechanism.
void mpi_loop()
Process requests from head node.
std::shared_ptr< KokkosHandle > kokkos_handle
Communicator communicator
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
std::unique_ptr< CommunicationEnvironment > communication_environment
MpiCallbacks & mpiCallbacks()
Returns a reference to the global callback class instance.
boost::mpi::communicator & comm
void full_initialization()
int size
The MPI world size.
int & this_node
The MPI rank.
Utils::Vector3i calc_node_index() const
Calculate the node index in the Cartesian topology.
Utils::Vector3i node_grid
void set_node_grid(Utils::Vector3i const &value)
Set new Cartesian topology.