preCICE v3.1.2
|
Interface for all interprocess communication classes. More...
#include <Communication.hpp>
Public Member Functions | |
Communication & | operator= (Communication &&)=delete |
virtual | ~Communication () |
Destructor, empty. | |
void | setRankOffset (Rank rankOffset) |
Set rank offset. | |
Connection Setup | |
virtual bool | isConnected () |
Returns true, if a connection to a remote participant has been setup. | |
virtual size_t | getRemoteCommunicatorSize ()=0 |
Returns the number of processes in the remote communicator. | |
auto | remoteCommunicatorRanks () |
Returns a range over all valid remote ranks. | |
virtual void | acceptConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int rankOffset=0)=0 |
Accepts connection from another communicator, which has to call requestConnection(). | |
virtual void | acceptConnectionAsServer (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int requesterCommunicatorSize)=0 |
Accepts connection from another communicator, which has to call requestConnectionAsClient(). | |
virtual void | requestConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int requesterRank, int requesterCommunicatorSize)=0 |
Connects to another communicator, which has to call acceptConnection(). | |
virtual void | requestConnectionAsClient (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, std::set< int > const &acceptorRanks, int requesterRank)=0 |
Connects to another communicator, which has to call acceptConnectionAsServer(). | |
void | connectIntraComm (std::string const &participantName, std::string const &tag, int rank, int size) |
virtual void | closeConnection ()=0 |
Disconnects from communication space, i.e. participant. | |
virtual void | prepareEstablishment (std::string const &acceptorName, std::string const &requesterName) |
Prepare environment used to establish the communication. | |
virtual void | cleanupEstablishment (std::string const &acceptorName, std::string const &requesterName) |
Clean-up environment used to establish the communication. | |
Reduction | |
virtual void | reduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank) |
Performs a reduce summation on the rank given by primaryRank. | |
virtual void | reduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive) |
Performs a reduce summation on the primary rank, every other rank has to call reduceSum. | |
virtual void | reduceSum (int itemToSend, int &itemToReceive, Rank primaryRank) |
virtual void | reduceSum (int itemsToSend, int &itemsToReceive) |
virtual void | allreduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank) |
virtual void | allreduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive) |
virtual void | allreduceSum (double itemToSend, double &itemToReceive, Rank primaryRank) |
virtual void | allreduceSum (double itemToSend, double &itemToReceive) |
virtual void | allreduceSum (int itemToSend, int &itemToReceive, Rank primaryRank) |
virtual void | allreduceSum (int itemToSend, int &itemToReceive) |
Broadcast | |
virtual void | broadcast (precice::span< const int > itemsToSend) |
virtual void | broadcast (precice::span< int > itemsToReceive, Rank rankBroadcaster) |
virtual void | broadcast (int itemToSend) |
virtual void | broadcast (int &itemToReceive, Rank rankBroadcaster) |
virtual void | broadcast (precice::span< const double > itemsToSend) |
virtual void | broadcast (precice::span< double > itemsToReceive, Rank rankBroadcaster) |
virtual void | broadcast (double itemToSend) |
virtual void | broadcast (double &itemToReceive, Rank rankBroadcaster) |
virtual void | broadcast (bool itemToSend) |
virtual void | broadcast (bool &itemToReceive, Rank rankBroadcaster) |
virtual void | broadcast (std::vector< int > const &v) |
virtual void | broadcast (std::vector< int > &v, Rank rankBroadcaster) |
virtual void | broadcast (std::vector< double > const &v) |
virtual void | broadcast (std::vector< double > &v, Rank rankBroadcaster) |
Send | |
virtual void | send (std::string const &itemToSend, Rank rankReceiver)=0 |
Sends a std::string to process with given rank. | |
virtual void | send (precice::span< const int > itemsToSend, Rank rankReceiver)=0 |
Sends an array of integer values. | |
virtual PtrRequest | aSend (precice::span< const int > itemsToSend, Rank rankReceiver)=0 |
virtual void | send (precice::span< const double > itemsToSend, Rank rankReceiver)=0 |
Sends an array of double values. | |
virtual PtrRequest | aSend (precice::span< const double > itemsToSend, Rank rankReceiver)=0 |
virtual void | send (double itemToSend, Rank rankReceiver)=0 |
Sends a double to process with given rank. | |
virtual PtrRequest | aSend (const double &itemToSend, Rank rankReceiver)=0 |
virtual void | send (int itemToSend, Rank rankReceiver)=0 |
Sends an int to process with given rank. | |
virtual PtrRequest | aSend (const int &itemToSend, Rank rankReceiver)=0 |
virtual void | send (bool itemToSend, Rank rankReceiver)=0 |
Sends a bool to process with given rank. | |
virtual PtrRequest | aSend (const bool &itemToSend, Rank rankReceiver)=0 |
Receive | |
virtual void | receive (std::string &itemToReceive, Rank rankSender)=0 |
Receives a std::string from process with given rank. | |
virtual void | receive (precice::span< int > itemsToReceive, Rank rankSender)=0 |
Receives an array of integer values. | |
virtual void | receive (precice::span< double > itemsToReceive, Rank rankSender)=0 |
Receives an array of double values. | |
virtual PtrRequest | aReceive (precice::span< double > itemsToReceive, int rankSender)=0 |
Asynchronously receives an array of double values. | |
virtual void | receive (double &itemToReceive, Rank rankSender)=0 |
Receives a double from process with given rank. | |
virtual PtrRequest | aReceive (double &itemToReceive, Rank rankSender)=0 |
Asynchronously receives a double from process with given rank. | |
virtual void | receive (int &itemToReceive, Rank rankSender)=0 |
Receives an int from process with given rank. | |
virtual PtrRequest | aReceive (int &itemToReceive, Rank rankSender)=0 |
Asynchronously receives an int from process with given rank. | |
virtual void | receive (bool &itemToReceive, Rank rankSender)=0 |
Receives a bool from process with given rank. | |
virtual PtrRequest | aReceive (bool &itemToReceive, Rank rankSender)=0 |
Asynchronously receives a bool from process with given rank. | |
Range communication | |
void | sendRange (precice::span< const double > itemsToSend, Rank rankReceiver) |
Sends a range of doubles (size + content) | |
void | sendRange (precice::span< const int > itemsToSend, Rank rankReceiver) |
Sends a range of ints (size + content) | |
std::vector< int > | receiveRange (Rank rankSender, AsVectorTag< int >) |
Receives a range of ints as a vector<int> | |
std::vector< double > | receiveRange (Rank rankSender, AsVectorTag< double >) |
Receives a range of doubles as a vector<double> | |
Protected Member Functions | |
virtual int | adjustRank (Rank rank) const |
Adjusts the given rank bases on the _rankOffset. | |
Protected Attributes | |
int | _rankOffset = 0 |
Rank offset for primaries-secondary communication, since ranks are from 0 to size-2. | |
bool | _isConnected = false |
Private Attributes | |
logging::Logger | _log {"com::Communication"} |
Interface for all interprocess communication classes.
By default, communication is done within the local communication space. In order to connect to a different communication space, i.e. coupling participant, the methods acceptConnection() and requestConnection() have to called by the two participants which intend to establish a connection. All following communication and process ranking refers to the remote communication space afterwards.
Sending methods prefixed with ‘a’ are asynchronous. It means that they return immediately, even though either the actual sending might have not been started yet or data from user buffer that is being supplied has not been safely stored away (to system buffer) yet. This implies that user buffer cannot be immediately reused (for writing) after asynchronous sending call returns. However, a special corresponding "request" object is returned by all asynchronous sending methods, which could be further used in future in order to properly wait (block execution) until either the corresponding sending request has truly finished or data from user buffer that is being supplied has been safely stored away (to system buffer) and, thus, can be reused (for writing).
The main benefit from asynchronous sending methods is their deterministic behavior, i.e. the guarantee that they can never block the execution (return immediately). The two typical scenarios where this comes handy are:
Definition at line 65 of file Communication.hpp.
|
inlinevirtual |
Destructor, empty.
Definition at line 71 of file Communication.hpp.
|
pure virtual |
Accepts connection from another communicator, which has to call requestConnection().
Establishes a 1-to-N communication, whereas the acceptor's side is the "1". Contrary to acceptConnectionAsServer(), the other side needs to be a proper communicator with ranks from 0 to N-1. It is not necessary to know this "N" a-priori on the acceptor's side. This communication is used for the 1:1 communication between two primary ranks and for the intra-participant communication. For the last case, setRankOffset() has to be set.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to. |
[in] | tag | Tag for establishing this connection |
[in] | acceptorRank | Rank of the accpeting process, usually the calling one. |
Implemented in precice::com::MPIDirectCommunication, precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
|
pure virtual |
Accepts connection from another communicator, which has to call requestConnectionAsClient().
Establishes a 1-to-N communication, whereas the acceptor's side is the "1". Contrary to acceptConnection(), the other side can have arbitrary ranks. However, we need to know its size "N" a-priori. This communication is only used in PointToPointCommunication, i.e. for the M-to-N communication between two participants.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to. |
[in] | tag | Tag for establishing this connection |
[in] | acceptorRank | Rank of accepting server, usually the rank of the current process. |
[in] | requesterCommunicatorSize | Size of the requester (N) |
Implemented in precice::com::MPIDirectCommunication, precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
|
protectedvirtual |
Adjusts the given rank bases on the _rankOffset.
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 354 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 123 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 144 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 154 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 175 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 94 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 113 of file Communication.cpp.
|
pure virtual |
Asynchronously receives a bool from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously receives a double from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously receives an int from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously receives an array of double values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously sends a bool to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously sends a double to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously sends an int to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously sends an array of double values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Asynchronously sends an array of integer values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 270 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 263 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 257 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 244 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 218 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 205 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 224 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 185 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 237 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 198 of file Communication.cpp.
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
inlinevirtual |
Clean-up environment used to establish the communication.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to. |
Reimplemented in precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
Definition at line 220 of file Communication.hpp.
|
pure virtual |
Disconnects from communication space, i.e. participant.
This method is called on destruction.
Implemented in precice::com::MPIDirectCommunication, precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
void precice::com::Communication::connectIntraComm | ( | std::string const & | participantName, |
std::string const & | tag, | ||
int | rank, | ||
int | size ) |
Establishes the intra-participant communication connection.
[in] | participantName | Name of the calling participant. |
[in] | tag | Tag for establishing this connection |
[in] | rank | The current rank in the participant |
[in] | size | Total size of the participant |
Definition at line 14 of file Communication.cpp.
|
pure virtual |
Returns the number of processes in the remote communicator.
Implemented in precice::com::MPIDirectCommunication, precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
|
inlinevirtual |
Returns true, if a connection to a remote participant has been setup.
Definition at line 79 of file Communication.hpp.
|
delete |
|
inlinevirtual |
Prepare environment used to establish the communication.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to. |
Reimplemented in precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
Definition at line 211 of file Communication.hpp.
|
pure virtual |
Receives a bool from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Receives a double from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Receives an int from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Receives an array of double values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Receives an array of integer values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Receives a std::string from process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
std::vector< double > precice::com::Communication::receiveRange | ( | Rank | rankSender, |
AsVectorTag< double > | ) |
Receives a range of doubles as a vector<double>
Definition at line 341 of file Communication.cpp.
std::vector< int > precice::com::Communication::receiveRange | ( | Rank | rankSender, |
AsVectorTag< int > | ) |
Receives a range of ints as a vector<int>
Definition at line 328 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 69 of file Communication.cpp.
|
virtual |
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 83 of file Communication.cpp.
|
virtual |
Performs a reduce summation on the primary rank, every other rank has to call reduceSum.
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 42 of file Communication.cpp.
|
virtual |
Performs a reduce summation on the rank given by primaryRank.
Reimplemented in precice::com::MPIDirectCommunication.
Definition at line 60 of file Communication.cpp.
|
inline |
Returns a range over all valid remote ranks.
Definition at line 98 of file Communication.hpp.
|
pure virtual |
Connects to another communicator, which has to call acceptConnection().
Establishes a 1-to-N communication, whereas the requestor's side is the "N". Contrary to requestConnectionAsClient(), this side needs to be a proper communicator with ranks from 0 to N-1. All ranks need to call this function. This communication is used for the 1:1 communication between two primary ranks, and for the intra-participant communication.
[in] | acceptorName | Name of remote participant to connect to. |
[in] | requesterName | Name of calling participant. |
[in] | tag | Tag for establishing this connection |
[in] | requesterRank | Rank of the requester (has to go from 0 to N-1) |
[in] | requesterCommunicatorSize | Size of the requester (N) |
Implemented in precice::com::MPIDirectCommunication, precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
|
pure virtual |
Connects to another communicator, which has to call acceptConnectionAsServer().
Establishes a 1-to-N communication, whereas the requestor's side is the "N". Contrary to requestConnection(), this side can have arbitrary ranks (e.g. 2,3,7). All ranks need to call this function. This communication is only used in PointToPointCommunication, i.e. for the M-to-N communication between two participants.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to |
[in] | tag | Tag for establishing this connection |
[in] | acceptorRanks | Set of ranks that accept a connection |
[in] | requesterRank | Rank that requests the connection, usually the caller's rank |
Implemented in precice::com::MPIDirectCommunication, precice::com::MPIPortsCommunication, precice::com::MPISinglePortsCommunication, and precice::com::SocketCommunication.
|
pure virtual |
Sends a bool to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Sends a double to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Sends an int to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Sends an array of double values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Sends an array of integer values.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
|
pure virtual |
Sends a std::string to process with given rank.
Implemented in precice::com::MPICommunication, and precice::com::SocketCommunication.
void precice::com::Communication::sendRange | ( | precice::span< const double > | itemsToSend, |
Rank | rankReceiver ) |
Sends a range of doubles (size + content)
Definition at line 310 of file Communication.cpp.
void precice::com::Communication::sendRange | ( | precice::span< const int > | itemsToSend, |
Rank | rankReceiver ) |
Sends a range of ints (size + content)
Definition at line 319 of file Communication.cpp.
|
inline |
Set rank offset.
Definition at line 369 of file Communication.hpp.
|
protected |
Definition at line 378 of file Communication.hpp.
|
private |
Definition at line 384 of file Communication.hpp.
|
protected |
Rank offset for primaries-secondary communication, since ranks are from 0 to size-2.
Definition at line 376 of file Communication.hpp.