62 void Foam::ptscotchDecomp::check(
const int retVal,
const char* str)
67 <<
"Call to scotch routine " << str <<
" failed." 268 const fileName& meshPath,
269 const List<label>& adjncy,
270 const List<label>& xadj,
272 List<label>& finalDecomp
275 List<label> dummyAdjncy(1);
276 List<label> dummyXadj(1);
283 (adjncy.size() ? adjncy.begin() : dummyAdjncy.begin()),
285 (xadj.size() ? xadj.begin() : dummyXadj.begin()),
295 const fileName& meshPath,
296 const label adjncySize,
297 const label adjncy[],
298 const label xadjSize,
302 List<label>& finalDecomp
307 Pout<<
"ptscotchDecomp : entering with xadj:" << xadjSize <<
endl;
311 if (decompositionDict_.found(
"scotchCoeffs"))
313 const dictionary& scotchCoeffs =
314 decompositionDict_.subDict(
"scotchCoeffs");
316 if (scotchCoeffs.lookupOrDefault(
"writeGraph",
false))
323 Pout<<
"Dumping Scotch graph file to " << str.
name() << endl
324 <<
"Use this in combination with dgpart." <<
endl;
326 globalIndex globalCells(xadjSize-1);
330 str << version <<
nl;
337 str << globalCells.size();
339 str <<
' ' <<
returnReduce(xadj[xadjSize-1], sumOp<label>())
344 str <<
' ' << xadj[xadjSize-1] <<
nl;
348 str << baseval <<
' ' <<
"000" <<
nl;
349 for (
label celli = 0; celli < xadjSize-1; celli++)
351 label start = xadj[celli];
352 label end = xadj[celli+1];
355 for (
label i = start; i < end; i++)
357 str <<
' ' << adjncy[i];
368 SCOTCH_Strat stradat;
369 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
371 if (decompositionDict_.found(
"scotchCoeffs"))
373 const dictionary& scotchCoeffs =
374 decompositionDict_.subDict(
"scotchCoeffs");
378 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
382 Info<<
"ptscotchDecomp : Using strategy " << strategy <<
endl;
384 SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
400 scalar minWeights =
gMin(cWeights);
401 scalar maxWeights =
gMax(cWeights);
403 if (maxWeights > minWeights)
408 <<
"Illegal minimum weight " << minWeights
412 if (cWeights.size() != xadjSize-1)
415 <<
"Number of cell weights " << cWeights.size()
416 <<
" does not equal number of cells " << xadjSize-1
421 scalar velotabSum =
gSum(cWeights)/minWeights;
423 scalar rangeScale(1.0);
427 if (velotabSum > scalar(
labelMax - 1))
431 rangeScale = 0.9*scalar(
labelMax - 1)/velotabSum;
434 <<
"Sum of weights has overflowed integer: " << velotabSum
435 <<
", compressing weight scale by a factor of " << rangeScale
442 if (maxWeights > minWeights)
447 velotab.setSize(cWeights.size());
451 velotab[i] = int((cWeights[i]/minWeights - 1)*rangeScale) + 1;
470 SCOTCH_Dgraph grafdat;
471 check(SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD),
"SCOTCH_dgraphInit");
476 Pout<<
"SCOTCH_dgraphBuild with:" << nl
477 <<
"xadjSize-1 : " << xadjSize-1 << nl
478 <<
"xadj : " << uintptr_t(xadj) << nl
479 <<
"velotab : " << uintptr_t(velotab.begin()) << nl
480 <<
"adjncySize : " << adjncySize << nl
481 <<
"adjncy : " << uintptr_t(adjncy) << nl
493 const_cast<SCOTCH_Num*>(xadj),
496 const_cast<SCOTCH_Num*>(xadj+1),
498 const_cast<SCOTCH_Num*>(velotab.begin()),
503 const_cast<SCOTCH_Num*>(adjncy),
513 Pout<<
"SCOTCH_dgraphCheck" <<
endl;
515 check(SCOTCH_dgraphCheck(&grafdat),
"SCOTCH_dgraphCheck");
527 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
529 List<label> processorWeights;
530 if (decompositionDict_.found(
"scotchCoeffs"))
532 const dictionary& scotchCoeffs =
533 decompositionDict_.subDict(
"scotchCoeffs");
535 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
537 if (processorWeights.size())
541 Info<<
"ptscotchDecomp : Using procesor weights " 547 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
559 SCOTCH_archCmplt(&archdat, nProcessors_),
567 int oldExcepts = fedisableexcept
577 finalDecomp.setSize(
max(1, xadjSize-1));
597 feenableexcept(oldExcepts);
620 SCOTCH_dgraphExit(&grafdat);
622 SCOTCH_stratExit(&stradat);
624 SCOTCH_archExit(&archdat);
632 Foam::ptscotchDecomp::ptscotchDecomp(
const dictionary& decompositionDict)
634 decompositionMethod(decompositionDict)
642 const polyMesh& mesh,
647 if (points.size() != mesh.nCells())
650 <<
"Can use this decomposition method only for the whole mesh" 652 <<
"and supply one coordinate (cellCentre) for every cell." << endl
653 <<
"The number of coordinates " << points.size() << endl
654 <<
"The number of cells in the mesh " << mesh.nCells()
664 CompactListList<label> cellCells;
675 List<label> finalDecomp;
678 mesh.time().path()/mesh.name(),
689 decomp[i] = finalDecomp[i];
697 const polyMesh& mesh,
703 if (agglom.size() != mesh.nCells())
706 <<
"Size of cell-to-coarse map " << agglom.size()
707 <<
" differs from number of cells in mesh " << mesh.nCells()
715 CompactListList<label> cellCells;
726 List<label> finalDecomp;
729 mesh.time().path()/mesh.name(),
737 labelList fineDistribution(agglom.size());
739 forAll(fineDistribution, i)
741 fineDistribution[i] = finalDecomp[agglom[i]];
744 return fineDistribution;
755 if (cellCentres.size() != globalCellCells.size())
758 <<
"Inconsistent number of cells (" << globalCellCells.size()
759 <<
") and number of cell centres (" << cellCentres.size()
768 CompactListList<label> cellCells(globalCellCells);
771 List<label> finalDecomp;
785 decomp[i] = finalDecomp[i];
virtual const fileName & name() const
Return the name of the stream.
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.
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.
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.
prefixOSstream Pout(cout, "Pout")
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)