38 #pragma GCC diagnostic ignored "-Wold-style-cast"
56 sizeof(Foam::label) <=
sizeof(SCOTCH_Num),
57 "SCOTCH_Num is too small for Foam::label, check your scotch headers"
80 static inline void check(
const int retVal,
const char* what)
85 <<
"Call to scotch routine " << what
86 <<
" failed (" << retVal <<
")\n"
103 Foam::label Foam::ptscotchDecomp::decompose
107 const List<scalar>& cWeights,
111 const SCOTCH_Num numCells =
max(0, (xadj.size()-1));
114 ConstPrecisionAdaptor<SCOTCH_Num, label, List> adjncy_param(adjncy);
115 ConstPrecisionAdaptor<SCOTCH_Num, label, List> xadj_param(xadj);
118 decomp.resize(numCells);
120 PrecisionAdaptor<SCOTCH_Num, label, List> decomp_param(decomp,
false);
123 labelList adjncy_dummy, xadj_dummy, decomp_dummy;
126 adjncy_dummy.
resize(1, 0);
127 adjncy_param.set(adjncy_dummy);
129 xadj_dummy.resize(2, 0);
130 xadj_param.set(xadj_dummy);
132 decomp_dummy.resize(1, 0);
133 decomp_param.clear();
134 decomp_param.set(decomp_dummy);
140 Pout<<
"ptscotchDecomp : " << numCells <<
" cells" <<
endl;
151 Pout<<
"Dumping Scotch graph file to " << str.
name() <<
endl
152 <<
"Use this in combination with dgpart." <<
endl;
154 const label numConnect = adjncy.size();
155 const label nTotCells =
returnReduce(numCells, sumOp<label>());
156 const label nTotConnect =
returnReduce(numConnect, sumOp<label>());
166 str << nTotCells <<
' ' << nTotConnect <<
nl;
170 str << numCells <<
' ' << numConnect <<
nl;
174 str <<
"0 000" <<
nl;
176 for (label celli = 0; celli < numCells; ++celli)
178 const label beg = xadj[celli];
179 const label
end = xadj[celli+1];
183 for (label i = beg; i <
end; ++i)
185 str <<
' ' << adjncy[i];
193 SCOTCH_randomReset();
199 SCOTCH_Strat stradat;
202 SCOTCH_stratInit(&stradat),
210 <<
"ptscotchDecomp : Using strategy " << strategy <<
endl;
212 SCOTCH_stratDgraphMap(&stradat, strategy.c_str());
224 bool hasWeights =
returnReduce(!cWeights.empty(), orOp<bool>());
226 const scalar minWeights = hasWeights ?
gMin(cWeights) : scalar(1);
232 <<
"Illegal minimum weight " << minWeights
236 else if (hasWeights && (cWeights.size() != numCells))
239 <<
"Number of cell weights " << cWeights.size()
240 <<
" does not equal number of cells " << numCells
245 List<SCOTCH_Num> velotab;
249 scalar rangeScale(1);
251 const scalar velotabSum =
gSum(cWeights)/minWeights;
253 const scalar upperRange =
static_cast<scalar
>
258 if (velotabSum > upperRange)
262 rangeScale = 0.9*upperRange/velotabSum;
265 <<
"Sum of weights overflows SCOTCH_Num: " << velotabSum
266 <<
", compressing by factor " << rangeScale <<
endl;
272 velotab.resize(cWeights.size());
276 velotab[i] =
static_cast<SCOTCH_Num
>
278 ((cWeights[i]/minWeights - 1)*rangeScale) + 1
286 velotab.resize(1, 1);
299 SCOTCH_Dgraph grafdat;
302 SCOTCH_dgraphInit(&grafdat, MPI_COMM_WORLD),
308 Pout<<
"SCOTCH_dgraphBuild with:" <<
nl
309 <<
"numCells : " << numCells <<
nl
310 <<
"xadj : " <<
name(xadj_param().cdata()) <<
nl
311 <<
"velotab : " <<
name(velotab.cdata()) <<
nl
312 <<
"adjncySize : " << adjncy_param().size() <<
nl
313 <<
"adjncy : " <<
name(adjncy_param().cdata()) <<
nl
327 xadj_param.constCast().data(),
330 (xadj_param.constCast().data()+1),
338 adjncy_param.constCast().data(),
347 Pout<<
"SCOTCH_dgraphCheck" <<
endl;
351 SCOTCH_dgraphCheck(&grafdat),
367 SCOTCH_archInit(&archdat),
371 List<SCOTCH_Num> procWeights;
375 && !procWeights.empty()
381 <<
"processorWeights (" << procWeights.size()
382 <<
") != number of domains (" <<
nDomains_ <<
")" <<
nl
387 <<
"ptscotchDecomp : Using procesor weights "
388 << procWeights <<
endl;
392 SCOTCH_archCmpltw(&archdat,
nDomains_, procWeights.cdata()),
412 int oldExcepts = fedisableexcept
431 decomp_param.ref().data()
437 feenableexcept(oldExcepts);
457 SCOTCH_dgraphExit(&grafdat);
458 SCOTCH_stratExit(&stradat);
459 SCOTCH_archExit(&archdat);
467 Foam::ptscotchDecomp::ptscotchDecomp
469 const dictionary& decompDict,
474 coeffsDict_(findCoeffsDict(
"scotchCoeffs", selectionType::NULL_DICT))
482 const polyMesh&
mesh,
493 <<
"Can only use this decomposition method for entire mesh" <<
nl
494 <<
"and supply one coordinate (cellCentre) for every cell." <<
nl
495 <<
"The number of coordinates " <<
points.size() <<
nl
496 <<
"The number of cells in the mesh " <<
mesh.nCells() <<
nl
505 CompactListList<label> cellCells;
531 const polyMesh&
mesh,
543 <<
"Size of cell-to-coarse map " << agglom.size()
544 <<
" differs from number of cells in mesh " <<
mesh.
nCells()
552 CompactListList<label> cellCells;
573 labelList fineDistribution(agglom.size());
575 forAll(fineDistribution, i)
577 fineDistribution[i] = decomp[agglom[i]];
580 return fineDistribution;
592 graphPath_ =
"ptscotch";
594 if (cellCentres.size() != globalCellCells.size())
597 <<
"Inconsistent number of cells (" << globalCellCells.size()
598 <<
") and number of cell centres (" << cellCentres.size()
607 CompactListList<label> cellCells(globalCellCells);