Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
kmetis.c
Go to the documentation of this file.
1 /*
2  * Copyright 1997, Regents of the University of Minnesota
3  *
4  * kmetis.c
5  *
6  * This file contains the top level routines for the multilevel k-way partitioning
7  * algorithm KMETIS.
8  *
9  * Started 7/28/97
10  * George
11  *
12  * $Id: kmetis.c,v 1.1 1998/11/27 17:59:15 karypis Exp $
13  *
14  */
15 
16 #include <metis.h>
17 
18 
19 /*************************************************************************
20 * This function is the entry point for KMETIS
21 **************************************************************************/
22 void METIS_PartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
23  idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts,
24  int *options, int *edgecut, idxtype *part)
25 {
26  int i;
27  float *tpwgts;
28 
29  tpwgts = fmalloc(*nparts, "KMETIS: tpwgts");
30  for (i=0; i<*nparts; i++)
31  tpwgts[i] = 1.0/(1.0*(*nparts));
32 
33  METIS_WPartGraphKway(nvtxs, xadj, adjncy, vwgt, adjwgt, wgtflag, numflag, nparts,
34  tpwgts, options, edgecut, part);
35 
36  free(tpwgts);
37 }
38 
39 
40 /*************************************************************************
41 * This function is the entry point for KWMETIS
42 **************************************************************************/
43 void METIS_WPartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
44  idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts,
45  float *tpwgts, int *options, int *edgecut, idxtype *part)
46 {
47  int i, j;
49  CtrlType ctrl;
50 
51  if (*numflag == 1)
52  Change2CNumbering(*nvtxs, xadj, adjncy);
53 
54  SetUpGraph(&graph, OP_KMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag);
55 
56  if (options[0] == 0) { /* Use the default parameters */
57  ctrl.CType = KMETIS_CTYPE;
58  ctrl.IType = KMETIS_ITYPE;
59  ctrl.RType = KMETIS_RTYPE;
60  ctrl.dbglvl = KMETIS_DBGLVL;
61  }
62  else {
63  ctrl.CType = options[OPTION_CTYPE];
64  ctrl.IType = options[OPTION_ITYPE];
65  ctrl.RType = options[OPTION_RTYPE];
66  ctrl.dbglvl = options[OPTION_DBGLVL];
67  }
68  ctrl.optype = OP_KMETIS;
69  ctrl.CoarsenTo = amax((*nvtxs)/(40*log2_function(*nparts)), 20*(*nparts));
70  ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo);
71 
72  InitRandom(-1);
73 
74  AllocateWorkSpace(&ctrl, &graph, *nparts);
75 
76  IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
77  IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));
78 
79  *edgecut = MlevelKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03);
80 
81  IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
82  IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));
83 
84  FreeWorkSpace(&ctrl, &graph);
85 
86  if (*numflag == 1)
87  Change2FNumbering(*nvtxs, xadj, adjncy, part);
88 }
89 
90 
91 /*************************************************************************
92 * This function takes a graph and produces a bisection of it
93 **************************************************************************/
94 int MlevelKWayPartitioning(CtrlType *ctrl, GraphType *graph, int nparts, idxtype *part, float *tpwgts, float ubfactor)
95 {
96  int i, j, nvtxs, tvwgt, tpwgts2[2];
97  GraphType *cgraph;
98  int wgtflag=3, numflag=0, options[10], edgecut;
99 
100  cgraph = Coarsen2Way(ctrl, graph);
101 
102  IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr));
103  AllocateKWayPartitionMemory(ctrl, cgraph, nparts);
104 
105  options[0] = 1;
106  options[OPTION_CTYPE] = MATCH_SHEMKWAY;
107  options[OPTION_ITYPE] = IPART_GGPKL;
108  options[OPTION_RTYPE] = RTYPE_FM;
109  options[OPTION_DBGLVL] = 0;
110 
111  METIS_WPartGraphRecursive(&cgraph->nvtxs, cgraph->xadj, cgraph->adjncy, cgraph->vwgt,
112  cgraph->adjwgt, &wgtflag, &numflag, &nparts, tpwgts, options,
113  &edgecut, cgraph->where);
114 
115  IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr));
116  IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial %d-way partitioning cut: %d\n", nparts, edgecut));
117 
118  IFSET(ctrl->dbglvl, DBG_KWAYPINFO, ComputePartitionInfo(cgraph, nparts, cgraph->where));
119 
120  RefineKWay(ctrl, graph, cgraph, nparts, tpwgts, ubfactor);
121 
122  idxcopy(graph->nvtxs, graph->where, part);
123 
124  GKfree(&graph->gdata, &graph->rdata, LTERM);
125 
126  return graph->mincut;
127 
128 }
129 
#define KMETIS_RTYPE
Definition: defs.h:51
void METIS_WPartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part)
Definition: kmetis.c:43
timer TotalTmr
Definition: struct.h:230
#define log2_function
Definition: rename.h:414
int optype
Definition: struct.h:222
#define SetUpGraph
Definition: rename.h:72
#define fmalloc
Definition: rename.h:384
#define KMETIS_ITYPE
Definition: defs.h:50
#define OPTION_CTYPE
Definition: defs.h:30
#define Coarsen2Way
Definition: rename.h:34
int IType
Definition: struct.h:218
int mincut
Definition: struct.h:175
idxtype * rdata
Definition: struct.h:157
#define AllocateKWayPartitionMemory
Definition: rename.h:107
#define ComputePartitionInfo
Definition: rename.h:356
#define IPART_GGPKL
Definition: defs.h:108
#define idxsum
Definition: rename.h:399
#define stoptimer(tmr)
Definition: macros.h:54
HitTile_Vector graph
int CType
Definition: struct.h:217
idxtype * where
Definition: struct.h:176
#define LTERM
Definition: defs.h:18
int idxtype
Definition: struct.h:19
#define InitRandom
Definition: rename.h:412
#define AllocateWorkSpace
Definition: rename.h:161
#define IFSET(a, flag, cmd)
Definition: macros.h:61
int dbglvl
Definition: struct.h:216
#define InitTimers
Definition: rename.h:373
void METIS_WPartGraphRecursive(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, float *tpwgts, int *options, int *edgecut, idxtype *part)
Definition: pmetis.c:45
#define Change2CNumbering
Definition: rename.h:62
#define DBG_IPART
Definition: defs.h:158
#define OPTION_RTYPE
Definition: defs.h:32
#define KMETIS_DBGLVL
Definition: defs.h:52
#define RTYPE_FM
Definition: defs.h:113
idxtype * adjwgt
Definition: struct.h:166
#define idxcopy(n, a, b)
Definition: macros.h:44
void METIS_PartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, int *options, int *edgecut, idxtype *part)
Definition: kmetis.c:22
#define DBG_KWAYPINFO
Definition: defs.h:160
int CoarsenTo
Definition: struct.h:215
#define MATCH_SHEMKWAY
Definition: defs.h:101
void GKfree(void **ptr1,...)
Definition: util.c:121
#define amax(a, b)
Definition: macros.h:29
#define OP_KMETIS
Definition: defs.h:90
timer InitPartTmr
Definition: struct.h:230
#define PrintTimers
Definition: rename.h:374
#define FreeWorkSpace
Definition: rename.h:162
#define KMETIS_CTYPE
Definition: defs.h:49
idxtype * vwgt
Definition: struct.h:163
#define DBG_TIME
Definition: defs.h:154
int RType
Definition: struct.h:219
idxtype * gdata
Definition: struct.h:157
int maxvwgt
Definition: struct.h:220
#define OPTION_ITYPE
Definition: defs.h:31
#define MlevelKWayPartitioning
Definition: rename.h:92
int nvtxs
Definition: struct.h:161
#define RefineKWay
Definition: rename.h:106
idxtype * adjncy
Definition: struct.h:165
idxtype * xadj
Definition: struct.h:162
#define Change2FNumbering
Definition: rename.h:63
#define OPTION_DBGLVL
Definition: defs.h:33
#define starttimer(tmr)
Definition: macros.h:53