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" 80 static inline void check(
const int retVal,
const char* what)
85 <<
"Call to scotch routine " << what
86 <<
" failed (" << retVal <<
")\n" 103 Foam::label Foam::ptscotchDecomp::decompose
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());
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
> 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);
467 Foam::ptscotchDecomp::ptscotchDecomp
469 const dictionary& decompDict,
474 coeffsDict_(findCoeffsDict(
"scotchCoeffs", selectionType::NULL_DICT))
482 const polyMesh&
mesh,
493 <<
"Can only use this decomposition method for entire mesh" <<
nl 494 <<
"and supply one coordinate (cellCentre) for every cell." <<
nl 495 <<
"The number of coordinates " <<
points.size() <<
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()
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
List< labelList > labelListList
A List of labelList.
fileName path() const
Return path.
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
label nDomains_
Number of domains for the decomposition.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Type gMin(const FieldField< Field, Type > &f)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static Foam::fileName getGraphPathBase(const polyMesh &mesh)
label size() const noexcept
The number of elements in table.
static CompactListList< T > pack(const UList< SubListType > &lists, const bool checkOverflow=false)
Construct by packing together the list of lists.
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
const Time & time() const
Return the top-level database.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
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.
#define forAll(list, i)
Loop across all elements in list.
Foam::word regionName(Foam::polyMesh::defaultRegion)
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
vectorField pointField
pointField is a vectorField.
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
#define DebugInfo
Report an information message using Foam::Info.
int debug
Static debugging option.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
defineTypeNameAndDebug(combustionModel, 0)
static void check(const int retVal, const char *what)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
#define WarningInFunction
Report a warning using Foam::Warning.
const word & name() const
Return reference to name.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
label nCells() const noexcept
Number of mesh cells.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
List< label > labelList
A List of labels.
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...