96 int sigrval=0, renumber=0;
124 graph =
SetupGraph(ctrl, *nvtxs, *ncon, xadj, adjncy, vwgt, vsize, adjwgt);
165 if ((nvtxs = graph->
nvtxs) == 0) {
166 printf(
"\t***Cannot bisect a graph with 0 vertices!\n" 167 "\t***You are trying to partition a graph into too many parts!\n");
177 for (i=0; i<
ncon; i++) {
178 tpwgts2[
i] =
rsum((nparts>>1), tpwgts+i, ncon);
179 tpwgts2[ncon+
i] = 1.0 - tpwgts2[
i];
187 label = graph->
label;
188 where = graph->
where;
189 for (i=0; i<nvtxs; i++)
190 part[label[i]] = where[i] + fpart;
199 for (i=0; i<
ncon; i++) {
200 wsum =
rsum((nparts>>1), tpwgts+i, ncon);
201 rscale((nparts>>1), 1.0/wsum, tpwgts+i, ncon);
202 rscale(nparts-(nparts>>1), 1.0/(1.0-wsum), tpwgts+(nparts>>1)*ncon+i, ncon);
210 tpwgts+(nparts>>1)*ncon, fpart+(nparts>>1));
212 else if (nparts == 3) {
215 tpwgts+(nparts>>1)*ncon, fpart+(nparts>>1));
228 idx_t i, niparts, bestobj=0, curobj=0, *bestwhere=
NULL;
230 real_t bestbal=0.0, curbal=0.0;
239 for (i=0; i<ctrl->
ncuts; i++) {
251 || (curbal <= 0.0005 && bestobj > curobj)
252 || (bestbal > 0.0005 && curbal < bestbal)) {
255 if (i < ctrl->ncuts-1)
263 if (i < ctrl->ncuts-1)
267 if (bestobj != curobj) {
283 idx_t i,
j, k,
l, istart, iend, mypart, nvtxs,
ncon, snvtxs[2], snedges[2];
285 idx_t *sxadj[2], *svwgt[2], *sadjncy[2], *sadjwgt[2], *slabel[2];
287 idx_t *auxadjncy, *auxadjwgt;
294 nvtxs = graph->
nvtxs;
300 label = graph->
label;
301 where = graph->
where;
308 snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0;
309 for (i=0; i<nvtxs; i++) {
311 rename[
i] = snvtxs[k]++;
312 snedges[k] += xadj[i+1]-xadj[
i];
316 sxadj[0] = lgraph->
xadj;
317 svwgt[0] = lgraph->
vwgt;
318 sadjncy[0] = lgraph->
adjncy;
319 sadjwgt[0] = lgraph->
adjwgt;
320 slabel[0] = lgraph->
label;
323 sxadj[1] = rgraph->
xadj;
324 svwgt[1] = rgraph->
vwgt;
325 sadjncy[1] = rgraph->
adjncy;
326 sadjwgt[1] = rgraph->
adjwgt;
327 slabel[1] = rgraph->
label;
329 snvtxs[0] = snvtxs[1] = snedges[0] = snedges[1] = 0;
330 sxadj[0][0] = sxadj[1][0] = 0;
331 for (i=0; i<nvtxs; i++) {
336 if (bndptr[i] == -1) {
337 auxadjncy = sadjncy[mypart] + snedges[mypart] - istart;
338 auxadjwgt = sadjwgt[mypart] + snedges[mypart] - istart;
339 for(j=istart; j<iend; j++) {
340 auxadjncy[
j] = adjncy[
j];
341 auxadjwgt[
j] = adjwgt[
j];
343 snedges[mypart] += iend-istart;
346 auxadjncy = sadjncy[mypart];
347 auxadjwgt = sadjwgt[mypart];
349 for (j=istart; j<iend; j++) {
351 if (where[k] == mypart) {
353 auxadjwgt[l++] = adjwgt[
j];
360 for (k=0; k<
ncon; k++)
361 svwgt[mypart][snvtxs[mypart]*ncon+k] = vwgt[i*ncon+k];
363 slabel[mypart][snvtxs[mypart]] = label[
i];
364 sxadj[mypart][++snvtxs[mypart]] = snedges[mypart];
367 for (mypart=0; mypart<2; mypart++) {
368 iend = sxadj[mypart][snvtxs[mypart]];
369 auxadjncy = sadjncy[mypart];
370 for (i=0; i<iend; i++)
371 auxadjncy[i] = rename[auxadjncy[i]];
374 lgraph->
nedges = snedges[0];
375 rgraph->
nedges = snedges[1];
idx_t idx_t idx_t idx_t * vwgt
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t real_t idx_t idx_t idx_t * part
#define gk_startcputimer(tmr)
#define ComputeLoadImbalanceDiff
#define gk_stopcputimer(tmr)
idx_t idx_t idx_t idx_t idx_t idx_t idx_t * nparts
#define Compute2WayPartitionParams
NonlinearFactorGraph graph
idx_t MlevelRecursiveBisection(ctrl_t *ctrl, graph_t *graph, idx_t nparts, idx_t *part, real_t *tpwgts, idx_t fpart)
idx_t idx_t idx_t idx_t idx_t * vsize
#define ASSERT(expression)
#define AllocateWorkSpace
static const Line3 l(Rot3(), 1, 1)
idx_t idx_t idx_t idx_t idx_t idx_t real_t idx_t idx_t * objval
idx_t MultilevelBisect(ctrl_t *ctrl, graph_t *graph, real_t *tpwgts)
#define Change2CNumbering
void SplitGraphPart(ctrl_t *ctrl, graph_t *graph, graph_t **r_lgraph, graph_t **r_rgraph)
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t real_t * ubvec
void gk_malloc_cleanup(int showstats)
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t * tpwgts
idx_t idx_t idx_t idx_t idx_t idx_t * adjwgt
idx_t idx_t idx_t idx_t * where
#define Setup2WayBalMultipliers
idx_t idx_t idx_t * adjncy
int METIS_PartGraphRecursive(idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *vsize, idx_t *adjwgt, idx_t *nparts, real_t *tpwgts, real_t *ubvec, idx_t *options, idx_t *objval, idx_t *part)
Recursive partitioning routine.
#define IFSET(a, flag, cmd)
#define Change2FNumbering
#define Init2WayPartition