preCICE v3.1.2
Loading...
Searching...
No Matches
MPIPortsCommunication.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 {
23public:
24 explicit MPIPortsCommunication(std::string addressDirectory = ".");
25
26 virtual ~MPIPortsCommunication();
27
28 virtual size_t getRemoteCommunicatorSize() override;
29
30 virtual void acceptConnection(std::string const &acceptorName,
31 std::string const &requesterName,
32 std::string const &tag,
33 int acceptorRank,
34 int rankOffset = 0) override;
35
36 virtual void acceptConnectionAsServer(std::string const &acceptorName,
37 std::string const &requesterName,
38 std::string const &tag,
39 int acceptorRank,
40 int requesterCommunicatorSize) override;
41
42 virtual void requestConnection(std::string const &acceptorName,
43 std::string const &requesterName,
44 std::string const &tag,
45 int requesterRank,
46 int requesterCommunicatorSize) override;
47
48 virtual void requestConnectionAsClient(std::string const & acceptorName,
49 std::string const & requesterName,
50 std::string const & tag,
51 std::set<int> const &acceptorRanks,
52 int requesterRank) override;
53
54 virtual void closeConnection() override;
55
56 virtual void prepareEstablishment(std::string const &acceptorName,
57 std::string const &requesterName) override;
58
59 virtual void cleanupEstablishment(std::string const &acceptorName,
60 std::string const &requesterName) override;
61
62private:
63 virtual MPI_Comm &communicator(Rank rank) override;
64
65 virtual Rank rank(int rank) override;
66
67 logging::Logger _log{"com::MPIPortsCommunication"};
68
70
73
75 std::string _portName = std::string(MPI_MAX_PORT_NAME, '\0');
76
77 bool _isAcceptor = false;
78};
79} // namespace com
80} // namespace precice
81
82#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 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.
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().
This class provides a lightweight logger.
Definition Logger.hpp:16
Main namespace of the precice library.
int Rank
Definition Types.hpp:37