/************************************************************************* * This function is the entry point of refinement **************************************************************************/ void MocRefine2Way(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, float ubfactor) { int i; float tubvec[MAXNCON]; for (i=0; i<graph->ncon; i++) tubvec[i] = 1.0; IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); /* Compute the parameters of the coarsest graph */ MocCompute2WayPartitionParams(ctrl, graph); for (;;) { ASSERT(CheckBnd(graph)); IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); switch (ctrl->RType) { case RTYPE_FM: MocBalance2Way(ctrl, graph, tpwgts, 1.03); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); break; case 2: MocBalance2Way(ctrl, graph, tpwgts, 1.03); MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, tubvec, 8); break; default: errexit("Unknown refinement type: %d\n", ctrl->RType); } IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); if (graph == orggraph) break; graph = graph->finer; IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); MocProject2WayPartition(ctrl, graph); IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); } MocBalance2Way(ctrl, graph, tpwgts, 1.01); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 8); IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); }
/************************************************************************* * This function takes a graph and produces a bisection by using a region * growing algorithm. The resulting partition is returned in * graph->where **************************************************************************/ void MocGrowBisection(CtrlType *ctrl, GraphType *graph, float *tpwgts, float ubfactor) { int i, j, k, nvtxs, ncon, from, bestcut, mincut, nbfs; idxtype *bestwhere, *where; nvtxs = graph->nvtxs; MocAllocate2WayPartitionMemory(ctrl, graph); where = graph->where; bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); nbfs = 2*(nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); bestcut = idxsum(graph->nedges, graph->adjwgt); for (; nbfs>0; nbfs--) { idxset(nvtxs, 1, where); where[RandomInRange(nvtxs)] = 0; MocCompute2WayPartitionParams(ctrl, graph); MocInit2WayBalance(ctrl, graph, tpwgts); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); MocBalance2Way(ctrl, graph, tpwgts, 1.02); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 4); if (bestcut >= graph->mincut) { bestcut = graph->mincut; idxcopy(nvtxs, where, bestwhere); if (bestcut == 0) break; } } graph->mincut = bestcut; idxcopy(nvtxs, bestwhere, where); /*GKfree(&bestwhere, LTERM);*/ GKfree1((void**)&bestwhere); }
/************************************************************************* * This function takes a graph and produces a bisection by using a region * growing algorithm. The resulting partition is returned in * graph->where **************************************************************************/ void MocRandomBisection(CtrlType *ctrl, GraphType *graph, float *tpwgts, float ubfactor) { int i, ii, j, k, nvtxs, ncon, from, bestcut, mincut, nbfs, qnum; idxtype *bestwhere, *where, *perm; int counts[MAXNCON]; float *nvwgt; nvtxs = graph->nvtxs; ncon = graph->ncon; nvwgt = graph->nvwgt; MocAllocate2WayPartitionMemory(ctrl, graph); where = graph->where; bestwhere = idxmalloc(nvtxs, "BisectGraph: bestwhere"); nbfs = 2*(nvtxs <= ctrl->CoarsenTo ? SMALLNIPARTS : LARGENIPARTS); bestcut = idxsum(graph->nedges, graph->adjwgt); perm = idxmalloc(nvtxs, "BisectGraph: perm"); for (; nbfs>0; nbfs--) { for (i=0; i<ncon; i++) counts[i] = 0; RandomPermute(nvtxs, perm, 1); /* Partition by spliting the queues randomly */ for (ii=0; ii<nvtxs; ii++) { i = perm[ii]; qnum = samax(ncon, nvwgt+i*ncon); where[i] = counts[qnum]; counts[qnum] = (counts[qnum]+1)%2; } MocCompute2WayPartitionParams(ctrl, graph); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 6); MocBalance2Way(ctrl, graph, tpwgts, 1.02); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 6); MocBalance2Way(ctrl, graph, tpwgts, 1.02); MocFM_2WayEdgeRefine(ctrl, graph, tpwgts, 6); /* printf("Edgecut: %6d, NPwgts: [", graph->mincut); for (i=0; i<graph->ncon; i++) printf("(%.3f %.3f) ", graph->npwgts[i], graph->npwgts[graph->ncon+i]); printf("]\n"); */ if (bestcut > graph->mincut) { bestcut = graph->mincut; idxcopy(nvtxs, where, bestwhere); if (bestcut == 0) break; } } graph->mincut = bestcut; idxcopy(nvtxs, bestwhere, where); GKfree((void**)&bestwhere, &perm, LTERM); }