Nektar++
Public Member Functions | Private Attributes | List of all members
Nektar::MultiRegions::Pairwise Class Referencefinal

#include <AssemblyCommDG.h>

Inheritance diagram for Nektar::MultiRegions::Pairwise:
[legend]

Public Member Functions

 Pairwise (const LibUtilities::CommSharedPtr &comm, const std::map< int, std::vector< int > > &rankSharedEdges, const std::map< int, std::vector< int > > &edgeToTrace)
 
void PerformExchange (const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd) final
 
- Public Member Functions inherited from Nektar::MultiRegions::ExchangeMethod
 ExchangeMethod ()=default
 Default constructor. More...
 
virtual ~ExchangeMethod ()=default
 Default destructor. More...
 
virtual void PerformExchange (const Array< OneD, NekDouble > &testFwd, Array< OneD, NekDouble > &testBwd)=0
 

Private Attributes

LibUtilities::CommSharedPtr m_comm
 Communicator. More...
 
Array< OneD, int > m_edgeTraceIndex
 List of trace index locations in recv/send buff. More...
 
Array< OneD, NekDoublem_recvBuff
 Receive buffer for exchange. More...
 
Array< OneD, NekDoublem_sendBuff
 Send buffer for exchange. More...
 
LibUtilities::CommRequestSharedPtr m_recvRequest
 List of receive requests. More...
 
LibUtilities::CommRequestSharedPtr m_sendRequest
 List of send requests. More...
 

Detailed Description

Uses persistent MPI_Irecv and MPI_Isend operations to perform the exchange of quadrature values. This allows for varying exchange array sizes to minimise communication data size. Ranks only communicate with ranks with which they need to exchange data, i.e. are adjacent in the mesh or share a periodic boundary condition. On each rank there are 'n' receives and 'n' sends posted where 'n' is the number of other ranks with which communication is needed. We use persistent communication methods to reduce overhead.

Definition at line 202 of file AssemblyCommDG.h.

Constructor & Destructor Documentation

◆ Pairwise()

Nektar::MultiRegions::Pairwise::Pairwise ( const LibUtilities::CommSharedPtr comm,
const std::map< int, std::vector< int > > &  rankSharedEdges,
const std::map< int, std::vector< int > > &  edgeToTrace 
)

Definition at line 177 of file AssemblyCommDG.cpp.

180 : m_comm(comm)
181{
182 int cnt = 0;
183 int nNeighbours = rankSharedEdges.size();
184 Array<OneD, int> sendCount(nNeighbours, -1);
185
186 // List of partition to trace map indices of the quad points to exchange
187 std::vector<std::pair<int, std::vector<int>>> vecPairPartitionTrace;
188 for (const auto &rankEdgeSet : rankSharedEdges)
189 {
190 std::vector<int> edgeTraceIndex;
191 for (size_t i : rankEdgeSet.second)
192 {
193 std::vector<int> edgeIndex = edgeToTrace.at(i);
194 edgeTraceIndex.insert(edgeTraceIndex.end(), edgeIndex.begin(),
195 edgeIndex.end());
196 }
197
198 vecPairPartitionTrace.emplace_back(
199 std::make_pair(rankEdgeSet.first, edgeTraceIndex));
200
201 sendCount[cnt++] = edgeTraceIndex.size();
202 }
203
204 Array<OneD, int> sendDisp(nNeighbours, 0);
205 for (size_t i = 1; i < nNeighbours; ++i)
206 {
207 sendDisp[i] = sendDisp[i - 1] + sendCount[i - 1];
208 }
209
210 size_t totSends = std::accumulate(sendCount.begin(), sendCount.end(), 0);
211
212 m_recvBuff = Array<OneD, NekDouble>(totSends, -1);
213 m_sendBuff = Array<OneD, NekDouble>(totSends, -1);
214 m_edgeTraceIndex = Array<OneD, int>(totSends, -1);
215
216 // Set up m_edgeTraceIndex to reduce complexity when performing exchange
217 cnt = 0;
218 for (auto &i : vecPairPartitionTrace)
219 {
220 for (auto j : i.second)
221 {
222 m_edgeTraceIndex[cnt++] = j;
223 }
224 }
225
226 m_recvRequest = m_comm->CreateRequest(vecPairPartitionTrace.size());
227 m_sendRequest = m_comm->CreateRequest(vecPairPartitionTrace.size());
228
229 // Construct persistent requests
230 for (size_t i = 0; i < vecPairPartitionTrace.size(); ++i)
231 {
232 size_t len = vecPairPartitionTrace[i].second.size();
233
234 // Initialise receive requests
235 m_comm->RecvInit(vecPairPartitionTrace[i].first,
236 m_recvBuff[sendDisp[i]], len, m_recvRequest, i);
237
238 // Initialise send requests
239 m_comm->SendInit(vecPairPartitionTrace[i].first,
240 m_sendBuff[sendDisp[i]], len, m_sendRequest, i);
241 }
242}
LibUtilities::CommRequestSharedPtr m_sendRequest
List of send requests.
Array< OneD, NekDouble > m_sendBuff
Send buffer for exchange.
Array< OneD, NekDouble > m_recvBuff
Receive buffer for exchange.
LibUtilities::CommRequestSharedPtr m_recvRequest
List of receive requests.
Array< OneD, int > m_edgeTraceIndex
List of trace index locations in recv/send buff.
LibUtilities::CommSharedPtr m_comm
Communicator.

