preCICE v3.2.0
Loading...
Searching...
No Matches
M2N.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <memory>
5#include <string>
6#include <type_traits>
7#include <vector>
9#include "SharedPointer.hpp"
10#include "com/SharedPointer.hpp"
11#include "logging/Logger.hpp"
14
15namespace precice {
16namespace mesh {
17class Mesh;
18} // namespace mesh
19
20namespace m2n {
21
22// Forward declaration to friend unit tests which only use the primary com
23struct WhiteboxAccessor;
24
31class M2N {
32public:
33 M2N(com::PtrCommunication intraComm, DistributedComFactory::SharedPointer distrFactory, bool useOnlyPrimaryCom = false, bool useTwoLevelInit = false);
34
36 ~M2N();
37
39 bool isConnected();
40
48 void acceptPrimaryRankConnection(const std::string &acceptorName,
49 const std::string &requesterName,
50 std::string_view configHash);
51
59 void requestPrimaryRankConnection(const std::string &acceptorName,
60 const std::string &requesterName,
61 std::string_view configHash);
62
69 void acceptSecondaryRanksConnection(const std::string &acceptorName,
70 const std::string &requesterName);
71
78 void requestSecondaryRanksConnection(const std::string &acceptorName,
79 const std::string &requesterName);
80
85 void acceptSecondaryRanksPreConnection(const std::string &acceptorName,
86 const std::string &requesterName);
87
92 void requestSecondaryRanksPreConnection(const std::string &acceptorName,
93 const std::string &requesterName);
94
95 /*
96 * @brief After preliminary communication channels were set up and after
97 * the mesh partitions were communicated locally for every mesh,
98 * call this function to update and complete the communication
99 * channels for every communicated mesh
100 */
102
115 void prepareEstablishment(const std::string &acceptorName,
116 const std::string &requesterName);
117
130 void cleanupEstablishment(const std::string &acceptorName,
131 const std::string &requesterName);
132
139 void closeConnection();
140
143
146
149
152
154 void send(precice::span<double const> itemsToSend,
155 int meshID,
156 int valueDimension);
157
162 void send(bool itemToSend);
163
168 void send(double itemToSend);
169
174 void send(precice::span<double const> itemsToSend);
175
180 void send(int itemToSend);
181
184
186 void scatterAllCommunicationMap(std::map<int, std::vector<int>> &localCommunicationMap, mesh::Mesh &mesh);
187
189 void broadcastSend(int itemToSend, mesh::Mesh &mesh);
190
194 void receive(precice::span<double> itemsToReceive,
195 int meshID,
196 int valueDimension);
197
199 void receive(bool &itemToReceive);
200
202 void receive(double &itemToReceive);
203
205 void receive(precice::span<double> itemsToReceive);
206
208 void receive(int &itemToReceive);
209
212
214 void gatherAllCommunicationMap(std::map<int, std::vector<int>> &localCommunicationMap, mesh::Mesh &mesh);
215
221
223 {
224 return _useTwoLevelInit;
225 }
226
227private:
229
232
235
237
239
241
242 // The following flag is (solely) needed for unit tests between two serial participants.
243 // To also use the secondary communication would require a lengthy setup of meshes
244 // and their re-partitioning, which could also not be moved to some fixture as the M2Ns
245 // are created through the configuration.
246 // See e.g. "CplSchemeTests/ExplicitCouplingSchemeTests/testConfiguredSimpleExplicitCoupling"
247 // This flag gives a loophole. It is set to false for normal use and modified in the
248 // respective tests through a friend declaration.
249
251 bool _useOnlyPrimaryCom = false;
252
254 bool _useTwoLevelInit = false;
255
256 // @brief To allow access to _useOnlyPrimaryCom
257 friend struct WhiteboxAccessor;
258
260 void checkRemoteInfo(std::string_view localParticipant,
261 std::string_view remoteParticipant,
262 std::string_view localConfigHash,
263 std::string_view remoteInfo);
264};
265
268 static auto useOnlyPrimaryCom(PtrM2N m2n) -> typename std::add_lvalue_reference<decltype(m2n->_useOnlyPrimaryCom)>::type
269 {
270 return m2n->_useOnlyPrimaryCom;
271 }
272};
273
274} // namespace m2n
275} // namespace precice
This class provides a lightweight logger.
Definition Logger.hpp:17
std::shared_ptr< DistributedComFactory > SharedPointer
void scatterAllCommunicationMap(std::map< int, std::vector< int > > &localCommunicationMap, mesh::Mesh &mesh)
Scatters a communication map over connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:333
void broadcastReceiveAll(std::vector< int > &itemToReceive, mesh::Mesh &mesh)
Receives an int per connected rank on remote participant (concerning the given mesh) @para[out] itemT...
Definition M2N.cpp:424
bool _isPrimaryRankConnected
Definition M2N.hpp:238
void closeDistributedConnections()
Disconnects all connections of the DistributedCommunication.
Definition M2N.cpp:235
void createDistributedCommunication(const mesh::PtrMesh &mesh)
Creates a new distributes communication for that mesh, stores the pointer in _distComs.
Definition M2N.cpp:256
void closePrimaryRankConnection()
Disconnects the primary connection.
Definition M2N.cpp:223
std::map< int, DistributedCommunication::SharedPointer > _distComs
mesh::getID() -> Pointer to distributed communication
Definition M2N.hpp:231
com::PtrCommunication _interComm
connection between the primary ranks of the connected participants
Definition M2N.hpp:234
void acceptPrimaryRankConnection(const std::string &acceptorName, const std::string &requesterName, std::string_view configHash)
Connects to another participant, which has to call requestConnection().
Definition M2N.cpp:73
logging::Logger _log
Definition M2N.hpp:228
void cleanupEstablishment(const std::string &acceptorName, const std::string &requesterName)
cleans-up to establish the connections
Definition M2N.cpp:173
void gatherAllCommunicationMap(std::map< int, std::vector< int > > &localCommunicationMap, mesh::Mesh &mesh)
Gathers a communication maps from connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:444
void broadcastSendMesh(mesh::Mesh &mesh)
Broadcasts a mesh to connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:322
void closeConnection()
Disconnects from communication space, i.e. participant.
Definition M2N.cpp:216
com::PtrCommunication getPrimaryRankCommunication()
Get the basic communication between the 2 primary ranks.
Definition M2N.cpp:250
void checkRemoteInfo(std::string_view localParticipant, std::string_view remoteParticipant, std::string_view localConfigHash, std::string_view remoteInfo)
checks the info of the remote participant against the version and config hash of the local participan...
Definition M2N.cpp:54
void acceptSecondaryRanksPreConnection(const std::string &acceptorName, const std::string &requesterName)
Definition M2N.cpp:180
bool _useOnlyPrimaryCom
between two serial participants, only use the primary com and no secondary com
Definition M2N.hpp:251
void acceptSecondaryRanksConnection(const std::string &acceptorName, const std::string &requesterName)
Connects to another participant, which has to call requestConnection().
Definition M2N.cpp:132
void requestSecondaryRanksConnection(const std::string &acceptorName, const std::string &requesterName)
Connects to another participant, which has to call acceptConnection().
Definition M2N.cpp:149
bool _areSecondaryRanksConnected
Definition M2N.hpp:240
friend struct WhiteboxAccessor
Definition M2N.hpp:257
void broadcastReceiveAllMesh(mesh::Mesh &mesh)
Receive mesh partitions per connected rank on remote participant (concerning the given mesh)
Definition M2N.cpp:433
void requestSecondaryRanksPreConnection(const std::string &acceptorName, const std::string &requesterName)
Definition M2N.cpp:194
DistributedComFactory::SharedPointer _distrFactory
Definition M2N.hpp:236
M2N(com::PtrCommunication intraComm, DistributedComFactory::SharedPointer distrFactory, bool useOnlyPrimaryCom=false, bool useTwoLevelInit=false)
Definition M2N.cpp:23
bool usesTwoLevelInitialization()
Definition M2N.hpp:222
bool isConnected()
Returns true, if a connection to a remote participant has been setup.
Definition M2N.cpp:38
void requestPrimaryRankConnection(const std::string &acceptorName, const std::string &requesterName, std::string_view configHash)
Connects to another participant, which has to call acceptConnection().
Definition M2N.cpp:102
void broadcastSend(int itemToSend, mesh::Mesh &mesh)
Broadcasts an int to connected ranks on remote participant (concerning the given mesh)
Definition M2N.cpp:343
void completeSecondaryRanksConnection()
Definition M2N.cpp:208
bool _useTwoLevelInit
use the two-level initialization concept
Definition M2N.hpp:254
void prepareEstablishment(const std::string &acceptorName, const std::string &requesterName)
prepares to establish the connections
Definition M2N.cpp:166
~M2N()
Destructor, empty.
Definition M2N.cpp:31
void send(precice::span< double const > itemsToSend, int meshID, int valueDimension)
Sends an array of double values from all ranks (different for each rank).
Definition M2N.cpp:263
void receive(precice::span< double > itemsToReceive, int meshID, int valueDimension)
Definition M2N.cpp:352
Container and creator for meshes.
Definition Mesh.hpp:38
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
std::shared_ptr< Communication > PtrCommunication
contains the logic of the parallel communication between participants.
Definition BoundM2N.cpp:12
std::shared_ptr< M2N > PtrM2N
provides Mesh, Data and primitives.
std::shared_ptr< Mesh > PtrMesh
Main namespace of the precice library.
struct giving access _useOnlyPrimaryCom
Definition M2N.hpp:267
static auto useOnlyPrimaryCom(PtrM2N m2n) -> typename std::add_lvalue_reference< decltype(m2n->_useOnlyPrimaryCom)>::type
Definition M2N.hpp:268