19 : _addressDirectory(
std::move(addressDirectory))
55 res = MPI_Open_port(MPI_INFO_NULL, sm.
data());
73 int requesterRank = -1;
74 MPI_Recv(&requesterRank, 1, MPI_INT, 0, 42,
communicator, MPI_STATUS_IGNORE);
76 int requesterCommunicatorSize = -1;
77 MPI_Recv(&requesterCommunicatorSize, 1, MPI_INT, 0, 42,
communicator, MPI_STATUS_IGNORE);
79 MPI_Send(&acceptorRank, 1, MPI_INT, 0, 42,
communicator);
82 if (peerCurrent == 0) {
83 peerCount = requesterCommunicatorSize;
87 "Requester communicator size is {} which is invalid.", requesterCommunicatorSize);
89 "Current requester size from rank {} is {} but should be {}", requesterRank, requesterCommunicatorSize, peerCount);
91 "Rank {} has already been connected. Duplicate requests are not allowed.", requesterRank);
95 }
while (++peerCurrent < peerCount);
109 int requesterCommunicatorSize)
111 PRECICE_TRACE(acceptorName, requesterName, acceptorRank, requesterCommunicatorSize);
112 PRECICE_ASSERT(requesterCommunicatorSize >= 0,
"Requester communicator size has to be positive.");
119 res = MPI_Open_port(MPI_INFO_NULL, sm.
data());
127 for (
int connection = 0; connection < requesterCommunicatorSize; ++connection) {
134 int requesterRank = -1;
135 MPI_Recv(&requesterRank, 1, MPI_INT, 0, 42,
communicator, MPI_STATUS_IGNORE);
155 int requesterCommunicatorSize)
174 MPI_Send(&requesterRank, 1, MPI_INT, 0, 42,
communicator);
176 MPI_Send(&requesterCommunicatorSize, 1, MPI_INT, 0, 42,
communicator);
178 int acceptorRank = -1;
179 MPI_Recv(&acceptorRank, 1, MPI_INT, 0, 42,
communicator, MPI_STATUS_IGNORE);
196 PRECICE_TRACE(acceptorName, requesterName, acceptorRanks, requesterRank);
201 for (
int acceptorRank : acceptorRanks) {
212 MPI_Send(&requesterRank, 1, MPI_INT, 0, 42,
communicator);
230 "MPI_Comm_disconnect failed with message: {}", res.
message());
246 create_directories(dir);
248 PRECICE_WARN(
"Creating directory for connection info failed with: {}", e.
what());
#define PRECICE_WARN_IF(condition,...)
#define PRECICE_WARN(...)
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_CHECK(check,...)
#define PRECICE_ASSERT(...)
void setRankOffset(Rank rankOffset)
Set rank offset.
virtual bool isConnected()
Returns true, if a connection to a remote participant has been setup.
Reads the connection info for the given participant/rank information.
std::string read() const
Reads the info from the connection info file. Will block, if the the file is not present.
Writes the connection info for the given participant/rank information.
void write(std::string_view info) const
Write the string info, e.g. IP:port to the connection info file.
virtual void closeConnection() override
Disconnects from communication space, i.e. participant.
virtual 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().
virtual void prepareEstablishment(std::string const &acceptorName, std::string const &requesterName) override
Prepare environment used to establish the communication.
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 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 cleanupEstablishment(std::string const &acceptorName, std::string const &requesterName) override
Clean-up environment used to establish the communication.
std::map< int, MPI_Comm > _communicators
Remote rank -> communicator map.
MPIPortsCommunication(std::string addressDirectory=".")
std::string _portName
Name of the port used for connection.
virtual MPI_Comm & communicator(Rank rank) override
Returns the communicator.
std::string _addressDirectory
virtual ~MPIPortsCommunication()
virtual Rank rank(int rank) override
virtual size_t getRemoteCommunicatorSize() override
Returns the number of processes in the remote communicator.
virtual 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().
Utility class to build a string from C functions with output pointers and static maximum length.
T generic_string(T... args)
std::string localDirectory(std::string_view acceptorName, std::string_view requesterName, std::string_view addressDirectory)
contains the data communication abstraction layer.
std::string message() const