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-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#include <utils/Vector.hpp>
35
36#include <boost/mpi.hpp>
37#include <boost/mpi/communicator.hpp>
38#include <boost/mpi/environment.hpp>
39
40#include <mpi.h>
41
42#include <cassert>
43#include <memory>
44#include <tuple>
45#include <utility>
46
47boost::mpi::communicator comm_cart;
49
50namespace Communication {
51static std::shared_ptr<MpiCallbacks> m_callbacks;
52
53/* We use a singleton callback class for now. */
55 assert(m_callbacks && "Mpi not initialized!");
56
57 return *m_callbacks;
58}
59
60std::shared_ptr<MpiCallbacks> mpiCallbacksHandle() {
61 assert(m_callbacks && "Mpi not initialized!");
62
63 return m_callbacks;
64}
65} // namespace Communication
66
68
69int this_node = -1;
70
71namespace Communication {
72void init(std::shared_ptr<boost::mpi::environment> mpi_env) {
74
76 std::make_shared<Communication::MpiCallbacks>(comm_cart, mpi_env);
77
79
80#ifdef WALBERLA
82#endif
83
84#ifdef CUDA
86#endif
87}
88
90} // namespace Communication
91
93 : comm{::comm_cart}, node_grid{}, this_node{::this_node}, size{-1} {}
94
96 auto constexpr reorder = false;
98 this_node = comm.rank();
99 // check topology validity
100 std::ignore = Utils::Mpi::cart_neighbors<3>(comm);
101}
102
104 assert(this_node == -1);
105 assert(size == -1);
106 MPI_Comm_size(MPI_COMM_WORLD, &size);
107 node_grid = Utils::Mpi::dims_create<3>(size);
109}
110
112 node_grid = value;
114}
115
117 return Utils::Mpi::cart_coords<3>(comm, this_node);
118}
119
120std::shared_ptr<boost::mpi::environment> mpi_init(int argc, char **argv) {
121 return std::make_shared<boost::mpi::environment>(argc, argv);
122}
123
124void mpi_loop() {
125 if (this_node != 0)
126 mpiCallbacks().loop();
127}
Vector implementation and trait types for boost qvm interoperability.
The interface of the MPI callback mechanism.
void loop() const
Start the MPI loop.
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.
void init_comm_cart()
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.