Nektar++
Public Member Functions | Private Attributes | List of all members
Nektar::MultiRegions::InterfaceMapDG Class Reference

#include <InterfaceMapDG.h>

Public Member Functions

 ~InterfaceMapDG ()=default
 Default destructor. More...
 
 InterfaceMapDG (const SpatialDomains::MeshGraphSharedPtr &graph, const ExpListSharedPtr &trace)
 
void ExchangeTrace (Array< OneD, NekDouble > &Fwd, Array< OneD, NekDouble > &Bwd)
 Perform the trace exchange between processors, given the forwards and backwards spaces. More...
 
void ExchangeCoords ()
 Perform the coordinate exchange between processors. This is where the missing coordinates on the interface are found and sent to all other processors on the other side of that interface so the matching ranks can be found. More...
 

Private Attributes

SpatialDomains::MeshGraphSharedPtr m_graph
 Mesh associated with this expansion list. More...
 
SpatialDomains::MovementSharedPtr m_movement
 Movement object associated with the non-conformal interfaces. More...
 
std::vector< InterfaceTraceSharedPtrm_localInterfaces
 Interface sides present on current process. More...
 
const ExpListSharedPtr m_trace
 Trace expansion list. More...
 
std::vector< InterfaceExchangeSharedPtrm_exchange
 Vector of interface exchanges, i.e. every rank-to-rank comm needed. More...
 

Detailed Description

Implements the communication patterns to allow for exchange of information across non-conformal interfaces and across different partitions. Holds all the InterfaceExchange objects in m_exchange.

Definition at line 226 of file InterfaceMapDG.h.

Constructor & Destructor Documentation

◆ ~InterfaceMapDG()

Nektar::MultiRegions::InterfaceMapDG::~InterfaceMapDG ( )
default

Default destructor.

◆ InterfaceMapDG()

Nektar::MultiRegions::InterfaceMapDG::InterfaceMapDG ( const SpatialDomains::MeshGraphSharedPtr graph,
const ExpListSharedPtr trace 
)

Sets up the InterfaceExchange objects stored in m_exchange, each object is rank -> rank and contains a vector of InterfaceTrace objects corresponding to shared interfaces between those ranks.

Definition at line 53 of file InterfaceMapDG.cpp.

