/************************************************************************* * This function is the entry point of refinement **************************************************************************/ void MocRefine2Way2(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float *tpwgts, float *ubvec) { 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: MocBalance2Way2(ctrl, graph, tpwgts, ubvec); MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 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)); } 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 MocGrowBisection2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) { 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); MocBalance2Way2(ctrl, graph, tpwgts, ubvec); MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 4); MocBalance2Way2(ctrl, graph, tpwgts, ubvec); MocFM_2WayEdgeRefine2(ctrl, graph, tpwgts, ubvec, 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); }