preCICE v3.3.0
|
Implements Communication by using sockets. More...
#include <SocketCommunication.hpp>
Public Member Functions | |
SocketCommunication (unsigned short portNumber=0, bool reuseAddress=false, std::string networkName=utils::networking::loopbackInterfaceName(), std::string addressDirectory=".") | |
SocketCommunication (std::string const &addressDirectory) | |
~SocketCommunication () override | |
size_t | getRemoteCommunicatorSize () override |
Returns the number of processes in the remote communicator. | |
void | acceptConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int rankOffset=0) override |
Accepts connection from another communicator, which has to call requestConnection(). | |
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(). | |
void | requestConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int requesterRank, int requesterCommunicatorSize) override |
Connects to another communicator, which has to call acceptConnection(). | |
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(). | |
void | closeConnection () override |
Disconnects from communication space, i.e. participant. | |
void | send (std::string const &itemToSend, Rank rankReceiver) override |
Sends a std::string to process with given rank. | |
void | send (precice::span< const int > itemsToSend, Rank rankReceiver) override |
Sends an array of integer values. | |
PtrRequest | aSend (precice::span< const int > itemsToSend, Rank rankReceiver) override |
Asynchronously sends an array of integer values. | |
void | send (precice::span< const double > itemsToSend, Rank rankReceiver) override |
Sends an array of double values. | |
PtrRequest | aSend (precice::span< const double > itemsToSend, Rank rankReceiver) override |
Asynchronously sends an array of double values. | |
void | send (double itemToSend, Rank rankReceiver) override |
Sends a double to process with given rank. | |
PtrRequest | aSend (const double &itemToSend, Rank rankReceiver) override |
Asynchronously sends a double to process with given rank. | |
void | send (int itemToSend, Rank rankReceiver) override |
Sends an int to process with given rank. | |
PtrRequest | aSend (const int &itemToSend, Rank rankReceiver) override |
Asynchronously sends an int to process with given rank. | |
void | send (bool itemToSend, Rank rankReceiver) override |
Sends a bool to process with given rank. | |
PtrRequest | aSend (const bool &itemToSend, Rank rankReceiver) override |
Asynchronously sends a bool to process with given rank. | |
void | receive (std::string &itemToReceive, Rank rankSender) override |
Receives a std::string from process with given rank. | |
void | receive (precice::span< int > itemsToReceive, Rank rankSender) override |
Receives an array of integer values. | |
void | receive (precice::span< double > itemsToReceive, Rank rankSender) override |
Receives an array of double values. | |
PtrRequest | aReceive (precice::span< double > itemsToReceive, int rankSender) override |
Asynchronously receives an array of double values. | |
void | receive (double &itemToReceive, Rank rankSender) override |
Receives a double from process with given rank. | |
PtrRequest | aReceive (double &itemToReceive, Rank rankSender) override |
Asynchronously receives a double from process with given rank. | |
void | receive (int &itemToReceive, Rank rankSender) override |
Receives an int from process with given rank. | |
PtrRequest | aReceive (int &itemToReceive, Rank rankSender) override |
Asynchronously receives an int from process with given rank. | |
void | receive (bool &itemToReceive, Rank rankSender) override |
Receives a bool from process with given rank. | |
PtrRequest | aReceive (bool &itemToReceive, Rank rankSender) override |
Asynchronously receives a bool from process with given rank. | |
void | prepareEstablishment (std::string const &acceptorName, std::string const &requesterName) override |
Prepare environment used to establish the communication. | |
void | cleanupEstablishment (std::string const &acceptorName, std::string const &requesterName) override |
Clean-up environment used to establish the communication. | |
Public Member Functions inherited from precice::com::Communication | |
Communication & | operator= (Communication &&)=delete |
virtual | ~Communication ()=default |
Destructor, empty. | |
void | setRankOffset (Rank rankOffset) |
Set rank offset. | |
virtual bool | isConnected () |
Returns true, if a connection to a remote participant has been setup. | |
auto | remoteCommunicatorRanks () |
Returns a range over all valid remote ranks. | |
void | connectIntraComm (std::string const &participantName, std::string const &tag, int rank, int size) |
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) |
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) |
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> |
Private Types | |
using | IOContext = boost::asio::io_context |
using | Socket = boost::asio::ip::tcp::socket |
using | WorkGuard = boost::asio::executor_work_guard<IOContext::executor_type> |
Private Member Functions | |
bool | isClient () |
bool | isServer () |
std::string | getIpAddress () |
Private Attributes | |
logging::Logger | _log {"com::SocketCommunication"} |
unsigned short | _portNumber |
Port used for socket connection. | |
bool | _reuseAddress |
std::string | _networkName |
Name of network to communicate over. | |
std::string | _addressDirectory |
Directory where IP address is exchanged by file. | |
std::shared_ptr< IOContext > | _ioContext |
std::unique_ptr< WorkGuard > | _workGuard |
std::thread | _thread |
std::map< int, std::shared_ptr< Socket > > | _sockets |
Remote rank -> socket map. | |
SocketSendQueue | _queue |
Additional Inherited Members | |
Protected Member Functions inherited from precice::com::Communication | |
virtual int | adjustRank (Rank rank) const |
Adjusts the given rank bases on the _rankOffset. | |
Protected Attributes inherited from precice::com::Communication | |
int | _rankOffset = 0 |
Rank offset for primaries-secondary communication, since ranks are from 0 to size-2. | |
bool | _isConnected = false |
Implements Communication by using sockets.
Definition at line 20 of file SocketCommunication.hpp.
|
private |
Definition at line 143 of file SocketCommunication.hpp.
|
private |
Definition at line 144 of file SocketCommunication.hpp.
|
private |
Definition at line 145 of file SocketCommunication.hpp.
precice::com::SocketCommunication::SocketCommunication | ( | unsigned short | portNumber = 0, |
bool | reuseAddress = false, | ||
std::string | networkName = utils::networking::loopbackInterfaceName(), | ||
std::string | addressDirectory = "." ) |
Definition at line 23 of file SocketCommunication.cpp.
|
explicit |
|
override |
|
overridevirtual |
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 accepting process, usually the calling one. |
Implements precice::com::Communication.
Definition at line 56 of file SocketCommunication.cpp.
|
overridevirtual |
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) |
Implements precice::com::Communication.
Definition at line 140 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously receives a bool from process with given rank.
Implements precice::com::Communication.
Definition at line 698 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously receives a double from process with given rank.
Implements precice::com::Communication.
Definition at line 636 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously receives an int from process with given rank.
Implements precice::com::Communication.
Definition at line 657 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously receives an array of double values.
Implements precice::com::Communication.
Definition at line 595 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously sends a bool to process with given rank.
Implements precice::com::Communication.
Definition at line 523 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously sends a double to process with given rank.
Implements precice::com::Communication.
Definition at line 481 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously sends an int to process with given rank.
Implements precice::com::Communication.
Definition at line 502 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously sends an array of double values.
Implements precice::com::Communication.
Definition at line 446 of file SocketCommunication.cpp.
|
overridevirtual |
Asynchronously sends an array of integer values.
Implements precice::com::Communication.
Definition at line 411 of file SocketCommunication.cpp.
|
overridevirtual |
Clean-up environment used to establish the communication.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to. |
Reimplemented from precice::com::Communication.
Definition at line 398 of file SocketCommunication.cpp.
|
overridevirtual |
Disconnects from communication space, i.e. participant.
This method is called on destruction.
Implements precice::com::Communication.
Definition at line 324 of file SocketCommunication.cpp.
|
private |
|
overridevirtual |
Returns the number of processes in the remote communicator.
Implements precice::com::Communication.
Definition at line 49 of file SocketCommunication.cpp.
|
private |
|
private |
|
overridevirtual |
Prepare environment used to establish the communication.
[in] | acceptorName | Name of calling participant. |
[in] | requesterName | Name of remote participant to connect to. |
Reimplemented from precice::com::Communication.
Definition at line 385 of file SocketCommunication.cpp.
|
overridevirtual |
Receives a bool from process with given rank.
Implements precice::com::Communication.
Definition at line 682 of file SocketCommunication.cpp.
|
overridevirtual |
Receives a double from process with given rank.
Implements precice::com::Communication.
Definition at line 620 of file SocketCommunication.cpp.
|
overridevirtual |
Receives an int from process with given rank.
Implements precice::com::Communication.
Definition at line 641 of file SocketCommunication.cpp.
|
overridevirtual |
Receives an array of double values.
Implements precice::com::Communication.
Definition at line 579 of file SocketCommunication.cpp.
|
overridevirtual |
Receives an array of integer values.
Implements precice::com::Communication.
Definition at line 563 of file SocketCommunication.cpp.
|
overridevirtual |
Receives a std::string from process with given rank.
Implements precice::com::Communication.
Definition at line 542 of file SocketCommunication.cpp.
|
overridevirtual |
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) |
Implements precice::com::Communication.
Definition at line 205 of file SocketCommunication.cpp.
|
overridevirtual |
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 |
Implements precice::com::Communication.
Definition at line 266 of file SocketCommunication.cpp.
|
overridevirtual |
Sends a bool to process with given rank.
Implements precice::com::Communication.
Definition at line 507 of file SocketCommunication.cpp.
|
overridevirtual |
Sends a double to process with given rank.
Implements precice::com::Communication.
Definition at line 465 of file SocketCommunication.cpp.
|
overridevirtual |
Sends an int to process with given rank.
Implements precice::com::Communication.
Definition at line 486 of file SocketCommunication.cpp.
|
overridevirtual |
Sends an array of double values.
Implements precice::com::Communication.
Definition at line 430 of file SocketCommunication.cpp.
|
overridevirtual |
Sends an array of integer values.
Implements precice::com::Communication.
Definition at line 369 of file SocketCommunication.cpp.
|
overridevirtual |
Sends a std::string to process with given rank.
Implements precice::com::Communication.
Definition at line 351 of file SocketCommunication.cpp.
|
private |
Directory where IP address is exchanged by file.
Definition at line 141 of file SocketCommunication.hpp.
|
private |
Definition at line 147 of file SocketCommunication.hpp.
|
private |
Definition at line 130 of file SocketCommunication.hpp.
|
private |
Name of network to communicate over.
Definition at line 138 of file SocketCommunication.hpp.
|
private |
Port used for socket connection.
Definition at line 133 of file SocketCommunication.hpp.
|
private |
Definition at line 154 of file SocketCommunication.hpp.
|
private |
Definition at line 135 of file SocketCommunication.hpp.
|
private |
Remote rank -> socket map.
Definition at line 152 of file SocketCommunication.hpp.
|
private |
Definition at line 149 of file SocketCommunication.hpp.
|
private |
Definition at line 148 of file SocketCommunication.hpp.