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()
185 toMaster<< adjncy << SubField<label>(xadj, xadj.size()-1)
191 fromMaster >> finalDecomp;
201 const fileName& meshPath,
202 const List<label>& adjncy,
203 const List<label>& xadj,
206 List<label>& finalDecomp
210 if (decompositionDict_.found(
"scotchCoeffs"))
212 const dictionary& scotchCoeffs =
213 decompositionDict_.subDict(
"scotchCoeffs");
215 if (scotchCoeffs.lookupOrDefault(
"writeGraph",
false))
217 OFstream str(meshPath +
".grf");
219 Info<<
"Dumping Scotch graph file to " << str.name() << endl
220 <<
"Use this in combination with gpart." <<
endl;
223 str << version <<
nl;
225 str << xadj.size()-1 <<
' ' << adjncy.size() <<
nl;
229 label hasEdgeWeights = 0;
230 label hasVertexWeights = 0;
231 label numericflag = 10*hasEdgeWeights+hasVertexWeights;
232 str << baseval <<
' ' << numericflag <<
nl;
233 for (
label celli = 0; celli < xadj.size()-1; celli++)
235 label start = xadj[celli];
236 label end = xadj[celli+1];
239 for (
label i = start; i < end; i++)
241 str <<
' ' << adjncy[i];
253 SCOTCH_Strat stradat;
254 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
256 if (decompositionDict_.found(
"scotchCoeffs"))
258 const dictionary& scotchCoeffs =
259 decompositionDict_.subDict(
"scotchCoeffs");
262 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
266 Info<<
"scotchDecomp : Using strategy " << strategy <<
endl;
268 SCOTCH_stratGraphMap(&stradat, strategy.c_str());
284 scalar minWeights =
min(cWeights);
285 if (!cWeights.empty())
290 <<
"Illegal minimum weight " << minWeights
294 if (cWeights.size() != xadj.size()-1)
297 <<
"Number of cell weights " << cWeights.size()
298 <<
" does not equal number of cells " << xadj.size()-1
302 scalar velotabSum =
sum(cWeights)/minWeights;
304 scalar rangeScale(1.0);
306 if (velotabSum > scalar(
labelMax - 1))
310 rangeScale = 0.9*scalar(
labelMax - 1)/velotabSum;
313 <<
"Sum of weights has overflowed integer: " << velotabSum
314 <<
", compressing weight scale by a factor of " << rangeScale
319 velotab.setSize(cWeights.size());
323 velotab[i] = int((cWeights[i]/minWeights - 1)*rangeScale) + 1;
329 SCOTCH_Graph grafdat;
330 check(SCOTCH_graphInit(&grafdat),
"SCOTCH_graphInit");
348 check(SCOTCH_graphCheck(&grafdat),
"SCOTCH_graphCheck");
356 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
358 List<label> processorWeights;
359 if (decompositionDict_.found(
"scotchCoeffs"))
361 const dictionary& scotchCoeffs =
362 decompositionDict_.subDict(
"scotchCoeffs");
364 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
366 if (processorWeights.size())
370 Info<<
"scotchDecomp : Using procesor weights " << processorWeights
375 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
383 SCOTCH_archCmplt(&archdat, nProcessors_),
431 int oldExcepts = fedisableexcept
439 finalDecomp.setSize(xadj.size()-1);
454 feenableexcept(oldExcepts);
473 SCOTCH_graphExit(&grafdat);
475 SCOTCH_stratExit(&stradat);
477 SCOTCH_archExit(&archdat);
485 Foam::scotchDecomp::scotchDecomp(
const dictionary& decompositionDict)
487 decompositionMethod(decompositionDict)
495 const polyMesh& mesh,
500 if (points.size() != mesh.nCells())
503 <<
"Can use this decomposition method only for the whole mesh" 505 <<
"and supply one coordinate (cellCentre) for every cell." << endl
506 <<
"The number of coordinates " << points.size() << endl
507 <<
"The number of cells in the mesh " << mesh.nCells()
512 CompactListList<label> cellCells;
523 List<label> finalDecomp;
526 mesh.time().path()/mesh.name(),
537 decomp[i] = finalDecomp[i];
545 const polyMesh& mesh,
551 if (agglom.size() != mesh.nCells())
554 <<
"Size of cell-to-coarse map " << agglom.size()
555 <<
" differs from number of cells in mesh " << mesh.nCells()
560 CompactListList<label> cellCells;
571 List<label> finalDecomp;
574 mesh.time().path()/mesh.name(),
582 labelList fineDistribution(agglom.size());
584 forAll(fineDistribution, i)
586 fineDistribution[i] = finalDecomp[agglom[i]];
589 return fineDistribution;
600 if (cellCentres.size() != globalCellCells.size())
603 <<
"Inconsistent number of cells (" << globalCellCells.size()
604 <<
") and number of cell centres (" << cellCentres.size()
613 CompactListList<label> cellCells(globalCellCells);
616 List<label> finalDecomp;
630 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)
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)