66 void Foam::scotchDecomp::check(
const int retVal,
const char* str)
71 <<
"Call to scotch routine " << str <<
" failed." 79 const fileName& meshPath,
80 const List<label>& adjncy,
81 const List<label>& xadj,
84 List<label>& finalDecomp
102 Info<<
"scotchDecomp : running in parallel." 103 <<
" Decomposing all of graph on master processor." <<
endl;
105 globalIndex globalCells(xadj.size()-1);
111 Field<label> allAdjncy(nTotalConnections);
112 Field<label> allXadj(globalCells.size()+1);
116 label nTotalCells = 0;
119 allXadj[nTotalCells] = xadj[celli];
120 allWeights[nTotalCells++] = cWeights[celli];
122 nTotalConnections = 0;
125 allAdjncy[nTotalConnections++] = adjncy[i];
131 Field<label> nbrAdjncy(fromSlave);
132 Field<label> nbrXadj(fromSlave);
139 allXadj[nTotalCells] = nTotalConnections+nbrXadj[celli];
140 allWeights[nTotalCells++] = nbrWeights[celli];
145 allAdjncy[nTotalConnections++] = nbrAdjncy[i];
148 allXadj[nTotalCells] = nTotalConnections;
151 Field<label> allFinalDecomp;
166 toSlave << SubField<label>
169 globalCells.localSize(slave),
170 globalCells.offset(slave)
174 finalDecomp = SubField<label>
177 globalCells.localSize()
189 toMaster<< adjncy << SubField<label>(xadj, xadj.size()-1)
199 fromMaster >> finalDecomp;
209 const fileName& meshPath,
210 const List<label>& adjncy,
211 const List<label>& xadj,
214 List<label>& finalDecomp
218 if (decompositionDict_.found(
"scotchCoeffs"))
220 const dictionary& scotchCoeffs =
221 decompositionDict_.subDict(
"scotchCoeffs");
223 if (scotchCoeffs.lookupOrDefault(
"writeGraph",
false))
225 OFstream str(meshPath +
".grf");
227 Info<<
"Dumping Scotch graph file to " << str.name() << endl
228 <<
"Use this in combination with gpart." <<
endl;
231 str << version <<
nl;
233 str << xadj.size()-1 <<
' ' << adjncy.size() <<
nl;
237 label hasEdgeWeights = 0;
238 label hasVertexWeights = 0;
239 label numericflag = 10*hasEdgeWeights+hasVertexWeights;
240 str << baseval <<
' ' << numericflag <<
nl;
241 for (
label celli = 0; celli < xadj.size()-1; celli++)
243 label start = xadj[celli];
244 label end = xadj[celli+1];
247 for (
label i = start; i < end; i++)
249 str <<
' ' << adjncy[i];
261 SCOTCH_Strat stradat;
262 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
264 if (decompositionDict_.found(
"scotchCoeffs"))
266 const dictionary& scotchCoeffs =
267 decompositionDict_.subDict(
"scotchCoeffs");
270 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
274 Info<<
"scotchDecomp : Using strategy " << strategy <<
endl;
276 SCOTCH_stratGraphMap(&stradat, strategy.c_str());
292 scalar minWeights =
min(cWeights);
293 if (!cWeights.empty())
298 <<
"Illegal minimum weight " << minWeights
302 if (cWeights.size() != xadj.size()-1)
305 <<
"Number of cell weights " << cWeights.size()
306 <<
" does not equal number of cells " << xadj.size()-1
310 scalar velotabSum =
sum(cWeights)/minWeights;
312 scalar rangeScale(1.0);
314 if (velotabSum > scalar(
labelMax - 1))
318 rangeScale = 0.9*scalar(
labelMax - 1)/velotabSum;
321 <<
"Sum of weights has overflowed integer: " << velotabSum
322 <<
", compressing weight scale by a factor of " << rangeScale
327 velotab.setSize(cWeights.size());
331 velotab[i] = int((cWeights[i]/minWeights - 1)*rangeScale) + 1;
337 SCOTCH_Graph grafdat;
338 check(SCOTCH_graphInit(&grafdat),
"SCOTCH_graphInit");
356 check(SCOTCH_graphCheck(&grafdat),
"SCOTCH_graphCheck");
364 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
366 List<label> processorWeights;
367 if (decompositionDict_.found(
"scotchCoeffs"))
369 const dictionary& scotchCoeffs =
370 decompositionDict_.subDict(
"scotchCoeffs");
372 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
374 if (processorWeights.size())
378 Info<<
"scotchDecomp : Using processor weights " << processorWeights
383 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
391 SCOTCH_archCmplt(&archdat, nProcessors_),
439 int oldExcepts = fedisableexcept
447 finalDecomp.setSize(xadj.size()-1);
462 feenableexcept(oldExcepts);
481 SCOTCH_graphExit(&grafdat);
483 SCOTCH_stratExit(&stradat);
485 SCOTCH_archExit(&archdat);
495 decompositionMethod(decompositionDict)
503 const polyMesh& mesh,
508 if (points.size() != mesh.nCells())
511 <<
"Can use this decomposition method only for the whole mesh" 513 <<
"and supply one coordinate (cellCentre) for every cell." << endl
514 <<
"The number of coordinates " << points.size() << endl
515 <<
"The number of cells in the mesh " << mesh.nCells()
520 CompactListList<label> cellCells;
531 List<label> finalDecomp;
534 mesh.time().path()/mesh.name(),
545 decomp[i] = finalDecomp[i];
553 const polyMesh& mesh,
559 if (agglom.size() != mesh.nCells())
562 <<
"Size of cell-to-coarse map " << agglom.size()
563 <<
" differs from number of cells in mesh " << mesh.nCells()
568 CompactListList<label> cellCells;
579 List<label> finalDecomp;
582 mesh.time().path()/mesh.name(),
590 labelList fineDistribution(agglom.size());
592 forAll(fineDistribution, i)
594 fineDistribution[i] = finalDecomp[agglom[i]];
597 return fineDistribution;
608 if (cellCentres.size() != globalCellCells.size())
611 <<
"Inconsistent number of cells (" << globalCellCells.size()
612 <<
") and number of cell centres (" << cellCentres.size()
621 CompactListList<label> cellCells(globalCellCells);
624 List<label> finalDecomp;
638 decomp[i] = finalDecomp[i];
List< labelList > labelListList
A List of labelList.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t 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.
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.
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.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
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)