ENH: use PrecisionAdaptor in kahipDecomp

This commit is contained in:
Mark Olesen
2019-10-29 11:42:55 +01:00
committed by Andrew Heather
parent 328513fcaa
commit fd4ffc8a27
3 changed files with 30 additions and 71 deletions

View File

@ -26,6 +26,7 @@ License
#include "kahipDecomp.H" #include "kahipDecomp.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "Time.H" #include "Time.H"
#include "PrecisionAdaptor.H"
#include "kaHIP_interface.h" #include "kaHIP_interface.h"
@ -33,6 +34,9 @@ License
#include <map> #include <map>
#include <vector> #include <vector>
// Provide a clear error message if we have a severe size mismatch
// Allow widening, but not narrowing
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -217,59 +221,30 @@ Foam::label Foam::kahipDecomp::decomposeSerial
// Output: number of cut edges // Output: number of cut edges
int edgeCut = 0; int edgeCut = 0;
#if WM_LABEL_SIZE == 32 // Addressing
ConstPrecisionAdaptor<int, label, List> xadj_param(xadj);
// Input: ConstPrecisionAdaptor<int, label, List> adjncy_param(adjncy);
int* xadjPtr = const_cast<int*>(xadj.begin());
int* adjncyPtr = const_cast<int*>(adjncy.begin());
// Output: cell -> processor addressing // Output: cell -> processor addressing
decomp.setSize(numCells); decomp.resize(numCells);
int* decompPtr = decomp.begin(); PrecisionAdaptor<int, label, List> decomp_param(decomp);
#elif WM_LABEL_SIZE == 64
// input (copy)
List<int> xadjCopy(xadj.size());
List<int> adjncyCopy(adjncy.size());
forAll(xadj,i)
{
xadjCopy[i] = xadj[i];
}
forAll(adjncy,i)
{
adjncyCopy[i] = adjncy[i];
}
int* xadjPtr = xadjCopy.begin();
int* adjncyPtr = adjncyCopy.begin();
if (decomp.size() != numCells)
{
decomp.clear();
}
// Output: cell -> processor addressing
List<int> decompCopy(numCells);
int* decompPtr = decompCopy.begin();
#endif
#if 0 // WIP: #ifdef KAFFPA_CPP_INTERFACE #if 0 // WIP: #ifdef KAFFPA_CPP_INTERFACE
kaffpa_cpp kaffpa_cpp
( (
&numCells, // num vertices in graph &numCells, // num vertices in graph
(cellWeights.size() ? cellWeights.begin() : nullptr), // vertex wts (cellWeights.size() ? cellWeights.begin() : nullptr), // vertex wts
xadjPtr, // indexing into adjncy xadj_param.constCast().data(), // indexing into adjncy
nullptr, // edge wts nullptr, // edge wts
adjncyPtr, // neighbour info adjncy_param.constCast().data(), // neighbour info
&nParts, // nparts &nParts, // nparts
&imbalance, // amount of imbalance allowed &imbalance, // amount of imbalance allowed
!verbose, // suppress output !verbose, // suppress output
seed, // for random seed, // for random
int(kahipConfig), int(kahipConfig),
&edgeCut, // [output] &edgeCut, // [output]
decompPtr, // [output] decomp_param.ref().data(), // [output]
sizingParams sizingParams
); );
#else #else
@ -277,35 +252,19 @@ Foam::label Foam::kahipDecomp::decomposeSerial
( (
&numCells, // num vertices in graph &numCells, // num vertices in graph
(cellWeights.size() ? cellWeights.begin() : nullptr), // vertex wts (cellWeights.size() ? cellWeights.begin() : nullptr), // vertex wts
xadjPtr, // indexing into adjncy xadj_param.constCast().data(), // indexing into adjncy
nullptr, // edge wts nullptr, // edge wts
adjncyPtr, // neighbour info adjncy_param.constCast().data(), // neighbour info
&nParts, // nparts &nParts, // nparts
&imbalance, // amount of imbalance allowed &imbalance, // amount of imbalance allowed
!verbose, // suppress output !verbose, // suppress output
seed, // for random seed, // for random
int(kahipConfig), int(kahipConfig),
&edgeCut, // [output] &edgeCut, // [output]
decompPtr // [output] decomp_param.ref().data() // [output]
); );
#endif #endif
#if WM_LABEL_SIZE == 64
// Drop input copy
xadjCopy.clear();
adjncyCopy.clear();
// Copy back to List<label>
decomp.setSize(numCells);
forAll(decompCopy, i)
{
decomp[i] = decompCopy[i];
}
decompCopy.clear();
#endif
return edgeCut; return edgeCut;
} }

