Loading...
Searching...
No Matches
communications.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#if BITPIT_ENABLE_MPI==1
26
27#ifndef __BITPIT_COMMUNICATIONS_HPP__
28#define __BITPIT_COMMUNICATIONS_HPP__
29
30#include <mpi.h>
31#include <vector>
32#include <unordered_map>
33
34#include "bitpit_common.hpp"
35#include "bitpit_containers.hpp"
36
37#include "communications_buffers.hpp"
38
39namespace bitpit {
40
42{
43
44public:
45 BITPIT_PUBLIC_API static const int TAG_AUTO = -1;
46
47 DataCommunicator(MPI_Comm communicator);
49
50 const MPI_Comm & getCommunicator() const;
51
52 int getRank() const;
53 int getProcessorCount() const;
54
55 void finalize(bool synchronous = false);
56
57 void setTag(int exchangeTag);
58 void setTags(int exchangeTag, int discoverTag, int notificationTag);
59 void setExchangeTag(int tag);
60 void setDiscoverTag(int tag);
61 void setNotificationTag(int tag);
62 int getTag() const;
63 int getExchangeTag() const;
64 int getDiscoverTag() const;
65 int getNotificationTag() const;
66
67 void clearAllSends(bool synchronous = false);
68 void clearAllRecvs(bool synchronous = false);
69
70 void clearSend(int rank);
71 void clearRecv(int rank);
72
73 void setSend(int rank, long length = 0);
74 void setRecv(int rank, long length = 0);
75
76 void resizeSend(int rank, long resize);
77 void resizeRecv(int rank, long resize);
78
79 void setRecvsContinuous(bool enabled);
80 bool areRecvsContinuous();
81
82 void discoverSends();
83 void discoverRecvs();
84
85 int getSendCount();
86 int getRecvCount();
87
88 const std::vector<int> & getSendRanks() const;
89 const std::vector<int> & getRecvRanks() const;
90
91 SendBuffer & getSendBuffer(int rank);
92 RecvBuffer & getRecvBuffer(int rank);
93
94 void startSend(int dstRank);
95 void startAllSends();
96
97 void startRecv(int srcRank);
98 void startAllRecvs();
99
100 int waitAnySend(const std::vector<int> &blackList = std::vector<int>());
101 void waitSend(int rank);
102 void waitAllSends();
103
104 int waitAnyRecv(const std::vector<int> &blackList = std::vector<int>());
105 void waitRecv(int rank);
106 void waitAllRecvs();
107
108 bool isSendActive(int rank);
109 bool isRecvActive(int rank);
110
111 void cancelSend(int rank);
112 void cancelRecv(int rank);
113
114 void cancelAllSends(bool synchronous = false);
115 void cancelAllRecvs(bool synchronous = false);
116
117private:
118 MPI_Comm m_communicator;
119 int m_rank;
120 int m_exchangeTag;
121 int m_discoverTag;
122 int m_notificationTag;
123 bool m_customExchangeTag;
124 bool m_customDiscoverTag;
125 bool m_customNotificationTag;
126 bool m_recvsContinuous;
127
128 std::vector<int> m_recvRanks;
129 std::unordered_map<int, int> m_recvIds;
130 std::vector<MPI_Request> m_recvRequests;
131 std::vector<RecvBuffer> m_recvBuffers;
132
133 std::vector<int> m_sendRanks;
134 std::unordered_map<int, int> m_sendIds;
135 std::vector<MPI_Request> m_sendRequests;
136 std::vector<SendBuffer> m_sendBuffers;
137
138 void _startSend(int dstRank);
139 void _startRecv(int srcRank);
140
141 MPI_Datatype getChunkDataType(int chunkSize) const;
142
143};
144
145}
146
147# endif
148
149# endif
The DataCommunicator class provides the infrastructure needed to exchange data among processes.
int waitAnySend(const std::vector< int > &blackList=std::vector< int >())
void clearAllSends(bool synchronous=false)
void finalize(bool synchronous=false)
void setRecv(int rank, long length=0)
const MPI_Comm & getCommunicator() const
void startRecv(int srcRank)
SendBuffer & getSendBuffer(int rank)
const std::vector< int > & getRecvRanks() const
void resizeSend(int rank, long resize)
void setTags(int exchangeTag, int discoverTag, int notificationTag)
const std::vector< int > & getSendRanks() const
int waitAnyRecv(const std::vector< int > &blackList=std::vector< int >())
DataCommunicator(MPI_Comm communicator)
void resizeRecv(int rank, long resize)
void setSend(int rank, long length=0)
void cancelAllRecvs(bool synchronous=false)
void cancelAllSends(bool synchronous=false)
void setTag(int exchangeTag)
void clearAllRecvs(bool synchronous=false)
void setRecvsContinuous(bool enabled)
RecvBuffer & getRecvBuffer(int rank)
void startSend(int dstRank)
Buffer to be used for receive communications.
Buffer to be used for send communications.
--- layout: doxygen_footer ---