oomph_metis_from_parmetis_3.1.1/macros.h
Go to the documentation of this file.
1 /*
2  * Copyright 1997, Regents of the University of Minnesota
3  *
4  * macros.h
5  *
6  * This file contains macros used in multilevel
7  *
8  * Started 9/25/94
9  * George
10  *
11  * $Id: macros.h,v 1.7 2003/07/21 19:11:40 karypis Exp $
12  *
13  */
14 
15 
16 /*************************************************************************
17 * The following macro returns a random number in the specified range
18 **************************************************************************/
19 #define RandomInRange(u) ((int)(1.0*(u)*rand()/(RAND_MAX+1.0)))
20 
21 #define amax(a, b) ((a) >= (b) ? (a) : (b))
22 #define amin(a, b) ((a) >= (b) ? (b) : (a))
23 
24 #define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b)))
25 #define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b)))
26 #define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b)))
27 
28 #define SWAP(a, b, tmp) \
29  do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0)
30 
31 #define INC_DEC(a, b, val) \
32  do {(a) += (val); (b) -= (val);} while(0)
33 
34 
35 #define scopy(n, a, b) (float *)memcpy((void *)(b), (void *)(a), sizeof(float)*(n))
36 #define idxcopy(n, a, b) (idxtype *)memcpy((void *)(b), (void *)(a), sizeof(idxtype)*(n))
37 
38 #define HASHFCT(key, size) ((key)%(size))
39 
40 
41 /*************************************************************************
42 * Timer macros
43 **************************************************************************/
44 #define cleartimer(tmr) (tmr = 0.0)
45 #define starttimer(tmr) (tmr -= seconds())
46 #define stoptimer(tmr) (tmr += seconds())
47 #define gettimer(tmr) (tmr)
48 
49 
50 /*************************************************************************
51 * This macro is used to handle dbglvl
52 **************************************************************************/
53 #define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd);
54 
55 /*************************************************************************
56 * These macros are used for debuging memory leaks
57 **************************************************************************/
58 #ifdef DMALLOC
59 #define imalloc(n, msg) (malloc(sizeof(int)*(n)))
60 #define fmalloc(n, msg) (malloc(sizeof(float)*(n)))
61 #define idxmalloc(n, msg) (malloc(sizeof(idxtype)*(n)))
62 #define ismalloc(n, val, msg) (iset((n), (val), malloc(sizeof(int)*(n))))
63 #define idxsmalloc(n, val, msg) (idxset((n), (val), malloc(sizeof(idxtype)*(n))))
64 #define GKmalloc(a, b) (malloc((a)))
65 #endif
66 
67 #ifdef DMALLOC
68 # define MALLOC_CHECK(ptr);
69 /*
70 # define MALLOC_CHECK(ptr) \
71  if (malloc_verify((ptr)) == DMALLOC_VERIFY_ERROR) { \
72  printf("***MALLOC_CHECK failed on line %d of file %s: " #ptr "\n", \
73  __LINE__, __FILE__); \
74  abort(); \
75  }
76 */
77 #else
78 # define MALLOC_CHECK(ptr) ;
79 #endif
80 
81 
82 
83 /*************************************************************************
84 * This macro converts a length array in a CSR one
85 **************************************************************************/
86 #define MAKECSR(i, n, a) \
87  do { \
88  for (i=1; i<n; i++) a[i] += a[i-1]; \
89  for (i=n; i>0; i--) a[i] = a[i-1]; \
90  a[0] = 0; \
91  } while(0)
92 
93 
94 /*************************************************************************
95 * These macros insert and remove nodes from the boundary list
96 **************************************************************************/
97 #define BNDInsert(nbnd, bndind, bndptr, vtx) \
98  do { \
99  ASSERT(bndptr[vtx] == -1); \
100  bndind[nbnd] = vtx; \
101  bndptr[vtx] = nbnd++;\
102  } while(0)
103 
104 #define BNDDelete(nbnd, bndind, bndptr, vtx) \
105  do { \
106  ASSERT(bndptr[vtx] != -1); \
107  bndind[bndptr[vtx]] = bndind[--nbnd]; \
108  bndptr[bndind[nbnd]] = bndptr[vtx]; \
109  bndptr[vtx] = -1; \
110  } while(0)
111 
112 
113 
114 /*************************************************************************
115 * These are debugging macros
116 **************************************************************************/
117 #ifdef DEBUG
118 # define ASSERT(expr) \
119  if (!(expr)) { \
120  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
121  __LINE__, __FILE__); \
122  abort(); \
123  }
124 #else
125 # define ASSERT(expr) ;
126 #endif
127 
128 #ifdef DEBUG
129 # define ASSERTP(expr, msg) \
130  if (!(expr)) { \
131  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
132  __LINE__, __FILE__); \
133  printf msg ; \
134  abort(); \
135  }
136 #else
137 # define ASSERTP(expr, msg) ;
138 #endif