56 : m_graph(meshGraph), m_movement(meshGraph->GetMovement()), m_trace(trace)
57{
58 auto comm = m_trace->GetComm()->GetSpaceComm();
59 auto interfaceCollection = m_movement->GetInterfaces();
60
61 // myIndxLR contains the info about what interface edges are present on
62 // current rank with each interface no, i, consisting of:
63 // [i] = indx
64 // [i + 1] = 0 (non), = 1 (left only), = 2 (right only), = 3 (both)
65 std::map<int, int> myIndxLRMap;
66
67 // localInterfaces contains a map of interface ID to a pair of interface
68 // traces, this pair is 'left' and 'right' interface and is used to
69 // construct and store the traces for interfaces present on the current rank
70 std::map<int, std::pair<InterfaceTraceSharedPtr, InterfaceTraceSharedPtr>>
71 localInterfaces;
72
73 // Map of m_localInterfaces vector to interface ID
74 Array<OneD, int> indxToInterfaceID(interfaceCollection.size());
75
76 // Loops over all interfaces and check if either side, 'left' or 'right'
77 // are empty on the current rank, if not empty then populate the local
78 // interface data structures and keep track using myIndxLRMap
79 size_t cnt = 0;
80 for (const auto &interface : interfaceCollection)
81 {
82 indxToInterfaceID[cnt] = interface.first.first;
83 myIndxLRMap[interface.first.first] = 0;
84
85 if (!interface.second->GetLeftInterface()->IsEmpty())
86 {
87 myIndxLRMap[interface.first.first] += 1;
88
89 localInterfaces[interface.first.first].first =
91 trace, interface.second->GetLeftInterface());
92 m_localInterfaces.emplace_back(
93 localInterfaces[interface.first.first].first);
94 }
95
96 if (!interface.second->GetRightInterface()->IsEmpty())
97 {
98 myIndxLRMap[interface.first.first] += 2;
99
100 localInterfaces[interface.first.first].second =
102 trace, interface.second->GetRightInterface());
103 m_localInterfaces.emplace_back(
104 localInterfaces[interface.first.first].second);
105 }
106
107 cnt++;
108 }
109
110 // Send num of interfaces size so all partitions can prepare buffers
111 int nRanks = comm->GetSize();
112
113 // Send all interface edges present to all partitions
114 Array<OneD, int> interfaceEdges(myIndxLRMap.size());
115 cnt = 0;
116 for (auto pres : myIndxLRMap)
117 {
118 interfaceEdges[cnt++] = pres.second;
119 }
120 Array<OneD, int> rankLocalInterfaceIds(myIndxLRMap.size() * nRanks, 0);
121 comm->AllGather(interfaceEdges, rankLocalInterfaceIds);
122
123 // Map of rank to vector of interface traces
124 std::map<int, std::vector<InterfaceTraceSharedPtr>> oppRankSharedInterface;
125
126 // Find what interface Ids match with other ranks, then check if opposite
127 // edge
128 size_t myRank = comm->GetRank();
129 size_t numInterfaces = interfaceCollection.size();
130 for (int i = 0; i < nRanks; ++i)
131 {
132 for (size_t j = 0; j < numInterfaces; ++j)
133 {
134 int otherId = indxToInterfaceID[j];
135
136 // otherCode represents for a specific interface ID what sides are
137 // present on rank i, 0=non, 1=left, 2=right, 3=both
138 int otherCode = rankLocalInterfaceIds[i * numInterfaces + j];
139
140 // myCode represents for a specific interface ID what sides are
141 // present on this rank/process 0=non, 1=left, 2=right, 3=both
142 int myCode = myIndxLRMap[otherId];
143
144 // Special case if checking current rank (this process)
145 if (i == myRank)
146 {
147 // If contains both edges locally then set check local to true
148 if (myCode == 3)
149 {
150 localInterfaces[otherId].first->SetCheckLocal(true);
151 localInterfaces[otherId].second->SetCheckLocal(true);
152 }
153
154 continue;
155 }
156
157 // Checks if this ranks 'left' matches any 'right' on other rank
158 if ((myCode == 1 && otherCode == 2) ||
159 (myCode == 1 && otherCode == 3) ||
160 (myCode == 3 && otherCode == 2))
161 {
162 oppRankSharedInterface[i].emplace_back(
163 localInterfaces[otherId].first);
164 }
165 // Checks if this ranks 'right' matches any 'left' on other rank
166 else if ((myCode == 2 && otherCode == 1) ||
167 (myCode == 2 && otherCode == 3) ||
168 (myCode == 3 && otherCode == 1))
169 {
170 oppRankSharedInterface[i].emplace_back(
171 localInterfaces[otherId].second);
172 }
173 // Checks if this ranks 'both' matches any 'both' on other rank
174 else if (myCode == 3 && otherCode == 3)
175 {
176 oppRankSharedInterface[i].emplace_back(
177 localInterfaces[otherId].first);
178 oppRankSharedInterface[i].emplace_back(
179 localInterfaces[otherId].second);
180 }
181 }
182 }
183
184 // Create individual interface exchange objects (each object is rank ->
185 // rank) and contains a vector of interfaceTrace objects
186 for (auto &rank : oppRankSharedInterface)
187 {
188 m_exchange.emplace_back(
190 m_movement, m_trace, comm, rank));
191 }
192
193 // Find missing coordinates on interface from other side
195}
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
SpatialDomains::MeshGraphSharedPtr m_graph
Mesh associated with this expansion list.
const ExpListSharedPtr m_trace
Trace expansion list.
std::vector< InterfaceExchangeSharedPtr > m_exchange
Vector of interface exchanges, i.e. every rank-to-rank comm needed.
void ExchangeCoords()
Perform the coordinate exchange between processors. This is where the missing coordinates on the inte...
SpatialDomains::MovementSharedPtr m_movement
Movement object associated with the non-conformal interfaces.
std::vector< InterfaceTraceSharedPtr > m_localInterfaces
Interface sides present on current process.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ExchangeCoords(), m_exchange, m_localInterfaces, m_movement, and m_trace.

Member Function Documentation

◆ ExchangeCoords()

void Nektar::MultiRegions::InterfaceMapDG::ExchangeCoords ( )

Perform the coordinate exchange between processors. This is where the missing coordinates on the interface are found and sent to all other processors on the other side of that interface so the matching ranks can be found.

Definition at line 197 of file InterfaceMapDG.cpp.

198{
199 LibUtilities::Timer timer;
200 timer.Start();
201
202 auto comm = m_trace->GetComm();
203 auto zones = m_movement->GetZones();
204
205 LibUtilities::Timer timer2;
206 timer2.Start();
207 for (auto &interfaceTrace : m_localInterfaces)
208 {
209 interfaceTrace->CalcLocalMissing(m_movement);
210 }
211 timer2.Stop();
212 timer2.AccumulateRegion("InterfaceMapDG::ExchangeCoords local", 1);
213
214 // If parallel communication is needed
215 if (!m_exchange.empty())
216 {
217 LibUtilities::Timer timer3;
218 timer3.Start();
219
220 auto requestSend = comm->CreateRequest(m_exchange.size());
221 auto requestRecv = comm->CreateRequest(m_exchange.size());
222
223 for (int i = 0; i < m_exchange.size(); ++i)
224 {
225 m_exchange[i]->RankFillSizes(requestSend, requestRecv, i);
226 }
227 comm->WaitAll(requestSend);
228 comm->WaitAll(requestRecv);
229
230 for (int i = 0; i < m_exchange.size(); ++i)
231 {
232 m_exchange[i]->SendMissing(requestSend, requestRecv, i);
233 }
234 comm->WaitAll(requestSend);
235 comm->WaitAll(requestRecv);
236
237 for (auto &i : m_exchange)
238 {
239 i->CalcRankDistances();
240 }
241
242 timer3.Stop();
243 timer3.AccumulateRegion("InterfaceMapDG::ExchangeCoords parallel", 1);
244 }
245
246 m_movement->GetCoordExchangeFlag() = false;
247
248 timer.Stop();
249 timer.AccumulateRegion("InterfaceMapDG::ExchangeCoords");
250}

