ENH: additional protection against zero-sized graph offset lists

- for metis-like graphs there is no guarantee that a zero-sized graph
  has an offsets list with size 1 or size 0, so always use

     numCells = max(0, xadj.size()-1)

  this was already done in most places, but missed in the
  decomposeGeneral method

STYLE: use sumOp<label>() instead of plusOp<label>()
This commit is contained in:
Mark Olesen
2022-03-03 21:17:35 +01:00
committed by Andrew Heather
parent e11fde900c
commit 0867816490
6 changed files with 21 additions and 17 deletions

View File

@ -208,8 +208,8 @@ bool setField
doCorrectBoundaryConditions(ctrl.correctBCs, output);
const label numTotal = returnReduce(output.size(), plusOp<label>());
reduce(numValuesChanged, plusOp<label>());
const label numTotal = returnReduce(output.size(), sumOp<label>());
reduce(numValuesChanged, sumOp<label>());
if (numValuesChanged == numTotal)
{

View File

@ -265,8 +265,8 @@ bool Foam::functionObjects::fvExpressionField::setField
if (action_ == actionType::opModify && log)
{
const label numTotal = returnReduce(output.size(), plusOp<label>());
reduce(numValuesChanged, plusOp<label>());
const label numTotal = returnReduce(output.size(), sumOp<label>());
reduce(numValuesChanged, sumOp<label>());
Info<< this->name() << ": set ";
if (numValuesChanged == numTotal)

View File

@ -49,8 +49,10 @@ void Foam::decompositionInformation::populate
subdist.resize(nDomain, Zero);
}
const label nCells = max(0, xadj.size()-1);
for (label celli = 0; celli < nCells; ++celli)
// Protect against zero-sized offset list
const label numCells = max(0, (xadj.size()-1));
for (label celli = 0; celli < numCells; ++celli)
{
const label ownProc = decomp[celli];

View File

@ -29,7 +29,6 @@ License
#include "decompositionMethod.H"
#include "globalIndex.H"
#include "syncTools.H"
#include "Tuple2.H"
#include "faceSet.H"
#include "regionSplit.H"
#include "localPointRegion.H"
@ -481,7 +480,7 @@ void Foam::decompositionMethod::calcCellCells
// Create global cell numbers
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
globalIndex globalAgglom
const globalIndex globalAgglom
(
nLocalCoarse,
Pstream::msgType(),
@ -680,7 +679,7 @@ void Foam::decompositionMethod::calcCellCells
// Create global cell numbers
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
globalIndex globalAgglom
const globalIndex globalAgglom
(
nLocalCoarse,
Pstream::msgType(),

View File

@ -56,8 +56,11 @@ Foam::label Foam::metisLikeDecomp::decomposeGeneral
<< " Decomposing all of graph on master processor." << endl;
}
// Protect against zero-sized offset list
const label numCells = max(0, (xadj.size()-1));
const globalIndex globalAdjncy(adjncy.size());
const globalIndex globalCells(xadj.size()-1);
const globalIndex globalCells(numCells);
List<label> allAdjncy(globalAdjncy.gather(adjncy));
@ -107,13 +110,13 @@ Foam::label Foam::metisLikeDecomp::decomposeGeneral
{
// Send my part of the graph (local numbering)
if (xadj.size() <= 1)
if (!numCells)
{
// Nothing to do
}
else
{
SubList<label> procSlot(xadj, xadj.size()-1);
SubList<label> procSlot(xadj, numCells);
OPstream::write
(

View File

@ -253,11 +253,11 @@ void Foam::multiLevelDecomp::subsetGlobalCellCells
labelList& cutConnections
) const
{
const globalIndex globalCells(cellCells.size());
// Determine new index for cells by inverting subset
labelList oldToNew(invert(cellCells.size(), set));
globalIndex globalCells(cellCells.size());
// Subset locally the elements for which I have data
subCellCells = UIndirectList<labelList>(cellCells, set);
@ -275,7 +275,7 @@ void Foam::multiLevelDecomp::subsetGlobalCellCells
// subCellCells : indexes into oldToNew and allDist
// Globally compact numbering for cells in set.
globalIndex globalSubCells(set.size());
const globalIndex globalSubCells(set.size());
// Now subCellCells contains indices into oldToNew which are the
// new locations of the neighbouring cells.
@ -417,7 +417,7 @@ void Foam::multiLevelDecomp::decompose
nOutsideConnections
);
label nPoints = returnReduce(domainPoints.size(), plusOp<label>());
label nPoints = returnReduce(domainPoints.size(), sumOp<label>());
Pstream::listCombineGather(nOutsideConnections, plusEqOp<label>());
Pstream::listCombineScatter(nOutsideConnections);
label nPatches = 0;
@ -525,7 +525,7 @@ void Foam::multiLevelDecomp::decompose
}
}
reduce(nPoints, plusOp<label>());
reduce(nPoints, sumOp<label>());
Pstream::listCombineGather
(
nOutsideConnections,