References m_comm, m_edgeTraceIndex, m_recvBuff, m_recvRequest, m_sendBuff, and m_sendRequest.

Member Function Documentation

◆ PerformExchange()

void Nektar::MultiRegions::Pairwise::PerformExchange ( const Array< OneD, NekDouble > &  testFwd,
Array< OneD, NekDouble > &  testBwd 
)
finalvirtual

Perform MPI comm exchange taking the Fwd trace and sending partition edge trace values to the matching locations in the Bwd trace of corresponding adjacent partitions.

Parameters
[in]testFwdThe values to send to adjacent partitions
[out]testBwdThe values received from adjacent partitions

Implements Nektar::MultiRegions::ExchangeMethod.

Definition at line 313 of file AssemblyCommDG.cpp.

315{
316 // Perform receive posts
317 m_comm->StartAll(m_recvRequest);
318
319 // Fill send buffer from Fwd trace
320 for (size_t i = 0; i < m_edgeTraceIndex.size(); ++i)
321 {
322 m_sendBuff[i] = testFwd[m_edgeTraceIndex[i]];
323 }
324
325 // Perform send posts
326 m_comm->StartAll(m_sendRequest);
327
328 // Wait for all send/recvs to complete
329 m_comm->WaitAll(m_sendRequest);
330 m_comm->WaitAll(m_recvRequest);
331
332 // Fill Bwd trace from recv buffer
333 for (size_t i = 0; i < m_edgeTraceIndex.size(); ++i)
334 {
335 testBwd[m_edgeTraceIndex[i]] = m_recvBuff[i];
336 }
337}

References m_comm, m_edgeTraceIndex, m_recvBuff, m_recvRequest, m_sendBuff, and m_sendRequest.

Member Data Documentation

◆ m_comm

LibUtilities::CommSharedPtr Nektar::MultiRegions::Pairwise::m_comm
private

Communicator.

Definition at line 216 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_edgeTraceIndex

Array<OneD, int> Nektar::MultiRegions::Pairwise::m_edgeTraceIndex
private

List of trace index locations in recv/send buff.

Definition at line 218 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_recvBuff

Array<OneD, NekDouble> Nektar::MultiRegions::Pairwise::m_recvBuff
private

Receive buffer for exchange.

Definition at line 220 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_recvRequest

LibUtilities::CommRequestSharedPtr Nektar::MultiRegions::Pairwise::m_recvRequest
private

List of receive requests.

Definition at line 224 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_sendBuff

Array<OneD, NekDouble> Nektar::MultiRegions::Pairwise::m_sendBuff
private

Send buffer for exchange.

Definition at line 222 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_sendRequest

LibUtilities::CommRequestSharedPtr Nektar::MultiRegions::Pairwise::m_sendRequest
private

List of send requests.

Definition at line 226 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().