diff --git a/src/parallel/decompose/scotchDecomp/scotchDecomp.C b/src/parallel/decompose/scotchDecomp/scotchDecomp.C index 17ff685d49e2cfd6b32342b79e128f0d97f65aed..0851431b9655992d946b32dd0f99652cfa888478 100644 --- a/src/parallel/decompose/scotchDecomp/scotchDecomp.C +++ b/src/parallel/decompose/scotchDecomp/scotchDecomp.C @@ -409,11 +409,32 @@ Foam::label Foam::scotchDecomp::decomposeOneProc << exit(FatalError); } + scalar velotabSum = sum(cWeights)/minWeights; + + scalar rangeScale(1.0); + + if (velotabSum > scalar(INT_MAX - 1)) + { + // 0.9 factor of safety to avoid floating point round-off in + // rangeScale tipping the subsequent sum over the integer limit. + rangeScale = 0.9*scalar(INT_MAX - 1)/velotabSum; + + WarningIn + ( + "scotchDecomp::decompose" + "(const pointField&, const scalarField&)" + ) << "Sum of weights has overflowed integer: " << velotabSum + << ", compressing weight scale by a factor of " << rangeScale + << endl; + } + // Convert to integers. velotab.setSize(cWeights.size()); + forAll(velotab, i) { - velotab[i] = int(cWeights[i]/minWeights); + velotab[i] = + int((cWeights[i]/minWeights - 1)*rangeScale) + 1; } }