40#ifndef MPICH_SKIP_MPICXX
41#define MPICH_SKIP_MPICXX
43#ifndef OMPI_SKIP_MPICXX
44#define OMPI_SKIP_MPICXX
48#pragma GCC diagnostic ignored "-Wold-style-cast"
65 sizeof(Foam::label) <=
sizeof(SCOTCH_Num),
66 "SCOTCH_Num is too small for Foam::label, check your scotch headers"
89static inline void check(
const int retVal,
const char* what)
94 <<
"Call to scotch routine " << what
95 <<
" failed (" << retVal <<
")\n"
112Foam::label Foam::ptscotchDecomp::decompose
114 const labelList& adjncy,
115 const labelList& xadj,
116 const List<scalar>& cWeights,
120 const SCOTCH_Num numCells =
Foam::max(0, (xadj.size()-1));
123 ConstPrecisionAdaptor<SCOTCH_Num, label, List> adjncy_param(adjncy);
124 ConstPrecisionAdaptor<SCOTCH_Num, label, List> xadj_param(xadj);
127 decomp.resize_nocopy(numCells);
129 PrecisionAdaptor<SCOTCH_Num, label, List> decomp_param(decomp,
false);
132 labelList adjncy_dummy, xadj_dummy, decomp_dummy;
135 adjncy_dummy.resize(1, 0);
136 adjncy_param.set(adjncy_dummy);
138 xadj_dummy.resize(2, 0);
139 xadj_param.set(xadj_dummy);
141 decomp_dummy.resize(1, 0);
142 decomp_param.clear();
143 decomp_param.set(decomp_dummy);
149 Pout<<
"ptscotchDecomp : " << numCells <<
" cells" <<
endl;
153 if (coeffsDict_.getOrDefault(
"writeGraph",
false))
160 Pout<<
"Dumping Scotch graph file to " << str.
name() <<
endl
161 <<
"Use this in combination with dgpart." <<
endl;
163 const label numConnect = adjncy.size();
164 const label nTotCells =
returnReduce(numCells, sumOp<label>());
165 const label nTotConnect =
returnReduce(numConnect, sumOp<label>());
175 str << nTotCells <<
' ' << nTotConnect <<
nl;
179 str << numCells <<
' ' << numConnect <<
nl;
183 str <<
"0 000" <<
nl;
185 for (label celli = 0; celli < numCells; ++celli)
187 const label beg = xadj[celli];
188 const label
end = xadj[celli+1];
192 for (label i = beg; i <
end; ++i)
194 str <<
' ' << adjncy[i];
202 SCOTCH_randomReset();
208 SCOTCH_Strat stradat;
211 SCOTCH_stratInit(&stradat),
216 if (coeffsDict_.readIfPresent(
"strategy", strategy))
219 <<
"ptscotchDecomp : Using strategy " << strategy <<
endl;
221 SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
235 const scalar minWeights = hasWeights ?
gMin(cWeights) : scalar(1);
241 <<
"Illegal minimum weight " << minWeights
245 else if (hasWeights && (cWeights.size() != numCells))
248 <<
"Number of cell weights " << cWeights.size()
249 <<
" does not equal number of cells " << numCells
254 List<SCOTCH_Num> velotab;
258 scalar rangeScale(1);
260 const scalar velotabSum =
gSum(cWeights)/minWeights;
262 const scalar upperRange =
static_cast<scalar
>
264 std::numeric_limits<SCOTCH_Num>::max()-1
267 if (velotabSum > upperRange)
271 rangeScale = 0.9*upperRange/velotabSum;
274 <<
"Sum of weights overflows SCOTCH_Num: " << velotabSum
275 <<
", compressing by factor " << rangeScale <<
endl;
281 velotab.resize(cWeights.size());
285 velotab[i] =
static_cast<SCOTCH_Num
>
287 ((cWeights[i]/minWeights - 1)*rangeScale) + 1
295 velotab.resize(1, 1);
306 velotab.resize(numCells);
315 velotab =
static_cast<SCOTCH_Num
>(1);
327 SCOTCH_Dgraph grafdat;
330 SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD),
336 Pout<<
"SCOTCH_dgraphBuild with:" <<
nl
337 <<
"numCells : " << numCells <<
nl
338 <<
"xadj : " <<
name(xadj_param().cdata()) <<
nl
339 <<
"velotab : " <<
name(velotab.cdata()) <<
nl
340 <<
"adjncySize : " << adjncy_param().size() <<
nl
341 <<
"adjncy : " <<
name(adjncy_param().cdata()) <<
nl
355 xadj_param.constCast().data(),
358 (xadj_param.constCast().data()+1),
366 adjncy_param.constCast().data(),
375 Pout<<
"SCOTCH_dgraphCheck" <<
endl;
379 SCOTCH_dgraphCheck(&grafdat),
395 SCOTCH_archInit(&archdat),
399 List<SCOTCH_Num> procWeights;
402 coeffsDict_.readIfPresent(
"processorWeights", procWeights)
403 && !procWeights.empty()
409 <<
"processorWeights (" << procWeights.size()
410 <<
") != number of domains (" <<
nDomains_ <<
")" <<
nl
415 <<
"ptscotchDecomp : Using procesor weights "
416 << procWeights <<
endl;
420 SCOTCH_archCmpltw(&archdat,
nDomains_, procWeights.cdata()),
427 List<SCOTCH_Num> domains;
428 List<scalar> dWeights;
431 coeffsDict_.readIfPresent
437 && coeffsDict_.readIfPresent
446 <<
"Ignoring multi-level decomposition since"
447 <<
" not supported by ptscotch."
448 <<
" It is supported by scotch" <<
endl;
465 int oldExcepts = fedisableexcept
484 decomp_param.ref().data()
490 feenableexcept(oldExcepts);
510 SCOTCH_dgraphExit(&grafdat);
511 SCOTCH_stratExit(&stradat);
512 SCOTCH_archExit(&archdat);
553 <<
"Number of cell centres (" <<
points.size()
554 <<
") != number of cells (" <<
mesh.nCells() <<
")"
563 CompactListList<label> cellCells;
593 <<
"Agglomeration size (" << agglom.
size()
594 <<
") != number of cells (" <<
mesh.nCells() <<
")"
603 CompactListList<label> cellCells;
636 graphPath_ =
"ptscotch";
638 if (!cellCentres.
empty() && (cellCentres.
size() != globalCellCells.
size()))
641 <<
"Number of cell centres (" << cellCentres.
size()
642 <<
") != number of cells (" << globalCellCells.
size() <<
")"
672 graphPath_ =
"ptscotch";
674 if (!cellCentres.
empty() && (cellCentres.
size() != globalCellCells.
size()))
677 <<
"Number of cell centres (" << cellCentres.
size()
678 <<
") != number of cells (" << globalCellCells.
size() <<
")"
686 auto cellCells(CompactListList<label>::pack(globalCellCells));
if(maxValue - minValue< SMALL)
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A packed storage of objects of type <T> using an offset table for access.
const labelList & offsets() const noexcept
Return the offset table (= size()+1).
const List< T > & values() const noexcept
Return the packed values.
static CompactListList< T > pack(const UList< SubListType > &lists, const bool checkOverflow=false)
Construct by packing together the list of lists.
label size() const noexcept
The primary size (the number of rows/sublists).
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name).
fileName path() const
The path for the case = rootPath/caseName.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
void size(const label n)
Older name for setAddressableSize.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
Abstract base class for domain decomposition.
selectionType
Selection type when handling the coefficients dictionary.
label nDomains_
Number of domains for the decomposition.
decompositionMethod(const label numDomains)
Construct with specified number of domains, no coefficients or constraints.
static FOAM_NO_DANGLING_REFERENCE const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Locate coeffsName dictionary or the fallback "coeffs" dictionary within an enclosing dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A class for handling file names.
const Time & time() const
Return the top-level database.
const word & name() const
Return reference to name.
static void calcCellCells(const polyMesh &mesh, const labelUList &agglom, const label nLocalCoarse, const bool parallel, CompactListList< label > &cellCells)
Determine (local or global) cellCells from mesh agglomeration.
Mesh consisting of general polyhedral cells.
PTScotch domain decomposition.
ptscotchDecomp(const ptscotchDecomp &)=delete
No copy construct.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Type gSum(const FieldField< Field, Type > &f)
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
static void check(const int retVal, const char *what)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static Foam::fileName getGraphPathBase(const polyMesh &mesh)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Type gMin(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.