OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::SuperCommunicator< T, SUPER > Class Template Reference

Generic communicator for overlaps between blocks of SUPER. More...

#include <superCommunicator.h>

+ Inheritance diagram for olb::SuperCommunicator< T, SUPER >:
+ Collaboration diagram for olb::SuperCommunicator< T, SUPER >:

Public Member Functions

 SuperCommunicator (SUPER &super)
 
 ~SuperCommunicator ()
 
template<typename FIELD >
void requestField ()
 Request FIELD for communication.
 
template<typename... FIELDS>
void requestFields ()
 Convenience method for requesting multiple FIELDS in one call.
 
void requestCell (LatticeR< SUPER::d+1 > latticeR)
 Request single cell in the padding area for communication.
 
void requestOverlap (int width)
 Request all cells in overlap of width for communication.
 
void requestOverlap (int width, FunctorPtr< SuperIndicatorF< T, SUPER::d > > &&indicatorF)
 Request all indicated cells in overlap of width for communication.
 
void clearRequestedCells ()
 Remove all requested cells.
 
void exchangeRequests ()
 Exchange requests between processes.
 
void communicate ()
 Perform communication.
 
const std::set< int > & getRemoteCuboids () const
 Returns set of non-local neighborhood cuboid indices.
 

Detailed Description

template<typename T, typename SUPER>
class olb::SuperCommunicator< T, SUPER >

Generic communicator for overlaps between blocks of SUPER.

This class provides inter-block communication for any super structures containing overlapping blocks.

SUPER must expose load balancer via getLoadBalancer SUPER must expose cuboid geometry via getCuboidGeometry

Blocks must be exposed via SUPER::getBlock Blocks must implement FieldsCommunicatable

Definition at line 53 of file superCommunicator.h.

Constructor & Destructor Documentation

◆ SuperCommunicator()

template<typename T , typename SUPER >
olb::SuperCommunicator< T, SUPER >::SuperCommunicator ( SUPER & super)

Definition at line 39 of file superCommunicator.hh.

40 :
41 _super(super)
42#ifdef PARALLEL_MODE_MPI
43, _tagCoordinator(super.getLoadBalancer())
44, _enabled(false)
45#endif
46{
47#ifdef PARALLEL_MODE_MPI
48 if (MPI_Comm_dup(MPI_COMM_WORLD, &_neighborhoodComm) != MPI_SUCCESS) {
49 throw std::runtime_error("Unable to duplicate MPI communicator");
50 }
51 if (MPI_Comm_dup(MPI_COMM_WORLD, &_communicatorComm) != MPI_SUCCESS) {
52 throw std::runtime_error("Unable to duplicate MPI communicator");
53 }
54#endif
55
56 auto& cuboidGeometry = _super.getCuboidGeometry();
57 auto& load = _super.getLoadBalancer();
58
59 for (int iC = 0; iC < load.size(); ++iC) {
60 _blockNeighborhoods.emplace_back(
61 std::make_unique<BlockCommunicationNeighborhood<T,SUPER::d>>( cuboidGeometry
62 , load, load.glob(iC)
63 , _super.getOverlap()
64#ifdef PARALLEL_MODE_MPI
65 , _neighborhoodComm
66#endif
67 ));
68 }
69}

◆ ~SuperCommunicator()

template<typename T , typename SUPER >
olb::SuperCommunicator< T, SUPER >::~SuperCommunicator ( )

Definition at line 72 of file superCommunicator.hh.

73{
74#ifdef PARALLEL_MODE_MPI
75 MPI_Comm_free(&_neighborhoodComm);
76 MPI_Comm_free(&_communicatorComm);
77#endif
78}

Member Function Documentation

◆ clearRequestedCells()

template<typename T , typename SUPER >
void olb::SuperCommunicator< T, SUPER >::clearRequestedCells ( )

Remove all requested cells.

Definition at line 179 of file superCommunicator.hh.

180{
181 auto& load = _super.getLoadBalancer();
182 for (int iC = 0; iC < load.size(); ++iC) {
183 _blockNeighborhoods[iC]->clearRequestedCells();
184 }
185 _ready = false;
186 _enabled = false;
187}

◆ communicate()

template<typename T , typename SUPER >
void olb::SuperCommunicator< T, SUPER >::communicate ( )

Perform communication.

Definition at line 190 of file superCommunicator.hh.

191{
192 if (!_enabled) {
193 return;
194 }
195 if (!_ready) {
196 throw std::logic_error("Requests must be re-exchanged after any changes");
197 }
198
199 auto& load = _super.getLoadBalancer();
200#ifdef PARALLEL_MODE_MPI
201 for (int iC = 0; iC < load.size(); ++iC) {
202 _blockCommunicators[iC]->receive();
203 }
204 for (int iC = 0; iC < load.size(); ++iC) {
205 _blockCommunicators[iC]->send();
206 }
207 for (int iC = 0; iC < load.size(); ++iC) {
208 _blockCommunicators[iC]->unpack();
209 }
210 for (int iC = 0; iC < load.size(); ++iC) {
211 _blockCommunicators[iC]->wait();
212 }
213#else // not using PARALLEL_MODE_MPI
214 for (int iC = 0; iC < load.size(); ++iC) {
215 _blockCommunicators[iC]->copy();
216 }
217#endif
218}

◆ exchangeRequests()

template<typename T , typename SUPER >
void olb::SuperCommunicator< T, SUPER >::exchangeRequests ( )

Exchange requests between processes.

Definition at line 81 of file superCommunicator.hh.

