00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define RandomInRange(u) ((int)(1.0*(u)*rand()/(RAND_MAX+1.0)))
00020
00021 #define amax(a, b) ((a) >= (b) ? (a) : (b))
00022 #define amin(a, b) ((a) >= (b) ? (b) : (a))
00023
00024 #define AND(a, b) ((a) < 0 ? ((-(a))&(b)) : ((a)&(b)))
00025 #define OR(a, b) ((a) < 0 ? -((-(a))|(b)) : ((a)|(b)))
00026 #define XOR(a, b) ((a) < 0 ? -((-(a))^(b)) : ((a)^(b)))
00027
00028 #define SWAP(a, b, tmp) \
00029 do {(tmp) = (a); (a) = (b); (b) = (tmp);} while(0)
00030
00031 #define INC_DEC(a, b, val) \
00032 do {(a) += (val); (b) -= (val);} while(0)
00033
00034
00035 #define icopy(n, a, b) memcpy((b), (a), sizeof(int)*(n))
00036 #define scopy(n, a, b) memcpy((b), (a), sizeof(floattype)*(n))
00037 #define idxcopy(n, a, b) memcpy((b), (a), sizeof(idxtype)*(n))
00038
00039 #define HASHFCT(key, size) ((key)%(size))
00040
00041
00042
00043
00044
00045 #define cleartimer(tmr) (tmr = 0.0)
00046 #define starttimer(tmr) (tmr -= MPI_Wtime())
00047 #define stoptimer(tmr) (tmr += MPI_Wtime())
00048 #define gettimer(tmr) (tmr)
00049
00050
00051
00052
00053
00054 #define IFSET(a, flag, cmd) if ((a)&(flag)) (cmd);
00055
00056
00057
00058
00059 #ifdef DMALLOC
00060 #define imalloc(n, msg) (malloc(sizeof(int)*(n)))
00061 #define fmalloc(n, msg) (malloc(sizeof(floattype)*(n)))
00062 #define idxmalloc(n, msg) (malloc(sizeof(idxtype)*(n)))
00063 #define ismalloc(n, val, msg) (iset((n), (val), malloc(sizeof(int)*(n))))
00064 #define idxsmalloc(n, val, msg) (idxset((n), (val), malloc(sizeof(idxtype)*(n))))
00065 #define GKmalloc(a, b) (malloc(a))
00066 #endif
00067
00068 #ifdef DMALLOC
00069 # define MALLOC_CHECK(ptr);
00070
00071
00072
00073
00074
00075
00076
00077
00078 #else
00079 # define MALLOC_CHECK(ptr) ;
00080 #endif
00081
00082
00083
00084
00085 #define MAKECSR(i, n, a) \
00086 do { \
00087 for (i=1; i<n; i++) a[i] += a[i-1]; \
00088 for (i=n; i>0; i--) a[i] = a[i-1]; \
00089 a[0] = 0; \
00090 } while(0)
00091
00092
00093 #define SHIFTCSR(i, n, a) \
00094 do { \
00095 for (i=n; i>0; i--) a[i] = a[i-1]; \
00096 a[0] = 0; \
00097 } while(0)
00098
00099
00100
00101 #ifdef DEBUG
00102 # define ASSERT(ctrl, expr) \
00103 if (!(expr)) { \
00104 myprintf(ctrl, "***ASSERTION failed on line %d of file %s: " #expr "\n", \
00105 __LINE__, __FILE__); \
00106 abort(); \
00107 }
00108 #else
00109 # define ASSERT(ctrl, expr) ;
00110 #endif
00111
00112 #ifdef DEBUG
00113 # define ASSERTP(ctrl, expr, msg) \
00114 if (!(expr)) { \
00115 myprintf(ctrl, "***ASSERTION failed on line %d of file %s:" #expr "\n", \
00116 __LINE__, __FILE__); \
00117 myprintf msg ; \
00118 abort(); \
00119 }
00120 #else
00121 # define ASSERTP(ctrl, expr,msg) ;
00122 #endif
00123
00124 #ifdef DEBUGS
00125 # define ASSERTS(expr) \
00126 if (!(expr)) { \
00127 printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
00128 __LINE__, __FILE__); \
00129 abort(); \
00130 }
00131 #else
00132 # define ASSERTS(expr) ;
00133 #endif
00134
00135 #ifdef DEBUGS
00136 # define ASSERTSP(expr, msg) \
00137 if (!(expr)) { \
00138 printf("***ASSERTION failed on line %d of file %s: " #expr "\n", \
00139 __LINE__, __FILE__); \
00140 printf msg ; \
00141 abort(); \
00142 }
00143 #else
00144 # define ASSERTSP(expr, msg) ;
00145 #endif
00146
00147
00148
00149
00150 #define BNDInsert(nbnd, bndind, bndptr, vtx) \
00151 do { \
00152 bndind[nbnd] = vtx; \
00153 bndptr[vtx] = nbnd++;\
00154 } while(0)
00155
00156 #define BNDDelete(nbnd, bndind, bndptr, vtx) \
00157 do { \
00158 bndind[bndptr[vtx]] = bndind[--nbnd]; \
00159 bndptr[bndind[nbnd]] = bndptr[vtx]; \
00160 bndptr[vtx] = -1; \
00161 } while(0)
00162
00163