Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
communication.cpp
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#include "config/config.hpp"
23
24#include "communication.hpp"
25
26#include "cuda/init.hpp"
27#include "errorhandling.hpp"
28
29#ifdef WALBERLA
31#endif
32
33#ifdef CABANA
34#include <Cabana_Core.hpp>
35#include <Kokkos_Core.hpp>
36#endif
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
47#include <cassert>
48#include <memory>
49#include <tuple>
50#include <utility>
51
52boost::mpi::communicator comm_cart;
54
55namespace Communication {
56static std::shared_ptr<MpiCallbacks> m_callbacks;
57
58/* We use a singleton callback class for now. */
60 assert(m_callbacks && "Mpi not initialized!");
61
62 return *m_callbacks;
63}
64
65std::shared_ptr<MpiCallbacks> mpiCallbacksHandle() {
66 assert(m_callbacks && "Mpi not initialized!");
67
68 return m_callbacks;
69}
70} // namespace Communication
71
73
74int this_node = -1;
75
76namespace Communication {
77void init(std::shared_ptr<boost::mpi::environment> mpi_env) {
79
81 std::make_shared<Communication::MpiCallbacks>(comm_cart, mpi_env);
82
84
85#ifdef WALBERLA
87#endif
88
89#ifdef CUDA
91#endif
92
93#ifdef CABANA
94 Kokkos::initialize();
95#endif
96}
97
98void deinit() {
100
101#ifdef CABANA
102 Kokkos::finalize();
103#endif
104}
105} // namespace Communication
106
108 : comm{::comm_cart}, node_grid{}, this_node{::this_node}, size{-1} {}
109
111 auto constexpr reorder = false;
113 this_node = comm.rank();
114 // check topology validity
115 std::ignore = Utils::Mpi::cart_neighbors<3>(comm);
116}
117
119 assert(this_node == -1);
120 assert(size == -1);
122 node_grid = Utils::Mpi::dims_create<3>(size);
124}
125
127 node_grid = value;
129}
130
132 return Utils::Mpi::cart_coords<3>(comm, this_node);
133}
134
135std::shared_ptr<boost::mpi::environment> mpi_init(int argc, char **argv) {
136 return std::make_shared<boost::mpi::environment>(argc, argv);
137}
138
139void mpi_loop() {
140 if (this_node != 0)
141 mpiCallbacks().loop();
142}
Vector implementation and trait types for boost qvm interoperability.
The interface of the MPI callback mechanism.
void loop() const
Start the MPI loop.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
void mpi_loop()
Process requests from head node.
Communicator communicator
boost::mpi::communicator comm_cart
The communicator.
std::shared_ptr< boost::mpi::environment > mpi_init(int argc, char **argv)
Initialize MPI.
int this_node
The number of this node.
This file contains the defaults for ESPResSo.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
void cuda_on_program_start()
Called on program start.
Definition init.cpp:115
std::shared_ptr< MpiCallbacks > mpiCallbacksHandle()
static std::shared_ptr< MpiCallbacks > m_callbacks
void init(std::shared_ptr< boost::mpi::environment > mpi_env)
Init globals for communication.
MpiCallbacks & mpiCallbacks()
Returns a reference to the global callback class instance.
void init_error_handling(std::weak_ptr< Communication::MpiCallbacks > callbacks)
Initialize the error collection system.
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
void mpi_init()
Initialize waLBerla's MPI manager.
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.