preCICE v3.1.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
precice::com::MPIDirectCommunication Class Reference

Provides connection methods for processes located in one communicator. More...

#include <MPIDirectCommunication.hpp>

Inheritance diagram for precice::com::MPIDirectCommunication:
[legend]
Collaboration diagram for precice::com::MPIDirectCommunication:
[legend]

Public Member Functions

 MPIDirectCommunication ()
 
virtual ~MPIDirectCommunication ()
 
virtual size_t getRemoteCommunicatorSize () override
 Returns the number of processes in the remote communicator.
 
virtual void acceptConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int rankOffset=0) 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 void requestConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int requesterRank, int requesterCommunicatorSize) override
 
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 closeConnection () override
 See precice::com::Communication::closeConnection().
 
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.
 
virtual void reduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive) override
 Performs a reduce summation on the primary rank, every other rank has to call reduceSum.
 
virtual void reduceSum (int itemToSend, int &itemsToReceive, Rank primaryRank) override
 
virtual void reduceSum (int itemToSend, int &itemsToReceive) override
 
virtual void allreduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive, Rank primaryRank) override
 
virtual void allreduceSum (precice::span< double const > itemsToSend, precice::span< double > itemsToReceive) override
 
virtual void allreduceSum (double itemToSend, double &itemsToReceive, Rank primaryRank) override
 
virtual void allreduceSum (double itemToSend, double &itemsToReceive) override
 
virtual void allreduceSum (int itemToSend, int &itemsToReceive, Rank primaryRank) override
 
virtual void allreduceSum (int itemToSend, int &itemsToReceive) override
 
virtual void broadcast (precice::span< const int > itemsToSend) override
 
virtual void broadcast (precice::span< int > itemsToReceive, Rank rankBroadcaster) override
 
virtual void broadcast (int itemToSend) override
 
virtual void broadcast (int &itemToReceive, Rank rankBroadcaster) override
 
virtual void broadcast (precice::span< const double > itemsToSend) override
 
virtual void broadcast (precice::span< double > itemsToReceive, Rank rankBroadcaster) override
 
virtual void broadcast (double itemToSend) override
 
virtual void broadcast (double &itemToReceive, Rank rankBroadcaster) override
 
virtual void broadcast (bool itemToSend) override
 
virtual void broadcast (bool &itemToReceive, Rank rankBroadcaster) override
 
- Public Member Functions inherited from precice::com::MPICommunication
 MPICommunication ()
 
virtual ~MPICommunication ()
 Destructor, empty.
 
virtual void send (std::string const &itemToSend, Rank rankReceiver) override
 Sends a std::string to process with given rank.
 
virtual void send (precice::span< const int > itemsToSend, Rank rankReceiver) override
 Sends an array of integer values.
 
virtual PtrRequest aSend (precice::span< const int > itemsToSend, Rank rankReceiver) override
 Asynchronously sends an array of integer values.
 
virtual void send (precice::span< const double > itemsToSend, Rank rankReceiver) override
 Sends an array of double values.
 
virtual PtrRequest aSend (precice::span< const double > itemsToSend, Rank rankReceiver) override
 Asynchronously sends an array of double values.
 
virtual void send (double itemToSend, Rank rankReceiver) override
 Sends a double to process with given rank.
 
virtual PtrRequest aSend (const double &itemToSend, Rank rankReceiver) override
 Asynchronously sends a double to process with given rank.
 
virtual void send (int itemToSend, Rank rankReceiver) override
 Sends an int to process with given rank.
 
virtual PtrRequest aSend (const int &itemToSend, Rank rankReceiver) override
 Asynchronously sends an int to process with given rank.
 
virtual void send (bool itemToSend, Rank rankReceiver) override
 Sends a bool to process with given rank.
 
virtual PtrRequest aSend (const bool &itemToSend, Rank rankReceiver) override
 Asynchronously sends a bool to process with given rank.
 
virtual void receive (std::string &itemToReceive, Rank rankSender) override
 Receives a std::string from process with given rank.
 
virtual void receive (precice::span< int > itemsToReceive, Rank rankSender) override
 Receives an array of integer values.
 
virtual void receive (precice::span< double > itemsToReceive, Rank rankSender) override
 Receives an array of double values.
 
virtual PtrRequest aReceive (precice::span< double > itemsToReceive, int rankSender) override
 Asynchronously receives an array of double values.
 
virtual void receive (double &itemToReceive, Rank rankSender) override
 Receives a double from process with given rank.
 
virtual PtrRequest aReceive (double &itemToReceive, Rank rankSender) override
 Asynchronously receives a double from process with given rank.
 
