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