23 idx_t nads=0, *vadids, *vadwgts;
42 for (pid=0; pid<
nparts; pid++) {
50 for (nads=0, ii=pptr[pid]; ii<pptr[pid+1]; ii++) {
54 if (rinfo[i].ed > 0) {
58 for (j=0; j<nnbrs; j++) {
60 if (vadwgts[other] == 0)
61 vadids[nads++] =
other;
75 for (nads=0, ii=pptr[pid]; ii<pptr[pid+1]; ii++) {
79 if (rinfo[i].ned > 0) {
83 for (j=0; j<nnbrs; j++) {
85 if (vadwgts[other] == 0)
86 vadids[nads++] =
other;
99 if (ctrl->
maxnads[pid] < nads) {
102 "ComputeSubDomainGraph: adids[pid]");
104 "ComputeSubDomainGraph: adids[pid]");
107 ctrl->
nads[pid] = nads;
108 for (j=0; j<nads; j++) {
109 ctrl->
adids[pid][
j] = vadids[
j];
110 ctrl->
adwgts[pid][
j] = vadwgts[vadids[
j]];
112 vadwgts[vadids[
j]] = 0;
142 for (i=0; i<2; i++) {
143 nads = ctrl->
nads[u];
145 for (j=0; j<nads; j++) {
146 if (ctrl->
adids[u][j] == v) {
155 if (ctrl->
maxnads[u] == nads) {
158 "IncreaseEdgeSubDomainGraph: adids[pid]");
160 "IncreaseEdgeSubDomainGraph: adids[pid]");
163 ctrl->
adwgts[u][nads] = ewgt;
165 if (r_maxndoms !=
NULL && nads > *r_maxndoms) {
166 printf(
"You just increased the maxndoms: %"PRIDX" %"PRIDX"\n",
174 if (ctrl->
adwgts[u][j] == 0) {
178 if (r_maxndoms !=
NULL && nads+1 == *r_maxndoms)
182 ctrl->
nads[u] = nads;
194 idx_t i, ii,
j, k,
ncon,
nparts, scheme, pid_from, pid_to, me,
other, nvtxs,
195 total,
max, avg, totalout, nind=0, ncand=0, ncand2, target, target2,
199 *mypmat, *otherpmat, *kpmat, *
ind;
200 idx_t *nads, **adids, **adwgts;
209 nvtxs = graph->
nvtxs;
216 where = graph->
where;
217 pwgts = graph->
pwgts;
253 for (i=0; i<
nparts; i++) {
254 for (j=0; j<
ncon; j++)
263 total =
isum(nparts, nads, 1);
265 max = nads[
iargmax(nparts, nads)];
268 printf(
"Adjacent Subdomain Stats: Total: %3"PRIDX", " 270 total, max,
iargmax(nparts, nads), avg));
272 if (max < badfactor*avg)
277 for (i=0; i<
nparts; i++) {
278 if (nads[i] >= avg + (max-avg)/2)
284 totalout =
isum(nads[me], adwgts[me], 1);
286 for (ncand2=0, i=0; i<nads[me]; i++) {
287 mypmat[adids[me][
i]] = adwgts[me][
i];
290 if (2*nads[me]*adwgts[me][i] < totalout) {
291 cand2[ncand2].val = adids[me][
i];
292 cand2[ncand2++].key = adwgts[me][
i];
297 printf(
"Me: %"PRIDX
", Degree: %4"PRIDX
", TotalOut: %"PRIDX
",\n",
298 me, nads[me], totalout));
310 target = target2 = -1;
311 for (scheme=0; scheme<2; scheme++) {
312 for (min=0; min<ncand2; min++) {
313 other = cand2[
min].val;
328 for (nind=0, ii=pptr[pid_from]; ii<pptr[pid_from+1]; ii++) {
330 ASSERT(where[i] == pid_from);
331 for (j=xadj[i]; j<xadj[i+1]; j++) {
332 if (where[adjncy[j]] == pid_to) {
341 iset(ncon, 0, cpwgt);
342 for (ncand=0, ii=0; ii<nind; ii++) {
344 iaxpy(ncon, 1, vwgt+i*ncon, 1, cpwgt, 1);
346 for (j=xadj[i]; j<xadj[i+1]; j++) {
347 if ((k = where[adjncy[j]]) == pid_from)
349 if (otherpmat[k] == 0)
350 cand[ncand++].val = k;
351 otherpmat[k] += (adjwgt ? adjwgt[
j] : 1);
355 for (i=0; i<ncand; i++) {
356 cand[
i].key = otherpmat[cand[
i].val];
363 printf(
"\tMinOut: %4"PRIDX
", to: %3"PRIDX
", TtlWgt: %5"PRIDX
"[#:%"PRIDX
"]\n",
364 mypmat[other], other,
isum(ncon, cpwgt, 1), nind));
369 for (i=0; i<ncand; i++) {
374 if (!
ivecaxpylez(ncon, 1, cpwgt, pwgts+k*ncon, maxpwgt+k*ncon))
378 for (j=0; j<nads[k]; j++)
379 kpmat[adids[k][j]] = adwgts[k][j];
384 for (j=0; j<
nparts; j++) {
385 if (otherpmat[j] > 0 && kpmat[j] == 0 && nads[j]+1 >= nads[me])
392 for (nadd=0, j=0; j<
nparts; j++) {
393 if (otherpmat[j] > 0 && kpmat[j] == 0)
398 printf(
"\t\tto=%"PRIDX
", nadd=%"PRIDX
", %"PRIDX
"\n", k, nadd, nads[k]));
400 if (nads[k]+nadd < nads[me]) {
401 if (target2 == -1 || nads[target2]+bestnadd > nads[k]+nadd ||
402 (nads[target2]+bestnadd == nads[k]+nadd && bestnadd > nadd)) {
413 for (j=0; j<nads[k]; j++)
414 kpmat[adids[k][j]] = 0;
422 for (i=0; i<ncand; i++)
423 otherpmat[cand[i].val] = 0;
425 if (target == -1 && target2 != -1)
430 printf(
"\t\tScheme: %"PRIDX
". Moving to %"PRIDX
"\n", scheme, target));
441 for (i=0; i<nads[me]; i++)
442 mypmat[adids[me][i]] = 0;
480 idx_t i, ii,
j, jj, k,
l, nvtxs, nbnd, from, me;
485 nvtxs = graph->
nvtxs;
490 where = graph->
where;
501 if (myrinfo->
inbr == -1) {
508 for (k=0; k<myrinfo->
nnbrs; k++) {
509 if (mynbrs[k].pid == to)
512 if (k == myrinfo->
nnbrs) {
513 ASSERT(k < xadj[i+1]-xadj[i]);
534 for (j=xadj[i]; j<xadj[i+1]; j++) {
540 from, to, myrinfo, adjwgt[j], nbnd, bndptr, bndind,
BNDTYPE_REFINE);
544 if (me != from && me != to) {
564 idx_t i, ii,
j, jj, k,
l, nvtxs, from, me,
other, xgain, ewgt;
569 nvtxs = graph->
nvtxs;
571 vsize = graph->
vsize;
573 where = graph->
where;
580 if (myrinfo->
inbr == -1) {
586 xgain = (myrinfo->
nid == 0 && myrinfo->
ned > 0 ? vsize[
i] : 0);
592 for (k=0; k<myrinfo->
nnbrs; k++) {
593 if (mynbrs[k].pid == to)
597 if (k == myrinfo->
nnbrs) {
600 if (myrinfo->
nid > 0)
604 for (j=xadj[i]; j<xadj[i+1]; j++) {
615 for (l=0; l<orinfo->
nnbrs; l++) {
616 if (onbrs[l].pid == to)
619 if (l == orinfo->
nnbrs)
624 for (l=0; l<orinfo->
nnbrs; l++) {
625 if (onbrs[l].pid == to)
628 if (l == orinfo->
nnbrs)
632 for (l=0; l<orinfo->
nnbrs; l++) {
633 if (onbrs[l].pid == from && onbrs[l].ned == 1) {
645 graph->
minvol -= (xgain + mynbrs[k].
gv);
647 ewgt = myrinfo->
nid-mynbrs[k].
ned;
659 for (j=xadj[i]; j<xadj[i+1]; j++) {
660 me = where[adjncy[
j]];
661 if (me != from && me != to) {
688 nvtxs = graph->
nvtxs;
693 pmat =
ismalloc(nparts*nparts, 0,
"ComputeSubDomainGraph: pmat");
695 for (i=0; i<nvtxs; i++) {
697 for (j=xadj[i]; j<xadj[i+1]; j++) {
700 pmat[me*nparts+where[k]] += adjwgt[
j];
706 for (i=0; i<
nparts; i++) {
707 for (k=0, j=0; j<
nparts; j++) {
708 if (pmat[i*nparts+j] > 0)
724 printf(
"Total adjacent subdomains: %"PRIDX", Max: %"PRIDX"\n", total, max);
const gtsam::Symbol key('X', 0)
idx_t idx_t idx_t idx_t * vwgt
void ComputeSubDomainGraph(ctrl_t *ctrl, graph_t *graph)
#define ASSERTP(expr, msg)
void MoveGroupMinConnForVol(ctrl_t *ctrl, graph_t *graph, idx_t to, idx_t nind, idx_t *ind, idx_t *vmarker, idx_t *pmarker, idx_t *modind)
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
void PrintSubDomainGraph(graph_t *graph, idx_t nparts, idx_t *where)
idx_t idx_t idx_t idx_t idx_t * vsize
#define ASSERT(expression)
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
static const Line3 l(Rot3(), 1, 1)
void UpdateEdgeSubDomainGraph(ctrl_t *ctrl, idx_t u, idx_t v, idx_t ewgt, idx_t *r_maxndoms)
Array< int, Dynamic, 1 > v
void EliminateSubDomainEdges(ctrl_t *ctrl, graph_t *graph)
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t * tpwgts
idx_t idx_t idx_t idx_t idx_t idx_t * adjwgt
void gk_free(void **ptr1,...)
idx_t idx_t idx_t idx_t * where
idx_t idx_t idx_t * adjncy
void MoveGroupMinConnForCut(ctrl_t *ctrl, graph_t *graph, idx_t to, idx_t nind, idx_t *ind)
#define UpdateAdjacentVertexInfoAndBND(ctrl, vid, adjlen, me, from, to, myrinfo, ewgt, nbnd, bndptr, bndind, bndtype)
#define UpdateMovedVertexInfoAndBND(i, from, k, to, myrinfo, mynbrs, where, nbnd, bndptr, bndind, bndtype)
#define IFSET(a, flag, cmd)