virtual void receive (int &itemToReceive, Rank rankSender) override
 Receives an int from process with given rank.
 
virtual PtrRequest aReceive (int &itemToReceive, Rank rankSender) override
 Asynchronously receives an int from process with given rank.
 
virtual void receive (bool &itemToReceive, Rank rankSender) override
 Receives a bool from process with given rank.
 
virtual PtrRequest aReceive (bool &itemToReceive, Rank rankSender) override
 Asynchronously receives a bool from process with given rank.
 
- Public Member Functions inherited from precice::com::Communication
Communicationoperator= (Communication &&)=delete
 
virtual ~Communication ()
 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 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.
 
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>
 

Protected Member Functions

virtual int adjustRank (Rank rank) const override
 Turn the rank adjustment into a noop for direct communication.
 

Private Member Functions

virtual MPI_Commcommunicator (Rank rank=0) override
 Returns the communicator.
 
virtual Rank rank (int rank) override
 

Private Attributes

logging::Logger _log {"com::MPIDirectCommunication"}
 
utils::Parallel::CommStatePtr _commState = nullptr
 CommState to use.
 

Additional Inherited Members

- 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
 

Detailed Description

Provides connection methods for processes located in one communicator.

This communication class can be used when the communicating participants are either compiled into one executable or, are started by one mpi execution call on the command line.

It is imporant, that all processes in the used communicator have to participate in the communication. If one of the processes does not call either acceptConnection(), or closeConnection(), a deadlock is achieved.

Definition at line 29 of file MPIDirectCommunication.hpp.

Constructor & Destructor Documentation

◆ MPIDirectCommunication()

precice::com::MPIDirectCommunication::MPIDirectCommunication ( )

Creates a MPI Direct communication based on the current global communicator.

Definition at line 14 of file MPIDirectCommunication.cpp.

◆ ~MPIDirectCommunication()

precice::com::MPIDirectCommunication::~MPIDirectCommunication ( )
virtual

Definition at line 19 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ acceptConnection()

void precice::com::MPIDirectCommunication::acceptConnection ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int acceptorRank,
int rankOffset = 0 )
overridevirtual

See precice::com::Communication::acceptConnection().

Attention
Calls precice::utils::Parallel::splitCommunicator() if local and global communicators are equal.

Implements precice::com::Communication.

Definition at line 34 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ acceptConnectionAsServer()

virtual void precice::com::MPIDirectCommunication::acceptConnectionAsServer ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int acceptorRank,
int requesterCommunicatorSize )
inlineoverridevirtual

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.

Parameters
[in]acceptorNameName of calling participant.
[in]requesterNameName of remote participant to connect to.
[in]tagTag for establishing this connection
[in]acceptorRankRank of accepting server, usually the rank of the current process.
[in]requesterCommunicatorSizeSize of the requester (N)

Implements precice::com::Communication.

Definition at line 54 of file MPIDirectCommunication.hpp.

◆ adjustRank()

int precice::com::MPIDirectCommunication::adjustRank ( Rank rank) const
overrideprotectedvirtual

Turn the rank adjustment into a noop for direct communication.

Reimplemented from precice::com::Communication.

Definition at line 220 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ allreduceSum() [1/6]

void precice::com::MPIDirectCommunication::allreduceSum ( double itemToSend,
double & itemsToReceive )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 122 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ allreduceSum() [2/6]

void precice::com::MPIDirectCommunication::allreduceSum ( double itemToSend,
double & itemsToReceive,
Rank primaryRank )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 128 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ allreduceSum() [3/6]

void precice::com::MPIDirectCommunication::allreduceSum ( int itemToSend,
int & itemsToReceive )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 134 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ allreduceSum() [4/6]

void precice::com::MPIDirectCommunication::allreduceSum ( int itemToSend,
int & itemsToReceive,
Rank primaryRank )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 140 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ allreduceSum() [5/6]

void precice::com::MPIDirectCommunication::allreduceSum ( precice::span< double const > itemsToSend,
precice::span< double > itemsToReceive )
overridevirtual
Attention
This method modifies the input buffer.

Reimplemented from precice::com::Communication.

Definition at line 108 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ allreduceSum() [6/6]

void precice::com::MPIDirectCommunication::allreduceSum ( precice::span< double const > itemsToSend,
precice::span< double > itemsToReceive,
Rank primaryRank )
overridevirtual
Attention
This method modifies the input buffer.

Reimplemented from precice::com::Communication.

Definition at line 115 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [1/10]

void precice::com::MPIDirectCommunication::broadcast ( bool & itemToReceive,
Rank rankBroadcaster )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 201 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [2/10]

