54 namespace decompositionMethods
77 void Foam::decompositionMethods::scotch::check
86 <<
"Call to scotch routine " << str <<
" failed."
94 const fileName& meshPath,
116 Info<<
"scotch : running in parallel."
117 <<
" Decomposing all of graph on master processor." <<
endl;
119 globalIndex globalCells(xadj.size()-1);
125 Field<label> allAdjncy(nTotalConnections);
126 Field<label> allXadj(globalCells.size()+1);
130 label nTotalCells = 0;
131 forAll(cellWeights, celli)
133 allXadj[nTotalCells] = xadj[celli];
134 allWeights[nTotalCells++] = cellWeights[celli];
136 nTotalConnections = 0;
139 allAdjncy[nTotalConnections++] = adjncy[i];
145 Field<label> nbrAdjncy(fromSlave);
146 Field<label> nbrXadj(fromSlave);
153 allXadj[nTotalCells] = nTotalConnections+nbrXadj[celli];
154 allWeights[nTotalCells++] = nbrWeights[celli];
159 allAdjncy[nTotalConnections++] = nbrAdjncy[i];
162 allXadj[nTotalCells] = nTotalConnections;
165 Field<label> allFinalDecomp;
180 toSlave << SubField<label>
183 globalCells.localSize(slave),
184 globalCells.offset(slave)
188 decomp = SubField<label>
191 globalCells.localSize()
203 toMaster<< adjncy << SubField<label>(xadj, xadj.size()-1)
213 fromMaster >> decomp;
220 Foam::label Foam::decompositionMethods::scotch::decomposeOneProc
222 const fileName& meshPath,
231 if (decompositionDict_.found(
"scotchCoeffs"))
233 const dictionary& scotchCoeffs =
234 decompositionDict_.subDict(
"scotchCoeffs");
236 if (scotchCoeffs.lookupOrDefault(
"writeGraph",
false))
238 OFstream str(meshPath +
".grf");
240 Info<<
"Dumping Scotch graph file to " << str.name() <<
endl
241 <<
"Use this in combination with gpart." <<
endl;
244 str << version <<
nl;
246 str << xadj.size()-1 <<
' ' << adjncy.size() <<
nl;
250 label hasEdgeWeights = 0;
251 label hasVertexWeights = 0;
252 label numericflag = 10*hasEdgeWeights+hasVertexWeights;
253 str << baseval <<
' ' << numericflag <<
nl;
254 for (
label celli = 0; celli < xadj.size()-1; celli++)
256 label start = xadj[celli];
257 label end = xadj[celli+1];
260 for (
label i = start; i < end; i++)
262 str <<
' ' << adjncy[i];
274 SCOTCH_randomReset();
280 SCOTCH_Strat stradat;
281 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
283 if (decompositionDict_.found(
"scotchCoeffs"))
285 const dictionary& scotchCoeffs =
286 decompositionDict_.subDict(
"scotchCoeffs");
289 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
293 Info<<
"scotch : Using strategy " << strategy <<
endl;
295 SCOTCH_stratGraphMap(&stradat, strategy.c_str());
306 if (!cellWeights.empty())
308 if (cellWeights.size() != xadj.size()-1)
311 <<
"Number of cell weights " << cellWeights.size()
312 <<
" does not equal number of cells " << xadj.size()-1
317 velotab = scaleWeights(cellWeights, nWeights,
false);
321 SCOTCH_Graph grafdat;
322 check(SCOTCH_graphInit(&grafdat),
"SCOTCH_graphInit");
340 check(SCOTCH_graphCheck(&grafdat),
"SCOTCH_graphCheck");
348 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
351 if (decompositionDict_.found(
"scotchCoeffs"))
353 const dictionary& scotchCoeffs =
354 decompositionDict_.subDict(
"scotchCoeffs");
356 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
358 if (processorWeights.size())
362 Info<<
"scotch : Using processor weights " << processorWeights
367 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
375 SCOTCH_archCmplt(&archdat, nProcessors_),
382 int oldExcepts = fedisableexcept
390 decomp.setSize(xadj.size()-1);
405 feenableexcept(oldExcepts);
409 SCOTCH_graphExit(&grafdat);
412 SCOTCH_stratExit(&stradat);
415 SCOTCH_archExit(&archdat);
425 decompositionMethod(decompositionDict)
433 const polyMesh& mesh,
438 if (
points.size() != mesh.nCells())
441 <<
"Can use this decomposition method only for the whole mesh"
443 <<
"and supply one coordinate (cellCentre) for every cell." <<
endl
444 <<
"The number of coordinates " <<
points.size() <<
endl
445 <<
"The number of cells in the mesh " << mesh.nCells()
452 CompactListList<label> cellCells;
466 mesh.time().path()/mesh.name(),
479 const polyMesh& mesh,
485 if (agglom.size() != mesh.nCells())
488 <<
"Size of cell-to-coarse map " << agglom.size()
489 <<
" differs from number of cells in mesh " << mesh.nCells()
493 checkWeights(agglomPoints, pointWeights);
496 CompactListList<label> cellCells;
510 mesh.time().path()/mesh.name(),
518 labelList fineDistribution(agglom.size());
520 forAll(fineDistribution, i)
522 fineDistribution[i] = decomp[agglom[i]];
525 return fineDistribution;
536 if (cellCentres.size() != globalCellCells.size())
539 <<
"Inconsistent number of cells (" << globalCellCells.size()
540 <<
") and number of cell centres (" << cellCentres.size()
544 checkWeights(cellCentres, cellWeights);
550 CompactListList<label> cellCells(globalCellCells);
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
static int masterNo()
Process index of the master.
static bool master(const label communicator=0)
Am I the master process.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool & parRun()
Is this a parallel run?
label checkWeights(const pointField &points, const scalarField &pointWeights) const
Check the weights against the points.
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.
virtual labelList decompose(const pointField &points, const scalarField &pointWeights)
Inherit decompose from decompositionMethod.
scotch(const dictionary &decompositionDict)
Construct given the decomposition dictionary and mesh.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
volScalarField scalarField(fieldObject, mesh)
defineTypeNameAndDebug(metis, 0)
addToRunTimeSelectionTable(decompositionMethod, metis, decomposer)
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
vectorField pointField
pointField is a vectorField.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< labelList > labelListList
A List of labelList.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.