Skip to content

Commit 098e2c2

Browse files
committed
patchkernel: fix partitionig of empty patches
Even if we are partitiniong an empty patch, we still need to go through the whole preparation to make sure all internal data structures are properly initialized.
1 parent 7eb58f6 commit 098e2c2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/patchkernel/patch_kernel_parallel.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,25 +1833,25 @@ double PatchKernel::evalPartitioningUnbalance(const std::unordered_map<long, dou
18331833
*/
18341834
std::vector<adaption::Info> PatchKernel::_partitioningPrepare(const std::unordered_map<long, double> &cellWeights, double defaultWeight, bool trackPartitioning)
18351835
{
1836-
// Early return if the mesh is empty
1837-
if (empty(true)) {
1838-
return std::vector<adaption::Info>();
1839-
}
1840-
1841-
// Early return if there is a single partition
1842-
if (getProcessorCount() == 1) {
1843-
return std::vector<adaption::Info>();
1844-
}
1836+
// Check if the patch needs a non-trivial partitioning
1837+
//
1838+
// A non-trivial partitioning is needed only if the patch is not empty
1839+
// and if there are multiple processes associated with the patch.
1840+
bool isCellRankEvaluationNeeded = (!empty(true) && (getProcessorCount() > 1));
18451841

18461842
// Default partitioning can only be used when the patch is all on a single process
1847-
if (isDistributed()) {
1848-
throw std::runtime_error("Default partitioning can only be used when the patch is all on a single process");
1843+
if (isCellRankEvaluationNeeded) {
1844+
if (isDistributed()) {
1845+
throw std::runtime_error("Default partitioning can only be used when the patch is all on a single process");
1846+
}
18491847
}
18501848

18511849
// Evaluate partitioning
1850+
//
1851+
// Only the owner of the patch need to evaluate the partitioning.
18521852
#if BITPIT_ENABLE_METIS==1
18531853
std::unordered_map<long, int> cellRanks;
1854-
if (getRank() == getOwner()) {
1854+
if (isCellRankEvaluationNeeded && getRank() == getOwner()) {
18551855
// Initialize map between patch vertices and METIS nodes
18561856
//
18571857
// METIS node numbering needs to be contiguous and needs to start from zero.

0 commit comments

Comments
 (0)