62 void Foam::ptscotchDecomp::check(
const int retVal,
const char* str)
67 <<
"Call to scotch routine " << str <<
" failed." 264 const fileName& meshPath,
265 const List<label>& adjncy,
266 const List<label>& xadj,
268 List<label>& finalDecomp
271 List<label> dummyAdjncy(1);
272 List<label> dummyXadj(1);
279 (adjncy.size() ? adjncy.begin() : dummyAdjncy.begin()),
281 (xadj.size() ? xadj.begin() : dummyXadj.begin()),
291 const fileName& meshPath,
292 const label adjncySize,
293 const label adjncy[],
294 const label xadjSize,
298 List<label>& finalDecomp
303 Pout<<
"ptscotchDecomp : entering with xadj:" << xadjSize <<
endl;
307 if (decompositionDict_.found(
"scotchCoeffs"))
309 const dictionary& scotchCoeffs =
310 decompositionDict_.subDict(
"scotchCoeffs");
312 if (scotchCoeffs.lookupOrDefault(
"writeGraph",
false))
319 Pout<<
"Dumping Scotch graph file to " << str.
name() << endl
320 <<
"Use this in combination with dgpart." <<
endl;
322 globalIndex globalCells(xadjSize-1);
326 str << version <<
nl;
333 str << globalCells.size();
335 str <<
' ' <<
returnReduce(xadj[xadjSize-1], sumOp<label>())
340 str <<
' ' << xadj[xadjSize-1] <<
nl;
344 str << baseval <<
' ' <<
"000" <<
nl;
345 for (
label celli = 0; celli < xadjSize-1; celli++)
347 label start = xadj[celli];
348 label end = xadj[celli+1];
351 for (
label i = start; i < end; i++)
353 str <<
' ' << adjncy[i];
364 SCOTCH_Strat stradat;
365 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
367 if (decompositionDict_.found(
"scotchCoeffs"))
369 const dictionary& scotchCoeffs =
370 decompositionDict_.subDict(
"scotchCoeffs");
374 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
378 Info<<
"ptscotchDecomp : Using strategy " << strategy <<
endl;
380 SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
396 scalar minWeights =
gMin(cWeights);
397 scalar maxWeights =
gMax(cWeights);
399 if (maxWeights > minWeights)
404 <<
"Illegal minimum weight " << minWeights
408 if (cWeights.size() != xadjSize-1)
411 <<
"Number of cell weights " << cWeights.size()
412 <<
" does not equal number of cells " << xadjSize-1
417 scalar velotabSum =
gSum(cWeights)/minWeights;
419 scalar rangeScale(1.0);
423 if (velotabSum > scalar(
labelMax - 1))
427 rangeScale = 0.9*scalar(
labelMax - 1)/velotabSum;
430 <<
"Sum of weights has overflowed integer: " << velotabSum
431 <<
", compressing weight scale by a factor of " << rangeScale
438 if (maxWeights > minWeights)
443 velotab.setSize(cWeights.size());
447 velotab[i] = int((cWeights[i]/minWeights - 1)*rangeScale) + 1;
466 SCOTCH_Dgraph grafdat;
467 check(SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD),
"SCOTCH_dgraphInit");
472 Pout<<
"SCOTCH_dgraphBuild with:" << nl
473 <<
"xadjSize-1 : " << xadjSize-1 << nl
474 <<
"xadj : " << uintptr_t(xadj) << nl
475 <<
"velotab : " << uintptr_t(velotab.begin()) << nl
476 <<
"adjncySize : " << adjncySize << nl
477 <<
"adjncy : " << uintptr_t(adjncy) << nl
489 const_cast<SCOTCH_Num*>(xadj),
492 const_cast<SCOTCH_Num*>(xadj+1),
494 const_cast<SCOTCH_Num*>(velotab.begin()),
499 const_cast<SCOTCH_Num*>(adjncy),
509 Pout<<
"SCOTCH_dgraphCheck" <<
endl;
511 check(SCOTCH_dgraphCheck(&grafdat),
"SCOTCH_dgraphCheck");
523 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
525 List<label> processorWeights;
526 if (decompositionDict_.found(
"scotchCoeffs"))
528 const dictionary& scotchCoeffs =
529 decompositionDict_.subDict(
"scotchCoeffs");
531 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
533 if (processorWeights.size())
537 Info<<
"ptscotchDecomp : Using procesor weights " 543 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
555 SCOTCH_archCmplt(&archdat, nProcessors_),
563 int oldExcepts = fedisableexcept
573 finalDecomp.setSize(
max(1, xadjSize-1));
593 feenableexcept(oldExcepts);
616 SCOTCH_dgraphExit(&grafdat);
618 SCOTCH_stratExit(&stradat);
620 SCOTCH_archExit(&archdat);
628 Foam::ptscotchDecomp::ptscotchDecomp(
const dictionary& decompositionDict)
630 decompositionMethod(decompositionDict)
638 const polyMesh& mesh,
643 if (points.size() != mesh.nCells())
646 <<
"Can use this decomposition method only for the whole mesh" 648 <<
"and supply one coordinate (cellCentre) for every cell." << endl
649 <<
"The number of coordinates " << points.size() << endl
650 <<
"The number of cells in the mesh " << mesh.nCells()
660 CompactListList<label> cellCells;
671 List<label> finalDecomp;
674 mesh.time().path()/mesh.name(),
685 decomp[i] = finalDecomp[i];
693 const polyMesh& mesh,
699 if (agglom.size() != mesh.nCells())
702 <<
"Size of cell-to-coarse map " << agglom.size()
703 <<
" differs from number of cells in mesh " << mesh.nCells()
711 CompactListList<label> cellCells;
722 List<label> finalDecomp;
725 mesh.time().path()/mesh.name(),
733 labelList fineDistribution(agglom.size());
735 forAll(fineDistribution, i)
737 fineDistribution[i] = finalDecomp[agglom[i]];
740 return fineDistribution;
751 if (cellCentres.size() != globalCellCells.size())
754 <<
"Inconsistent number of cells (" << globalCellCells.size()
755 <<
") and number of cell centres (" << cellCentres.size()
764 CompactListList<label> cellCells(globalCellCells);
767 List<label> finalDecomp;
781 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.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Type gMin(const FieldField< Field, Type > &f)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
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.
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.
Type gSum(const FieldField< Field, Type > &f)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual const fileName & name() const
Return the name of the stream.
static const label labelMax
List< label > labelList
A List of labels.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
prefixOSstream Pout(cout,"Pout")
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
word name(const complex &)
Return a string representation of a complex.
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)