From 69f2911e04ffb1b19eef1fafb8c040af271f656e Mon Sep 17 00:00:00 2001 From: Tor Aamodt Date: Thu, 15 Jul 2010 18:09:46 -0800 Subject: creating branch for adding support for CUDA 3.x and Fermi [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6829] --- .../DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c | 328 +++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c (limited to 'benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c') diff --git a/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c new file mode 100644 index 0000000..d39f1e0 --- /dev/null +++ b/benchmarks/CUDA/DG/3rdParty/ParMetis-3.1/METISLib/mbalance2.c @@ -0,0 +1,328 @@ +/* + * Copyright 1997, Regents of the University of Minnesota + * + * mbalance2.c + * + * This file contains code that is used to forcefully balance either + * bisections or k-sections + * + * Started 7/29/97 + * George + * + * $Id: mbalance2.c,v 1.1 2003/07/16 15:55:07 karypis Exp $ + * + */ + +#include + + +/************************************************************************* +* This function is the entry point of the bisection balancing algorithms. +**************************************************************************/ +void MocBalance2Way2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i; + float tvec[MAXNCON]; + + Compute2WayHLoadImbalanceVec(graph->ncon, graph->npwgts, tpwgts, tvec); + if (!AreAllBelow(graph->ncon, tvec, ubvec)) + MocGeneral2WayBalance2(ctrl, graph, tpwgts, ubvec); +} + + + +/************************************************************************* +* This function performs an edge-based FM refinement +**************************************************************************/ +void MocGeneral2WayBalance2(CtrlType *ctrl, GraphType *graph, float *tpwgts, float *ubvec) +{ + int i, ii, j, k, l, kwgt, nvtxs, ncon, nbnd, nswaps, from, to, pass, me, limit, tmp, cnum; + idxtype *xadj, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind; + idxtype *moved, *swaps, *perm, *qnum; + float *nvwgt, *npwgts, origbal[MAXNCON], minbal[MAXNCON], newbal[MAXNCON]; + PQueueType parts[MAXNCON][2]; + int higain, oldgain, mincut, newcut, mincutorder; + float *maxwgt, *minwgt, tvec[MAXNCON]; + + + nvtxs = graph->nvtxs; + ncon = graph->ncon; + xadj = graph->xadj; + nvwgt = graph->nvwgt; + adjncy = graph->adjncy; + adjwgt = graph->adjwgt; + where = graph->where; + id = graph->id; + ed = graph->ed; + npwgts = graph->npwgts; + bndptr = graph->bndptr; + bndind = graph->bndind; + + moved = idxwspacemalloc(ctrl, nvtxs); + swaps = idxwspacemalloc(ctrl, nvtxs); + perm = idxwspacemalloc(ctrl, nvtxs); + qnum = idxwspacemalloc(ctrl, nvtxs); + + limit = amin(amax(0.01*nvtxs, 15), 100); + + /* Setup the weight intervals of the two subdomains */ + minwgt = fwspacemalloc(ctrl, 2*ncon); + maxwgt = fwspacemalloc(ctrl, 2*ncon); + + for (i=0; i<2; i++) { + for (j=0; jmincut; + mincutorder = -1; + + if (ctrl->dbglvl&DBG_REFINE) { + printf("Parts: ["); + for (l=0; lnvtxs, graph->nbnd, graph->mincut); + for (i=0; imincut); + ASSERT(CheckBnd(graph)); + + /* Insert all nodes in the priority queues */ + nbnd = graph->nbnd; + RandomPermute(nvtxs, perm, 1); + for (ii=0; ii limit) { /* We hit the limit, undo last move */ + newcut += (ed[higain]-id[higain]); + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+from*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + break; + } + + where[higain] = to; + moved[higain] = nswaps; + swaps[nswaps] = higain; + + if (ctrl->dbglvl&DBG_MOVEINFO) { + printf("Moved %6d from %d(%d). Gain: %5d, Cut: %5d, NPwgts: ", higain, from, cnum, ed[higain]-id[higain], newcut); + for (i=0; i 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + for (j=xadj[higain]; j 0 && bndptr[k] == -1) + BNDInsert(nbnd, bndind, bndptr, k); + } + + } + + + + /**************************************************************** + * Roll back computations + *****************************************************************/ + for (i=0; imincutorder; nswaps--) { + higain = swaps[nswaps]; + + to = where[higain] = (where[higain]+1)%2; + SWAP(id[higain], ed[higain], tmp); + if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1]) + BNDDelete(nbnd, bndind, bndptr, higain); + else if (ed[higain] > 0 && bndptr[higain] == -1) + BNDInsert(nbnd, bndind, bndptr, higain); + + saxpy(ncon, 1.0, nvwgt+higain*ncon, 1, npwgts+to*ncon, 1); + saxpy(ncon, -1.0, nvwgt+higain*ncon, 1, npwgts+((to+1)%2)*ncon, 1); + for (j=xadj[higain]; j 0) + BNDInsert(nbnd, bndind, bndptr, k); + } + } + + if (ctrl->dbglvl&DBG_REFINE) { + printf("\tMincut: %6d at %5d, NBND: %6d, NPwgts: [", mincut, mincutorder, nbnd); + for (i=0; imincut = mincut; + graph->nbnd = nbnd; + + + for (i=0; i= maxdiff) { + maxdiff = diff; + *from = j; + *cnum = i; + } + } + } + +/* DELETE +j = *from; +for (i=0; i 0) { + maxdiff = (npwgts[(*from)*ncon+i] - maxwgt[(*from)*ncon+i]); + *cnum = i; + break; + } + } + + for (i++; i maxdiff && PQueueGetSize(&queues[i][*from]) > 0) { + maxdiff = diff; + *cnum = i; + } + } + } + + /* If the constraints ar OK, select a high gain vertex */ + if (*from == -1) { + maxgain = -100000; + for (j=0; j<2; j++) { + for (i=0; i 0 && PQueueGetKey(&queues[i][j]) > maxgain) { + maxgain = PQueueGetKey(&queues[i][0]); + *from = j; + *cnum = i; + } + } + } + + /* printf("(%2d %2d) %3d\n", *from, *cnum, maxgain); */ + } +} -- cgit v1.3