wspace.c
Go to the documentation of this file.
1 
11 #include "metislib.h"
12 
13 
14 /*************************************************************************/
16 /*************************************************************************/
18 {
19  size_t coresize;
20 
21  switch (ctrl->optype) {
22  case METIS_OP_PMETIS:
23  coresize = 3*(graph->nvtxs+1)*sizeof(idx_t) +
24  5*(ctrl->nparts+1)*graph->ncon*sizeof(idx_t) +
25  5*(ctrl->nparts+1)*graph->ncon*sizeof(real_t);
26  break;
27  default:
28  coresize = 4*(graph->nvtxs+1)*sizeof(idx_t) +
29  5*(ctrl->nparts+1)*graph->ncon*sizeof(idx_t) +
30  5*(ctrl->nparts+1)*graph->ncon*sizeof(real_t);
31  }
32  /*coresize = 0;*/
33  ctrl->mcore = gk_mcoreCreate(coresize);
34 
35  ctrl->nbrpoolsize = 0;
36  ctrl->nbrpoolcpos = 0;
37 }
38 
39 
40 /*************************************************************************/
42 /*************************************************************************/
43 void AllocateRefinementWorkSpace(ctrl_t *ctrl, idx_t nbrpoolsize)
44 {
45  ctrl->nbrpoolsize = nbrpoolsize;
46  ctrl->nbrpoolcpos = 0;
47  ctrl->nbrpoolreallocs = 0;
48 
49  switch (ctrl->objtype) {
50  case METIS_OBJTYPE_CUT:
51  ctrl->cnbrpool = (cnbr_t *)gk_malloc(ctrl->nbrpoolsize*sizeof(cnbr_t),
52  "AllocateRefinementWorkSpace: cnbrpool");
53  break;
54 
55  case METIS_OBJTYPE_VOL:
56  ctrl->vnbrpool = (vnbr_t *)gk_malloc(ctrl->nbrpoolsize*sizeof(vnbr_t),
57  "AllocateRefinementWorkSpace: vnbrpool");
58  break;
59 
60  default:
61  gk_errexit(SIGERR, "Unknown objtype of %d\n", ctrl->objtype);
62  }
63 
64 
65  /* Allocate the memory for the sparse subdomain graph */
66  if (ctrl->minconn) {
67  ctrl->pvec1 = imalloc(ctrl->nparts+1, "AllocateRefinementWorkSpace: pvec1");
68  ctrl->pvec2 = imalloc(ctrl->nparts+1, "AllocateRefinementWorkSpace: pvec2");
69  ctrl->maxnads = ismalloc(ctrl->nparts, INIT_MAXNAD, "AllocateRefinementWorkSpace: maxnads");
70  ctrl->nads = imalloc(ctrl->nparts, "AllocateRefinementWorkSpace: nads");
71  ctrl->adids = iAllocMatrix(ctrl->nparts, INIT_MAXNAD, 0, "AllocateRefinementWorkSpace: adids");
72  ctrl->adwgts = iAllocMatrix(ctrl->nparts, INIT_MAXNAD, 0, "AllocateRefinementWorkSpace: adwgts");
73  }
74 }
75 
76 
77 /*************************************************************************/
79 /*************************************************************************/
80 void FreeWorkSpace(ctrl_t *ctrl)
81 {
83 
85  printf(" nbrpool statistics\n"
86  " nbrpoolsize: %12zu nbrpoolcpos: %12zu\n"
87  " nbrpoolreallocs: %12zu\n\n",
88  ctrl->nbrpoolsize, ctrl->nbrpoolcpos,
89  ctrl->nbrpoolreallocs));
90 
91  gk_free((void **)&ctrl->cnbrpool, &ctrl->vnbrpool, LTERM);
92  ctrl->nbrpoolsize = 0;
93  ctrl->nbrpoolcpos = 0;
94 
95  if (ctrl->minconn) {
96  iFreeMatrix(&(ctrl->adids), ctrl->nparts, INIT_MAXNAD);
97  iFreeMatrix(&(ctrl->adwgts), ctrl->nparts, INIT_MAXNAD);
98 
99  gk_free((void **)&ctrl->pvec1, &ctrl->pvec2,
100  &ctrl->maxnads, &ctrl->nads, LTERM);
101  }
102 }
103 
104 
105 /*************************************************************************/
107 /*************************************************************************/
108 void *wspacemalloc(ctrl_t *ctrl, size_t nbytes)
109 {
110  return gk_mcoreMalloc(ctrl->mcore, nbytes);
111 }
112 
113 
114 /*************************************************************************/
117 /*************************************************************************/
118 void wspacepush(ctrl_t *ctrl)
119 {
120  gk_mcorePush(ctrl->mcore);
121 }
122 
123 
124 /*************************************************************************/
126 /*************************************************************************/
127 void wspacepop(ctrl_t *ctrl)
128 {
129  gk_mcorePop(ctrl->mcore);
130 }
131 
132 
133 /*************************************************************************/
135 /*************************************************************************/
137 {
138  return (idx_t *)wspacemalloc(ctrl, n*sizeof(idx_t));
139 }
140 
141 
142 /*************************************************************************/
144 /*************************************************************************/
146 {
147  return (real_t *)wspacemalloc(ctrl, n*sizeof(real_t));
148 }
149 
150 
151 /*************************************************************************/
153 /*************************************************************************/
155 {
156  return (ikv_t *)wspacemalloc(ctrl, n*sizeof(ikv_t));
157 }
158 
159 
160 /*************************************************************************/
162 /*************************************************************************/
164 {
165  ctrl->nbrpoolcpos = 0;
166 }
167 
168 
169 /*************************************************************************/
171 /*************************************************************************/
173 {
174  ctrl->nbrpoolcpos += nnbrs;
175 
176  if (ctrl->nbrpoolcpos > ctrl->nbrpoolsize) {
177  ctrl->nbrpoolsize += gk_max(10*nnbrs, ctrl->nbrpoolsize/2);
178 
179  ctrl->cnbrpool = (cnbr_t *)gk_realloc(ctrl->cnbrpool,
180  ctrl->nbrpoolsize*sizeof(cnbr_t), "cnbrpoolGet: cnbrpool");
181  ctrl->nbrpoolreallocs++;
182  }
183 
184  return ctrl->nbrpoolcpos - nnbrs;
185 }
186 
187 
188 /*************************************************************************/
190 /*************************************************************************/
192 {
193  ctrl->nbrpoolcpos = 0;
194 }
195 
196 
197 /*************************************************************************/
199 /*************************************************************************/
201 {
202  ctrl->nbrpoolcpos += nnbrs;
203 
204  if (ctrl->nbrpoolcpos > ctrl->nbrpoolsize) {
205  ctrl->nbrpoolsize += gk_max(10*nnbrs, ctrl->nbrpoolsize/2);
206 
207  ctrl->vnbrpool = (vnbr_t *)gk_realloc(ctrl->vnbrpool,
208  ctrl->nbrpoolsize*sizeof(vnbr_t), "vnbrpoolGet: vnbrpool");
209  ctrl->nbrpoolreallocs++;
210  }
211 
212  return ctrl->nbrpoolcpos - nnbrs;
213 }
214 
cnbr_t
Definition: libmetis/struct.h:23
vnbrpoolReset
void vnbrpoolReset(ctrl_t *ctrl)
Definition: wspace.c:191
ctrl_t::pvec2
idx_t * pvec2
Definition: libmetis/struct.h:200
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
cnbrpoolReset
void cnbrpoolReset(ctrl_t *ctrl)
Definition: wspace.c:163
ctrl_t::nparts
idx_t nparts
Definition: libmetis/struct.h:163
gk_free
void gk_free(void **ptr1,...)
Definition: memory.c:202
cnbrpoolGetNext
idx_t cnbrpoolGetNext(ctrl_t *ctrl, idx_t nnbrs)
Definition: wspace.c:172
ctrl_t
Definition: libmetis/struct.h:139
imalloc
#define imalloc
Definition: gklib_rename.h:42
IFSET
#define IFSET(a, flag, cmd)
Definition: gk_macros.h:45
ctrl_t::maxnads
idx_t * maxnads
Definition: libmetis/struct.h:196
ctrl_t::cnbrpool
cnbr_t * cnbrpool
Definition: libmetis/struct.h:188
iFreeMatrix
#define iFreeMatrix
Definition: gklib_rename.h:21
gk_realloc
void * gk_realloc(void *oldptr, size_t nbytes, char *msg)
Definition: memory.c:172
ismalloc
#define ismalloc
Definition: gklib_rename.h:68
vnbr_t
Definition: libmetis/struct.h:47
n
int n
Definition: BiCGSTAB_simple.cpp:1
ctrl_t::nads
idx_t * nads
Definition: libmetis/struct.h:197
wspacemalloc
void * wspacemalloc(ctrl_t *ctrl, size_t nbytes)
Definition: wspace.c:108
ctrl_t::pvec1
idx_t * pvec1
Definition: libmetis/struct.h:200
ctrl_t::adwgts
idx_t ** adwgts
Definition: libmetis/struct.h:199
METIS_DBG_INFO
@ METIS_DBG_INFO
Definition: include/metis.h:340
wspacepush
void wspacepush(ctrl_t *ctrl)
Definition: wspace.c:118
ctrl_t::nbrpoolsize
size_t nbrpoolsize
Definition: libmetis/struct.h:184
LTERM
#define LTERM
Definition: gk_defs.h:14
ctrl_t::objtype
mobjtype_et objtype
Definition: libmetis/struct.h:141
ctrl_t::nbrpoolreallocs
size_t nbrpoolreallocs
Definition: libmetis/struct.h:186
SIGERR
#define SIGERR
Definition: gk_defs.h:38
ctrl_t::minconn
idx_t minconn
Definition: libmetis/struct.h:150
vnbrpoolGetNext
idx_t vnbrpoolGetNext(ctrl_t *ctrl, idx_t nnbrs)
Definition: wspace.c:200
iwspacemalloc
idx_t * iwspacemalloc(ctrl_t *ctrl, idx_t n)
Definition: wspace.c:136
METIS_OP_PMETIS
@ METIS_OP_PMETIS
Definition: include/metis.h:263
AllocateRefinementWorkSpace
void AllocateRefinementWorkSpace(ctrl_t *ctrl, idx_t nbrpoolsize)
Definition: wspace.c:43
gk_mcoreCreate
gk_mcore_t * gk_mcoreCreate(size_t coresize)
Definition: mcore.c:18
ikvwspacemalloc
ikv_t * ikvwspacemalloc(ctrl_t *ctrl, idx_t n)
Definition: wspace.c:154
ctrl_t::adids
idx_t ** adids
Definition: libmetis/struct.h:198
AllocateWorkSpace
void AllocateWorkSpace(ctrl_t *ctrl, graph_t *graph)
Definition: wspace.c:17
ctrl_t::optype
moptype_et optype
Definition: libmetis/struct.h:140
iAllocMatrix
#define iAllocMatrix
Definition: gklib_rename.h:20
METIS_OBJTYPE_VOL
@ METIS_OBJTYPE_VOL
Definition: include/metis.h:356
rwspacemalloc
real_t * rwspacemalloc(ctrl_t *ctrl, idx_t n)
Definition: wspace.c:145
real_t
float real_t
Definition: include/metis.h:132
INIT_MAXNAD
#define INIT_MAXNAD
Definition: libmetis/defs.h:25
METIS_OBJTYPE_CUT
@ METIS_OBJTYPE_CUT
Definition: include/metis.h:355
ctrl_t::dbglvl
mdbglvl_et dbglvl
Definition: libmetis/struct.h:142
metislib.h
ctrl_t::mcore
gk_mcore_t * mcore
Definition: libmetis/struct.h:180
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
gk_max
#define gk_max(a, b)
Definition: gk_macros.h:16
ctrl_t::nbrpoolcpos
size_t nbrpoolcpos
Definition: libmetis/struct.h:185
gk_malloc
void * gk_malloc(size_t nbytes, char *msg)
Definition: memory.c:140
wspacepop
void wspacepop(ctrl_t *ctrl)
Definition: wspace.c:127
gk_mcorePop
void gk_mcorePop(gk_mcore_t *mcore)
Definition: mcore.c:198
gk_errexit
void gk_errexit(int signum, char *f_str,...)
Definition: error.c:76
ctrl_t::vnbrpool
vnbr_t * vnbrpool
Definition: libmetis/struct.h:191
gk_mcoreDestroy
void gk_mcoreDestroy(gk_mcore_t **r_mcore, int showstats)
Definition: mcore.c:67
graph_t
Definition: libmetis/struct.h:82
gk_mcorePush
void gk_mcorePush(gk_mcore_t *mcore)
Definition: mcore.c:175
idx_t
int32_t idx_t
Definition: include/metis.h:101
gk_mcoreMalloc
void * gk_mcoreMalloc(gk_mcore_t *mcore, size_t nbytes)
Definition: mcore.c:140
FreeWorkSpace
void FreeWorkSpace(ctrl_t *ctrl)
Definition: wspace.c:80


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:43:12