View File

@ -190,12 +190,12 @@ Foam::label Foam::metisDecomp::decomposeSerial
idx_t nProcs = nDomains_; idx_t nProcs = nDomains_;
// Addressing // Addressing
ConstPrecisionAdaptor<idx_t, label, List> xadj_metis(xadj); ConstPrecisionAdaptor<idx_t, label, List> xadj_param(xadj);
ConstPrecisionAdaptor<idx_t, label, List> adjncy_metis(adjncy); ConstPrecisionAdaptor<idx_t, label, List> adjncy_param(adjncy);
// Output: cell -> processor addressing // Output: cell -> processor addressing
PrecisionAdaptor<idx_t, label, List> decomp_metis(decomp); decomp.resize(numCells);
decomp_metis.ref().setSize(numCells); PrecisionAdaptor<idx_t, label, List> decomp_param(decomp);
// Output: number of cut edges // Output: number of cut edges
idx_t edgeCut = 0; idx_t edgeCut = 0;
@ -206,8 +206,8 @@ Foam::label Foam::metisDecomp::decomposeSerial
( (
&numCells, // num vertices in graph &numCells, // num vertices in graph
&ncon, // num balancing constraints &ncon, // num balancing constraints
xadj_metis.ref().data(), // indexing into adjncy xadj_param.constCast().data(), // indexing into adjncy
adjncy_metis.ref().data(), // neighbour info adjncy_param.constCast().data(), // neighbour info
cellWeights.data(), // vertex wts cellWeights.data(), // vertex wts
nullptr, // vsize: total communication vol nullptr, // vsize: total communication vol
faceWeights.data(), // edge wts faceWeights.data(), // edge wts
@ -216,7 +216,7 @@ Foam::label Foam::metisDecomp::decomposeSerial
nullptr, // ubvec: processor imbalance (default) nullptr, // ubvec: processor imbalance (default)
options.data(), options.data(),
&edgeCut, &edgeCut,
decomp_metis.ref().data() decomp_param.ref().data()
); );
} }
else else
@ -225,8 +225,8 @@ Foam::label Foam::metisDecomp::decomposeSerial
( (
&numCells, // num vertices in graph &numCells, // num vertices in graph
&ncon, // num balancing constraints &ncon, // num balancing constraints
xadj_metis.ref().data(), // indexing into adjncy xadj_param.constCast().data(), // indexing into adjncy
adjncy_metis.ref().data(), // neighbour info adjncy_param.constCast().data(), // neighbour info
cellWeights.data(), // vertex wts cellWeights.data(), // vertex wts
nullptr, // vsize: total communication vol nullptr, // vsize: total communication vol
faceWeights.data(), // edge wts faceWeights.data(), // edge wts
@ -235,7 +235,7 @@ Foam::label Foam::metisDecomp::decomposeSerial
nullptr, // ubvec: processor imbalance (default) nullptr, // ubvec: processor imbalance (default)
options.data(), options.data(),
&edgeCut, &edgeCut,
decomp_metis.ref().data() decomp_param.ref().data()
); );
} }

View File

@ -127,10 +127,10 @@ Foam::label Foam::scotchDecomp::decomposeSerial
const label numericflag = 10*hasEdgeWeights+hasVertexWeights; const label numericflag = 10*hasEdgeWeights+hasVertexWeights;
str << baseval << ' ' << numericflag << nl; str << baseval << ' ' << numericflag << nl;
for (label celli = 0; celli < xadj.size()-1; ++celli) for (label celli = 1; celli < xadj.size(); ++celli)
{ {
const label start = xadj[celli]; const label start = xadj[celli-1];
const label end = xadj[celli+1]; const label end = xadj[celli];
str << end-start; // size str << end-start; // size