mt-Metis
base.h
Go to the documentation of this file.
1 
13 #ifndef MTMETIS_BASE_H
14 #define MTMETIS_BASE_H
15 
16 
17 
18 
19 /******************************************************************************
20 * EXTERNAL INCLUDES ***********************************************************
21 ******************************************************************************/
22 
23 
24 #define _POSIX_SOURCE 1
25 
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <omp.h>
29 #include <mtmetis.h>
30 #include <domlib.h>
31 
32 
33 
34 
35 /******************************************************************************
36 * MACRO INCLUDES **************************************************************
37 ******************************************************************************/
38 
39 
40 #include "strings.h"
41 #include "macros.h"
42 
43 
44 
45 
46 /******************************************************************************
47 * TYPES ***********************************************************************
48 ******************************************************************************/
49 
50 
51 #ifdef MTMETIS_64BIT_THREADS
52 typedef uint64_t mtmetis_tid_type;
53 #else
54 typedef uint32_t mtmetis_tid_type;
55 #endif
56 
57 
58 typedef int64_t mtmetis_twgt_type;
59 typedef uint16_t mtmetis_offset_type;
60 
61 
62 /* rename mtmetis.h types for internal use */
63 #define vtx_type mtmetis_vtx_type
64 #define adj_type mtmetis_adj_type
65 #define wgt_type mtmetis_wgt_type
66 #define twgt_type mtmetis_twgt_type
67 #define pid_type mtmetis_pid_type
68 #define tid_type mtmetis_tid_type
69 #define real_type mtmetis_real_type
70 #define offset_type mtmetis_offset_type
71 
72 
73 
74 
75 /******************************************************************************
76 * CONSTANTS *******************************************************************
77 ******************************************************************************/
78 
79 
80 /* macros */
81 #define DEF_NULL_VTX ((vtx_type)-1)
82 #define DEF_NULL_ADJ ((adj_type)-1)
83 #define DEF_NULL_PID ((pid_type)-1)
84 #define DEF_NULL_TID ((tid_type)-1)
85 #define DEF_NULL_WGT ((wgt_type)-1)
86 #define DEF_NULL_OFFSET ((offset_type)-1)
87 
88 
89 /* type null values */
90 static const vtx_type NULL_VTX = DEF_NULL_VTX;
91 static const wgt_type NULL_WGT = DEF_NULL_WGT;
92 static const adj_type NULL_ADJ = DEF_NULL_ADJ;
93 static const pid_type NULL_PID = DEF_NULL_PID;
94 static const tid_type NULL_TID = DEF_NULL_TID;
95 static const offset_type NULL_OFFSET = DEF_NULL_OFFSET;
96 
97 
98 /* thread specific constants */
99 static const vtx_type BLOCKSIZE = 0x1000;
100 static const int BLOCKSHIFT = 12;
101 static const vtx_type BLOCKMASK = 0x0FFF;
102 
103 
104 
105 
106 /******************************************************************************
107 * DOMLIB MACROS ***************************************************************
108 ******************************************************************************/
109 
110 
111 /* vtx_type */
112 #define DLMEM_PREFIX vtx
113 #define DLMEM_TYPE_T vtx_type
114 #define DLMEM_DLTYPE DLTYPE_INTEGRAL
115 #define DLMEM_STATIC
116 #include "dlmem_headers.h"
117 #undef DLMEM_STATIC
118 #undef DLMEM_DLTYPE
119 #undef DLMEM_PREFIX
120 #undef DLMEM_TYPE_T
121 
122 
123 #define DLMATH_PREFIX vtx
124 #define DLMATH_TYPE_T vtx_type
125 #define DLMATH_DLTYPE DLTYPE_INTEGRAL
126 #define DLMATH_STATIC
127 #include "dlmath_headers.h"
128 #undef DLMATH_STATIC
129 #undef DLMATH_DLTYPE
130 #undef DLMATH_PREFIX
131 #undef DLMATH_TYPE_T
132 
133 
134 #define DLRAND_PREFIX vtx
135 #define DLRAND_TYPE_T vtx_type
136 #define DLRAND_DLTYPE DLTYPE_INTEGRAL
137 #define DLRAND_STATIC
138 #include "dlrand_headers.h"
139 #undef DLRAND_STATIC
140 #undef DLRAND_DLTYPE
141 #undef DLRAND_PREFIX
142 #undef DLRAND_TYPE_T
143 
144 
145 #define DLSTATS_PREFIX vtx
146 #define DLSTATS_TYPE_T vtx_type
147 #define DLSTATS_STATIC
148 #include "dlstats_headers.h"
149 #undef DLSTATS_STATIC
150 #undef DLSTATS_PREFIX
151 #undef DLSTATS_TYPE_T
152 
153 
154 #define DLISET_PREFIX vtx
155 #define DLISET_TYPE_T vtx_type
156 #define DLISET_STATIC
157 #include "dliset_headers.h"
158 #undef DLISET_STATIC
159 #undef DLISET_TYPE_T
160 #undef DLISET_PREFIX
161 
162 
163 #define DLTHREAD_PREFIX vtx
164 #define DLTHREAD_TYPE_T vtx_type
165 #define DLTHREAD_STATIC 1
166 #include "dlthread_reduction_headers.h"
167 #undef DLTHREAD_STATIC
168 #undef DLTHREAD_TYPE_T
169 #undef DLTHREAD_PREFIX
170 
171 
172 #define DLSORT_PREFIX vtx
173 #define DLSORT_TYPE_T vtx_type
174 #define DLSORT_STATIC
175 #include "dlsort_headers.h"
176 #undef DLSORT_STATIC
177 #undef DLSORT_TYPE_T
178 #undef DLSORT_PREFIX
179 
180 
181 
182 
183 /* adj_type */
184 #define DLMEM_PREFIX adj
185 #define DLMEM_TYPE_T adj_type
186 #define DLMEM_DLTYPE DLTYPE_INTEGRAL
187 #define DLMEM_STATIC
188 #include "dlmem_headers.h"
189 #undef DLMEM_STATIC
190 #undef DLMEM_DLTYPE
191 #undef DLMEM_PREFIX
192 #undef DLMEM_TYPE_T
193 
194 
195 #define DLMATH_PREFIX adj
196 #define DLMATH_TYPE_T adj_type
197 #define DLMATH_DLTYPE DLTYPE_INTEGRAL
198 #define DLMATH_STATIC
199 #include "dlmath_headers.h"
200 #undef DLMATH_STATIC
201 #undef DLMATH_DLTYPE
202 #undef DLMATH_PREFIX
203 #undef DLMATH_TYPE_T
204 
205 
206 #define DLRAND_PREFIX adj
207 #define DLRAND_TYPE_T adj_type
208 #define DLRAND_DLTYPE DLTYPE_INTEGRAL
209 #define DLRAND_STATIC
210 #include "dlrand_headers.h"
211 #undef DLRAND_STATIC
212 #undef DLRAND_DLTYPE
213 #undef DLRAND_PREFIX
214 #undef DLRAND_TYPE_T
215 
216 
217 #define DLSTATS_PREFIX adj
218 #define DLSTATS_TYPE_T adj_type
219 #define DLSTATS_STATIC
220 #include "dlstats_headers.h"
221 #undef DLSTATS_STATIC
222 #undef DLSTATS_PREFIX
223 #undef DLSTATS_TYPE_T
224 
225 
226 #define DLTHREAD_PREFIX adj
227 #define DLTHREAD_TYPE_T adj_type
228 #define DLTHREAD_STATIC 1
229 #include "dlthread_reduction_headers.h"
230 #undef DLTHREAD_STATIC
231 #undef DLTHREAD_TYPE_T
232 #undef DLTHREAD_PREFIX
233 
234 
235 
236 
237 /* pid_type */
238 #define DLMEM_PREFIX pid
239 #define DLMEM_TYPE_T pid_type
240 #define DLMEM_DLTYPE DLTYPE_INTEGRAL
241 #define DLMEM_STATIC
242 #include "dlmem_headers.h"
243 #undef DLMEM_STATIC
244 #undef DLMEM_DLTYPE
245 #undef DLMEM_PREFIX
246 #undef DLMEM_TYPE_T
247 
248 
249 #define DLMATH_PREFIX pid
250 #define DLMATH_TYPE_T pid_type
251 #define DLMATH_DLTYPE DLTYPE_INTEGRAL
252 #define DLMATH_STATIC
253 #include "dlmath_headers.h"
254 #undef DLMATH_STATIC
255 #undef DLMATH_DLTYPE
256 #undef DLMATH_PREFIX
257 #undef DLMATH_TYPE_T
258 
259 
260 #define DLRAND_PREFIX pid
261 #define DLRAND_TYPE_T pid_type
262 #define DLRAND_DLTYPE DLTYPE_INTEGRAL
263 #define DLRAND_STATIC
264 #include "dlrand_headers.h"
265 #undef DLRAND_STATIC
266 #undef DLRAND_DLTYPE
267 #undef DLRAND_PREFIX
268 #undef DLRAND_TYPE_T
269 
270 
271 #define DLSTATS_PREFIX pid
272 #define DLSTATS_TYPE_T pid_type
273 #define DLSTATS_STATIC
274 #include "dlstats_headers.h"
275 #undef DLSTATS_STATIC
276 #undef DLSTATS_PREFIX
277 #undef DLSTATS_TYPE_T
278 
279 
280 /* tid_type */
281 #define DLMEM_PREFIX tid
282 #define DLMEM_TYPE_T tid_type
283 #define DLMEM_DLTYPE DLTYPE_INTEGRAL
284 #define DLMEM_STATIC
285 #include "dlmem_headers.h"
286 #undef DLMEM_STATIC
287 #undef DLMEM_DLTYPE
288 #undef DLMEM_PREFIX
289 #undef DLMEM_TYPE_T
290 
291 
292 #define DLMATH_PREFIX tid
293 #define DLMATH_TYPE_T tid_type
294 #define DLMATH_DLTYPE DLTYPE_INTEGRAL
295 #define DLMATH_STATIC
296 #include "dlmath_headers.h"
297 #undef DLMATH_STATIC
298 #undef DLMATH_DLTYPE
299 #undef DLMATH_PREFIX
300 #undef DLMATH_TYPE_T
301 
302 
303 /* wgt_type */
304 #define DLMEM_PREFIX wgt
305 #define DLMEM_TYPE_T wgt_type
306 #define DLMEM_DLTYPE DLTYPE_INTEGRAL
307 #define DLMEM_STATIC
308 #include "dlmem_headers.h"
309 #undef DLMEM_STATIC
310 #undef DLMEM_DLTYPE
311 #undef DLMEM_PREFIX
312 #undef DLMEM_TYPE_T
313 
314 
315 #define DLMATH_PREFIX wgt
316 #define DLMATH_TYPE_T wgt_type
317 #define DLMATH_DLTYPE DLTYPE_INTEGRAL
318 #define DLMATH_STATIC
319 #include "dlmath_headers.h"
320 #undef DLMATH_STATIC
321 #undef DLMATH_DLTYPE
322 #undef DLMATH_PREFIX
323 #undef DLMATH_TYPE_T
324 
325 
326 #define DLRAND_PREFIX wgt
327 #define DLRAND_TYPE_T wgt_type
328 #define DLRAND_DLTYPE DLTYPE_INTEGRAL
329 #define DLRAND_STATIC
330 #include "dlrand_headers.h"
331 #undef DLRAND_STATIC
332 #undef DLRAND_DLTYPE
333 #undef DLRAND_PREFIX
334 #undef DLRAND_TYPE_T
335 
336 
337 #define DLSTATS_PREFIX wgt
338 #define DLSTATS_TYPE_T wgt_type
339 #define DLSTATS_STATIC
340 #include "dlstats_headers.h"
341 #undef DLSTATS_STATIC
342 #undef DLSTATS_PREFIX
343 #undef DLSTATS_TYPE_T
344 
345 
346 #define DLTHREAD_PREFIX wgt
347 #define DLTHREAD_TYPE_T wgt_type
348 #define DLTHREAD_STATIC 1
349 #include "dlthread_reduction_headers.h"
350 #undef DLTHREAD_STATIC
351 #undef DLTHREAD_TYPE_T
352 #undef DLTHREAD_PREFIX
353 
354 
355 /* twgt_type */
356 #define DLTHREAD_PREFIX twgt
357 #define DLTHREAD_TYPE_T twgt_type
358 #define DLTHREAD_STATIC 1
359 #include "dlthread_reduction_headers.h"
360 #undef DLTHREAD_STATIC
361 #undef DLTHREAD_TYPE_T
362 #undef DLTHREAD_PREFIX
363 
364 
365 #define DLMATH_PREFIX twgt
366 #define DLMATH_TYPE_T twgt_type
367 #define DLMATH_DLTYPE DLTYPE_INTEGRAL
368 #define DLMATH_STATIC
369 #include "dlmath_headers.h"
370 #undef DLMATH_STATIC
371 #undef DLMATH_DLTYPE
372 #undef DLMATH_PREFIX
373 #undef DLMATH_TYPE_T
374 
375 
376 /* real_type */
377 #define DLMEM_PREFIX real
378 #define DLMEM_TYPE_T real_type
379 #define DLMEM_DLTYPE DLTYPE_FLOAT
380 #define DLMEM_STATIC
381 #include "dlmem_headers.h"
382 #undef DLMEM_STATIC
383 #undef DLMEM_DLTYPE
384 #undef DLMEM_PREFIX
385 #undef DLMEM_TYPE_T
386 
387 
388 #define DLMATH_PREFIX real
389 #define DLMATH_TYPE_T real_type
390 #define DLMATH_DLTYPE DLTYPE_FLOAT
391 #define DLMATH_STATIC
392 #include "dlmath_headers.h"
393 #undef DLMATH_STATIC
394 #undef DLMATH_DLTYPE
395 #undef DLMATH_PREFIX
396 #undef DLMATH_TYPE_T
397 
398 
399 #define DLTHREAD_PREFIX double
400 #define DLTHREAD_TYPE_T double
401 #define DLTHREAD_STATIC 1
402 #include "dlthread_reduction_headers.h"
403 #undef DLTHREAD_STATIC
404 #undef DLTHREAD_TYPE_T
405 #undef DLTHREAD_PREFIX
406 
407 
408 /* int */
409 
410 #define DLTHREAD_PREFIX int
411 #define DLTHREAD_TYPE_T int
412 #define DLTHREAD_STATIC 1
413 #include "dlthread_reduction_headers.h"
414 #undef DLTHREAD_STATIC
415 #undef DLTHREAD_TYPE_T
416 #undef DLTHREAD_PREFIX
417 
418 
419 /* offset_type */
420 
421 #define DLMEM_PREFIX offset
422 #define DLMEM_TYPE_T offset_type
423 #define DLMEM_STATIC 1
424 #include "dlmem_headers.h"
425 #undef DLMEM_STATIC
426 #undef DLMEM_TYPE_T
427 #undef DLMEM_PREFIX
428 
429 
430 
431 
432 /******************************************************************************
433 * MACROS **********************************************************************
434 ******************************************************************************/
435 
436 
437 #ifdef DEBUG
438  #define par_dprintf(...) \
439  do { \
440  _Pragma("omp master") \
441  { \
442  dprintf( __VA_ARGS__ ); \
443  } \
444  } while(0)
445 #else
446  #define par_dprintf(...)
447 #endif
448 
449 #define par_vprintf(...) \
450  do { \
451  _Pragma("omp master") \
452  { \
453  vprintf( __VA_ARGS__ ); \
454  } \
455  } while(0)
456 
457 
458 
459 
460 /******************************************************************************
461 * INLINE FUNCTIONS ************************************************************
462 ******************************************************************************/
463 
464 
465 static inline vtx_type gvtx_to_lvtx(
466  vtx_type const v,
467  vtx_type const mask)
468 {
469  DL_ASSERT(mask > 0,"The mask is set to 0!\n");
470  DL_ASSERT(v > mask,"Global vertex number is smaller than mask (gvtx = %"
471  PF_VTX_T", mask = %"PF_VTX_T")\n",v,mask);
472  return v & mask;
473 }
474 
475 
476 static inline vtx_type lvtx_to_gvtx(
477  vtx_type const v,
478  tid_type const t,
479  int const shift)
480 {
481  DL_ASSERT(shift > 0,"The mask size is set to 0!\n");
482  DL_ASSERT(v < (vtx_type)(1 << shift),"Local vertex number is greater than "
483  "shift (lvtx = %"PF_VTX_T", shift = %d)\n",v,shift);
484  return ((t+1) << shift) | v;
485 }
486 
487 
488 static inline tid_type gvtx_to_tid(
489  vtx_type const v,
490  int const shift)
491 {
492  DL_ASSERT(shift > 0,"The shift size is set to %d!\n",shift);
493  DL_ASSERT(v >= (vtx_type)(1 << shift),"Global vertex number is too small "
494  "(gvtx = %"PF_VTX_T", shift = %d)\n",v,shift);
495  return (v >> shift)-1;
496 }
497 
498 
499 static inline vtx_type max_gvtx(
500  int const shift,
501  tid_type const nthreads)
502 {
503  return (vtx_type)(1 << shift)*(nthreads+1);
504 }
505 
506 
507 static inline int is_bnd(
508  wgt_type const id,
509  wgt_type const ed,
510  int const greedy)
511 {
512  if (greedy) {
513  return ed >= id;
514  } else {
515  return (ed > 0) || (id == 0);
516  }
517 }
518 
519 
520 /* avoid having to pass each element */
521 #define gvtx_to_lvtx(v,dist) gvtx_to_lvtx(v,(dist).mask)
522 #define lvtx_to_gvtx(v,t,dist) lvtx_to_gvtx(v,t,(dist).shift)
523 #define gvtx_to_tid(v,dist) gvtx_to_tid(v,(dist).shift)
524 #define max_gvtx(graph) max_gvtx((graph)->dist.shift,(graph)->dist.nthreads)
525 
526 
527 
528 
529 
530 
531 #endif
String defines for mt-Metis.
Macros and some micro-Macros...
Library entry points.