/* * Copyright 1997, Regents of the University of Minnesota * * balancemylink.c * * This file contains code that implements the edge-based FM refinement * * Started 7/23/97 * George * * $Id: balancemylink.c 10542 2011-07-11 16:56:22Z karypis $ */ #include #define PE 0 /************************************************************************* * This function performs an edge-based FM refinement **************************************************************************/ idx_t BalanceMyLink(ctrl_t *ctrl, graph_t *graph, idx_t *home, idx_t me, idx_t you, real_t *flows, real_t maxdiff, real_t *diff_cost, real_t *diff_lbavg, real_t avgvwgt) { idx_t h, i, ii, j, k, mype; idx_t nvtxs, ncon; idx_t nqueues, minval, maxval, higain, vtx, edge, totalv; idx_t from, to, qnum, index, nchanges, cut, tmp; idx_t pass, nswaps, nmoves, multiplier; idx_t *xadj, *vsize, *adjncy, *adjwgt, *where, *ed, *id; idx_t *hval, *nvpq, *inq, *map, *rmap, *ptr, *myqueue, *changes; real_t *nvwgt, *lbvec, *pwgts, *tpwgts, *my_wgt; real_t newgain; real_t lbavg, bestflow, mycost; real_t ipc_factor, redist_factor, ftmp; rpq_t **queues; WCOREPUSH; gkMPI_Comm_rank(MPI_COMM_WORLD, &mype); nvtxs = graph->nvtxs; ncon = graph->ncon; xadj = graph->xadj; nvwgt = graph->nvwgt; vsize = graph->vsize; adjncy = graph->adjncy; adjwgt = graph->adjwgt; where = graph->where; ipc_factor = ctrl->ipc_factor; redist_factor = ctrl->redist_factor; hval = iwspacemalloc(ctrl, nvtxs); id = iwspacemalloc(ctrl, nvtxs); ed = iwspacemalloc(ctrl, nvtxs); map = iwspacemalloc(ctrl, nvtxs); rmap = iwspacemalloc(ctrl, nvtxs); myqueue = iwspacemalloc(ctrl, nvtxs); changes = iwspacemalloc(ctrl, nvtxs); lbvec = rwspacemalloc(ctrl, ncon); pwgts = rset(2*ncon, 0.0, rwspacemalloc(ctrl, 2*ncon)); tpwgts = rwspacemalloc(ctrl, 2*ncon); my_wgt = rset(ncon, 0.0, rwspacemalloc(ctrl, ncon)); for (h=0; h 0) { queues[i] = rpqCreate(nvpq[i]); queues[nqueues+i] = rpqCreate(nvpq[i]); } /* compute internal/external degrees */ iset(nvtxs, 0, id); iset(nvtxs, 0, ed); for (j=0; j fabs(flows[j])) j = h; } bestflow = fabs(flows[j]); nchanges = nmoves = 0; for (ii=0; ii avgvwgt) break; } } else { for (j=0; j fabs(flows[j])) j = h; } ftmp = fabs(flows[j]); if (ftmp < bestflow) { bestflow = ftmp; nchanges = 0; } else { changes[nchanges++] = vtx; } gk_SWAP(id[vtx], ed[vtx], tmp); for (j=xadj[vtx]; j 0) { rpqReset(queues[i]); rpqReset(queues[i+nqueues]); } } if (nmoves == 0) break; } /***************************/ /* compute 2-way imbalance */ /***************************/ for (i=0; i 0) { rpqDestroy(queues[i]); rpqDestroy(queues[i+nqueues]); } } WCOREPOP; return nswaps; }