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

178 : m_comm(comm)
179{
180 int cnt = 0;
181 int nNeighbours = rankSharedEdges.size();
182 Array<OneD, int> sendCount(nNeighbours, -1);
183
184 // List of partition to trace map indices of the quad points to exchange
185 std::vector<std::pair<int, std::vector<int>>> vecPairPartitionTrace;
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 vecPairPartitionTrace.emplace_back(
197 std::make_pair(rankEdgeSet.first, edgeTraceIndex));
198
199 sendCount[cnt++] = edgeTraceIndex.size();
200 }
201
202 Array<OneD, int> sendDisp(nNeighbours, 0);
203 for (size_t i = 1; i < nNeighbours; ++i)
204 {
205 sendDisp[i] = sendDisp[i - 1] + sendCount[i - 1];
206 }
207
208 size_t totSends = std::accumulate(sendCount.begin(), sendCount.end(), 0);
209
210 m_recvBuff = Array<OneD, NekDouble>(totSends, -1);
211 m_sendBuff = Array<OneD, NekDouble>(totSends, -1);
212 m_edgeTraceIndex = Array<OneD, int>(totSends, -1);
213
214 // Set up m_edgeTraceIndex to reduce complexity when performing exchange
215 cnt = 0;
216 for (auto &i : vecPairPartitionTrace)
217 {
218 for (auto j : i.second)
219 {
220 m_edgeTraceIndex[cnt++] = j;
221 }
222 }
223
224 m_recvRequest = m_comm->CreateRequest(vecPairPartitionTrace.size());
225 m_sendRequest = m_comm->CreateRequest(vecPairPartitionTrace.size());
226
227 // Construct persistent requests
228 for (size_t i = 0; i < vecPairPartitionTrace.size(); ++i)
229 {
230 size_t len = vecPairPartitionTrace[i].second.size();
231
232 // Initialise receive requests
233 m_comm->RecvInit(vecPairPartitionTrace[i].first,
234 m_recvBuff[sendDisp[i]], len, m_recvRequest, i);
235
236 // Initialise send requests
237 m_comm->SendInit(vecPairPartitionTrace[i].first,
238 m_sendBuff[sendDisp[i]], len, m_sendRequest, i);
239 }
240}
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 303 of file AssemblyCommDG.cpp.

305{
306 // Perform receive posts
307 m_comm->StartAll(m_recvRequest);
308
309 // Fill send buffer from Fwd trace
310 Vmath::Gathr(int(m_edgeTraceIndex.size()), testFwd.data(),
311 m_edgeTraceIndex.data(), m_sendBuff.data());
312
313 // Perform send posts
314 m_comm->StartAll(m_sendRequest);
315
316 // Wait for all send/recvs to complete
317 m_comm->WaitAll(m_sendRequest);
318 m_comm->WaitAll(m_recvRequest);
319
320 // Fill Bwd trace from recv buffer
321 Vmath::Scatr(int(m_edgeTraceIndex.size()), m_recvBuff.data(),
322 m_edgeTraceIndex.data(), testBwd.data());
323}
void Gathr(I n, const T *x, const I *y, T *z)
Gather vector z[i] = x[y[i]].
Definition: Vmath.hpp:507
void Scatr(int n, const T *x, const int *y, T *z)
Scatter vector z[y[i]] = x[i].
Definition: Vmath.hpp:539

References Vmath::Gathr(), m_comm, m_edgeTraceIndex, m_recvBuff, m_recvRequest, m_sendBuff, m_sendRequest, and Vmath::Scatr().

Member Data Documentation

◆ m_comm

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

Communicator.

Definition at line 213 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 215 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 217 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 221 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 219 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 223 of file AssemblyCommDG.h.

Referenced by Pairwise(), and PerformExchange().