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...
 

Private Attributes

LibUtilities::CommSharedPtr m_comm
 Communicator. More...
 
std::vector< std::pair< int, std::vector< int > > > m_vecPairPartitionTrace
 List of partition to trace map indices of the quad points to exchange. More...
 
Array< OneD, int > m_sendDisp
 List of displacements. 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  for (const auto &rankEdgeSet : rankSharedEdges)
187  {
188  std::vector<int> edgeTraceIndex;
189  for (size_t i : rankEdgeSet.second)
190  {
191  std::vector<int> edgeIndex = edgeToTrace.at(i);
192  edgeTraceIndex.insert(edgeTraceIndex.end(), edgeIndex.begin(),
193  edgeIndex.end());
194  }
195 
196  m_vecPairPartitionTrace.emplace_back(
197  std::make_pair(rankEdgeSet.first, edgeTraceIndex));
198 
199  sendCount[cnt++] = edgeTraceIndex.size();
200  }
201 
202  m_sendDisp = Array<OneD, int>(nNeighbours, 0);
203 
204  for (size_t i = 1; i < nNeighbours; ++i)
205  {
206  m_sendDisp[i] = m_sendDisp[i - 1] + sendCount[i - 1];
207  }
208 
209  size_t totSends = std::accumulate(sendCount.begin(), sendCount.end(), 0);
210 
211  m_recvBuff = Array<OneD, NekDouble>(totSends, -1);
212  m_sendBuff = Array<OneD, NekDouble>(totSends, -1);
213 
214  m_recvRequest = m_comm->CreateRequest(m_vecPairPartitionTrace.size());
215  m_sendRequest = m_comm->CreateRequest(m_vecPairPartitionTrace.size());
216 
217  // Construct persistent requests
218  for (size_t i = 0; i < m_vecPairPartitionTrace.size(); ++i)
219  {
220  size_t len = m_vecPairPartitionTrace[i].second.size();
221 
222  // Initialise receive requests
223  m_comm->RecvInit(m_vecPairPartitionTrace[i].first,
224  m_recvBuff[m_sendDisp[i]], len, m_recvRequest, i);
225 
226  // Initialise send requests
227  m_comm->SendInit(m_vecPairPartitionTrace[i].first,
228  m_sendBuff[m_sendDisp[i]], len, m_sendRequest, i);
229  }
230 }
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_sendDisp
List of displacements.
std::vector< std::pair< int, std::vector< int > > > m_vecPairPartitionTrace
List of partition to trace map indices of the quad points to exchange.
LibUtilities::CommSharedPtr m_comm
Communicator.

References m_comm, m_recvBuff, m_recvRequest, m_sendBuff, m_sendDisp, m_sendRequest, and m_vecPairPartitionTrace.

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 301 of file AssemblyCommDG.cpp.

303 {
304  // Perform receive posts
305  m_comm->StartAll(m_recvRequest);
306 
307  // Fill send buffer from Fwd trace
308  for (size_t i = 0; i < m_vecPairPartitionTrace.size(); ++i)
309  {
310  size_t len = m_vecPairPartitionTrace[i].second.size();
311  for (size_t j = 0; j < len; ++j)
312  {
313  m_sendBuff[m_sendDisp[i] + j] =
314  testFwd[m_vecPairPartitionTrace[i].second[j]];
315  }
316  }
317 
318  // Perform send posts
319  m_comm->StartAll(m_sendRequest);
320 
321  // Wait for all send/recvs to complete
322  m_comm->WaitAll(m_sendRequest);
323  m_comm->WaitAll(m_recvRequest);
324 
325  // Fill Bwd trace from recv buffer
326  for (size_t i = 0; i < m_vecPairPartitionTrace.size(); ++i)
327  {
328  size_t len = m_vecPairPartitionTrace[i].second.size();
329  for (size_t j = 0; j < len; ++j)
330  {
331  testBwd[m_vecPairPartitionTrace[i].second[j]] =
332  m_recvBuff[m_sendDisp[i] + j];
333  }
334  }
335 }

References m_comm, m_recvBuff, m_recvRequest, m_sendBuff, m_sendDisp, m_sendRequest, and m_vecPairPartitionTrace.

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_recvBuff

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

Receive buffer for exchange.

Definition at line 222 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 226 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 224 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_sendDisp

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

List of displacements.

Definition at line 220 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 228 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().

◆ m_vecPairPartitionTrace

std::vector<std::pair<int, std::vector<int> > > Nektar::MultiRegions::Pairwise::m_vecPairPartitionTrace
private

List of partition to trace map indices of the quad points to exchange.

Definition at line 218 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().