srefine.c
Go to the documentation of this file.
1 /*
2  * Copyright 1997, Regents of the University of Minnesota
3  *
4  * srefine.c
5  *
6  * This file contains code for the separator refinement algortihms
7  *
8  * Started 8/1/97
9  * George
10  *
11  * $Id: srefine.c 10515 2011-07-08 15:46:18Z karypis $
12  *
13  */
14 
15 #include "metislib.h"
16 
17 
18 /*************************************************************************/
22 /*************************************************************************/
23 void Refine2WayNode(ctrl_t *ctrl, graph_t *orggraph, graph_t *graph)
24 {
25 
27 
28  if (graph == orggraph) {
30  }
31  else {
32  do {
33  graph = graph->finer;
34 
38 
40  FM_2WayNodeBalance(ctrl, graph);
41 
43 
44  switch (ctrl->rtype) {
46  FM_2WayNodeRefine2Sided(ctrl, graph, ctrl->niter);
47  break;
49  FM_2WayNodeRefine1Sided(ctrl, graph, ctrl->niter);
50  break;
51  default:
52  gk_errexit(SIGERR, "Unknown rtype of %d\n", ctrl->rtype);
53  }
55 
56  } while (graph != orggraph);
57  }
58 
60 }
61 
62 
63 /*************************************************************************/
65 /**************************************************************************/
67 {
68  idx_t nvtxs;
69 
70  nvtxs = graph->nvtxs;
71 
72  graph->pwgts = imalloc(3, "Allocate2WayNodePartitionMemory: pwgts");
73  graph->where = imalloc(nvtxs, "Allocate2WayNodePartitionMemory: where");
74  graph->bndptr = imalloc(nvtxs, "Allocate2WayNodePartitionMemory: bndptr");
75  graph->bndind = imalloc(nvtxs, "Allocate2WayNodePartitionMemory: bndind");
76  graph->nrinfo = (nrinfo_t *)gk_malloc(nvtxs*sizeof(nrinfo_t), "Allocate2WayNodePartitionMemory: nrinfo");
77 }
78 
79 
80 /*************************************************************************/
82 /*************************************************************************/
84 {
85  idx_t i, j, nvtxs, nbnd;
86  idx_t *xadj, *adjncy, *vwgt;
87  idx_t *where, *pwgts, *bndind, *bndptr, *edegrees;
88  nrinfo_t *rinfo;
89  idx_t me, other;
90 
91  nvtxs = graph->nvtxs;
92  xadj = graph->xadj;
93  vwgt = graph->vwgt;
94  adjncy = graph->adjncy;
95 
96  where = graph->where;
97  rinfo = graph->nrinfo;
98  pwgts = iset(3, 0, graph->pwgts);
99  bndind = graph->bndind;
100  bndptr = iset(nvtxs, -1, graph->bndptr);
101 
102 
103  /*------------------------------------------------------------
104  / Compute now the separator external degrees
105  /------------------------------------------------------------*/
106  nbnd = 0;
107  for (i=0; i<nvtxs; i++) {
108  me = where[i];
109  pwgts[me] += vwgt[i];
110 
111  ASSERT(me >=0 && me <= 2);
112 
113  if (me == 2) { /* If it is on the separator do some computations */
114  BNDInsert(nbnd, bndind, bndptr, i);
115 
116  edegrees = rinfo[i].edegrees;
117  edegrees[0] = edegrees[1] = 0;
118 
119  for (j=xadj[i]; j<xadj[i+1]; j++) {
120  other = where[adjncy[j]];
121  if (other != 2)
122  edegrees[other] += vwgt[adjncy[j]];
123  }
124  }
125  }
126 
127  ASSERT(CheckNodeBnd(graph, nbnd));
128 
129  graph->mincut = pwgts[2];
130  graph->nbnd = nbnd;
131 }
132 
133 
134 /*************************************************************************/
136 /*************************************************************************/
138 {
139  idx_t i, j, nvtxs;
140  idx_t *cmap, *where, *cwhere;
141  graph_t *cgraph;
142 
143  cgraph = graph->coarser;
144  cwhere = cgraph->where;
145 
146  nvtxs = graph->nvtxs;
147  cmap = graph->cmap;
148 
150  where = graph->where;
151 
152  /* Project the partition */
153  for (i=0; i<nvtxs; i++) {
154  where[i] = cwhere[cmap[i]];
155  ASSERTP(where[i] >= 0 && where[i] <= 2, ("%"PRIDX" %"PRIDX" %"PRIDX" %"PRIDX"\n",
156  i, cmap[i], where[i], cwhere[cmap[i]]));
157  }
158 
159  FreeGraph(&graph->coarser);
160  graph->coarser = NULL;
161 
163 }
CheckNodeBnd
#define CheckNodeBnd
Definition: rename.h:67
ctrl_t::rtype
mrtype_et rtype
Definition: libmetis/struct.h:145
FM_2WayNodeRefine2Sided
#define FM_2WayNodeRefine2Sided
Definition: rename.h:222
ctrl_t
Definition: libmetis/struct.h:139
adjncy
idx_t idx_t idx_t * adjncy
Definition: include/metis.h:198
ctrl_t::RefTmr
double RefTmr
Definition: libmetis/struct.h:177
imalloc
#define imalloc
Definition: gklib_rename.h:42
graph_t::where
idx_t * where
Definition: libmetis/struct.h:105
IFSET
#define IFSET(a, flag, cmd)
Definition: gk_macros.h:45
CheckNodePartitionParams
#define CheckNodePartitionParams
Definition: rename.h:69
BNDInsert
#define BNDInsert(nbnd, bndind, bndptr, vtx)
Definition: metis/libmetis/macros.h:65
Allocate2WayNodePartitionMemory
void Allocate2WayNodePartitionMemory(ctrl_t *ctrl, graph_t *graph)
Definition: srefine.c:66
ctrl_t::UncoarsenTmr
double UncoarsenTmr
Definition: libmetis/struct.h:176
Compute2WayNodePartitionParams
void Compute2WayNodePartitionParams(ctrl_t *ctrl, graph_t *graph)
Definition: srefine.c:83
gk_startcputimer
#define gk_startcputimer(tmr)
Definition: gk_macros.h:33
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
METIS_RTYPE_SEP1SIDED
@ METIS_RTYPE_SEP1SIDED
Definition: include/metis.h:334
SIGERR
#define SIGERR
Definition: gk_defs.h:38
ctrl_t::ProjectTmr
double ProjectTmr
Definition: libmetis/struct.h:177
vwgt
idx_t idx_t idx_t idx_t * vwgt
Definition: include/metis.h:198
ASSERTP
#define ASSERTP(expr, msg)
Definition: gk_macros.h:131
ASSERT
#define ASSERT(expression)
Definition: ccolamd.c:872
xadj
idx_t idx_t * xadj
Definition: include/metis.h:197
iset
#define iset
Definition: gklib_rename.h:67
FreeGraph
#define FreeGraph
Definition: rename.h:98
Project2WayNodePartition
void Project2WayNodePartition(ctrl_t *ctrl, graph_t *graph)
Definition: srefine.c:137
nrinfo_t::edegrees
idx_t edegrees[2]
Definition: libmetis/struct.h:75
METIS_RTYPE_SEP2SIDED
@ METIS_RTYPE_SEP2SIDED
Definition: include/metis.h:333
Refine2WayNode
void Refine2WayNode(ctrl_t *ctrl, graph_t *orggraph, graph_t *graph)
Definition: srefine.c:23
FM_2WayNodeBalance
#define FM_2WayNodeBalance
Definition: rename.h:224
FM_2WayNodeRefine1Sided
#define FM_2WayNodeRefine1Sided
Definition: rename.h:223
PRIDX
#define PRIDX
Definition: include/metis.h:107
ctrl_t::niter
idx_t niter
Definition: libmetis/struct.h:158
nrinfo_t
Definition: libmetis/struct.h:74
ctrl_t::dbglvl
mdbglvl_et dbglvl
Definition: libmetis/struct.h:142
NULL
#define NULL
Definition: ccolamd.c:609
metislib.h
where
idx_t idx_t idx_t idx_t * where
Definition: include/metis.h:240
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gk_malloc
void * gk_malloc(size_t nbytes, char *msg)
Definition: memory.c:140
gk_stopcputimer
#define gk_stopcputimer(tmr)
Definition: gk_macros.h:34
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gk_errexit
void gk_errexit(int signum, char *f_str,...)
Definition: error.c:76
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
graph_t
Definition: libmetis/struct.h:82
idx_t
int32_t idx_t
Definition: include/metis.h:101
METIS_DBG_TIME
@ METIS_DBG_TIME
Definition: include/metis.h:341


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:59