119 #if defined(linux) || defined(linuxAMD64) || defined(linuxIA64)
123 #if defined(LINUX) && defined(__GNUC__)
151 void Foam::scotchDecomp::check(
const int retVal,
const char* str)
156 <<
"Call to scotch routine " << str <<
" failed."
163 Foam::label Foam::scotchDecomp::decompose
165 const List<int>& adjncy,
166 const List<int>& xadj,
169 List<int>& finalDecomp
173 if (decompositionDict_.found(
"scotchCoeffs"))
175 const dictionary& scotchCoeffs =
176 decompositionDict_.subDict(
"scotchCoeffs");
178 if (scotchCoeffs.found(
"writeGraph"))
180 Switch writeGraph(scotchCoeffs.lookup(
"writeGraph"));
184 OFstream str(mesh_.time().path() / mesh_.name() +
".grf");
186 Info<<
"Dumping Scotch graph file to " << str.name() <<
endl
187 <<
"Use this in combination with gpart." <<
endl;
190 str << version <<
nl;
192 str << xadj.size()-1 <<
' ' << adjncy.size() <<
nl;
196 label hasEdgeWeights = 0;
197 label hasVertexWeights = 0;
198 label numericflag = 10*hasEdgeWeights+hasVertexWeights;
199 str << baseval <<
' ' << numericflag <<
nl;
200 for (label cellI = 0; cellI < xadj.size()-1; cellI++)
202 label start = xadj[cellI];
203 label end = xadj[cellI+1];
206 for (label i = start; i < end; i++)
208 str <<
' ' << adjncy[i];
221 SCOTCH_Strat stradat;
222 check(SCOTCH_stratInit(&stradat),
"SCOTCH_stratInit");
224 if (decompositionDict_.found(
"scotchCoeffs"))
226 const dictionary& scotchCoeffs =
227 decompositionDict_.subDict(
"scotchCoeffs");
231 if (scotchCoeffs.readIfPresent(
"strategy", strategy))
235 Info<<
"scotchDecomp : Using strategy " << strategy <<
endl;
237 SCOTCH_stratGraphMap(&stradat, strategy.c_str());
252 scalar minWeights =
gMin(cWeights);
253 if (cWeights.size() > 0)
259 "scotchDecomp::decompose"
260 "(const pointField&, const scalarField&)"
261 ) <<
"Illegal minimum weight " << minWeights
265 if (cWeights.size() != xadj.size()-1)
269 "scotchDecomp::decompose"
270 "(const pointField&, const scalarField&)"
271 ) <<
"Number of cell weights " << cWeights.size()
272 <<
" does not equal number of cells " << xadj.size()-1
277 velotab.setSize(cWeights.size());
280 velotab[i] = int(cWeights[i]/minWeights);
286 SCOTCH_Graph grafdat;
287 check(SCOTCH_graphInit(&grafdat),
"SCOTCH_graphInit");
305 check(SCOTCH_graphCheck(&grafdat),
"SCOTCH_graphCheck");
313 check(SCOTCH_archInit(&archdat),
"SCOTCH_archInit");
315 List<label> processorWeights;
316 if (decompositionDict_.found(
"scotchCoeffs"))
318 const dictionary& scotchCoeffs =
319 decompositionDict_.subDict(
"scotchCoeffs");
321 scotchCoeffs.readIfPresent(
"processorWeights", processorWeights);
323 if (processorWeights.size())
327 Info<<
"scotchDecomp : Using procesor weights " << processorWeights
332 SCOTCH_archCmpltw(&archdat, nProcessors_, processorWeights.begin()),
340 SCOTCH_archCmplt(&archdat, nProcessors_),
354 int oldExcepts = fedisableexcept
362 finalDecomp.setSize(xadj.size()-1);
377 feenableexcept(oldExcepts);
396 SCOTCH_graphExit(&grafdat);
398 SCOTCH_stratExit(&stradat);
400 SCOTCH_archExit(&archdat);
408 Foam::scotchDecomp::scotchDecomp
427 if (points.
size() != mesh_.nCells())
431 "scotchDecomp::decompose(const pointField&, const scalarField&)"
433 <<
"Can use this decomposition method only for the whole mesh"
435 <<
"and supply one coordinate (cellCentre) for every cell." << endl
436 <<
"The number of coordinates " << points.
size() << endl
437 <<
"The number of cells in the mesh " << mesh_.nCells()
446 calcCSR(mesh_, adjncy, xadj);
450 decompose(adjncy, xadj, pointWeights, finalDecomp);
456 decomp[i] = finalDecomp[i];
469 if (agglom.
size() != mesh_.nCells())
473 "parMetisDecomp::decompose(const labelList&, const pointField&)"
474 ) <<
"Size of cell-to-coarse map " << agglom.
size()
475 <<
" differs from number of cells in mesh " << mesh_.nCells()
495 calcCSR(cellCells, adjncy, xadj);
500 decompose(adjncy, xadj, pointWeights, finalDecomp);
505 forAll(fineDistribution, i)
507 fineDistribution[i] = finalDecomp[agglom[i]];
510 return fineDistribution;
521 if (cellCentres.
size() != globalCellCells.
size())
525 "scotchDecomp::decompose"
526 "(const labelListList&, const pointField&, const scalarField&)"
527 ) <<
"Inconsistent number of cells (" << globalCellCells.
size()
528 <<
") and number of cell centres (" << cellCentres.
size()
539 calcCSR(globalCellCells, adjncy, xadj);
543 decompose(adjncy, xadj, cWeights, finalDecomp);
549 decomp[i] = finalDecomp[i];
578 if (isA<cyclicPolyPatch>(pbm[
patchi]))
586 adjncy.
setSize(nInternalFaces);
592 for (label cellI = 0; cellI < mesh.
nCells(); cellI++)
594 xadj[cellI] = freeAdj;
600 label faceI = cFaces[i];
605 || isA<cyclicPolyPatch>(pbm[pbm.
whichPatch(faceI)])
612 xadj[mesh.
nCells()] = freeAdj;
626 adjncy[xadj[own] + nFacesPerCell[own]++] = nei;
627 adjncy[xadj[nei] + nFacesPerCell[nei]++] = own;
633 if (isA<cyclicPolyPatch>(pbm[
patchi]))
637 label sizeby2 = faceCells.
size()/2;
639 for (label facei=0; facei<sizeby2; facei++)
641 label own = faceCells[facei];
642 label nei = faceCells[facei + sizeby2];
644 adjncy[xadj[own] + nFacesPerCell[own]++] = nei;
645 adjncy[xadj[nei] + nFacesPerCell[nei]++] = own;
661 label nConnections = 0;
663 forAll(cellCells, coarseI)
665 nConnections += cellCells[coarseI].
size();
679 forAll(cellCells, coarseI)
681 xadj[coarseI] = freeAdj;
683 const labelList& cCells = cellCells[coarseI];
687 adjncy[freeAdj++] = cCells[i];
690 xadj[cellCells.
size()] = freeAdj;