82{
83 auto& load = _super.getLoadBalancer();
84
85 for (int iC = 0; iC < load.size(); ++iC) {
86 _blockNeighborhoods[iC]->maintain();
87 }
88
89 for (int iC = 0; iC < load.size(); ++iC) {
90 for (std::type_index field : _fieldsRequested) {
91 _blockNeighborhoods[iC]->setFieldAvailability(
92 field, _super.getBlock(iC).hasCommunicatable(field));
93 }
94 }
95
96#ifdef PARALLEL_MODE_MPI
97 _tagCoordinator.template coordinate<SUPER::d>(_blockNeighborhoods);
98
99 for (int iC = 0; iC < load.size(); ++iC) {
100 _blockNeighborhoods[iC]->send(_tagCoordinator);
101 }
102 for (int iC = 0; iC < load.size(); ++iC) {
103 _blockNeighborhoods[iC]->receive(_tagCoordinator);
104 }
105 for (int iC = 0; iC < load.size(); ++iC) {
106 _blockNeighborhoods[iC]->wait();
107 }
108
109#else // not using PARALLEL_MODE_MPI
110 for (int iC = 0; iC < load.size(); ++iC) {
111 _blockNeighborhoods[iC]->forNeighbors([&](int localC) {
112 _blockNeighborhoods[iC]->setFieldsAvailability(localC, _super.getBlock(load.loc(localC)));
113 });
114 }
115#endif
116
117 _blockCommunicators.clear();
118 _blockCommunicators.resize(load.size());
119 for (int iC = 0; iC < load.size(); ++iC) {
120 auto* block = &_super.getBlock(iC);
121 _blockCommunicators[iC] = callUsingConcretePlatform<typename SUPER::block_t>(
122 block->getPlatform(),
123 block,
124 [&](auto* concreteBlock) -> std::unique_ptr<BlockCommunicator> {
125 return std::make_unique<ConcreteBlockCommunicator<std::remove_reference_t<decltype(*concreteBlock)>>>(
126 _super,
127 load,
128#ifdef PARALLEL_MODE_MPI
129 _tagCoordinator,
130 _communicatorComm,
131#endif
132 iC,
133 *_blockNeighborhoods[iC]);
134 });
135 }
136
137#ifdef PARALLEL_MODE_MPI
138 for (int iC = 0; iC < load.size(); ++iC) {
139 _blockNeighborhoods[iC]->forNeighbors([&](int remoteC) {
140 _remoteCuboidNeighborhood.emplace(remoteC);
141 });
142 }
143#endif
144
145 _ready = true;
146}

◆ getRemoteCuboids()

template<typename T , typename SUPER >
const std::set< int > & olb::SuperCommunicator< T, SUPER >::getRemoteCuboids ( ) const

Returns set of non-local neighborhood cuboid indices.

Definition at line 221 of file superCommunicator.hh.

222{
223 if (_ready) {
224 return _remoteCuboidNeighborhood;
225 } else {
226 throw std::logic_error("Requests must be re-exchanged after any changes");
227 }
228}

◆ requestCell()

template<typename T , typename SUPER >
void olb::SuperCommunicator< T, SUPER >::requestCell ( LatticeR< SUPER::d+1 > latticeR)

Request single cell in the padding area for communication.

Definition at line 149 of file superCommunicator.hh.

150{
151 _blockNeighborhoods[latticeR[0]]->requestCell(latticeR.data()+1);
152 _ready = false;
153 _enabled = true;
154}

References olb::Vector< T, D >::data().

+ Here is the call graph for this function:

◆ requestField()

template<typename T , typename SUPER >
template<typename FIELD >
void olb::SuperCommunicator< T, SUPER >::requestField ( )
inline

Request FIELD for communication.

Communication of dynamic fields depends on the availability at both ends of the exchange.

Definition at line 88 of file superCommunicator.h.

88 {
89 if (std::find(_fieldsRequested.begin(), _fieldsRequested.end(), typeid(FIELD)) == _fieldsRequested.end()) {
90 _fieldsRequested.emplace_back(typeid(FIELD));
91 for (auto& neighborhood : _blockNeighborhoods) {
92 neighborhood->template requestField<FIELD>();
93 }
94 }
95 }

◆ requestFields()

template<typename T , typename SUPER >
template<typename... FIELDS>
void olb::SuperCommunicator< T, SUPER >::requestFields ( )
inline

Convenience method for requesting multiple FIELDS in one call.

Definition at line 99 of file superCommunicator.h.

99 {
100 (requestField<FIELDS>(), ...);
101 }

◆ requestOverlap() [1/2]

template<typename T , typename SUPER >
void olb::SuperCommunicator< T, SUPER >::requestOverlap ( int width)

Request all cells in overlap of width for communication.

Definition at line 157 of file superCommunicator.hh.

158{
159 auto& load = _super.getLoadBalancer();
160 for (int iC = 0; iC < load.size(); ++iC) {
161 _blockNeighborhoods[iC]->requestOverlap(width);
162 }
163 _ready = false;
164 _enabled = true;
165}

◆ requestOverlap() [2/2]

template<typename T , typename SUPER >
void olb::SuperCommunicator< T, SUPER >::requestOverlap ( int width,
FunctorPtr< SuperIndicatorF< T, SUPER::d > > && indicatorF )

Request all indicated cells in overlap of width for communication.

Definition at line 168 of file superCommunicator.hh.

169{
170 auto& load = _super.getLoadBalancer();
171 for (int iC = 0; iC < load.size(); ++iC) {
172 _blockNeighborhoods[iC]->requestOverlap(width, indicatorF->getBlockIndicatorF(iC));
173 }
174 _ready = false;
175 _enabled = true;
176}

The documentation for this class was generated from the following files: