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 
void vnbrpoolReset(ctrl_t *ctrl)
Definition: wspace.c:191
#define iFreeMatrix
Definition: gklib_rename.h:21
idx_t * maxnads
void FreeWorkSpace(ctrl_t *ctrl)
Definition: wspace.c:80
vnbr_t * vnbrpool
#define imalloc
Definition: gklib_rename.h:42
#define ismalloc
Definition: gklib_rename.h:68
idx_t cnbrpoolGetNext(ctrl_t *ctrl, idx_t nnbrs)
Definition: wspace.c:172
int n
idx_t nvtxs
void gk_errexit(int signum, char *f_str,...)
Definition: error.c:77
mdbglvl_et dbglvl
idx_t vnbrpoolGetNext(ctrl_t *ctrl, idx_t nnbrs)
Definition: wspace.c:200
NonlinearFactorGraph graph
size_t nbrpoolcpos
void * gk_mcoreMalloc(gk_mcore_t *mcore, size_t nbytes)
Definition: mcore.c:140
idx_t * pvec2
size_t nbrpoolreallocs
gk_mcore_t * gk_mcoreCreate(size_t coresize)
Definition: mcore.c:18
void * gk_realloc(void *oldptr, size_t nbytes, char *msg)
Definition: memory.c:172
void cnbrpoolReset(ctrl_t *ctrl)
Definition: wspace.c:163
void * wspacemalloc(ctrl_t *ctrl, size_t nbytes)
Definition: wspace.c:108
#define SIGERR
Definition: gk_defs.h:38
moptype_et optype
#define gk_max(a, b)
Definition: gk_macros.h:16
int32_t idx_t
cnbr_t * cnbrpool
idx_t nparts
ikv_t * ikvwspacemalloc(ctrl_t *ctrl, idx_t n)
Definition: wspace.c:154
void gk_mcoreDestroy(gk_mcore_t **r_mcore, int showstats)
Definition: mcore.c:67
idx_t ncon
idx_t * nads
void AllocateRefinementWorkSpace(ctrl_t *ctrl, idx_t nbrpoolsize)
Definition: wspace.c:43
gk_mcore_t * mcore
float real_t
void wspacepop(ctrl_t *ctrl)
Definition: wspace.c:127
idx_t * pvec1
idx_t * iwspacemalloc(ctrl_t *ctrl, idx_t n)
Definition: wspace.c:136
void * gk_malloc(size_t nbytes, char *msg)
Definition: memory.c:140
void gk_free(void **ptr1,...)
Definition: memory.c:202
void wspacepush(ctrl_t *ctrl)
Definition: wspace.c:118
idx_t ** adids
#define INIT_MAXNAD
Definition: libmetis/defs.h:25
size_t nbrpoolsize
idx_t ** adwgts
#define IFSET(a, flag, cmd)
Definition: gk_macros.h:45
void gk_mcorePop(gk_mcore_t *mcore)
Definition: mcore.c:198
void AllocateWorkSpace(ctrl_t *ctrl, graph_t *graph)
Definition: wspace.c:17
#define iAllocMatrix
Definition: gklib_rename.h:20
idx_t minconn
void gk_mcorePush(gk_mcore_t *mcore)
Definition: mcore.c:175
real_t * rwspacemalloc(ctrl_t *ctrl, idx_t n)
Definition: wspace.c:145
mobjtype_et objtype
#define LTERM
Definition: gk_defs.h:14


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:25