Skip to content

Commit aae7e1d

Browse files
committed
patchkernel: allow evaluating patch owner also when patch is dirty
1 parent 305090c commit aae7e1d

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

src/patchkernel/patch_kernel.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ friend class PatchManager;
684684
int getRank() const;
685685
int getProcessorCount() const;
686686

687-
bool isDistributed() const;
688-
int getOwner() const;
687+
bool isDistributed(bool allowDirty = false) const;
688+
int getOwner(bool allowDirty = false) const;
689689

690690
void setHaloSize(std::size_t haloSize);
691691
std::size_t getHaloSize() const;
@@ -1015,6 +1015,7 @@ friend class PatchManager;
10151015
void updateGhostVertexExchangeInfo();
10161016

10171017
void updateOwner();
1018+
int evalOwner() const;
10181019

10191020
std::unordered_map<long, int> evaluateExchangeVertexOwners() const;
10201021
#endif

src/patchkernel/patch_kernel_parallel.cpp

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,50 +167,94 @@ int PatchKernel::getProcessorCount() const
167167
/*!
168168
Check if the patch is distributed among different processes.
169169
170+
A patch is distributed among different processes if it doesn't have an owner.
171+
172+
Setting the appropriate function argument, this function can be called also
173+
when the patch is not up-to-date. If dirty patches are allowed and the patch
174+
is actually dirty, the function will evaluate the owner on-the-fly. Otherwise
175+
the function will return the owner evaluated during the last update. In any
176+
case, if dirt patches are allowed, the function is a collective function and
177+
needs to be called by all processes (otherwise a deadlock will occur).
178+
170179
\return Return true if the patch is distributed among different processes,
171180
false otherwise.
172181
*/
173-
bool PatchKernel::isDistributed() const
182+
bool PatchKernel::isDistributed(bool allowDirty) const
174183
{
175-
return (getOwner() < 0);
184+
return (getOwner(allowDirty) < 0);
176185
}
177186

178187
/*!
179188
If the path is NOT distributed among different processes, returns the
180189
process that owns the patch, otherwise returns a negative number.
181190
191+
Setting the appropriate function argument, this function can be called also
192+
when the patch is not up-to-date. If dirty patches are allowed and the patch
193+
is actually dirty, the function will evaluate the owner on-the-fly. Otherwise
194+
the function will return the owner evaluated during the last update. In any
195+
case, if dirt patches are allowed, the function is a collective function and
196+
needs to be called by all processes (otherwise a deadlock will occur).
197+
198+
\param allowDirty if set to true, the function will evaluate the owner of a dirty
199+
patch on on-the-fly; otherwise the function will return the owner evaluated during
200+
the last updated, even if the patch is currently dirty. If dirty patch are allowed,
201+
the function is a collective function and needs to be called by all processes
202+
(otherwise a deadlock will occur)
182203
\return If the path is NOT distributed among different processes, returns
183204
the process that owns the patch, otherwise returns a negative number.
184205
*/
185-
int PatchKernel::getOwner() const
206+
int PatchKernel::getOwner(bool allowDirty) const
186207
{
187-
return m_owner;
208+
assert(allowDirty || arePartitioningInfoDirty(false));
209+
if (!allowDirty || !arePartitioningInfoDirty(true)) {
210+
return m_owner;
211+
} else {
212+
return evalOwner();
213+
}
188214
}
189215

190216
/*!
191-
Updates the owner of the patch.
217+
Evaluate the owner of the patch.
218+
219+
This function can be called also when the patch is not up-to-date. If the patch
220+
is up-to-date, the function will return the same result of PatchKernel::getOwner().
192221
193222
If the path is NOT distributed among different processes, the owner is set
194223
to the process that owns the cells, otherwise the owner is set to a negative
195224
number.
196225
*/
197-
void PatchKernel::updateOwner()
226+
int PatchKernel::evalOwner() const
198227
{
199228
long nInternalCells = getInternalCellCount();
200229
long nGlobalInternalCells = nInternalCells;
201230
if (isPartitioned()) {
202231
MPI_Allreduce(MPI_IN_PLACE, &nGlobalInternalCells, 1, MPI_LONG, MPI_SUM, getCommunicator());
203232
}
204233

234+
int owner;
205235
if (nInternalCells == nGlobalInternalCells) {
206-
m_owner = getRank();
236+
owner = getRank();
207237
} else {
208-
m_owner = -1;
238+
owner = -1;
209239
}
210240

211241
if (isPartitioned()) {
212-
MPI_Allreduce(MPI_IN_PLACE, &m_owner, 1, MPI_INT, MPI_MAX, getCommunicator());
242+
MPI_Allreduce(MPI_IN_PLACE, &owner, 1, MPI_INT, MPI_MAX, getCommunicator());
213243
}
244+
245+
return owner;
246+
}
247+
248+
/*!
249+
Updates the owner of the patch.
250+
251+
If the path is NOT distributed among different processes, the owner is set
252+
to the process that owns the cells, otherwise the owner is set to a negative
253+
number.
254+
*/
255+
void PatchKernel::updateOwner()
256+
{
257+
m_owner = evalOwner();
214258
}
215259

216260
/*!

0 commit comments

Comments
 (0)