37 #pragma GCC diagnostic ignored "-Wold-style-cast"
55 sizeof(Foam::label) ==
sizeof(SCOTCH_Num),
56 "sizeof(Foam::label) == sizeof(SCOTCH_Num), check your scotch headers"
83 void Foam::ptscotchDecomp::graphPath(
const polyMesh&
mesh)
const
85 graphPath_ =
mesh.time().path()/
mesh.name();
89 void Foam::ptscotchDecomp::check(
const int retVal,
const char* str)
94 <<
"Call to scotch routine " << str <<
" failed.\n"
289 Foam::label Foam::ptscotchDecomp::decompose
293 const List<scalar>& cWeights,
297 List<label> dummyAdjncy;
298 List<label> dummyXadj;
303 (adjncy.size() ? adjncy.begin() : dummyAdjncy.begin()),
305 (xadj.size() ? xadj.begin() : dummyXadj.begin()),
312 Foam::label Foam::ptscotchDecomp::decompose
314 const label adjncySize,
315 const label adjncy[],
316 const label xadjSize,
318 const List<scalar>& cWeights,
324 Pout<<
"ptscotchDecomp : entering with xadj:" << xadjSize <<
endl;
328 if (coeffsDict_.getOrDefault(
"writeGraph",
false))
335 Pout<<
"Dumping Scotch graph file to " << str.
name() <<
endl
336 <<
"Use this in combination with dgpart." <<
endl;
338 globalIndex globalCells(xadjSize-1);
349 str << globalCells.size();
351 str <<
' ' <<
returnReduce(xadj[xadjSize-1], sumOp<label>()) <<
nl;
355 str <<
' ' << xadj[xadjSize-1] <<
nl;
359 str << baseval <<
' ' <<
"000" <<
nl;
360 for (label celli = 0; celli < xadjSize-1; celli++)
362 const label start = xadj[celli];
363 const label
end = xadj[celli+1];
367 for (label i = start; i <
end; i++)
369 str <<
' ' << adjncy[i];
377 SCOTCH_randomReset();
383 SCOTCH_Strat stradat;
384 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
387 if (coeffsDict_.readIfPresent(
"strategy", strategy))
391 Info<<
"ptscotchDecomp : Using strategy " << strategy <<
endl;
393 SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
407 const scalar minWeights =
gMin(cWeights);
408 const scalar maxWeights =
gMax(cWeights);
410 if (maxWeights > minWeights)
415 <<
"Illegal minimum weight " << minWeights
419 if (cWeights.size() != xadjSize-1)
422 <<
"Number of cell weights " << cWeights.size()
423 <<
" does not equal number of cells " << xadjSize-1
428 scalar velotabSum =
gSum(cWeights)/minWeights;
430 scalar rangeScale(1.0);
434 if (velotabSum > scalar(
labelMax - 1))
438 rangeScale = 0.9*scalar(
labelMax - 1)/velotabSum;
441 <<
"Sum of weights has overflowed integer: " << velotabSum
442 <<
", compressing weight scale by a factor of " << rangeScale
449 if (maxWeights > minWeights)
454 velotab.setSize(cWeights.size());
458 velotab[i] = int((cWeights[i]/minWeights - 1)*rangeScale) + 1;
476 SCOTCH_Dgraph grafdat;
477 check(SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD),
"SCOTCH_dgraphInit");
482 Pout<<
"SCOTCH_dgraphBuild with:" <<
nl
483 <<
"xadjSize-1 : " << xadjSize-1 <<
nl
484 <<
"xadj : " <<
name(xadj) <<
nl
485 <<
"velotab : " <<
name(velotab.begin()) <<
nl
486 <<
"adjncySize : " << adjncySize <<
nl
487 <<
"adjncy : " <<
name(adjncy) <<
nl
499 const_cast<SCOTCH_Num*
>(xadj),
502 const_cast<SCOTCH_Num*
>(xadj+1),
504 const_cast<SCOTCH_Num*
>(velotab.begin()),
509 const_cast<SCOTCH_Num*
>(adjncy),
519 Pout<<
"SCOTCH_dgraphCheck" <<
endl;
521 check(SCOTCH_dgraphCheck(&grafdat),
"SCOTCH_dgraphCheck");
533 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
535 List<label> processorWeights;
538 coeffsDict_.readIfPresent(
"processorWeights", processorWeights)
539 && processorWeights.size()
544 Info<<
"ptscotchDecomp : Using procesor weights "
549 if (processorWeights.size() != nDomains_)
552 <<
"processorWeights not the same size"
553 <<
" as the wanted number of domains " << nDomains_
561 &archdat, nDomains_, processorWeights.begin()
574 SCOTCH_archCmplt(&archdat, nDomains_),
582 int oldExcepts = fedisableexcept
592 finalDecomp.setSize(
max(1, xadjSize-1));
612 feenableexcept(oldExcepts);
616 finalDecomp.setSize(xadjSize-1);
635 SCOTCH_dgraphExit(&grafdat);
637 SCOTCH_stratExit(&stradat);
639 SCOTCH_archExit(&archdat);
647 Foam::ptscotchDecomp::ptscotchDecomp(
const dictionary& decompDict)
649 decompositionMethod(decompDict),
650 coeffsDict_(findCoeffsDict(
"scotchCoeffs", selectionType::NULL_DICT))
654 Foam::ptscotchDecomp::ptscotchDecomp
656 const dictionary& decompDict,
661 coeffsDict_(findCoeffsDict(
"scotchCoeffs", selectionType::NULL_DICT))
669 const polyMesh&
mesh,
680 <<
"Can use this decomposition method only for the whole mesh"
682 <<
"and supply one coordinate (cellCentre) for every cell." <<
endl
683 <<
"The number of coordinates " <<
points.size() <<
endl
684 <<
"The number of cells in the mesh " <<
mesh.
nCells()
693 CompactListList<label> cellCells;
719 const polyMesh&
mesh,
731 <<
"Size of cell-to-coarse map " << agglom.size()
732 <<
" differs from number of cells in mesh " <<
mesh.
nCells()
740 CompactListList<label> cellCells;
761 labelList fineDistribution(agglom.size());
763 forAll(fineDistribution, i)
765 fineDistribution[i] = decomp[agglom[i]];
768 return fineDistribution;
780 graphPath_ =
"ptscotch";
782 if (cellCentres.size() != globalCellCells.size())
785 <<
"Inconsistent number of cells (" << globalCellCells.size()
786 <<
") and number of cell centres (" << cellCentres.size()
795 CompactListList<label> cellCells(globalCellCells);