oomph_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.8 2003/07/21 19:11:46 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 /* #define RandomInRange(u) (rand()%(u)) */
21 
22 #define amax(a, b) ((a) >= (b) ? (a) : (b))
23 #define amin(a, b) ((a) >= (b) ? (b) : (a))
24 
25 #define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b)))
26 #define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b)))
27 #define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b)))
28 
29 #define SWAP(a, b, tmp) \
30  do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0)
31 
32 #define INC_DEC(a, b, val) \
33  do {(a) += (val); (b) -= (val);} while(0)
34 
35 
36 #define icopy(n, a, b) memcpy((b), (a), sizeof(int)*(n))
37 #define scopy(n, a, b) memcpy((b), (a), sizeof(float)*(n))
38 #define idxcopy(n, a, b) memcpy((b), (a), sizeof(idxtype)*(n))
39 
40 #define HASHFCT(key, size) ((key)%(size))
41 
42 
43 /*************************************************************************
44 * Timer macros
45 **************************************************************************/
46 #define cleartimer(tmr) (tmr = 0.0)
47 #define starttimer(tmr) (tmr -= MPI_Wtime())
48 #define stoptimer(tmr) (tmr += MPI_Wtime())
49 #define gettimer(tmr) (tmr)
50 
51 
52 /*************************************************************************
53 * This macro is used to handle dbglvl
54 **************************************************************************/
55 #define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd);
56 
57 /*************************************************************************
58 * These macros are used for debuging memory leaks
59 **************************************************************************/
60 #ifdef DMALLOC
61 #define imalloc(n, msg) (malloc(sizeof(int)*(n)))
62 #define fmalloc(n, msg) (malloc(sizeof(float)*(n)))
63 #define idxmalloc(n, msg) (malloc(sizeof(idxtype)*(n)))
64 #define ismalloc(n, val, msg) (iset((n), (val), malloc(sizeof(int)*(n))))
65 #define idxsmalloc(n, val, msg) (idxset((n), (val), malloc(sizeof(idxtype)*(n))))
66 #define GKmalloc(a, b) (malloc(a))
67 #endif
68 
69 #ifdef DMALLOC
70 # define MALLOC_CHECK(ptr);
71 /*
72 # define MALLOC_CHECK(ptr) \
73  if (malloc_verify((ptr)) == DMALLOC_VERIFY_ERROR) { \
74  printf("***MALLOC_CHECK failed on line %d of file %s: " #ptr "\n", \
75  __LINE__, __FILE__); \
76  abort(); \
77  }
78 */
79 #else
80 # define MALLOC_CHECK(ptr) ;
81 #endif
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 #define SHIFTCSR(i, n, a) \
95  do { \
96  for (i=n; i>0; i--) a[i] = a[i-1]; \
97  a[0] = 0; \
98  } while(0)
99 
100 
101 
102 #ifndef NDEBUG
103 # define ASSERT(ctrl, expr) \
104  if (!(expr)) { \
105  myprintf(ctrl, "***ASSERTION failed on line %d of file %s: " #expr "\n", \
106  __LINE__, __FILE__); \
107  assert(expr); \
108  }
109 
110 # define ASSERTP(ctrl, expr, msg) \
111  if (!(expr)) { \
112  myprintf(ctrl, "***ASSERTION failed on line %d of file %s:" #expr "\n", \
113  __LINE__, __FILE__); \
114  myprintf msg ; \
115  assert(expr); \
116  }
117 
118 # define ASSERTS(expr) \
119  if (!(expr)) { \
120  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
121  __LINE__, __FILE__); \
122  assert(expr); \
123  }
124 
125 # define ASSERTSP(expr, msg) \
126  if (!(expr)) { \
127  printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
128  __LINE__, __FILE__); \
129  printf msg ; \
130  assert(expr); \
131  }
132 
133 #else
134 # define ASSERT(ctrl, expr) ;
135 # define ASSERTP(ctrl, expr,msg) ;
136 # define ASSERTS(expr) ;
137 # define ASSERTSP(expr, msg) ;
138 #endif
139 
140 
141 /*************************************************************************
142  * * These macros insert and remove nodes from the boundary list
143  * **************************************************************************/
144 #define BNDInsert(nbnd, bndind, bndptr, vtx) \
145  do { \
146  bndind[nbnd] = vtx; \
147  bndptr[vtx] = nbnd++;\
148  } while(0)
149 
150 #define BNDDelete(nbnd, bndind, bndptr, vtx) \
151  do { \
152  bndind[bndptr[vtx]] = bndind[--nbnd]; \
153  bndptr[bndind[nbnd]] = bndptr[vtx]; \
154  bndptr[vtx] = -1; \
155  } while(0)
156 
157