preCICE
Loading...
Searching...
No Matches
precice::com::MPISinglePortsCommunication Class Reference

Provides connection methods based on MPI ports (part of MPI 2.0). More...

#include <MPISinglePortsCommunication.hpp>

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

Public Member Functions

 MPISinglePortsCommunication (std::string addressDirectory=".")
 ~MPISinglePortsCommunication () override
size_t getRemoteCommunicatorSize () override
void acceptConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int rankOffset=0) override
void acceptConnectionAsServer (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int acceptorRank, int requesterCommunicatorSize) override
 requesterCommunicatorSize is not used, since connection is always made on the entire communicator
void requestConnection (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, int requesterRank, int requesterCommunicatorSize) override
void requestConnectionAsClient (std::string const &acceptorName, std::string const &requesterName, std::string const &tag, std::set< int > const &acceptorRanks, int requesterRank) override
void prepareEstablishment (std::string const &acceptorName, std::string const &requesterName) override
void cleanupEstablishment (std::string const &acceptorName, std::string const &requesterName) override
void closeConnection () override
Public Member Functions inherited from precice::com::MPICommunication
 MPICommunication ()
 ~MPICommunication () override=default
 Destructor, empty.
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.

Private Member Functions

MPI_Commcommunicator (Rank rank) override
 Returns the communicator.
Rank rank (int rank) override

Private Attributes

logging::Logger _log {"com::MPISinglePortsCommunication"}
std::string _addressDirectory
std::map< int, MPI_Comm_direct
 A map of direct communication channels based on MPI_COMM_SELF on both sides.
MPI_Comm _global = MPI_COMM_NULL
 The global inter-communicator that connects all ranks.
int _initialCommSize = -1
 The communicator size known from acceptConnection and requestConnection.
std::string _portName = std::string(MPI_MAX_PORT_NAME, '\0')
 Name of the port used for connection.
bool _isAcceptor = false

Detailed Description

Provides connection methods based on MPI ports (part of MPI 2.0).

The two participants to be connected can be run in two process groups started up individually, i.e. not within the same process group.

Notes on the implementation:

acceptConnection / requestConnection still uses one communicator per connection, created on MPI_COMM_SELF.

acceptConnectionAsServer / requestConnectionAsClient just uses communicator[0], so it actually creates just one comm.

The reason of that is that the first variant is called in various different ways, mostly just from the accepting/receiving rank. In order to just use a single communicator, accept/request must be called on the entire global communicator. This would require quite some rework of the calling code. The gains would also be minuscule, because accept/request is mainly used for 1:1 connection anyways.

The latter, in contrast, is only called from m2n::PointToPointCommunication, due to that the p2p class was also heavily modified. But this connection method is the most important, because it does the m2n heavy lifiting.

If we agree, that acceptConnection / requestConnection just does 1:1 connection, we can rewrite and simplify the code.

Definition at line 35 of file MPISinglePortsCommunication.hpp.

Constructor & Destructor Documentation

◆ MPISinglePortsCommunication()

precice::com::MPISinglePortsCommunication::MPISinglePortsCommunication ( std::string addressDirectory = ".")
explicit

Definition at line 22 of file MPISinglePortsCommunication.cpp.

◆ ~MPISinglePortsCommunication()

precice::com::MPISinglePortsCommunication::~MPISinglePortsCommunication ( )
override

Definition at line 30 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ acceptConnection()

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

Definition at line 49 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ acceptConnectionAsServer()

void precice::com::MPISinglePortsCommunication::acceptConnectionAsServer ( std::string const & acceptorName,
std::string const & requesterName,
std::string const & tag,
int acceptorRank,
int requesterCommunicatorSize )
override

requesterCommunicatorSize is not used, since connection is always made on the entire communicator

Definition at line 111 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ cleanupEstablishment()

void precice::com::MPISinglePortsCommunication::cleanupEstablishment ( std::string const & acceptorName,
std::string const & requesterName )
override

Definition at line 275 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ closeConnection()

void precice::com::MPISinglePortsCommunication::closeConnection ( )
override

Definition at line 208 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ communicator()

MPI_Comm & precice::com::MPISinglePortsCommunication::communicator ( Rank rank)
overrideprivatevirtual

Returns the communicator.

Implements precice::com::MPICommunication.

Definition at line 239 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ getRemoteCommunicatorSize()

size_t precice::com::MPISinglePortsCommunication::getRemoteCommunicatorSize ( )
override

Definition at line 36 of file MPISinglePortsCommunication.cpp.

◆ prepareEstablishment()

void precice::com::MPISinglePortsCommunication::prepareEstablishment ( std::string const & acceptorName,
std::string const & requesterName )
override

Definition at line 262 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ rank()

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

Implements precice::com::MPICommunication.

Definition at line 250 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ requestConnection()

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

Definition at line 151 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

◆ requestConnectionAsClient()

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

Definition at line 185 of file MPISinglePortsCommunication.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ _addressDirectory

std::string precice::com::MPISinglePortsCommunication::_addressDirectory
private

Definition at line 82 of file MPISinglePortsCommunication.hpp.

◆ _direct

std::map<int, MPI_Comm> precice::com::MPISinglePortsCommunication::_direct
private

A map of direct communication channels based on MPI_COMM_SELF on both sides.

These 1-1 connections are used until the has been a _global communicator established.

These direct connections connect MPI_COMM_SELF on both sides. The call to establish such a connection is thus not collective.

These connections are required for the primary and the intra-participant communications connections.

Definition at line 93 of file MPISinglePortsCommunication.hpp.

◆ _global

MPI_Comm precice::com::MPISinglePortsCommunication::_global = MPI_COMM_NULL
private

The global inter-communicator that connects all ranks.

Once established, this is the default communicator for all communication.

The call to establish this communicator is collective over both communicators. Thus the call to requestConnectionAsClient() and acceptConnectionAsServer() is the only time window where this global communicator can be established.

Definition at line 103 of file MPISinglePortsCommunication.hpp.

◆ _initialCommSize

int precice::com::MPISinglePortsCommunication::_initialCommSize = -1
private

The communicator size known from acceptConnection and requestConnection.

Definition at line 106 of file MPISinglePortsCommunication.hpp.

◆ _isAcceptor

bool precice::com::MPISinglePortsCommunication::_isAcceptor = false
private

Definition at line 111 of file MPISinglePortsCommunication.hpp.

◆ _log

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

Definition at line 80 of file MPISinglePortsCommunication.hpp.

◆ _portName

std::string precice::com::MPISinglePortsCommunication::_portName = std::string(MPI_MAX_PORT_NAME, '\0')
private

Name of the port used for connection.

Definition at line 109 of file MPISinglePortsCommunication.hpp.


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