preCICE v3.1.1
Loading...
Searching...
No Matches
MPISinglePortsCommunication.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef PRECICE_NO_MPI
3
4#include <map>
5#include <mpi.h>
6#include <set>
7#include <stddef.h>
8#include <string>
9
11#include "logging/Logger.hpp"
13
14namespace precice {
15namespace com {
37public:
38 explicit MPISinglePortsCommunication(std::string addressDirectory = ".");
39
41
42 virtual size_t getRemoteCommunicatorSize() override;
43
44 virtual void acceptConnection(std::string const &acceptorName,
45 std::string const &requesterName,
46 std::string const &tag,
47 int acceptorRank,
48 int rankOffset = 0) override;
49
50 virtual void acceptConnectionAsServer(std::string const &acceptorName,
51 std::string const &requesterName,
52 std::string const &tag,
53 int acceptorRank,
54 int requesterCommunicatorSize) override;
55
56 virtual void requestConnection(std::string const &acceptorName,
57 std::string const &requesterName,
58 std::string const &tag,
59 int requesterRank,
60 int requesterCommunicatorSize) override;
61
62 virtual void requestConnectionAsClient(std::string const & acceptorName,
63 std::string const & requesterName,
64 std::string const & tag,
65 std::set<int> const &acceptorRanks,
66 int requesterRank) override;
67
68 virtual void prepareEstablishment(std::string const &acceptorName,
69 std::string const &requesterName) override;
70
71 virtual void cleanupEstablishment(std::string const &acceptorName,
72 std::string const &requesterName) override;
73
74 virtual void closeConnection() override;
75
76private:
77 virtual MPI_Comm &communicator(Rank rank) override;
78
79 virtual Rank rank(int rank) override;
80
81 logging::Logger _log{"com::MPISinglePortsCommunication"};
82
84
95
104 MPI_Comm _global = MPI_COMM_NULL;
105
108
110 std::string _portName = std::string(MPI_MAX_PORT_NAME, '\0');
111
112 bool _isAcceptor = false;
113};
114} // namespace com
115} // namespace precice
116
117#endif // not PRECICE_NO_MPI
Provides implementation for basic MPI point-to-point communication.
Provides connection methods based on MPI ports (part of MPI 2.0).
virtual void prepareEstablishment(std::string const &acceptorName, std::string const &requesterName) override
Prepare environment used to establish the communication.
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().
MPI_Comm _global
The global inter-communicator that connects all ranks.
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 MPI_Comm & communicator(Rank rank) override
Returns the communicator.
std::string _portName
Name of the port used for connection.
virtual size_t getRemoteCommunicatorSize() override
Returns the number of processes in the remote communicator.
int _initialCommSize
The communicator size known from acceptConnection and requestConnection.
virtual void closeConnection() override
Disconnects from communication space, i.e. participant.
virtual 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
std::map< int, MPI_Comm > _direct
A map of direct communication channels based on MPI_COMM_SELF on both sides.
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 cleanupEstablishment(std::string const &acceptorName, std::string const &requesterName) override
Clean-up environment used to establish the communication.
MPISinglePortsCommunication(std::string addressDirectory=".")
This class provides a lightweight logger.
Definition Logger.hpp:16
Main namespace of the precice library.
int Rank
Definition Types.hpp:37