COMBINATORIAL_BLAS  1.6
util.h
Go to the documentation of this file.
1 // this files contains all the application independent little
2 // functions and macros used for the optimizer.
3 // In particular Peters debug macros and Dags stuff
4 // from dbasic.h cdefs, random,...
5 
7 // (c) 1997 Peter Sanders
8 // some little utilities for debugging adapted
9 // to the paros conventions
10 
11 #include <iostream>
12 
13 #ifndef UTIL
14 #define UTIL
15 
16 // default debug level. will be overidden e.g. if debug.h is included
17 #ifndef DEBUGLEVEL
18 #define DEBUGLEVEL 3
19 #endif
20 
21 #if DEBUGLEVEL >= 0
22 #define Debug0(A) A
23 #else
24 #define Debug0(A)
25 #endif
26 #if DEBUGLEVEL >= 1
27 #define Debug1(A) A
28 #else
29 #define Debug1(A)
30 #endif
31 #if DEBUGLEVEL >= 2
32 #define Debug2(A) A
33 #else
34 #define Debug2(A)
35 #endif
36 #if DEBUGLEVEL >= 3
37 #define Debug3(A) A
38 #else
39 #define Debug3(A)
40 #endif
41 #if DEBUGLEVEL >= 4
42 #define Debug4(A) A
43 #else
44 #define Debug4(A)
45 #endif
46 #if DEBUGLEVEL >= 5
47 #define Debug5(A) A
48 #else
49 #define Debug5(A)
50 #endif
51 #if DEBUGLEVEL >= 6
52 #define Debug6(A) A
53 #else
54 #define Debug6(A)
55 #endif
56 
57 #define Assert(c) if(!(c))\
58  {std::cout << "\nAssertion violation " << __FILE__ << ":" << __LINE__ << std::endl;}
59 #define Assert0(C) Debug0(Assert(C))
60 #define Assert1(C) Debug1(Assert(C))
61 #define Assert2(C) Debug2(Assert(C))
62 #define Assert3(C) Debug3(Assert(C))
63 #define Assert4(C) Debug4(Assert(C))
64 #define Assert5(C) Debug5(Assert(C))
65 
66 #define Error(s) {std::cout << "\nError:" << s << " " << __FILE__ << ":" << __LINE__ << std::endl;}
67 
69 
70 #ifndef Max
71 #define Max(x,y) ((x)>=(y)?(x):(y))
72 #endif
73 
74 #ifndef Min
75 #define Min(x,y) ((x)<=(y)?(x):(y))
76 #endif
77 
78 #ifndef Abs
79 #define Abs(x) ((x) < 0 ? -(x) : (x))
80 #endif
81 
82 #ifndef PI
83 #define PI 3.1415927
84 #endif
85 
86 // is this the right definition of limit?
87 inline double limit(double x, double bound)
88 {
89  if (x > bound) { return bound; }
90  else if (x < -bound) { return -bound; }
91  else return x;
92 }
93 
95 #include <time.h>
96 
97 // AL: sys/time.h does not exist on Windows, and this function is never used.
98 /*#include <sys/time.h>
99 
100 inline double wallClockTime()
101 { // struct timespec tp;
102 
103  timeval tim;
104  gettimeofday(&tim, NULL);
105  double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
106  return t1;
107 
108  // clock_gettime(CLOCK_REALTIME, &tp);
109  // return tp.tv_sec + tp.tv_nsec * 1e-9;
110 }*/
111 
112 // elapsed CPU time see also /usr/include/sys/time.h
113 inline double cpuTime()
114 { //struct timespec tp;
115 
116  return clock() * 1e-6;
117 // clock_gettime(CLOCK_VIRTUAL, &tp);
118 // return tp.tv_sec + tp.tv_nsec * 1e-9;
119 }
120 
121 #endif
double cpuTime()
Definition: util.h:113
double limit(double x, double bound)
Definition: util.h:87