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

#include <AssemblyCommDG.h>

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

Public Member Functions

 AllToAll (const LibUtilities::CommSharedPtr &comm, const int &maxQuad, const int &nRanks, const std::map< int, std::vector< int > > &rankSharedEdges, const std::map< int, std::vector< int > > &edgeToTrace)
 Default constructor. More...
 
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...
 
int m_maxQuad = 0
 Max number of quadrature points in an element. More...
 
int m_nRanks = 0
 Number of ranks/processes/partitions. More...
 
std::vector< int > m_allEdgeIndex
 List of trace map indices of the quad points to exchange. More...
 
int m_maxCount = 0
 Largest shared partition edge. More...
 

Detailed Description

Uses the MPI_AllToAll collective operation to perform the exchange of quadrature values. This does not allow for varying exchange array sizes so padding is used to ensure all partitions send/receive the same length array. All ranks communicate full array sizes to all other ranks. One collective operation is posted on each rank which requires communication.

Definition at line 99 of file AssemblyCommDG.h.

Constructor & Destructor Documentation

◆ AllToAll()

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

Default constructor.

Definition at line 44 of file AssemblyCommDG.cpp.

48 : m_comm(comm), m_maxQuad(maxQuad), m_nRanks(nRanks)
49{
50 for (size_t i = 0; i < nRanks; ++i)
51 {
52 if (rankSharedEdges.find(i) != rankSharedEdges.end())
53 {
54 m_maxCount = (rankSharedEdges.at(i).size() > m_maxCount)
55 ? static_cast<int>(rankSharedEdges.at(i).size())
56 : m_maxCount;
57 }
58 }
59
60 comm->AllReduce(m_maxCount, LibUtilities::ReduceMax);
61
62 // Creates the edge index vector where value -1 indicates
63 // padding of value 0 to be inserted instead of value from Fwd
64 for (size_t i = 0; i < nRanks; ++i)
65 {
66 if (rankSharedEdges.find(i) != rankSharedEdges.end())
67 {
68 for (size_t j = 0; j < rankSharedEdges.at(i).size(); ++j)
69 {
70 std::vector<int> edgeIndex =
71 edgeToTrace.at(rankSharedEdges.at(i)[j]);
72 if (edgeIndex.size() < maxQuad)
73 {
74 std::vector<int> diff(maxQuad - edgeIndex.size(), -1);
75 edgeIndex.insert(edgeIndex.end(), diff.begin(), diff.end());
76 }
77
78 m_allEdgeIndex.insert(m_allEdgeIndex.end(), edgeIndex.begin(),
79 edgeIndex.end());
80 }
81
82 if (rankSharedEdges.at(i).size() < m_maxCount)
83 {
84 std::vector<int> edgeIndex(
85 maxQuad * (m_maxCount - rankSharedEdges.at(i).size()), -1);
86 m_allEdgeIndex.insert(m_allEdgeIndex.end(), edgeIndex.begin(),
87 edgeIndex.end());
88 }
89 }
90 else
91 {
92 std::vector<int> edgeIndex(maxQuad * m_maxCount, -1);
93 m_allEdgeIndex.insert(m_allEdgeIndex.end(), edgeIndex.begin(),
94 edgeIndex.end());
95 }
96 }
97}
LibUtilities::CommSharedPtr m_comm
Communicator.
std::vector< int > m_allEdgeIndex
List of trace map indices of the quad points to exchange.
int m_nRanks
Number of ranks/processes/partitions.
int m_maxQuad
Max number of quadrature points in an element.
int m_maxCount
Largest shared partition edge.

References m_allEdgeIndex, m_maxCount, and Nektar::LibUtilities::ReduceMax.

Member Function Documentation

◆ PerformExchange()

void Nektar::MultiRegions::AllToAll::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 242 of file AssemblyCommDG.cpp.

244{
245 int size = m_maxQuad * m_maxCount * m_nRanks;
246 Array<OneD, NekDouble> sendBuff(size, -1);
247 Array<OneD, NekDouble> recvBuff(size, -1);
248
249 for (size_t j = 0; j < size; ++j)
250 {
251 if (m_allEdgeIndex[j] == -1)
252 {
253 sendBuff[j] = 0;
254 }
255 else
256 {
257 sendBuff[j] = testFwd[m_allEdgeIndex[j]];
258 }
259 }
260
261 m_comm->AlltoAll(sendBuff, recvBuff);
262
263 for (size_t j = 0; j < size; ++j)
264 {
265 if (m_allEdgeIndex[j] != -1)
266 {
267 testBwd[m_allEdgeIndex[j]] = recvBuff[j];
268 }
269 }
270}

References m_allEdgeIndex, m_comm, m_maxCount, m_maxQuad, and m_nRanks.

Member Data Documentation

◆ m_allEdgeIndex

std::vector<int> Nektar::MultiRegions::AllToAll::m_allEdgeIndex
private

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

Definition at line 121 of file AssemblyCommDG.h.

Referenced by AllToAll(), and PerformExchange().

◆ m_comm

LibUtilities::CommSharedPtr Nektar::MultiRegions::AllToAll::m_comm
private

Communicator.

Definition at line 115 of file AssemblyCommDG.h.

Referenced by PerformExchange().

◆ m_maxCount

int Nektar::MultiRegions::AllToAll::m_maxCount = 0
private

Largest shared partition edge.

Definition at line 123 of file AssemblyCommDG.h.

Referenced by AllToAll(), and PerformExchange().

◆ m_maxQuad

int Nektar::MultiRegions::AllToAll::m_maxQuad = 0
private

Max number of quadrature points in an element.

Definition at line 117 of file AssemblyCommDG.h.

Referenced by PerformExchange().

◆ m_nRanks

int Nektar::MultiRegions::AllToAll::m_nRanks = 0
private

Number of ranks/processes/partitions.

Definition at line 119 of file AssemblyCommDG.h.

Referenced by PerformExchange().