preCICE
Loading...
Searching...
No Matches
Communication.hpp File Reference
#include <set>
#include <stddef.h>
#include <string>
#include <vector>
#include "boost/range/irange.hpp"
#include "com/Request.hpp"
#include "com/SharedPointer.hpp"
#include "logging/Logger.hpp"
#include "precice/impl/Types.hpp"
#include "precice/span.hpp"
Include dependency graph for Communication.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  precice::com::AsVectorTag< T >

Namespaces

namespace  precice
 Main namespace of the precice library.
namespace  precice::com
 contains the data communication abstraction layer.

Functions

void precice::com::setRankOffset (Rank rankOffset)
 Set rank offset.
virtual int precice::com::adjustRank (Rank rank) const
 Adjusts the given rank bases on the _rankOffset.
void precice::com::connectCircularComm (std::string const &participantName, std::string const &tag, int rank, int size, com::Communication &left, com::Communication &right)
Connection Setup

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:

  1. Robustness — allows one to write deadlock-prone communication algorithms (see point-to-point communication).
  2. Efficiency — allows one to perform some useful computational work while sending is happening on the background.
Attention
All receive methods, that accept a raw array, expect it to be sized appropriately. Asynchronous receive methods also expect the vector be sized correctly. */ class Communication {

public: Communication &operator=(Communication &&) = delete;

/ Destructor, empty. virtual ~Communication() = default;

/ /

/ Returns true, if a connection to a remote participant has been setup. virtual bool isConnected() { return _isConnected; }

/**

Returns the number of processes in the remote communicator.

Precondition
A connection to the remote participant has been set up.
virtual size_t precice::com::getRemoteCommunicatorSize ()=0
auto precice::com::remoteCommunicatorRanks ()
 Returns a range over all valid remote ranks.
virtual void precice::com::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 precice::com::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 precice::com::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 precice::com::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 precice::com::connectIntraComm (std::string const &participantName, std::string const &tag, int rank, int size)
virtual void precice::com::closeConnection ()=0
 Disconnects from communication space, i.e. participant.
virtual void precice::com::prepareEstablishment (std::string const &acceptorName, std::string const &requesterName)
 Prepare environment used to establish the communication.
virtual void precice::com::cleanupEstablishment (std::string const &acceptorName, std::string const &requesterName)
 Clean-up environment used to establish the communication.
Reduction
virtual void precice::com::reduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank)
 Performs a reduce summation on the rank given by primaryRank.
virtual void precice::com::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 precice::com::reduceSum (int itemToSend, int &itemToReceive, Rank primaryRank)
virtual void precice::com::reduceSum (int itemsToSend, int &itemsToReceive)
virtual void precice::com::allreduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank)
virtual void precice::com::allreduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive)
virtual void precice::com::allreduceSum (double itemToSend, double &itemToReceive, Rank primaryRank)
virtual void precice::com::allreduceSum (double itemToSend, double &itemToReceive)
virtual void precice::com::allreduceSum (int itemToSend, int &itemToReceive, Rank primaryRank)
virtual void precice::com::allreduceSum (int itemToSend, int &itemToReceive)
Broadcast
virtual void precice::com::broadcast (precice::span< const int > itemsToSend)
virtual void precice::com::broadcast (precice::span< int > itemsToReceive, Rank rankBroadcaster)
virtual void precice::com::broadcast (int itemToSend)
virtual void precice::com::broadcast (int &itemToReceive, Rank rankBroadcaster)
virtual void precice::com::broadcast (precice::span< const double > itemsToSend)
virtual void precice::com::broadcast (precice::span< double > itemsToReceive, Rank rankBroadcaster)
virtual void precice::com::broadcast (double itemToSend)
virtual void precice::com::broadcast (double &itemToReceive, Rank rankBroadcaster)
virtual void precice::com::broadcast (bool itemToSend)
virtual void precice::com::broadcast (bool &itemToReceive, Rank rankBroadcaster)
virtual void precice::com::broadcast (std::vector< int > const &v)
virtual void precice::com::broadcast (std::vector< int > &v, Rank rankBroadcaster)
virtual void precice::com::broadcast (std::vector< double > const &v)
virtual void precice::com::broadcast (std::vector< double > &v, Rank rankBroadcaster)
Send
virtual void precice::com::send (std::string const &itemToSend, Rank rankReceiver)=0
 Sends a std::string to process with given rank.
virtual void precice::com::send (precice::span< const int > itemsToSend, Rank rankReceiver)=0
 Sends an array of integer values.
virtual PtrRequest precice::com::aSend (precice::span< const int > itemsToSend, Rank rankReceiver)=0
 Asynchronously sends an array of integer values.
virtual void precice::com::send (precice::span< const double > itemsToSend, Rank rankReceiver)=0
 Sends an array of double values.
virtual PtrRequest precice::com::aSend (precice::span< const double > itemsToSend, Rank rankReceiver)=0
 Asynchronously sends an array of double values.
virtual void precice::com::send (double itemToSend, Rank rankReceiver)=0
 Sends a double to process with given rank.
virtual PtrRequest precice::com::aSend (const double &itemToSend, Rank rankReceiver)=0
 Asynchronously sends a double to process with given rank.
virtual void precice::com::send (int itemToSend, Rank rankReceiver)=0
 Sends an int to process with given rank.
virtual PtrRequest precice::com::aSend (const int &itemToSend, Rank rankReceiver)=0
 Asynchronously sends an int to process with given rank.
virtual void precice::com::send (bool itemToSend, Rank rankReceiver)=0
 Sends a bool to process with given rank.
virtual PtrRequest precice::com::aSend (const bool &itemToSend, Rank rankReceiver)=0
 Asynchronously sends a bool to process with given rank.
Receive
virtual void precice::com::receive (std::string &itemToReceive, Rank rankSender)=0
 Receives a std::string from process with given rank.
virtual void precice::com::receive (precice::span< int > itemsToReceive, Rank rankSender)=0
 Receives an array of integer values.
virtual void precice::com::receive (precice::span< double > itemsToReceive, Rank rankSender)=0
 Receives an array of double values.
virtual PtrRequest precice::com::aReceive (precice::span< double > itemsToReceive, int rankSender)=0
 Asynchronously receives an array of double values.
virtual void precice::com::receive (double &itemToReceive, Rank rankSender)=0
 Receives a double from process with given rank.
virtual PtrRequest precice::com::aReceive (double &itemToReceive, Rank rankSender)=0
 Asynchronously receives a double from process with given rank.
virtual void precice::com::receive (int &itemToReceive, Rank rankSender)=0
 Receives an int from process with given rank.
virtual PtrRequest precice::com::aReceive (int &itemToReceive, Rank rankSender)=0
 Asynchronously receives an int from process with given rank.
virtual void precice::com::receive (bool &itemToReceive, Rank rankSender)=0
 Receives a bool from process with given rank.
virtual PtrRequest precice::com::aReceive (bool &itemToReceive, Rank rankSender)=0
 Asynchronously receives a bool from process with given rank.
Range communication
void precice::com::sendRange (precice::span< const double > itemsToSend, Rank rankReceiver)
 Sends a range of doubles (size + content).
void precice::com::sendRange (precice::span< const int > itemsToSend, Rank rankReceiver)
 Sends a range of ints (size + content).
std::vector< int > precice::com::receiveRange (Rank rankSender, AsVectorTag< int >)
 Receives a range of ints as a vector<int>.
std::vector< double > precice::com::receiveRange (Rank rankSender, AsVectorTag< double >)
 Receives a range of doubles as a vector<double>.

Variables

int precice::com::_rankOffset = 0
 Rank offset for primaries-secondary communication, since ranks are from 0 to size-2.
bool precice::com::_isConnected = false
logging::Logger precice::com::_log {"com::Communication"}
template<typename T>
constexpr auto precice::com::asVector = Communication::AsVectorTag<T>{}
 Allows to use Communication::AsVectorTag in a less verbose way.