74 void Foam::scotchDecomp::check(
const int retVal,
const char* str)
79 <<
"Call to scotch routine " << str <<
" failed." 87 const fileName& meshPath,
88 const List<label>& adjncy,
89 const List<label>& xadj,
92 List<label>& finalDecomp
110 Info<<
"scotchDecomp : running in parallel." 111 <<
" Decomposing all of graph on master processor." <<
endl;
113 globalIndex globalCells(xadj.size()-1);
119 Field<label> allAdjncy(nTotalConnections);
120 Field<label> allXadj(globalCells.size()+1);
124 label nTotalCells = 0;
127 allXadj[nTotalCells] = xadj[celli];
128 allWeights[nTotalCells++] = cWeights[celli];
130 nTotalConnections = 0;
133 allAdjncy[nTotalConnections++] = adjncy[i];
139 Field<label> nbrAdjncy(fromSlave);
140 Field<label> nbrXadj(fromSlave);
147 allXadj[nTotalCells] = nTotalConnections+nbrXadj[celli];
148 allWeights[nTotalCells++] = nbrWeights[celli];
153 allAdjncy[nTotalConnections++] = nbrAdjncy[i];
156 allXadj[nTotalCells] = nTotalConnections;
159 Field<label> allFinalDecomp;
174 toSlave << SubField<label>
177 globalCells.localSize(slave),
178 globalCells.offset(slave)
182 finalDecomp = SubField<label>
185 globalCells.localSize()
197 toMaster<< adjncy << SubField<label>(xadj, xadj.size()-1)
207 fromMaster >> finalDecomp;
217 const fileName& meshPath,
218 const List<label>& adjncy,
219 const List<label>& xadj,
222 List<label>& finalDecomp
226 if (decompositionDict_.found(
"scotchCoeffs"))
228 const dictionary& scotchCoeffs =
229 decompositionDict_.subDict(
"scotchCoeffs");
231 if (scotchCoeffs.lookupOrDefault(
"writeGraph",
false))
233 OFstream str(meshPath +
".grf");
235 Info<<
"Dumping Scotch graph file to " << str.name() << endl
236 <<
"Use this in combination with gpart." <<
endl;
239 str << version <<
nl;
241 str << xadj.size()-1 <<
' ' << adjncy.size() <<
nl;
245 label hasEdgeWeights = 0;
246 label hasVertexWeights = 0;
247 label numericflag = 10*hasEdgeWeights+hasVertexWeights;
248 str << baseval <<
' ' << numericflag <<
nl;
249 for (
label celli = 0; celli < xadj.size()-1; celli++)
251 label start = xadj[celli];
252 label end = xadj[celli+1];
255 for (
label i = start; i < end; i++)
257 str <<
' ' << adjncy[i];
269 SCOTCH_randomReset();
275 SCOTCH_Strat stradat;
276 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
278 if (decompositionDict_.found(
"scotchCoeffs"))
280 const dictionary& scotchCoeffs =
281 decompositionDict_.subDict(
"scotchCoeffs");
284 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
288 Info<<
"scotchDecomp : Using strategy " << strategy <<
endl;
290 SCOTCH_stratGraphMap(&stradat, strategy.c_str());
303 scalar minWeights =
min(cWeights);
304 if (!cWeights.empty())
309 <<
"Illegal minimum weight " << minWeights
313 if (cWeights.size() != xadj.size()-1)
316 <<
"Number of cell weights " << cWeights.size()
317 <<
" does not equal number of cells " << xadj.size()-1
321 scalar velotabSum =
sum(cWeights)/minWeights;
323 scalar rangeScale(1.0);
325 if (velotabSum > scalar(
labelMax - 1))
329 rangeScale = 0.9*scalar(
labelMax - 1)/velotabSum;
332 <<
"Sum of weights has overflowed integer: " << velotabSum
333 <<
", compressing weight scale by a factor of " << rangeScale
338 velotab.setSize(cWeights.size());
342 velotab[i] = int((cWeights[i]/minWeights - 1)*rangeScale) + 1;
348 SCOTCH_Graph grafdat;
349 check(SCOTCH_graphInit(&grafdat),
"SCOTCH_graphInit");
367 check(SCOTCH_graphCheck(&grafdat),
"SCOTCH_graphCheck");
375 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
377 List<label> processorWeights;
378 if (decompositionDict_.found(
"scotchCoeffs"))
380 const dictionary& scotchCoeffs =
381 decompositionDict_.subDict(
"scotchCoeffs");
383 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
385 if (processorWeights.size())
389 Info<<
"scotchDecomp : Using processor weights " << processorWeights
394 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
402 SCOTCH_archCmplt(&archdat, nProcessors_),
409 int oldExcepts = fedisableexcept
417 finalDecomp.setSize(xadj.size()-1);
432 feenableexcept(oldExcepts);
436 SCOTCH_graphExit(&grafdat);
439 SCOTCH_stratExit(&stradat);
442 SCOTCH_archExit(&archdat);
452 decompositionMethod(decompositionDict)
460 const polyMesh& mesh,
465 if (points.size() != mesh.nCells())
468 <<
"Can use this decomposition method only for the whole mesh" 470 <<
"and supply one coordinate (cellCentre) for every cell." << endl
471 <<
"The number of coordinates " << points.size() << endl
472 <<
"The number of cells in the mesh " << mesh.nCells()
477 CompactListList<label> cellCells;
488 List<label> finalDecomp;
491 mesh.time().path()/mesh.name(),
502 decomp[i] = finalDecomp[i];
510 const polyMesh& mesh,
516 if (agglom.size() != mesh.nCells())
519 <<
"Size of cell-to-coarse map " << agglom.size()
520 <<
" differs from number of cells in mesh " << mesh.nCells()
525 CompactListList<label> cellCells;
536 List<label> finalDecomp;
539 mesh.time().path()/mesh.name(),
547 labelList fineDistribution(agglom.size());
549 forAll(fineDistribution, i)
551 fineDistribution[i] = finalDecomp[agglom[i]];
554 return fineDistribution;
565 if (cellCentres.size() != globalCellCells.size())
568 <<
"Inconsistent number of cells (" << globalCellCells.size()
569 <<
") and number of cell centres (" << cellCentres.size()
578 CompactListList<label> cellCells(globalCellCells);
581 List<label> finalDecomp;
595 decomp[i] = finalDecomp[i];
List< labelList > labelListList
A List of labelList.
#define forAll(list, i)
Loop across all elements in list.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static int masterNo()
Process index of the master.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool master(const label communicator=0)
Am I the master process.
Holds information (coordinate and normal) regarding nearest wall point.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Macros for easy insertion into run-time selection tables.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
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.
vectorField pointField
pointField is a vectorField.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
static const label labelMax
List< label > labelList
A List of labels.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
scotchDecomp(const dictionary &decompositionDict)
Construct given the decomposition dictionary and mesh.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
#define WarningInFunction
Report a warning using Foam::Warning.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)