38#define MPICH_SKIP_MPICXX
39#define OMPI_SKIP_MPICXX
55 sizeof(Foam::label) <=
sizeof(SCOTCH_Num),
56 "SCOTCH_Num is too small for Foam::label, check your scotch headers"
79static inline void check(
const int retVal,
const char* what)
84 <<
"Call to scotch routine " << what
85 <<
" 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);
141 OFstream str(graphPath_ +
".grf");
143 Info<<
"Dumping Scotch graph file to " << str.name() <<
nl
144 <<
"Use this in combination with gpart." <<
endl;
146 const label numConnect = adjncy.size();
153 str << numCells <<
' ' << numConnect <<
nl;
157 str <<
"0 000" <<
nl;
159 for (label celli = 0; celli < numCells; ++celli)
161 const label beg = xadj[celli];
162 const label
end = xadj[celli+1];
166 for (label i = beg; i <
end; ++i)
168 str <<
' ' << adjncy[i];
176 SCOTCH_randomReset();
182 SCOTCH_Strat stradat;
185 SCOTCH_stratInit(&stradat),
192 DebugInfo <<
"scotchDecomp : Using strategy " << strategy <<
endl;
194 SCOTCH_stratGraphMap(&stradat, strategy.c_str());
206 bool hasWeights = !cWeights.empty();
209 const scalar minWeights = hasWeights ?
min(cWeights) : scalar(1);
215 <<
"Illegal minimum weight " << minWeights
219 else if (hasWeights && (cWeights.size() != numCells))
222 <<
"Number of cell weights " << cWeights.size()
223 <<
" does not equal number of cells " << numCells
228 List<SCOTCH_Num> velotab;
232 scalar rangeScale(1);
234 const scalar velotabSum =
sum(cWeights)/minWeights;
236 const scalar upperRange =
static_cast<scalar
>
238 std::numeric_limits<SCOTCH_Num>::max()-1
241 if (velotabSum > upperRange)
245 rangeScale = 0.9*upperRange/velotabSum;
248 <<
"Sum of weights overflows SCOTCH_Num: " << velotabSum
249 <<
", compressing by factor " << rangeScale <<
endl;
254 velotab.resize(cWeights.size());
258 velotab[i] =
static_cast<SCOTCH_Num
>
260 ((cWeights[i]/minWeights - 1)*rangeScale) + 1
271 SCOTCH_Graph grafdat;
274 SCOTCH_graphInit(&grafdat),
285 xadj_param().cdata(),
292 adjncy_param().cdata(),
299 SCOTCH_graphCheck(&grafdat),
311 SCOTCH_archInit(&archdat),
315 List<SCOTCH_Num> procWeights;
319 && !procWeights.empty()
325 <<
"processorWeights (" << procWeights.size()
326 <<
") != number of domains (" <<
nDomains_ <<
")" <<
nl
331 <<
"scotchDecomp : Using procesor weights "
332 << procWeights <<
endl;
336 SCOTCH_archCmpltw(&archdat,
nDomains_, procWeights.cdata()),
392 int oldExcepts = fedisableexcept
407 decomp_param.ref().data()
413 feenableexcept(oldExcepts);
429 SCOTCH_graphExit(&grafdat);
430 SCOTCH_stratExit(&stradat);
431 SCOTCH_archExit(&archdat);
441 const dictionary& decompDict,
445 metisLikeDecomp(typeName, decompDict,
regionName, selectionType::NULL_DICT)
453 const polyMesh&
mesh,
455 const scalarField& pointWeights
472 const polyMesh&
mesh,
499 graphPath_ =
"scotch.grf";
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void resize(const label len)
Adjust allocated size of list.
fileName path() const
Return path.
label nDomains_
Number of domains for the decomposition.
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.
const dictionary & coeffsDict_
Coefficients for all derived methods.
Mesh consisting of general polyhedral cells.
Scotch domain decomposition.
virtual label decomposeSerial(const labelList &adjncy, const labelList &xadj, const List< scalar > &cWeights, labelList &decomp) const
Decompose non-parallel.
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.
List< label > labelList
A List of labels.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
messageStream Info
Information stream (stdout output on master, null elsewhere)
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.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
static Foam::fileName getGraphPathBase(const polyMesh &mesh)
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.