| 1 |
/* |
| 2 |
* Copyright 1997, Regents of the University of Minnesota |
| 3 |
* |
| 4 |
* srefine.c |
| 5 |
* |
| 6 |
* This file contains code for the separator refinement algorithms |
| 7 |
* |
| 8 |
* Started 8/1/97 |
| 9 |
* George |
| 10 |
* |
| 11 |
* $Id: srefine.c 14362 2013-05-21 21:35:23Z karypis $ |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
#include "metislib.h" |
| 16 |
|
| 17 |
|
| 18 |
/*************************************************************************/ |
| 19 |
/*! This function is the entry point of the separator refinement. |
| 20 |
It does not perform any refinement on graph, but it starts by first |
| 21 |
projecting it to the next level finer graph and proceeds from there. */ |
| 22 |
/*************************************************************************/ |
| 23 |
void Refine2WayNode(ctrl_t *ctrl, graph_t *orggraph, graph_t *graph) |
| 24 |
{ |
| 25 |
|
| 26 |
|
| 27 |
if (graph == orggraph) { |
| 28 |
Compute2WayNodePartitionParams(ctrl, graph); |
| 29 |
} |
| 30 |
else { |
| 31 |
do { |
| 32 |
graph = graph->finer; |
| 33 |
|
| 34 |
Project2WayNodePartition(ctrl, graph); |
| 35 |
|
| 36 |
FM_2WayNodeBalance(ctrl, graph); |
| 37 |
|
| 38 |
|
| 39 |
switch (ctrl->rtype) { |
| 40 |
case METIS_RTYPE_SEP2SIDED: |
| 41 |
FM_2WayNodeRefine2Sided(ctrl, graph, ctrl->niter); |
| 42 |
break; |
| 43 |
case METIS_RTYPE_SEP1SIDED: |
| 44 |
FM_2WayNodeRefine1Sided(ctrl, graph, ctrl->niter); |
| 45 |
break; |
| 46 |
default: |
| 47 |
GK_ERREXIT("Unknown rtype of %d\n", ctrl->rtype); |
| 48 |
} |
| 49 |
|
| 50 |
} while (graph != orggraph); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
/*************************************************************************/ |
| 57 |
/*! This function allocates memory for 2-way node-based refinement */ |
| 58 |
/**************************************************************************/ |
| 59 |
void Allocate2WayNodePartitionMemory(ctrl_t *ctrl, graph_t *graph) |
| 60 |
{ |
| 61 |
idx_t nvtxs; |
| 62 |
|
| 63 |
nvtxs = graph->nvtxs; |
| 64 |
|
| 65 |
graph->pwgts = imalloc(3); |
| 66 |
graph->where = imalloc(nvtxs); |
| 67 |
graph->bndptr = imalloc(nvtxs); |
| 68 |
graph->bndind = imalloc(nvtxs); |
| 69 |
graph->nrinfo = (nrinfo_t *)malloc(nvtxs*sizeof(nrinfo_t)); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
/*************************************************************************/ |
| 74 |
/*! This function computes the edegrees[] to the left & right sides */ |
| 75 |
/*************************************************************************/ |
| 76 |
void Compute2WayNodePartitionParams(ctrl_t *ctrl, graph_t *graph) |
| 77 |
{ |
| 78 |
idx_t i, j, nvtxs, nbnd; |
| 79 |
const idx_t *xadj, *adjncy; |
| 80 |
idx_t *vwgt; |
| 81 |
idx_t *where, *pwgts, *bndind, *bndptr, *edegrees; |
| 82 |
nrinfo_t *rinfo; |
| 83 |
idx_t me, other; |
| 84 |
|
| 85 |
nvtxs = graph->nvtxs; |
| 86 |
xadj = graph->xadj_orig ? graph->xadj_orig : graph->xadj; |
| 87 |
vwgt = graph->vwgt; |
| 88 |
adjncy = graph->adjncy_orig ? graph->adjncy_orig : graph->adjncy; |
| 89 |
|
| 90 |
where = graph->where; |
| 91 |
rinfo = graph->nrinfo; |
| 92 |
pwgts = iset(3, 0, graph->pwgts); |
| 93 |
bndind = graph->bndind; |
| 94 |
bndptr = iset(nvtxs, -1, graph->bndptr); |
| 95 |
|
| 96 |
|
| 97 |
/*------------------------------------------------------------ |
| 98 |
/ Compute now the separator external degrees |
| 99 |
/------------------------------------------------------------*/ |
| 100 |
nbnd = 0; |
| 101 |
for (i=0; i<nvtxs; i++) { |
| 102 |
me = where[i]; |
| 103 |
pwgts[me] += vwgt[i]; |
| 104 |
|
| 105 |
if (me == 2) { /* If it is on the separator do some computations */ |
| 106 |
BNDInsert(nbnd, bndind, bndptr, i); |
| 107 |
|
| 108 |
edegrees = rinfo[i].edegrees; |
| 109 |
edegrees[0] = edegrees[1] = 0; |
| 110 |
|
| 111 |
for (j=xadj[i]; j<xadj[i+1]; j++) { |
| 112 |
other = where[adjncy[j]]; |
| 113 |
if (other != 2) |
| 114 |
edegrees[other] += vwgt[adjncy[j]]; |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
graph->mincut = pwgts[2]; |
| 121 |
graph->nbnd = nbnd; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
/*************************************************************************/ |
| 126 |
/*! This function projects the node-based bisection */ |
| 127 |
/*************************************************************************/ |
| 128 |
void Project2WayNodePartition(ctrl_t *ctrl, graph_t *graph) |
| 129 |
{ |
| 130 |
idx_t i, j, nvtxs; |
| 131 |
idx_t *cmap, *where, *cwhere; |
| 132 |
graph_t *cgraph; |
| 133 |
|
| 134 |
cgraph = graph->coarser; |
| 135 |
cwhere = cgraph->where; |
| 136 |
|
| 137 |
nvtxs = graph->nvtxs; |
| 138 |
cmap = graph->cmap; |
| 139 |
|
| 140 |
Allocate2WayNodePartitionMemory(ctrl, graph); |
| 141 |
where = graph->where; |
| 142 |
|
| 143 |
/* Project the partition */ |
| 144 |
for (i=0; i<nvtxs; i++) { |
| 145 |
where[i] = cwhere[cmap[i]]; |
| 146 |
} |
| 147 |
|
| 148 |
FreeGraph(&graph->coarser); |
| 149 |
graph->coarser = NULL; |
| 150 |
|
| 151 |
Compute2WayNodePartitionParams(ctrl, graph); |
| 152 |
} |