void precice::com::MPIDirectCommunication::broadcast ( bool itemToSend)
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 194 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [3/10]

void precice::com::MPIDirectCommunication::broadcast ( double & itemToReceive,
Rank rankBroadcaster )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 188 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [4/10]

void precice::com::MPIDirectCommunication::broadcast ( double itemToSend)
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 182 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [5/10]

void precice::com::MPIDirectCommunication::broadcast ( int & itemToReceive,
Rank rankBroadcaster )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 164 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [6/10]

void precice::com::MPIDirectCommunication::broadcast ( int itemToSend)
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 158 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [7/10]

void precice::com::MPIDirectCommunication::broadcast ( precice::span< const double > itemsToSend)
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 170 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [8/10]

void precice::com::MPIDirectCommunication::broadcast ( precice::span< const int > itemsToSend)
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 146 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [9/10]

void precice::com::MPIDirectCommunication::broadcast ( precice::span< double > itemsToReceive,
Rank rankBroadcaster )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 176 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ broadcast() [10/10]

void precice::com::MPIDirectCommunication::broadcast ( precice::span< int > itemsToReceive,
Rank rankBroadcaster )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 152 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ closeConnection()

void precice::com::MPIDirectCommunication::closeConnection ( )
overridevirtual

See precice::com::Communication::closeConnection().

Implements precice::com::Communication.

Definition at line 53 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ communicator()

MPI_Comm & precice::com::MPIDirectCommunication::communicator ( Rank rank = 0)
overrideprivatevirtual

Returns the communicator.

Implements precice::com::MPICommunication.

Definition at line 209 of file MPIDirectCommunication.cpp.

◆ getRemoteCommunicatorSize()

size_t precice::com::MPIDirectCommunication::getRemoteCommunicatorSize ( )
overridevirtual

Returns the number of processes in the remote communicator.

Precondition
A connection to the remote participant has been setup.

Implements precice::com::Communication.

Definition at line 25 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ rank()

int precice::com::MPIDirectCommunication::rank ( int rank)
overrideprivatevirtual

Implements precice::com::MPICommunication.

Definition at line 214 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ reduceSum() [1/4]

void precice::com::MPIDirectCommunication::reduceSum ( int itemToSend,
int & itemsToReceive )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 95 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ reduceSum() [2/4]

void precice::com::MPIDirectCommunication::reduceSum ( int itemToSend,
int & itemsToReceive,
Rank primaryRank )
overridevirtual

Reimplemented from precice::com::Communication.

Definition at line 102 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ reduceSum() [3/4]

void precice::com::MPIDirectCommunication::reduceSum ( precice::span< double const > itemsToSend,
precice::span< double > itemsToReceive )
overridevirtual

Performs a reduce summation on the primary rank, every other rank has to call reduceSum.

Attention
This method modifies the input buffer.

Reimplemented from precice::com::Communication.

Definition at line 80 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ reduceSum() [4/4]

void precice::com::MPIDirectCommunication::reduceSum ( precice::span< double const > itemsToSend,
precice::span< double > itemsToReceive,
Rank primaryRank )
overridevirtual

Performs a reduce summation on the rank given by primaryRank.

Reimplemented from precice::com::Communication.

Definition at line 88 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ requestConnection()

void precice::com::MPIDirectCommunication::requestConnection ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int requesterRank,
int requesterCommunicatorSize )
overridevirtual

See precice::com::Communication::requestConnection().

Attention
Calls precice::utils::Parallel::splitCommunicator() if local and global communicators are equal.

Implements precice::com::Communication.

Definition at line 63 of file MPIDirectCommunication.cpp.

Here is the call graph for this function:

◆ requestConnectionAsClient()

virtual void precice::com::MPIDirectCommunication::requestConnectionAsClient ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
std::set< int > const & acceptorRanks,
int requesterRank )
inlineoverridevirtual

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.

Parameters
[in]acceptorNameName of calling participant.
[in]requesterNameName of remote participant to connect to
[in]tagTag for establishing this connection
[in]acceptorRanksSet of ranks that accept a connection
[in]requesterRankRank that requests the connection, usually the caller's rank

Implements precice::com::Communication.

Definition at line 73 of file MPIDirectCommunication.hpp.

Member Data Documentation

◆ _commState

utils::Parallel::CommStatePtr precice::com::MPIDirectCommunication::_commState = nullptr
private

CommState to use.

Definition at line 133 of file MPIDirectCommunication.hpp.

◆ _log

logging::Logger precice::com::MPIDirectCommunication::_log {"com::MPIDirectCommunication"}
private

Definition at line 130 of file MPIDirectCommunication.hpp.


The documentation for this class was generated from the following files: