38#pragma GCC diagnostic ignored "-Wold-style-cast"
56 sizeof(Foam::label) <=
sizeof(SCOTCH_Num),
57 "SCOTCH_Num is too small for Foam::label, check your scotch headers"
80static inline void check(
const int retVal,
const char* what)
85 <<
"Call to scotch routine " << what
86 <<
" failed (" << retVal <<
")\n"
105 const labelList& adjncy,
106 const labelList& xadj,
107 const List<scalar>& cWeights,
111 const SCOTCH_Num numCells =
max(0, (xadj.size()-1));
114 ConstPrecisionAdaptor<SCOTCH_Num, label, List> adjncy_param(adjncy);
115 ConstPrecisionAdaptor<SCOTCH_Num, label, List> xadj_param(xadj);
118 decomp.resize(numCells);
120 PrecisionAdaptor<SCOTCH_Num, label, List> decomp_param(decomp,
false);
123 labelList adjncy_dummy, xadj_dummy, decomp_dummy;
126 adjncy_dummy.
resize(1, 0);
127 adjncy_param.set(adjncy_dummy);
129 xadj_dummy.resize(2, 0);
130 xadj_param.set(xadj_dummy);
132 decomp_dummy.resize(1, 0);
133 decomp_param.clear();
134 decomp_param.set(decomp_dummy);
140 Pout<<
"ptscotchDecomp : " << numCells <<
" cells" <<
endl;
151 Pout<<
"Dumping Scotch graph file to " << str.
name() <<
endl
152 <<
"Use this in combination with dgpart." <<
endl;
154 const label numConnect = adjncy.size();
155 const label nTotCells =
returnReduce(numCells, sumOp<label>());
156 const label nTotConnect =
returnReduce(numConnect, sumOp<label>());
166 str << nTotCells <<
' ' << nTotConnect <<
nl;
170 str << numCells <<
' ' << numConnect <<
nl;
174 str <<
"0 000" <<
nl;
176 for (label celli = 0; celli < numCells; ++celli)
178 const label beg = xadj[celli];
179 const label
end = xadj[celli+1];
183 for (label i = beg; i <
end; ++i)
185 str <<
' ' << adjncy[i];
193 SCOTCH_randomReset();
199 SCOTCH_Strat stradat;
202 SCOTCH_stratInit(&stradat),
210 <<
"ptscotchDecomp : Using strategy " << strategy <<
endl;
212 SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
224 bool hasWeights =
returnReduce(!cWeights.empty(), orOp<bool>());
226 const scalar minWeights = hasWeights ?
gMin(cWeights) : scalar(1);
232 <<
"Illegal minimum weight " << minWeights
236 else if (hasWeights && (cWeights.size() != numCells))
239 <<
"Number of cell weights " << cWeights.size()
240 <<
" does not equal number of cells " << numCells
245 List<SCOTCH_Num> velotab;
249 scalar rangeScale(1);
251 const scalar velotabSum =
gSum(cWeights)/minWeights;
253 const scalar upperRange =
static_cast<scalar
>
255 std::numeric_limits<SCOTCH_Num>::max()-1
258 if (velotabSum > upperRange)
262 rangeScale = 0.9*upperRange/velotabSum;
265 <<
"Sum of weights overflows SCOTCH_Num: " << velotabSum
266 <<
", compressing by factor " << rangeScale <<
endl;
272 velotab.resize(cWeights.size());
276 velotab[i] =
static_cast<SCOTCH_Num
>
278 ((cWeights[i]/minWeights - 1)*rangeScale) + 1
286 velotab.resize(1, 1);
299 SCOTCH_Dgraph grafdat;
302 SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD),
308 Pout<<
"SCOTCH_dgraphBuild with:" <<
nl
309 <<
"numCells : " << numCells <<
nl
310 <<
"xadj : " <<
name(xadj_param().cdata()) <<
nl
311 <<
"velotab : " <<
name(velotab.cdata()) <<
nl
312 <<
"adjncySize : " << adjncy_param().size() <<
nl
313 <<
"adjncy : " <<
name(adjncy_param().cdata()) <<
nl
327 xadj_param.constCast().data(),
330 (xadj_param.constCast().data()+1),
338 adjncy_param.constCast().data(),
347 Pout<<
"SCOTCH_dgraphCheck" <<
endl;
351 SCOTCH_dgraphCheck(&grafdat),
367 SCOTCH_archInit(&archdat),
371 List<SCOTCH_Num> procWeights;
375 && !procWeights.empty()
381 <<
"processorWeights (" << procWeights.size()
382 <<
") != number of domains (" <<
nDomains_ <<
")" <<
nl
387 <<
"ptscotchDecomp : Using procesor weights "
388 << procWeights <<
endl;
392 SCOTCH_archCmpltw(&archdat,
nDomains_, procWeights.cdata()),
412 int oldExcepts = fedisableexcept
431 decomp_param.ref().data()
437 feenableexcept(oldExcepts);
457 SCOTCH_dgraphExit(&grafdat);
458 SCOTCH_stratExit(&stradat);
459 SCOTCH_archExit(&archdat);
469 const dictionary& decompDict,
474 coeffsDict_(findCoeffsDict(
"scotchCoeffs", selectionType::NULL_DICT))
482 const polyMesh&
mesh,
484 const scalarField& pointWeights
493 <<
"Can only use this decomposition method for entire mesh" <<
nl
494 <<
"and supply one coordinate (cellCentre) for every cell." <<
nl
496 <<
"The number of cells in the mesh " <<
mesh.
nCells() <<
nl
505 CompactListList<label> cellCells;
531 const polyMesh&
mesh,
543 <<
"Size of cell-to-coarse map " << agglom.size()
544 <<
" differs from number of cells in mesh " <<
mesh.
nCells()
552 CompactListList<label> cellCells;
573 labelList fineDistribution(agglom.size());
575 forAll(fineDistribution, i)
577 fineDistribution[i] = decomp[agglom[i]];
580 return fineDistribution;
592 graphPath_ =
"ptscotch";
594 if (cellCentres.size() != globalCellCells.size())
597 <<
"Inconsistent number of cells (" << globalCellCells.size()
598 <<
") and number of cell centres (" << cellCentres.size()
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
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 number of elements in table.
void resize(const label len)
Adjust allocated size of list.
virtual const fileName & name() const
Get the name of the stream.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
fileName path() const
Return path.
void size(const label n)
Older name for setAddressableSize.
label nDomains_
Number of domains for the decomposition.
static void calcCellCells(const polyMesh &mesh, const labelList &agglom, const label nLocalCoarse, const bool global, CompactListList< label > &cellCells)
Helper: determine (local or global) cellCells from mesh.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
A class for handling file names.
const Time & time() const
Return the top-level database.
const word & name() const
Return reference to name.
Mesh consisting of general polyhedral cells.
label nCells() const noexcept
Number of mesh cells.
int myProcNo() const noexcept
Return processor number.
PTScotch domain decomposition.
bool decompose() const noexcept
Query the decompose flag (normally off)
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Foam::word regionName(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.
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)
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
List< label > labelList
A List of labels.
static void check(const int retVal, const char *what)
vectorField pointField
pointField is a vectorField.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< labelList > labelListList
A List of labelList.
static Foam::fileName getGraphPathBase(const polyMesh &mesh)
Type gMin(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
#define forAll(list, i)
Loop across all elements in list.