| 1 |
/* |
| 2 |
\file |
| 3 |
\brief This file contains the driving routines for multilevel refinement |
| 4 |
|
| 5 |
\date Started 7/24/1997 |
| 6 |
\author George |
| 7 |
\author Copyright 1997-2009, Regents of the University of Minnesota |
| 8 |
\version\verbatim $Id: refine.c 14362 2013-05-21 21:35:23Z karypis $ \endverbatim |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "metislib.h" |
| 12 |
|
| 13 |
|
| 14 |
/*************************************************************************/ |
| 15 |
/*! This function allocates memory for 2-way edge refinement */ |
| 16 |
/*************************************************************************/ |
| 17 |
void Allocate2WayPartitionMemory(ctrl_t *ctrl, graph_t *graph) |
| 18 |
{ |
| 19 |
idx_t nvtxs, ncon; |
| 20 |
|
| 21 |
nvtxs = graph->nvtxs; |
| 22 |
ncon = graph->ncon; |
| 23 |
|
| 24 |
graph->pwgts = imalloc(2*ncon); |
| 25 |
graph->where = imalloc(nvtxs); |
| 26 |
graph->bndptr = imalloc(nvtxs); |
| 27 |
graph->bndind = imalloc(nvtxs); |
| 28 |
graph->id = imalloc(nvtxs); |
| 29 |
graph->ed = imalloc(nvtxs); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
/*************************************************************************/ |
| 34 |
/*! This function computes the initial id/ed */ |
| 35 |
/*************************************************************************/ |
| 36 |
void Compute2WayPartitionParams(ctrl_t *ctrl, graph_t *graph) |
| 37 |
{ |
| 38 |
idx_t i, j, nvtxs, ncon, nbnd, mincut, istart, iend, tid, ted, me; |
| 39 |
const idx_t *xadj, *adjncy; |
| 40 |
idx_t *vwgt, *adjwgt, *pwgts; |
| 41 |
idx_t *where, *bndptr, *bndind, *id, *ed; |
| 42 |
|
| 43 |
nvtxs = graph->nvtxs; |
| 44 |
ncon = graph->ncon; |
| 45 |
xadj = graph->xadj_orig ? graph->xadj_orig : graph->xadj; |
| 46 |
vwgt = graph->vwgt; |
| 47 |
adjncy = graph->adjncy_orig ? graph->adjncy_orig : graph->adjncy; |
| 48 |
adjwgt = graph->adjwgt; |
| 49 |
|
| 50 |
where = graph->where; |
| 51 |
id = graph->id; |
| 52 |
ed = graph->ed; |
| 53 |
|
| 54 |
pwgts = iset(2*ncon, 0, graph->pwgts); |
| 55 |
bndptr = iset(nvtxs, -1, graph->bndptr); |
| 56 |
bndind = graph->bndind; |
| 57 |
|
| 58 |
/* Compute pwgts */ |
| 59 |
if (ncon == 1) { |
| 60 |
for (i=0; i<nvtxs; i++) { |
| 61 |
pwgts[where[i]] += vwgt[i]; |
| 62 |
} |
| 63 |
} |
| 64 |
else { |
| 65 |
for (i=0; i<nvtxs; i++) { |
| 66 |
me = where[i]; |
| 67 |
for (j=0; j<ncon; j++) |
| 68 |
pwgts[me*ncon+j] += vwgt[i*ncon+j]; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
/* Compute the required info for refinement */ |
| 74 |
for (nbnd=0, mincut=0, i=0; i<nvtxs; i++) { |
| 75 |
istart = xadj[i]; |
| 76 |
iend = xadj[i+1]; |
| 77 |
|
| 78 |
me = where[i]; |
| 79 |
tid = ted = 0; |
| 80 |
|
| 81 |
for (j=istart; j<iend; j++) { |
| 82 |
if (me == where[adjncy[j]]) |
| 83 |
tid += adjwgt[j]; |
| 84 |
else |
| 85 |
ted += adjwgt[j]; |
| 86 |
} |
| 87 |
id[i] = tid; |
| 88 |
ed[i] = ted; |
| 89 |
|
| 90 |
if (ted > 0 || istart == iend) { |
| 91 |
BNDInsert(nbnd, bndind, bndptr, i); |
| 92 |
mincut += ted; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
graph->mincut = mincut/2; |
| 97 |
graph->nbnd = nbnd; |
| 98 |
|
| 99 |
} |