25 for (ptr=graph, nlevels=0; ptr!=orggraph; ptr=ptr->
finer, nlevels++);
49 if (ctrl->
minconn && i == nlevels/2)
54 if (2*i >= nlevels && !
IsBalanced(ctrl, graph, .02)) {
65 if (contig && i == nlevels/2) {
81 if (graph == orggraph)
127 "AllocateKWayPartitionMemory: ckrinfo");
132 "AllocateKWayVolPartitionMemory: vkrinfo");
151 idx_t i,
j, k,
l, nvtxs,
ncon,
nparts, nbnd, mincut, me,
other;
156 nvtxs = graph->
nvtxs;
163 where = graph->
where;
164 pwgts =
iset(nparts*ncon, 0, graph->
pwgts);
172 for (i=0; i<nvtxs; i++) {
173 ASSERT(where[i] >= 0 && where[i] < nparts);
174 pwgts[where[
i]] += vwgt[
i];
178 for (i=0; i<nvtxs; i++) {
180 for (j=0; j<
ncon; j++)
181 pwgts[me*ncon+j] += vwgt[i*ncon+j];
195 for (i=0; i<nvtxs; i++) {
199 for (j=xadj[i]; j<xadj[i+1]; j++) {
200 if (me == where[adjncy[j]])
201 myrinfo->
id += adjwgt[
j];
203 myrinfo->
ed += adjwgt[
j];
207 if (myrinfo->
ed > 0) {
208 mincut += myrinfo->
ed;
213 for (j=xadj[i]; j<xadj[i+1]; j++) {
214 other = where[adjncy[
j]];
216 for (k=0; k<myrinfo->
nnbrs; k++) {
217 if (mynbrs[k].pid == other) {
218 mynbrs[k].
ed += adjwgt[
j];
222 if (k == myrinfo->
nnbrs) {
224 mynbrs[k].
ed = adjwgt[
j];
233 if (myrinfo->
ed-myrinfo->
id >= 0)
257 for (i=0; i<nvtxs; i++) {
261 for (j=xadj[i]; j<xadj[i+1]; j++) {
262 if (me == where[adjncy[j]])
269 if (myrinfo->
ned > 0) {
270 mincut += myrinfo->
ned;
275 for (j=xadj[i]; j<xadj[i+1]; j++) {
276 other = where[adjncy[
j]];
278 for (k=0; k<myrinfo->
nnbrs; k++) {
279 if (mynbrs[k].pid == other) {
284 if (k == myrinfo->
nnbrs) {
317 idx_t i,
j, k, nvtxs, nbnd,
nparts, me,
other, istart, iend, tid, ted;
319 idx_t *cmap, *
where, *bndptr, *bndind, *cwhere, *htable;
327 cwhere = cgraph->
where;
329 nvtxs = graph->
nvtxs;
337 where = graph->
where;
352 for (i=0; i<nvtxs; i++) {
354 where[
i] = cwhere[k];
361 for (nbnd=0, i=0; i<nvtxs; i++) {
368 for (tid=0, j=istart; j<iend; j++)
379 for (tid=0, ted=0, j=istart; j<iend; j++) {
380 other = where[adjncy[
j]];
386 if ((k = htable[other]) == -1) {
389 mynbrs[myrinfo->
nnbrs++].
ed = adjwgt[
j];
392 mynbrs[k].
ed += adjwgt[
j];
408 for (j=0; j<myrinfo->
nnbrs; j++)
409 htable[mynbrs[j].pid] = -1;
428 for (i=0; i<nvtxs; i++) {
430 where[
i] = cwhere[k];
437 for (i=0; i<nvtxs; i++) {
443 myrinfo->
nid = iend-istart;
451 for (tid=0, ted=0, j=istart; j<iend; j++) {
452 other = where[adjncy[
j]];
458 if ((k = htable[other]) == -1) {
478 for (j=0; j<myrinfo->
nnbrs; j++)
479 htable[mynbrs[j].pid] = -1;
510 idx_t *bndind, *bndptr;
512 nvtxs = graph->
nvtxs;
522 for (i=0; i<nvtxs; i++) {
528 for (i=0; i<nvtxs; i++) {
538 for (i=0; i<nvtxs; i++) {
544 for (i=0; i<nvtxs; i++) {
566 *bndind, *bndptr, *ophtable;
574 nvtxs = graph->
nvtxs;
576 vsize = graph->
vsize;
580 where = graph->
where;
588 for (i=0; i<nvtxs; i++) {
592 if (myrinfo->
nnbrs > 0) {
598 for (j=xadj[i]; j<xadj[i+1]; j++) {
604 for (k=0; k<orinfo->
nnbrs; k++)
605 ophtable[onbrs[k].pid] = k;
611 for (k=0; k<myrinfo->
nnbrs; k++) {
612 if (ophtable[mynbrs[k].pid] == -1)
613 mynbrs[k].
gv -= vsize[ii];
617 ASSERT(ophtable[me] != -1);
619 if (onbrs[ophtable[me]].ned == 1) {
622 for (k=0; k<myrinfo->
nnbrs; k++) {
623 if (ophtable[mynbrs[k].pid] != -1)
624 mynbrs[k].
gv += vsize[ii];
630 for (k=0; k<myrinfo->
nnbrs; k++) {
631 if (ophtable[mynbrs[k].pid] == -1)
632 mynbrs[k].
gv -= vsize[ii];
638 for (k=0; k<orinfo->
nnbrs; k++)
639 ophtable[onbrs[k].pid] = -1;
640 ophtable[
other] = -1;
644 for (k=0; k<myrinfo->
nnbrs; k++) {
645 if (mynbrs[k].gv > myrinfo->
gv)
646 myrinfo->
gv = mynbrs[k].
gv;
650 if (myrinfo->
ned > 0 && myrinfo->
nid == 0)
651 myrinfo->
gv += vsize[
i];
654 if (myrinfo->
gv >= 0)
void ComputeKWayPartitionParams(ctrl_t *ctrl, graph_t *graph)
idx_t idx_t idx_t idx_t * vwgt
void RefineKWay(ctrl_t *ctrl, graph_t *orggraph, graph_t *graph)
#define gk_startcputimer(tmr)
#define ComputeLoadImbalanceDiff
void AllocateKWayPartitionMemory(ctrl_t *ctrl, graph_t *graph)
#define gk_stopcputimer(tmr)
#define EliminateComponents
idx_t idx_t idx_t idx_t idx_t idx_t idx_t * nparts
void gk_errexit(int signum, char *f_str,...)
NonlinearFactorGraph graph
idx_t idx_t idx_t idx_t idx_t * vsize
#define ASSERT(expression)
static const Line3 l(Rot3(), 1, 1)
#define BNDInsert(nbnd, bndind, bndptr, vtx)
#define EliminateSubDomainEdges
int IsBalanced(ctrl_t *ctrl, graph_t *graph, real_t ffactor)
idx_t idx_t idx_t idx_t idx_t idx_t * adjwgt
void * gk_malloc(size_t nbytes, char *msg)
idx_t idx_t idx_t idx_t * where
idx_t idx_t idx_t * adjncy
void ComputeKWayVolGains(ctrl_t *ctrl, graph_t *graph)
void ComputeKWayBoundary(ctrl_t *ctrl, graph_t *graph, idx_t bndtype)
#define IFSET(a, flag, cmd)
void ProjectKWayPartition(ctrl_t *ctrl, graph_t *graph)
#define Greedy_KWayOptimize
#define FindPartitionInducedComponents