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

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

50  : m_comm(comm), m_maxQuad(maxQuad), m_nRanks(nRanks)
51 {
52  for (size_t i = 0; i < nRanks; ++i)
53  {
54  if (rankSharedEdges.find(i) != rankSharedEdges.end())
55  {
56  m_maxCount = (rankSharedEdges.at(i).size() > m_maxCount)
57  ? static_cast<int>(rankSharedEdges.at(i).size())
58  : m_maxCount;
59  }
60  }
61 
62  comm->AllReduce(m_maxCount, LibUtilities::ReduceMax);
63 
64  // Creates the edge index vector where value -1 indicates
65  // padding of value 0 to be inserted instead of value from Fwd
66  for (size_t i = 0; i < nRanks; ++i)
67  {
68  if (rankSharedEdges.find(i) != rankSharedEdges.end())
69  {
70  for (size_t j = 0; j < rankSharedEdges.at(i).size(); ++j)
71  {
72  std::vector<int> edgeIndex =
73  edgeToTrace.at(rankSharedEdges.at(i)[j]);
74  if (edgeIndex.size() < maxQuad)
75  {
76  std::vector<int> diff(maxQuad - edgeIndex.size(), -1);
77  edgeIndex.insert(edgeIndex.end(), diff.begin(), diff.end());
78  }
79 
80  m_allEdgeIndex.insert(m_allEdgeIndex.end(), edgeIndex.begin(),
81  edgeIndex.end());
82  }
83 
84  if (rankSharedEdges.at(i).size() < m_maxCount)
85  {
86  std::vector<int> edgeIndex(
87  maxQuad * (m_maxCount - rankSharedEdges.at(i).size()), -1);
88  m_allEdgeIndex.insert(m_allEdgeIndex.end(), edgeIndex.begin(),
89  edgeIndex.end());
90  }
91  }
92  else
93  {
94  std::vector<int> edgeIndex(maxQuad * m_maxCount, -1);
95  m_allEdgeIndex.insert(m_allEdgeIndex.end(), edgeIndex.begin(),
96  edgeIndex.end());
97  }
98  }
99 }
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 232 of file AssemblyCommDG.cpp.

234 {
235  int size = m_maxQuad * m_maxCount * m_nRanks;
236  Array<OneD, NekDouble> sendBuff(size, -1);
237  Array<OneD, NekDouble> recvBuff(size, -1);
238 
239  for (size_t j = 0; j < size; ++j)
240  {
241  if (m_allEdgeIndex[j] == -1)
242  {
243  sendBuff[j] = 0;
244  }
245  else
246  {
247  sendBuff[j] = testFwd[m_allEdgeIndex[j]];
248  }
249  }
250 
251  m_comm->AlltoAll(sendBuff, recvBuff);
252 
253  for (size_t j = 0; j < size; ++j)
254  {
255  if (m_allEdgeIndex[j] != -1)
256  {
257  testBwd[m_allEdgeIndex[j]] = recvBuff[j];
258  }
259  }
260 }

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 124 of file AssemblyCommDG.h.

Referenced by AllToAll(), and PerformExchange().

◆ m_comm

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

Communicator.

Definition at line 118 of file AssemblyCommDG.h.

Referenced by PerformExchange().

◆ m_maxCount

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

Largest shared partition edge.

Definition at line 126 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 120 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 122 of file AssemblyCommDG.h.

Referenced by PerformExchange().