ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
communication.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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#include <config/config.hpp>
23
24#include "communication.hpp"
25
26#include "cuda/init.hpp"
27#include "errorhandling.hpp"
28#include "fft/init.hpp"
29
30#ifdef ESPRESSO_WALBERLA
32#endif
33
34#include <Cabana_Core.hpp>
35#include <Kokkos_Core.hpp>
36#include <omp.h>
37
38#include <utils/Vector.hpp>
40
41#include <boost/mpi.hpp>
42#include <boost/mpi/communicator.hpp>
43#include <boost/mpi/environment.hpp>
44
45#include <mpi.h>
46#if defined(OPEN_MPI)
47#include <mpi-ext.h>
48#endif
49
50#include <cassert>
51#include <cstdlib>
52#include <memory>
53#include <optional>
54#include <string>
55#include <tuple>
56#include <utility>
57
59 KokkosHandle() { Kokkos::initialize(); }
60 ~KokkosHandle() { Kokkos::finalize(); }
61};
62
63boost::mpi::communicator comm_cart;
65std::unique_ptr<CommunicationEnvironment> communication_environment{};
66std::shared_ptr<KokkosHandle> kokkos_handle{};
67int this_node = -1;
68
69[[maybe_unused]] static auto get_env_variable(char const *const name) {
70 char const *const value = std::getenv(name);
71 std::optional<std::string> result{std::nullopt};
72 if (value) {
73 result = std::string(value);
74 }
75 return result;
76}
77
78static auto make_default_mpi_env() {
79 int argc = 0;
80 char **argv = nullptr;
81 return std::make_shared<boost::mpi::environment>(argc, argv);
82}
83
86
88 std::shared_ptr<boost::mpi::environment> mpi_env)
89 : m_mpi_env{std::move(mpi_env)} {
90 auto const num_threads_env = get_env_variable("OMP_NUM_THREADS");
91 if (not num_threads_env or num_threads_env->empty()) {
92 omp_set_num_threads(1);
93 }
94
95 m_is_mpi_gpu_aware = false;
96
97#if defined(OPEN_MPI)
98#if defined(OMPI_HAVE_MPI_EXT_ROCM) && OMPI_HAVE_MPI_EXT_ROCM
99 m_is_mpi_gpu_aware |= static_cast<bool>(MPIX_Query_rocm_support());
100#endif
101#if defined(OMPI_HAVE_MPI_EXT_CUDA) && OMPI_HAVE_MPI_EXT_CUDA
102 m_is_mpi_gpu_aware |= static_cast<bool>(MPIX_Query_cuda_support());
103#endif
104#endif // defined(OPEN_MPI)
105
106#if defined(MPICH)
107 auto const mpich_gpu_env = get_env_variable("MPIR_CVAR_ENABLE_GPU");
108 m_is_mpi_gpu_aware |= (mpich_gpu_env and *mpich_gpu_env == "1");
109#endif // defined(MPICH)
110
111#if defined(_CRAYC) or defined(__cray__)
112 auto const cray_mpich_gpu_env = get_env_variable("MPICH_GPU_SUPPORT_ENABLED");
113 m_is_mpi_gpu_aware |= (cray_mpich_gpu_env and *cray_mpich_gpu_env == "1");
114#endif // defined(_CRAYC) or defined(__cray__)
115
116#ifdef ESPRESSO_WALBERLA
118#endif
119
121
122 m_callbacks =
123 std::make_shared<Communication::MpiCallbacks>(comm_cart, m_mpi_env);
124
126
127#ifdef ESPRESSO_CUDA
129#endif
130
131#ifdef ESPRESSO_FFTW
133#endif
134
135 kokkos_handle = std::make_shared<KokkosHandle>();
136}
137
139 Kokkos::fence();
140 kokkos_handle.reset();
141
142#ifdef ESPRESSO_WALBERLA
144#endif
145
147 m_callbacks.reset();
148}
149
151 : comm{::comm_cart}, node_grid{}, this_node{::this_node}, size{-1},
152 locked_for_checkpointing{false} {}
153
155 auto constexpr reorder = false;
157 this_node = comm.rank();
158 // check topology validity
159 std::ignore = Utils::Mpi::cart_neighbors<3>(comm);
160#ifdef ESPRESSO_WALBERLA
162#endif
163}
164
166 assert(this_node == -1);
167 assert(size == -1);
168 MPI_Comm_size(MPI_COMM_WORLD, &size);
169 node_grid = Utils::Mpi::dims_create<3>(size);
171}
172
174 assert(not locked_for_checkpointing);
175 node_grid = value;
177}
178
180 return Utils::Mpi::cart_coords<3>(comm, this_node);
181}
182
183void mpi_loop() {
184 if (this_node != 0)
186}
Vector implementation and trait types for boost qvm interoperability.
void loop() const
Start the MPI loop.
DEVICE_QUALIFIER constexpr pointer data() noexcept
Definition Array.hpp:132
void mpi_loop()
Process requests from head node.
std::shared_ptr< KokkosHandle > kokkos_handle
Communicator communicator
static auto get_env_variable(char const *const name)
boost::mpi::communicator comm_cart
The communicator.
static auto make_default_mpi_env()
int this_node
The number of this node.
std::unique_ptr< CommunicationEnvironment > communication_environment
std::shared_ptr< KokkosHandle > kokkos_handle
Communicator communicator
boost::mpi::communicator comm_cart
The communicator.
void cuda_on_program_start()
Called on program start.
Definition cuda/init.cpp:91
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
void fft_on_program_start()
Definition fft/init.cpp:31
MpiCallbacks & mpiCallbacks()
Returns a reference to the global callback class instance.
void init_error_handling(boost::mpi::communicator const &comm)
Initialize the error collection system.
void deinit_error_handling()
boost::mpi::communicator cart_create(boost::mpi::communicator const &comm, Vector< int, dim > const &dims, bool reorder=true, Vector< int, dim > const &periodicity=Vector< int, dim >::broadcast(1))
Wrapper around MPI_Cart_create.
Definition cart_comm.hpp:54
STL namespace.
void mpi_deinit()
Release waLBerla's MPI manager and environment.
void mpi_reinit(int const *cart_topol)
Re-initialize waLBerla's MPI Cartesian communicator.
void mpi_init()
Initialize waLBerla's MPI manager and environment.
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.