26 int i, j, nvtxs, from, imax, gain, mindiff;
30 mindiff =
abs(tpwgts[0]-graph->
pwgts[0]);
33 if (graph->
pwgts[0] > tpwgts[0] && graph->
pwgts[0] < (
int)(ubfactor*tpwgts[0]))
35 if (graph->
pwgts[1] > tpwgts[1] && graph->
pwgts[1] < (
int)(ubfactor*tpwgts[1]))
53 int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, tmp;
54 idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts;
57 int higain, oldgain, mincut, mindiff;
75 mindiff =
abs(tpwgts[0]-pwgts[0]);
76 from = (pwgts[0] < tpwgts[0] ? 1 : 0);
80 printf(
"Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d [B]\n",
81 pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->
nvtxs, graph->
nbnd, graph->
mincut));
94 for (ii=0; ii<nbnd; ii++) {
96 ASSERT(ed[bndind[i]] > 0 ||
id[bndind[i]] == 0);
97 ASSERT(bndptr[bndind[i]] != -1);
98 if (where[bndind[i]] == from && vwgt[bndind[i]] <= mindiff)
99 PQueueInsert(&parts, bndind[i], ed[bndind[i]]-
id[bndind[i]]);
103 for (nswaps=0; nswaps<nvtxs; nswaps++) {
106 ASSERT(bndptr[higain] != -1);
108 if (pwgts[to]+vwgt[higain] > tpwgts[to])
111 mincut -= (ed[higain]-
id[higain]);
112 INC_DEC(pwgts[to], pwgts[from], vwgt[higain]);
115 moved[higain] = nswaps;
118 printf(
"Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-
id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1]));
123 SWAP(
id[higain], ed[higain], tmp);
124 if (ed[higain] == 0 && xadj[higain] < xadj[higain+1])
127 for (j=xadj[higain]; j<xadj[higain+1]; j++) {
129 oldgain = ed[k]-
id[k];
131 kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]);
135 if (bndptr[k] != -1) {
138 if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff)
142 if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff)
149 if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff)
157 printf(
"\tMinimum cut: %6d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, pwgts[0], pwgts[1], nbnd));
179 int i, ii, j, k, kwgt, nvtxs, nbnd, nswaps, from, to, pass, me, tmp;
180 idxtype *xadj, *vwgt, *adjncy, *adjwgt, *where, *id, *ed, *bndptr, *bndind, *pwgts;
183 int higain, oldgain, mincut, mindiff;
185 nvtxs = graph->
nvtxs;
190 where = graph->
where;
193 pwgts = graph->
pwgts;
201 mindiff =
abs(tpwgts[0]-pwgts[0]);
202 from = (pwgts[0] < tpwgts[0] ? 1 : 0);
206 printf(
"Partitions: [%6d %6d] T[%6d %6d], Nv-Nb[%6d %6d]. ICut: %6d [B]\n",
207 pwgts[0], pwgts[1], tpwgts[0], tpwgts[1], graph->
nvtxs, graph->
nbnd, graph->
mincut));
219 for (ii=0; ii<nvtxs; ii++) {
221 if (where[i] == from && vwgt[i] <= mindiff)
227 for (nswaps=0; nswaps<nvtxs; nswaps++) {
231 if (pwgts[to]+vwgt[higain] > tpwgts[to])
234 mincut -= (ed[higain]-
id[higain]);
235 INC_DEC(pwgts[to], pwgts[from], vwgt[higain]);
238 moved[higain] = nswaps;
241 printf(
"Moved %6d from %d. [%3d %3d] %5d [%4d %4d]\n", higain, from, ed[higain]-
id[higain], vwgt[higain], mincut, pwgts[0], pwgts[1]));
246 SWAP(
id[higain], ed[higain], tmp);
247 if (ed[higain] == 0 && bndptr[higain] != -1 && xadj[higain] < xadj[higain+1])
249 if (ed[higain] > 0 && bndptr[higain] == -1)
252 for (j=xadj[higain]; j<xadj[higain+1]; j++) {
254 oldgain = ed[k]-
id[k];
256 kwgt = (to == where[k] ? adjwgt[j] : -adjwgt[j]);
260 if (moved[k] == -1 && where[k] == from && vwgt[k] <= mindiff)
264 if (ed[k] == 0 && bndptr[k] != -1)
266 else if (ed[k] > 0 && bndptr[k] == -1)
272 printf(
"\tMinimum cut: %6d, PWGTS: [%6d %6d], NBND: %6d\n", mincut, pwgts[0], pwgts[1], nbnd));
void Balance2Way(CtrlType *ctrl, GraphType *graph, int *tpwgts, float ubfactor)
void General2WayBalance(CtrlType *ctrl, GraphType *graph, int *tpwgts)
void Bnd2WayBalance(CtrlType *ctrl, GraphType *graph, int *tpwgts)
__host__ __device__ int2 abs(int2 v)
#define INC_DEC(a, b, val)
#define BNDInsert(nbnd, bndind, bndptr, vtx)
#define BNDDelete(nbnd, bndind, bndptr, vtx)
#define IFSET(a, flag, cmd)