2#include <boost/container/flat_map.hpp>
3#include <boost/io/ios_state.hpp>
36 communication->send(
static_cast<int>(m.
size()), rankReceiver);
38 for (
auto const &i : m) {
39 auto const &rank = i.first;
40 auto const &indices = i.second;
41 communication->send(rank, rankReceiver);
42 communication->sendRange(indices, rankReceiver);
52 communication->receive(size, rankSender);
56 communication->receive(rank, rankSender);
64 communication->broadcast(
static_cast<int>(m.
size()));
66 for (
auto const &i : m) {
67 auto const &rank = i.first;
68 auto const &indices = i.second;
69 communication->broadcast(rank);
70 communication->broadcast(indices);
80 communication->broadcast(size, rankBroadcaster);
84 communication->broadcast(rank, rankBroadcaster);
85 communication->broadcast(m[rank], rankBroadcaster);
107 for (
auto &j : i.second) {
108 oss << i.first <<
":" << j <<
'\n';
139 maximum =
std::max(maximum,
static_cast<size_t>(size));
140 minimum =
std::min(minimum,
static_cast<size_t>(size));
150 maximum =
std::max(maximum,
static_cast<size_t>(size));
151 minimum =
std::min(minimum,
static_cast<size_t>(size));
156 if (minimum > maximum)
159 auto average =
static_cast<double>(total);
166 <<
"Number of Communication Partners per Interface Process:"
168 <<
" Total: " << total <<
"\n"
169 <<
" Maximum: " << maximum <<
"\n"
170 <<
" Minimum: " << minimum <<
"\n"
171 <<
" Average: " << average <<
"\n"
172 <<
"Number of Interface Processes: " << count <<
"\n"
185 size += i.second.size();
195 maximum =
std::max(maximum,
static_cast<size_t>(size));
196 minimum =
std::min(minimum,
static_cast<size_t>(size));
207 maximum =
std::max(maximum,
static_cast<size_t>(size));
208 minimum =
std::min(minimum,
static_cast<size_t>(size));
214 if (minimum > maximum)
217 auto average =
static_cast<double>(total);
224 <<
"Number of LVDIs per Interface Process:"
226 <<
" Total: " << total <<
'\n'
227 <<
" Maximum: " << maximum <<
'\n'
228 <<
" Minimum: " << minimum <<
'\n'
229 <<
" Average: " << average <<
'\n'
230 <<
"Number of Interface Processes: " << count <<
'\n'
268 auto iterator = thisVertexDistribution.
find(thisRank);
269 if (iterator == thisVertexDistribution.
end()) {
279 for (
const auto &[rank, vertices] : otherVertexDistribution) {
289 if (iterator->second.empty() || vertices.empty() || (vertices.back() < iterator->second.at(0)) || (vertices.at(0) > iterator->second.back())) {
298 vertices.begin(), vertices.end(),
301 if (!inters.
empty()) {
302 communicationMap.
insert({rank, std::move(inters)});
305 return communicationMap;
337 PRECICE_DEBUG(
"Exchange vertex distribution between both primary ranks");
338 Event e0(
"m2n.exchangeVertexDistribution");
353 _mesh->setVertexDistribution(vertexDistribution);
377 vertexDistribution, requesterVertexDistribution);
383 print(communicationMap);
387#ifdef P2P_LCM_PRINT_STATS
393 Event e4(
"m2n.createCommunications");
394 e4.
addData(
"Connections", communicationMap.
size());
395 if (communicationMap.
empty()) {
410 communicationMap.
size());
413 for (
auto const &comMap : communicationMap) {
414 int globalRequesterRank = comMap.first;
415 auto indices = std::move(communicationMap[globalRequesterRank]);
431 if (localConnectedRanks.
empty()) {
443 localConnectedRanks.
size());
447 for (
int connectedRank : localConnectedRanks) {
464 PRECICE_DEBUG(
"Exchange vertex distribution between both primary ranks");
465 Event e0(
"m2n.exchangeVertexDistribution");
468 c->requestConnection(acceptorName, requesterName,
469 "TMP-PRIMARYCOM-" +
_mesh->getName(),
481 _mesh->setVertexDistribution(vertexDistribution);
505 vertexDistribution, acceptorVertexDistribution);
511 print(communicationMap);
515#ifdef P2P_LCM_PRINT_STATS
521 Event e4(
"m2n.createCommunications");
522 e4.
addData(
"Connections", communicationMap.
size());
523 if (communicationMap.
empty()) {
532 for (
auto &i : communicationMap)
533 acceptingRanks.
emplace(i.first);
541 _communication->requestConnectionAsClient(acceptorName, requesterName,
546 for (
auto &i : communicationMap) {
547 auto globalAcceptorRank = i.first;
548 auto indices = std::move(i.second);
564 if (localConnectedRanks.
empty()) {
576 _communication->requestConnectionAsClient(acceptorName, requesterName,
580 for (
auto &connectedRank : localConnectedRanks) {
591 _mappings.push_back({i.remoteRank, std::move(localCommunicationMap[i.remoteRank]), i.request, {}});
619 buffer->reserve(
mapping.indices.size() * valueDimension);
620 for (
auto index :
mapping.indices) {
621 for (
int d = 0; d < valueDimension; ++d) {
622 buffer->push_back(itemsToSend[index * valueDimension + d]);
640 mapping.recvBuffer.resize(
mapping.indices.size() * valueDimension);
648 for (
auto index :
mapping.indices) {
649 for (
int d = 0; d < valueDimension; ++d) {
650 itemsToReceive[index * valueDimension + d] +=
mapping.recvBuffer[i * valueDimension + d];
691 _communication->sendRange(localCommunicationMap[connectionData.remoteRank], connectionData.remoteRank);
707 if (it->first->test())
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
T back_inserter(T... args)
std::map< int, std::vector< int > > CommunicationMap
mesh::PtrMesh _mesh
mesh that dictates the distribution of this mapping
DistributedCommunication(mesh::PtrMesh mesh)
void scatterAllCommunicationMap(CommunicationMap &localCommunicationMap) override
Scatters a communication map over connected ranks on remote participant.
PointToPointCommunication(com::PtrCommunicationFactory communicationFactory, mesh::PtrMesh mesh)
void broadcastSendMesh() override
Broadcasts a mesh to connected ranks on remote participant.
void gatherAllCommunicationMap(CommunicationMap &localCommunicationMap) override
Gathers a communication maps from connected ranks on remote participant.
void broadcastSend(int itemToSend) override
Broadcasts an int to connected ranks on remote participant.
bool isConnected() const override
Returns true, if a connection to a remote participant has been established.
std::vector< Mapping > _mappings
Local (for process rank in the current participant) vector of mappings (one to service each point-to-...
std::vector< ConnectionData > _connectionDataVector
Local (for process rank in the current participant) vector of ConnectionData (one to service each poi...
void acceptPreConnection(std::string const &acceptorName, std::string const &requesterName) override
Accepts connection from participant, which has to call requestPreConnection(). Only initial connectio...
com::PtrCommunicationFactory _communicationFactory
void receive(precice::span< double > itemsToReceive, int valueDimension=1) override
Receives a subset of local double values corresponding to local indices deduced from the current and ...
std::list< std::pair< std::shared_ptr< com::Request >, std::shared_ptr< std::vector< double > > > > bufferedRequests
void broadcastReceiveAll(std::vector< int > &itemToReceive) override
Receives an int per connected rank on remote participant @para[out] itemToReceive received ints from ...
void requestPreConnection(std::string const &acceptorName, std::string const &requesterName) override
Requests connection from participant, which has to call acceptConnection(). Only initial connection i...
void completeSecondaryRanksConnection() override
Completes the secondary connections for both acceptor and requester by updating the vertex list in _m...
~PointToPointCommunication() override
void checkBufferedRequests(bool blocking)
Checks all stored requests for completion and removes associated buffers.
void acceptConnection(std::string const &acceptorName, std::string const &requesterName) override
Accepts connection from participant, which has to call requestConnection().
void requestConnection(std::string const &acceptorName, std::string const &requesterName) override
Requests connection from participant, which has to call acceptConnection().
com::PtrCommunication _communication
Communication class used for this PointToPointCommunication.
void closeConnection() override
Disconnects from communication space, i.e. participant.
void broadcastReceiveAllMesh() override
Receive mesh partitions per connected rank on remote participant.
void send(precice::span< double const > itemsToSend, int valueDimension=1) override
Sends a subset of local double values corresponding to local indices deduced from the current and rem...
std::map< Rank, std::vector< VertexID > > CommunicationMap
A mapping from remote local ranks to the IDs that must be communicated.
std::map< Rank, std::vector< VertexID > > VertexDistribution
A mapping from rank to used (not necessarily owned) vertex IDs.
void stop()
Stops a running event.
void addData(std::string_view key, int value)
Adds named integer data, associated to an event.
A C++ 11 implementation of the non-owning C++20 std::span type.
PRECICE_SPAN_NODISCARD constexpr bool empty() const noexcept
constexpr iterator begin() const noexcept
constexpr iterator end() const noexcept
static Rank getRank()
Current rank.
static bool isPrimary()
True if this process is running the primary rank.
static auto allSecondaryRanks()
Returns an iterable range over salve ranks [1, _size)
static bool isSecondary()
True if this process is running a secondary rank.
static com::PtrCommunication & getCommunication()
Intra-participant communication.
void sendMesh(Communication &communication, int rankReceiver, const mesh::Mesh &mesh)
constexpr auto asVector
Allows to use Communication::AsVectorTag in a less verbose way.
std::shared_ptr< Request > PtrRequest
void receiveMesh(Communication &communication, int rankSender, mesh::Mesh &mesh)
std::shared_ptr< CommunicationFactory > PtrCommunicationFactory
std::shared_ptr< Communication > PtrCommunication
contains the logic of the parallel communication between participants.
std::map< int, std::vector< int > > buildCommunicationMap(mesh::Mesh::VertexDistribution const &thisVertexDistribution, mesh::Mesh::VertexDistribution const &otherVertexDistribution, int thisRank=utils::IntraComm::getRank())
void print(std::map< int, std::vector< int > > const &m)
void broadcastReceive(mesh::Mesh::VertexDistribution &m, int rankBroadcaster, const com::PtrCommunication &communication=utils::IntraComm::getCommunication())
void printCommunicationPartnerCountStats(std::map< int, std::vector< int > > const &m)
void printLocalIndexCountStats(std::map< int, std::vector< int > > const &m)
void receive(mesh::Mesh::VertexDistribution &m, int rankSender, const com::PtrCommunication &communication)
void broadcast(mesh::Mesh::VertexDistribution &m)
void send(mesh::Mesh::VertexDistribution const &m, int rankReceiver, const com::PtrCommunication &communication)
void broadcastSend(mesh::Mesh::VertexDistribution const &m, const com::PtrCommunication &communication=utils::IntraComm::getCommunication())
contains data mapping from points to meshes.
provides Mesh, Data and primitives.
std::shared_ptr< Mesh > PtrMesh
static constexpr SynchronizeTag Synchronize
Convenience instance of the SynchronizeTag.
void set_intersection_indices(InputIt1 ref1, InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first)
This function is by and large the same as std::set_intersection(). The only difference is that we don...
T setprecision(T... args)