mt-Metis
kwinfo.h
Go to the documentation of this file.
1 
13 #ifndef MTMETIS_KWINFO_H
14 #define MTMETIS_KWINFO_H
15 
16 
17 
18 
19 #include "base.h"
20 #include "graph.h"
21 #include "ctrl.h"
22 
23 
24 
25 
26 /******************************************************************************
27 * TYPES ***********************************************************************
28 ******************************************************************************/
29 
30 
31 typedef struct adjinfo_type {
32  wgt_type ed;
33  pid_type pid;
34 } adjinfo_type;
35 
36 
37 typedef struct kwnbrinfo_type {
38  wgt_type id;
39  wgt_type ed;
40  pid_type nnbrs;
41  adj_type nbrstart;
43 
44 
45 typedef struct kwinfo_type {
46  pid_type nparts;
47  vtx_iset_t * bnd;
48  kwnbrinfo_type * nbrinfo;
49  adj_type nnbrpool;
50  adj_type basennbrs;
51  size_t basebits;
52  size_t npools;
53  adjinfo_type ** nbrpools;
54  dlthread_lock_t lock;
55 } kwinfo_type;
56 
57 
58 
59 
60 /******************************************************************************
61 * DOMLIB MACROS ***************************************************************
62 ******************************************************************************/
63 
64 
65 #define DLMEM_PREFIX kwnbrinfo
66 #define DLMEM_TYPE_T kwnbrinfo_type
67 #include <dlmem_headers.h>
68 #undef DLMEM_TYPE_T
69 #undef DLMEM_PREFIX
70 
71 
72 #define DLMEM_PREFIX adjinfo
73 #define DLMEM_TYPE_T adjinfo_type
74 #include <dlmem_headers.h>
75 #undef DLMEM_TYPE_T
76 #undef DLMEM_PREFIX
77 
78 
79 
80 
81 /******************************************************************************
82 * FUNCTION PROTOTYPES *********************************************************
83 ******************************************************************************/
84 
85 
86 #define par_kwinfo_create MTMETIS_par_kwinfo_create
87 
94  ctrl_type * ctrl,
95  graph_type * graph);
96 
97 
98 #define par_kwinfo_free MTMETIS_par_kwinfo_free
99 
104 void par_kwinfo_free(
105  graph_type * graph);
106 
107 
108 
109 
110 /******************************************************************************
111 * INLINE FUNCTIONS ************************************************************
112 ******************************************************************************/
113 
114 
115 static inline adjinfo_type * kwinfo_get_nbrs(
116  kwinfo_type * const kwinfo,
117  vtx_type const v,
118  pid_type const maxnnbrs)
119 {
120  size_t pool;
121  adj_type psize, pstart;
122  kwnbrinfo_type * myrinfo;
123  adjinfo_type * mynbrs;
124 
125  if (maxnnbrs == 0) {
126  return NULL;
127  }
128 
129  myrinfo = kwinfo->nbrinfo + v;
130 
131  if (myrinfo->nbrstart == NULL_ADJ) {
132  myrinfo->nbrstart = kwinfo->nnbrpool;
133  kwinfo->nnbrpool += maxnnbrs;
134  }
135 
136  /* find the pool */
137  pool = size_downlog2(((myrinfo->nbrstart+maxnnbrs-1)>>kwinfo->basebits)+1);
138  psize = kwinfo->basennbrs << pool;
139  pstart = psize-kwinfo->basennbrs;
140 
141  /* allocate new pool if it doesn't exist */
142  if (kwinfo->nbrpools[pool] == NULL) {
143  kwinfo->nbrpools[pool] = malloc(sizeof(adjinfo_type)*psize);
144  }
145 
146  DL_ASSERT(myrinfo->nbrstart != NULL_ADJ,"Bad nbrstart");
147 
148  if (pstart > myrinfo->nbrstart) {
149  /* Got pushed out of the previous pool - bump up nbrstart */
150  myrinfo->nbrstart = pstart;
151  kwinfo->nnbrpool = pstart+maxnnbrs;
152  mynbrs = kwinfo->nbrpools[pool];
153  } else {
154  /* landed squarely in this pool */
155  mynbrs = kwinfo->nbrpools[pool] + (myrinfo->nbrstart - pstart);
156  }
157 
158  DL_ASSERT(mynbrs < kwinfo->nbrpools[pool] + psize,"Bad mynbrs");
159  DL_ASSERT(mynbrs >= kwinfo->nbrpools[pool],"Bad mynbrs");
160 
161  return mynbrs;
162 }
163 
164 
165 static inline adjinfo_type * kwinfo_get_nbrs_lk(
166  kwinfo_type * const kwinfo,
167  vtx_type const v,
168  pid_type const maxnnbrs)
169 {
170  size_t pool;
171  adj_type psize, pstart;
172  kwnbrinfo_type * myrinfo;
173  adjinfo_type * mynbrs;
174 
175  if (maxnnbrs == 0) {
176  return NULL;
177  }
178 
179  myrinfo = kwinfo->nbrinfo + v;
180 
181  if (myrinfo->nbrstart == NULL_ADJ) {
182  dlthread_set_lock(&(kwinfo->lock));
183  myrinfo->nbrstart = kwinfo->nnbrpool;
184  kwinfo->nnbrpool += maxnnbrs;
185  dlthread_unset_lock(&(kwinfo->lock));
186  }
187 
188  /* find the pool */
189  pool = size_downlog2(((myrinfo->nbrstart+maxnnbrs-1)>>kwinfo->basebits)+1);
190  psize = kwinfo->basennbrs << pool;
191  pstart = psize-kwinfo->basennbrs;
192 
193  /* allocate new pool if it doesn't exist */
194  if (kwinfo->nbrpools[pool] == NULL) {
195  dlthread_set_lock(&(kwinfo->lock));
196  if (kwinfo->nbrpools[pool] == NULL) {
197  kwinfo->nbrpools[pool] = malloc(sizeof(adjinfo_type)*psize);
198  }
199  dlthread_unset_lock(&(kwinfo->lock));
200  }
201 
202  DL_ASSERT(myrinfo->nbrstart != NULL_ADJ,"Bad nbrstart");
203 
204  if (pstart > myrinfo->nbrstart) {
205  /* Got pushed out of the previous pool - bump up nbrstart */
206  myrinfo->nbrstart = pstart;
207  kwinfo->nnbrpool = pstart+maxnnbrs;
208  mynbrs = kwinfo->nbrpools[pool];
209  } else {
210  /* landed squarely in this pool */
211  mynbrs = kwinfo->nbrpools[pool] + (myrinfo->nbrstart - pstart);
212  }
213 
214  DL_ASSERT(mynbrs < kwinfo->nbrpools[pool] + psize,"Bad mynbrs");
215  DL_ASSERT(mynbrs >= kwinfo->nbrpools[pool],"Bad mynbrs");
216 
217  return mynbrs;
218 }
219 
220 
221 static inline adjinfo_type const * kwinfo_get_nbrs_ro(
222  kwinfo_type const * const kwinfo,
223  vtx_type const v,
224  pid_type const maxnnbrs)
225 {
226  size_t pool;
227  adj_type psize, pstart;
228  kwnbrinfo_type * myrinfo;
229  adjinfo_type * mynbrs;
230 
231  myrinfo = kwinfo->nbrinfo + v;
232 
233  if (maxnnbrs == 0 || myrinfo->nbrstart == NULL_ADJ) {
234  return NULL;
235  }
236 
237  /* find the pool */
238  pool = size_downlog2(((myrinfo->nbrstart+maxnnbrs-1)>>kwinfo->basebits)+1);
239  psize = kwinfo->basennbrs << pool;
240  pstart = psize-kwinfo->basennbrs;
241 
242  mynbrs = kwinfo->nbrpools[pool] + (myrinfo->nbrstart - pstart);
243 
244  DL_ASSERT(mynbrs < kwinfo->nbrpools[pool] + psize,"Bad mynbrs");
245  DL_ASSERT(mynbrs >= kwinfo->nbrpools[pool],"Bad mynbrs");
246 
247  return mynbrs;
248 }
249 
250 
251 
252 #endif
Type and function prototypes for the ctrl structure.
Definition: graph.h:38
Definition: ctrl.h:48
Definition: kwinfo.h:31
void par_kwinfo_free(graph_type *graph)
Free a kwinfo and its associate memory owned by graph.
Definition: kwinfo.c:102
Types and functions for distributed graph objects.
Base types etc.
void par_kwinfo_create(ctrl_type *ctrl, graph_type *graph)
Allocate the memory arrays for refinement.
Definition: kwinfo.c:62
Definition: kwinfo.h:45
Definition: kwinfo.h:37