References Nektar::LibUtilities::Timer::AccumulateRegion(), m_exchange, m_localInterfaces, m_movement, m_trace, Nektar::LibUtilities::Timer::Start(), and Nektar::LibUtilities::Timer::Stop().

Referenced by ExchangeTrace(), and InterfaceMapDG().

◆ ExchangeTrace()

void Nektar::MultiRegions::InterfaceMapDG::ExchangeTrace ( Array< OneD, NekDouble > &  Fwd,
Array< OneD, NekDouble > &  Bwd 
)

Perform the trace exchange between processors, given the forwards and backwards spaces.

Parameters
FwdLocal forwards space of the trace (which will be sent)
BwdLocal backwards space of the trace (which will receive contributions)

Performs the trace exchange across interfaces 1) Calculate and send the Fwd trace to other ranks with pairwise comms 2) While waiting for the send/recv to complete we fill the local interfaces Bwd trace 3) Fill the remaining Bwd trace with the received trace data from other ranks

Definition at line 487 of file InterfaceMapDG.cpp.

489{
490 if (m_movement->GetCoordExchangeFlag())
491 {
493 }
494 auto comm = m_trace->GetComm();
495 // If no parallel exchange needed we only fill the local traces
496 if (m_exchange.empty())
497 {
498
499 // Fill local interface traces
500 for (auto &m_localInterface : m_localInterfaces)
501 {
502 m_localInterface->FillLocalBwdTrace(Fwd, Bwd);
503 }
504 }
505 else
506 {
507 auto requestSend = comm->CreateRequest(m_exchange.size());
508 auto requestRecv = comm->CreateRequest(m_exchange.size());
509 for (int i = 0; i < m_exchange.size(); ++i)
510 {
511 m_exchange[i]->SendFwdTrace(requestSend, requestRecv, i, Fwd);
512 }
513
514 // Fill local interface traces
515 for (auto &m_localInterface : m_localInterfaces)
516 {
517 m_localInterface->FillLocalBwdTrace(Fwd, Bwd);
518 }
519
520 comm->WaitAll(requestSend);
521 comm->WaitAll(requestRecv);
522
523 // Fill communicated interface traces
524 for (auto &i : m_exchange)
525 {
526 i->FillRankBwdTraceExchange(Bwd);
527 }
528 }
529}

References ExchangeCoords(), m_exchange, m_localInterfaces, m_movement, and m_trace.

Member Data Documentation

◆ m_exchange

std::vector<InterfaceExchangeSharedPtr> Nektar::MultiRegions::InterfaceMapDG::m_exchange
private

Vector of interface exchanges, i.e. every rank-to-rank comm needed.

Definition at line 269 of file InterfaceMapDG.h.

Referenced by ExchangeCoords(), ExchangeTrace(), and InterfaceMapDG().

◆ m_graph

SpatialDomains::MeshGraphSharedPtr Nektar::MultiRegions::InterfaceMapDG::m_graph
private

Mesh associated with this expansion list.

Definition at line 261 of file InterfaceMapDG.h.

◆ m_localInterfaces

std::vector<InterfaceTraceSharedPtr> Nektar::MultiRegions::InterfaceMapDG::m_localInterfaces
private

Interface sides present on current process.

Definition at line 265 of file InterfaceMapDG.h.

Referenced by ExchangeCoords(), ExchangeTrace(), and InterfaceMapDG().

◆ m_movement

SpatialDomains::MovementSharedPtr Nektar::MultiRegions::InterfaceMapDG::m_movement
private

Movement object associated with the non-conformal interfaces.

Definition at line 263 of file InterfaceMapDG.h.

Referenced by ExchangeCoords(), ExchangeTrace(), and InterfaceMapDG().

◆ m_trace

const ExpListSharedPtr Nektar::MultiRegions::InterfaceMapDG::m_trace
private

Trace expansion list.

Definition at line 267 of file InterfaceMapDG.h.

Referenced by ExchangeCoords(), ExchangeTrace(), and InterfaceMapDG().