2
* Copyright 1997, Regents of the University of Minnesota
6
* This file contains the top level routines for the multilevel k-way partitioning
12
* $Id: kvmetis.c,v 1.1 2005/05/17 10:21:40 vierinen Exp $
19
/*************************************************************************
20
* This function is the entry point for KMETIS
21
**************************************************************************/
22
void METIS_PartGraphVKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
23
idxtype *vsize, int *wgtflag, int *numflag, int *nparts,
24
int *options, int *volume, idxtype *part)
29
tpwgts = fmalloc(*nparts, "KMETIS: tpwgts");
30
for (i=0; i<*nparts; i++)
31
tpwgts[i] = 1.0/(1.0*(*nparts));
33
METIS_WPartGraphVKway(nvtxs, xadj, adjncy, vwgt, vsize, wgtflag, numflag, nparts,
34
tpwgts, options, volume, part);
40
/*************************************************************************
41
* This function is the entry point for KWMETIS
42
**************************************************************************/
43
void METIS_WPartGraphVKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
44
idxtype *vsize, int *wgtflag, int *numflag, int *nparts,
45
float *tpwgts, int *options, int *volume, idxtype *part)
52
Change2CNumbering(*nvtxs, xadj, adjncy);
54
VolSetUpGraph(&graph, OP_KVMETIS, *nvtxs, 1, xadj, adjncy, vwgt, vsize, *wgtflag);
56
if (options[0] == 0) { /* Use the default parameters */
57
ctrl.CType = KVMETIS_CTYPE;
58
ctrl.IType = KVMETIS_ITYPE;
59
ctrl.RType = KVMETIS_RTYPE;
60
ctrl.dbglvl = KVMETIS_DBGLVL;
63
ctrl.CType = options[OPTION_CTYPE];
64
ctrl.IType = options[OPTION_ITYPE];
65
ctrl.RType = options[OPTION_RTYPE];
66
ctrl.dbglvl = options[OPTION_DBGLVL];
68
ctrl.optype = OP_KVMETIS;
69
ctrl.CoarsenTo = amax((*nvtxs)/(40*log2int(*nparts)), 20*(*nparts));
70
ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo);
74
AllocateWorkSpace(&ctrl, &graph, *nparts);
76
IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
77
IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));
79
*volume = MlevelVolKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03);
81
IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
82
IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));
84
FreeWorkSpace(&ctrl, &graph);
87
Change2FNumbering(*nvtxs, xadj, adjncy, part);
91
/*************************************************************************
92
* This function takes a graph and produces a bisection of it
93
**************************************************************************/
94
int MlevelVolKWayPartitioning(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part,
95
float *tpwgts, float ubfactor)
97
int i, j, nvtxs, tvwgt, tpwgts2[2];
99
int wgtflag=3, numflag=0, options[10], edgecut;
101
cgraph = Coarsen2Way(ctrl, graph);
103
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr));
104
AllocateVolKWayPartitionMemory(ctrl, cgraph, nparts);
107
options[OPTION_CTYPE] = MATCH_SHEMKWAY;
108
options[OPTION_ITYPE] = IPART_GGPKL;
109
options[OPTION_RTYPE] = RTYPE_FM;
110
options[OPTION_DBGLVL] = 0;
112
METIS_WPartGraphRecursive(&cgraph->nvtxs, cgraph->xadj, cgraph->adjncy, cgraph->vwgt,
113
cgraph->adjwgt, &wgtflag, &numflag, &nparts, tpwgts, options,
114
&edgecut, cgraph->where);
116
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr));
117
IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial %d-way partitioning cut: %d\n", nparts, edgecut));
119
IFSET(ctrl->dbglvl, DBG_KWAYPINFO, ComputePartitionInfo(cgraph, nparts, cgraph->where));
121
RefineVolKWay(ctrl, graph, cgraph, nparts, tpwgts, ubfactor);
123
idxcopy(graph->nvtxs, graph->where, part);
125
GKfree(&graph->gdata, &graph->rdata, LTERM);
127
return graph->minvol;