2
* Copyright 1997, Regents of the University of Minnesota
6
* This file contains the driving routines for multilevel refinement
11
* $Id: mrefine.c,v 1.1 2005/05/17 10:21:56 vierinen Exp $
17
/*************************************************************************
18
* This function is the entry point of refinement
19
**************************************************************************/
20
void MocRefine2Way(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, float ubfactor)
23
float tubvec[MAXNCON];
25
for (i=0; i<graph->ncon; i++)
28
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr));
30
/* Compute the parameters of the coarsest graph */
31
MocCompute2WayPartitionParams(ctrl, graph);
34
ASSERT(CheckBnd(graph));
36
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr));
37
switch (ctrl->RType) {
39
MocBalance2Way(ctrl, graph, tpwgts, 1.03);
40
MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8);
43
MocBalance2Way(ctrl, graph, tpwgts, 1.03);
44
MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, tubvec, 8);
47
errexit("Unknown refinement type: %d\n", ctrl->RType);
49
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr));
51
if (graph == orggraph)
55
IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr));
56
MocProject2WayPartition(ctrl, graph);
57
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr));
60
MocBalance2Way(ctrl, graph, tpwgts, 1.01);
61
MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8);
63
IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr));
67
/*************************************************************************
68
* This function allocates memory for 2-way edge refinement
69
**************************************************************************/
70
void MocAllocate2WayPartitionMemory(CtrlType *ctrl, GraphType *graph)
77
graph->rdata = idxmalloc(5*nvtxs, "Allocate2WayPartitionMemory: rdata");
78
graph->where = graph->rdata;
79
graph->id = graph->rdata + nvtxs;
80
graph->ed = graph->rdata + 2*nvtxs;
81
graph->bndptr = graph->rdata + 3*nvtxs;
82
graph->bndind = graph->rdata + 4*nvtxs;
84
graph->npwgts = fmalloc(2*ncon, "npwgts");
88
/*************************************************************************
89
* This function computes the initial id/ed
90
**************************************************************************/
91
void MocCompute2WayPartitionParams(CtrlType *ctrl, GraphType *graph)
93
int i, j, k, l, nvtxs, ncon, nbnd, mincut;
94
idxtype *xadj, *adjncy, *adjwgt;
95
float *nvwgt, *npwgts;
96
idxtype *id, *ed, *where;
97
idxtype *bndptr, *bndind;
100
nvtxs = graph->nvtxs;
103
nvwgt = graph->nvwgt;
104
adjncy = graph->adjncy;
105
adjwgt = graph->adjwgt;
107
where = graph->where;
108
npwgts = sset(2*ncon, 0.0, graph->npwgts);
109
id = idxset(nvtxs, 0, graph->id);
110
ed = idxset(nvtxs, 0, graph->ed);
111
bndptr = idxset(nvtxs, -1, graph->bndptr);
112
bndind = graph->bndind;
115
/*------------------------------------------------------------
116
/ Compute now the id/ed degrees
117
/------------------------------------------------------------*/
119
for (i=0; i<nvtxs; i++) {
120
ASSERT(where[i] >= 0 && where[i] <= 1);
122
saxpy(ncon, 1.0, nvwgt+i*ncon, 1, npwgts+me*ncon, 1);
124
for (j=xadj[i]; j<xadj[i+1]; j++) {
125
if (me == where[adjncy[j]])
131
if (ed[i] > 0 || xadj[i] == xadj[i+1]) {
138
graph->mincut = mincut/2;
145
/*************************************************************************
146
* This function projects a partition, and at the same time computes the
147
* parameters for refinement.
148
**************************************************************************/
149
void MocProject2WayPartition(CtrlType *ctrl, GraphType *graph)
151
int i, j, k, nvtxs, nbnd, me;
152
idxtype *xadj, *adjncy, *adjwgt, *adjwgtsum;
153
idxtype *cmap, *where, *id, *ed, *bndptr, *bndind;
154
idxtype *cwhere, *cid, *ced, *cbndptr;
157
cgraph = graph->coarser;
158
cwhere = cgraph->where;
161
cbndptr = cgraph->bndptr;
163
nvtxs = graph->nvtxs;
166
adjncy = graph->adjncy;
167
adjwgt = graph->adjwgt;
168
adjwgtsum = graph->adjwgtsum;
170
MocAllocate2WayPartitionMemory(ctrl, graph);
172
where = graph->where;
173
id = idxset(nvtxs, 0, graph->id);
174
ed = idxset(nvtxs, 0, graph->ed);
175
bndptr = idxset(nvtxs, -1, graph->bndptr);
176
bndind = graph->bndind;
179
/* Go through and project partition and compute id/ed for the nodes */
180
for (i=0; i<nvtxs; i++) {
182
where[i] = cwhere[k];
183
cmap[i] = cbndptr[k];
186
for (nbnd=0, i=0; i<nvtxs; i++) {
189
id[i] = adjwgtsum[i];
191
if (xadj[i] == xadj[i+1]) {
196
if (cmap[i] != -1) { /* If it is an interface node. Note that cmap[i] = cbndptr[cmap[i]] */
197
for (j=xadj[i]; j<xadj[i+1]; j++) {
198
if (me != where[adjncy[j]])
203
if (ed[i] > 0 || xadj[i] == xadj[i+1]) {
211
graph->mincut = cgraph->mincut;
213
scopy(2*graph->ncon, cgraph->npwgts, graph->npwgts);
215
FreeGraph(graph->coarser);
216
graph->coarser = NULL;