/
Bisect.c
98 lines (76 loc) · 2.23 KB
/
Bisect.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright 1997, Regents of the University of Minnesota
* Modified by Jack Poulson, 2012
*/
#include "metislib.h"
void CliqOrder( ctrl_t *ctrl, graph_t *graph, idx_t *order, idx_t *sizes )
{
idx_t i, nvtxs;
idx_t offs[3];
idx_t *where;
nvtxs = graph->nvtxs;
MlevelNodeBisectionMultiple(ctrl, graph);
IFSET(ctrl->dbglvl, METIS_DBG_SEPINFO,
printf("Nvtxs: %6"PRIDX", [%6"PRIDX" %6"PRIDX" %6"PRIDX"]\n",
graph->nvtxs, graph->pwgts[0], graph->pwgts[1], graph->pwgts[2]));
/* Order the vertices */
where = graph->where;
sizes[0] = graph->pwgts[0];
sizes[1] = graph->pwgts[1];
sizes[2] = graph->pwgts[2];
offs[0] = 0;
offs[1] = sizes[0];
offs[2] = sizes[0]+sizes[1];
for( i=0; i<nvtxs; ++i )
order[i] = offs[where[i]]++;
FreeGraph(&graph);
}
/* TODO: Better error-handling */
void CliqBisect
( idx_t *nvtxs, idx_t *xadj, idx_t *adjncy,
idx_t *numSeps, real_t *imbalance, idx_t *order, idx_t *sizes )
{
int sigrval=0;
idx_t options[METIS_NOPTIONS];
graph_t *graph=NULL;
ctrl_t *ctrl;
if( *nvtxs == 0 )
{
sizes[0] = 0;
sizes[1] = 0;
sizes[2] = 0;
return;
}
/* set up malloc cleaning code and signal catchers */
if( !gk_malloc_init() )
return;
gk_sigtrap();
if( (sigrval = gk_sigcatch()) != 0 )
goto SIGTHROW;
/* set up the run time parameters */
METIS_SetDefaultOptions(options);
options[METIS_OPTION_COMPRESS] = 0;
options[METIS_OPTION_NSEPS] = *numSeps;
options[METIS_OPTION_UFACTOR] = (int)((*imbalance-1)*1000);
ctrl = SetupCtrl(METIS_OP_OMETIS, options, 1, 3, NULL, NULL);
if (!ctrl) {
gk_siguntrap();
return;
}
IFSET(ctrl->dbglvl, METIS_DBG_TIME, InitTimers(ctrl));
IFSET(ctrl->dbglvl, METIS_DBG_TIME, gk_startcputimer(ctrl->TotalTmr));
graph = SetupGraph(ctrl, *nvtxs, 1, xadj, adjncy, NULL, NULL, NULL);
ASSERT(CheckGraph(graph, 0, 1));
/* allocate workspace memory */
AllocateWorkSpace(ctrl, graph);
/* compute the bisection ordering */
CliqOrder( ctrl, graph, order, sizes );
IFSET(ctrl->dbglvl, METIS_DBG_TIME, gk_stopcputimer(ctrl->TotalTmr));
IFSET(ctrl->dbglvl, METIS_DBG_TIME, PrintTimers(ctrl));
/* clean up */
FreeCtrl(&ctrl);
SIGTHROW:
gk_siguntrap();
gk_malloc_cleanup(0);
return;
}