10
using namespace dolfin;
12
void metisKwayPartitioning(Graph& graph, int num_part, idxtype* vtx_part)
15
int num_vertices = graph.numVertices();
20
// This results in segfault
21
//idxtype* adjncy = reinterpret_cast<idxtype*>(graph.connectivity());
22
//idxtype* xadj = reinterpret_cast<idxtype*>(graph.offsets() + 1);
24
// Copying values instead (time to copy << time to partitioning)
25
idxtype* adjncy = new idxtype[graph.numArches()];
26
idxtype* xadj = new idxtype[graph.numVertices() + 1];
27
for(unsigned int i=0; i<graph.numArches(); ++i)
28
adjncy[i] = graph.connectivity()[i];
29
for(unsigned int i=0; i<=graph.numVertices(); ++i)
30
xadj[i] = graph.offsets()[i];
33
METIS_PartGraphKway(&num_vertices, xadj, adjncy, NULL, NULL, &wgtflag, &pnumflag, &num_part, options, &edgecut, vtx_part);
36
void metisRecursivePartitioning(Graph& graph, int num_part, int* vtx_part)
39
int num_vertices = graph.numVertices();
44
// This results in segfault
45
//idxtype* adjncy = reinterpret_cast<idxtype*>(graph.connectivity());
46
//idxtype* xadj = reinterpret_cast<idxtype*>(graph.offsets() + 1);
48
// Copying values instead (time to copy << time to partitioning)
49
idxtype* adjncy = new idxtype[graph.numArches()];
50
idxtype* xadj = new idxtype[graph.numVertices() + 1];
51
for(unsigned int i=0; i<graph.numArches(); ++i)
52
adjncy[i] = graph.connectivity()[i];
53
for(unsigned int i=0; i<=graph.numVertices(); ++i)
54
xadj[i] = graph.offsets()[i];
57
METIS_PartGraphRecursive(&num_vertices, xadj, adjncy, NULL, NULL, &wgtflag, &pnumflag, &num_part, options, &edgecut, vtx_part);
60
void scotchPartitioning(Graph& graph, int num_part, int* vtx_part)
65
if (SCOTCH_graphInit (&grafdat) != 0) {
66
std::cerr << "Error in SCOTCH_graphInit. Exiting" << std::endl;
69
if (SCOTCH_graphBuild (&grafdat, 0, static_cast<int>(graph.numVertices()), reinterpret_cast<int*>(graph.offsets()), NULL, NULL, NULL, static_cast<int>(graph.numArches()), reinterpret_cast<int*>(graph.connectivity()), NULL) != 0) {
70
std::cerr << "Error in SCOTCH_graphBuild. Exiting" << std::endl;
74
SCOTCH_stratInit(&strat);
77
if (SCOTCH_stratGraphBipart (&strat, "b{job=t,map=t,poli=S,strat=m{type=h,vert=80,low=h{pass=10}f{bal=0.0005,move=80},asc=b{bnd=d{dif=1,rem=1,pass=40}f{bal=0.005,move=80},org=f{bal=0.005,move=80}}}|m{type=h,vert=80,low=h{pass=10}f{bal=0.0005,move=80},asc=b{bnd=d{dif=1,rem=1,pass=40}f{bal=0.005,move=80},org=f{bal=0.005,move=80}}}}")) {
81
if (SCOTCH_graphPart (&grafdat, num_part, &strat, vtx_part) != 0) {
82
std::cerr << "Error in SCOTCH_graphPart. Exiting" << std::endl;
86
SCOTCH_stratExit (&strat);
87
SCOTCH_graphExit (&grafdat);