preCICE v3.1.2
Loading...
Searching...
No Matches
MPIDirectCommunication.hpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#pragma once
4
5#include <mpi.h>
6#include <set>
7#include <stddef.h>
8#include <string>
9
11#include "logging/Logger.hpp"
13#include "utils/Parallel.hpp"
14#include "utils/assertion.hpp"
15
16namespace precice {
17namespace com {
30public:
34
36
42 virtual size_t getRemoteCommunicatorSize() override;
43
48 virtual void acceptConnection(std::string const &acceptorName,
49 std::string const &requesterName,
50 std::string const &tag,
51 int acceptorRank,
52 int rankOffset = 0) override;
53
54 virtual void acceptConnectionAsServer(std::string const &acceptorName,
55 std::string const &requesterName,
56 std::string const &tag,
57 int acceptorRank,
58 int requesterCommunicatorSize) override
59 {
60 PRECICE_ASSERT(false, "Not implemented!");
61 }
62
67 virtual void requestConnection(std::string const &acceptorName,
68 std::string const &requesterName,
69 std::string const &tag,
70 int requesterRank,
71 int requesterCommunicatorSize) override;
72
73 virtual void requestConnectionAsClient(std::string const & acceptorName,
74 std::string const & requesterName,
75 std::string const & tag,
76 std::set<int> const &acceptorRanks,
77 int requesterRank) override
78 {
79 PRECICE_ASSERT(false, "Not implemented!");
80 }
81
83 virtual void closeConnection() override;
84
85 virtual void reduceSum(precice::span<double const> itemsToSend, precice::span<double> itemsToReceive, Rank primaryRank) override;
86
87 virtual void reduceSum(precice::span<double const> itemsToSend, precice::span<double> itemsToReceive) override;
88
89 virtual void reduceSum(int itemToSend, int &itemsToReceive, Rank primaryRank) override;
90
91 virtual void reduceSum(int itemToSend, int &itemsToReceive) override;
92
93 virtual void allreduceSum(precice::span<double const> itemsToSend, precice::span<double> itemsToReceive, Rank primaryRank) override;
94
95 virtual void allreduceSum(precice::span<double const> itemsToSend, precice::span<double> itemsToReceive) override;
96
97 virtual void allreduceSum(double itemToSend, double &itemsToReceive, Rank primaryRank) override;
98
99 virtual void allreduceSum(double itemToSend, double &itemsToReceive) override;
100
101 virtual void allreduceSum(int itemToSend, int &itemsToReceive, Rank primaryRank) override;
102
103 virtual void allreduceSum(int itemToSend, int &itemsToReceive) override;
104
105 virtual void broadcast(precice::span<const int> itemsToSend) override;
106
107 virtual void broadcast(precice::span<int> itemsToReceive, Rank rankBroadcaster) override;
108
109 virtual void broadcast(int itemToSend) override;
110
111 virtual void broadcast(int &itemToReceive, Rank rankBroadcaster) override;
112
113 virtual void broadcast(precice::span<const double> itemsToSend) override;
114
115 virtual void broadcast(precice::span<double> itemsToReceive, Rank rankBroadcaster) override;
116
117 virtual void broadcast(double itemToSend) override;
118
119 virtual void broadcast(double &itemToReceive, Rank rankBroadcaster) override;
120
121 virtual void broadcast(bool itemToSend) override;
122
123 virtual void broadcast(bool &itemToReceive, Rank rankBroadcaster) override;
124
125private:
126 virtual MPI_Comm &communicator(Rank rank = 0) override;
127
128 virtual Rank rank(int rank) override;
129
130 logging::Logger _log{"com::MPIDirectCommunication"};
131
134
135protected:
137 virtual int adjustRank(Rank rank) const override;
138};
139
140} // namespace com
141} // namespace precice
142
143#endif // not PRECICE_NO_MPI
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Provides implementation for basic MPI point-to-point communication.
Provides connection methods for processes located in one communicator.
virtual void acceptConnection(std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int rankOffset=0) override
virtual void requestConnection(std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int requesterRank, int requesterCommunicatorSize) override
virtual void acceptConnectionAsServer(std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int requesterCommunicatorSize) override
Accepts connection from another communicator, which has to call requestConnectionAsClient().
virtual size_t getRemoteCommunicatorSize() override
Returns the number of processes in the remote communicator.
virtual void requestConnectionAsClient(std::string const &acceptorName, std::string const &requesterName, std::string const &tag, std::set< int > const &acceptorRanks, int requesterRank) override
Connects to another communicator, which has to call acceptConnectionAsServer().
virtual void broadcast(precice::span< const int > itemsToSend) override
virtual int adjustRank(Rank rank) const override
Turn the rank adjustment into a noop for direct communication.
utils::Parallel::CommStatePtr _commState
CommState to use.
virtual void closeConnection() override
See precice::com::Communication::closeConnection().
virtual void allreduceSum(precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank) override
virtual MPI_Comm & communicator(Rank rank=0) override
Returns the communicator.
virtual void reduceSum(precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank) override
Performs a reduce summation on the rank given by primaryRank.
This class provides a lightweight logger.
Definition Logger.hpp:16
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
Main namespace of the precice library.
int Rank
Definition Types.hpp:37