MPSolve  3.2.1
debug.h
Go to the documentation of this file.
1 /*
2  * This file is part of MPSolve 3.2.1
3  *
4  * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5  * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6  *
7  * Authors:
8  * Leonardo Robol <leonardo.robol@unipi.it>
9  */
10 
17 #ifndef MPS_DEBUG_H_
18 #define MPS_DEBUG_H_
19 
20 #ifndef __WINDOWS
21 #include <unistd.h>
22 #else
23 #include <io.h>
24 #endif
25 
26 #include <mps/gmptools.h>
27 #include <gmp.h>
28 #include <time.h>
29 
30 MPS_BEGIN_DECLS
31 
32 /* Timer functions */
33 clock_t * mps_start_timer (void);
34 unsigned long int mps_stop_timer (clock_t * my_timer);
35 
36 /* Keep away assert() when compiling without debug */
37 #ifdef DISABLE_DEBUG
38 #define NDEBUG
39 #endif
40 
41 #ifdef NICE_DEBUG
42 
46 #define MPS_DEBUG_WITH_INFO(s, templ ...) { \
47  if (s->debug_level & MPS_DEBUG_INFO) { \
48  MPS_DEBUG (s, templ); \
49  } \
50 }
51 
55 #define MPS_DEBUG_WITH_IO(s, templ ...) { \
56  if (s->debug_level & MPS_DEBUG_IO) { \
57  MPS_DEBUG (s, templ); \
58  } \
59 }
60 
61 #define MPS_DEBUG(s, templ ...) { \
62  __MPS_DEBUG (s, templ); \
63  if (s->DOLOG) { \
64  fprintf (s->logstr, "\n"); \
65  } \
66 }
67 
72 #define MPS_DEBUG_MPC(s, digits, c, name ...) { \
73  __MPS_DEBUG_EQ (s, name); \
74  if (s->DOLOG) { \
75  mpc_outln_str (s->logstr, 10, digits, c); \
76  } \
77 }
78 
83 #define MPS_DEBUG_MPF(s, digits, c, name ...) { \
84  __MPS_DEBUG_EQ (s, name); \
85  if (s->DOLOG) { \
86  mpf_out_str (s->logstr, 10, digits, c); \
87  fprintf (s->logstr, "\n"); \
88  } \
89 }
90 
91 #define MPS_DEBUG_MPC2(s, radius, c, name ...) { \
92  __MPS_DEBUG_EQ (s, name); \
93  if (s->DOLOG) { \
94  int t = -rdpe_log10 (radius) - 1; \
95  cdpe_t ctmp; \
96  rdpe_t mm; \
97  mpc_get_cdpe (ctmp, c); \
98  cdpe_mod (mm, ctmp); \
99  t += rdpe_log (mm); \
100  mpc_outln_str (s->logstr, 10, t, c); \
101  } \
102 }
103 
104 
108 #define MPS_DEBUG_RDPE(s, r, name ...) { \
109  __MPS_DEBUG_EQ (s, name); \
110  if (s->DOLOG) { \
111  rdpe_outln_str (s->logstr, r); \
112  } \
113 }
114 
118 #define MPS_DEBUG_CDPE(s, c, name ...) { \
119  __MPS_DEBUG_EQ (s, name); \
120  if (s->DOLOG) { \
121  cdpe_outln_str (s->logstr, c); \
122  } \
123 }
124 
128 #define MPS_DEBUG_CPLX(s, c, name ...) { \
129  __MPS_DEBUG_EQ (s, name); \
130  if (s->DOLOG) { \
131  cplx_outln_str (s->logstr, c); \
132  } \
133 }
134 
139 #define MPS_DEBUG_BREAK(s) if (s->DOLOG) { \
140  fprintf (s->logstr, "\n"); \
141  }
142 
147 #define __MPS_DEBUG_EQ(s, templ ...) \
148  __MPS_DEBUG (s, templ); \
149  if (s->DOLOG) { \
150  fprintf (s->logstr, " = "); \
151  }
152 
156 #ifndef __WINDOWS
157 #define MPS_DEBUG_CALL(s, function) if (s->DOLOG && (s->debug_level & MPS_DEBUG_FUNCTION_CALLS)) { \
158  if (isatty (fileno (s->logstr))) { \
159  __MPS_DEBUG (s, "Called \033[31;1m"); \
160  } \
161  else { \
162  __MPS_DEBUG (s, "Called "); \
163  } \
164  if (isatty (fileno (s->logstr))) { \
165  fprintf (s->logstr, function); fprintf (s->logstr, "()\033[0m\n"); \
166  } \
167  else \
168  { \
169  fprintf (s->logstr, function); fprintf (s->logstr, "()\n"); \
170  } \
171  }
172 #else
173 #define MPS_DEBUG_CALL(s, function) if (s->DOLOG && (s->debug_level & MPS_DEBUG_FUNCTION_CALLS)) { \
174  if (_isatty (_fileno (s->logstr))) { \
175  __MPS_DEBUG (s, "Called \033[31;1m"); \
176  } \
177  else { \
178  __MPS_DEBUG (s, "Called "); \
179  } \
180  if (_isatty (_fileno (s->logstr))) { \
181  fprintf (s->logstr, function); fprintf (s->logstr, "()\033[0m\n"); \
182  } \
183  else \
184  { \
185  fprintf (s->logstr, function); fprintf (s->logstr, "()\n"); \
186  } \
187  }
188 #endif
189 
190 #define MPS_DEBUG_THIS_CALL(ctx) MPS_DEBUG_CALL (ctx, __FUNCTION__)
191 
192 
196 #if __STDC_VERSION__ >= 199901L
197 #ifndef __WINDOWS
198 #define __MPS_DEBUG(s, templ ...) if (s->DOLOG) { \
199  if (isatty (fileno (s->logstr))) { \
200  fprintf (s->logstr, "%s:%d \033[32;1m%s()\033[;0m ", \
201  __FILE__, __LINE__, __FUNCTION__); \
202  } \
203  else { \
204  fprintf (s->logstr, "%s:%d %s() ", \
205  __FILE__, __LINE__, __FUNCTION__); \
206  } \
207  fprintf (s->logstr, templ); \
208  }
209 #else
210 #define __MPS_DEBUG(s, templ ...) if (s->DOLOG) { \
211  if (_isatty (_fileno (s->logstr))) { \
212  fprintf (s->logstr, "%s:%d \033[32;1m%s()\033[;0m ", \
213  __FILE__, __LINE__, __FUNCTION__); \
214  } \
215  else { \
216  fprintf (s->logstr, "%s:%d %s() ", \
217  __FILE__, __LINE__, __FUNCTION__); \
218  } \
219  fprintf (s->logstr, templ); \
220  }
221 #endif
222 
223 #endif
224 #else
225 #define MPS_DEBUG(args ...)
226 #define MPS_DEBUG_MPC(args ...)
227 #define MPS_DEBUG_CPLX(args ...)
228 #define MPS_DEBUG_RDPE(args ...)
229 #define MPS_DEBUG_CDPE(args ...)
230 #define MPS_DEBUG_CALL(args ...)
231 #define MPS_DEBUG_MCLUSTER_ROOTS(args ...)
232 #define MPS_DEBUG_THIS_CALL(ctx)
233 #define MPS_DEBUG_WITH_INFO(args ...)
234 #define MPS_DEBUG_WITH_IO(args ...)
235 #define __MPS_DEBUG(args ...)
236 #endif
237 
238 /*
239  * Ansi C version implemented without using variadic macros, only for compatibility
240  * since could became imprecise when using complex debug instructions.
241  */
242 #ifndef DISABLE_DEBUG
243 #if __STDC_VERSION__ < 199901L
244 #include <mps/mps.h>
245 #ifdef MPS_DEBUG
246 #undef MPS_DEBUG
247 #endif
248 #ifdef __MPS_DEBUG
249 #undef __MPS_DEBUG
250 #endif
251 #define MPS_DEBUG __c_impl__MPS_DEBUG
252 #define __MPS_DEBUG __c_impl____MPS_DEBUG
253 void __c_impl__MPS_DEBUG (mps_context * s, const char *templ, ...);
254 void __c_impl____MPS_DEBUG (mps_context * s, const char *templ, ...);
255 #endif
256 #endif
257 
262 #define MPS_DEBUG_INFO (0x0001 << 0)
263 
268 #define MPS_DEBUG_CLUSTER (0x0001 << 1)
269 
274 #define MPS_DEBUG_APPROXIMATIONS (0x0001 << 2)
275 
280 #define MPS_DEBUG_IMPROVEMENT (0x0001 << 3)
281 
286 #define MPS_DEBUG_TIMINGS (0x0001 << 4)
287 
291 #define MPS_DEBUG_FUNCTION_CALLS (0x0001 << 5)
292 
296 #define MPS_DEBUG_IO (0x0001 << 6)
297 
301 #define MPS_DEBUG_MEMORY (0x0001 << 7)
302 
307 #define MPS_DEBUG_PACKETS (0x0001 << 8)
308 
312 #define MPS_DEBUG_REGENERATION (0x0001 << 9)
313 
319 #define MPS_DEBUG_TRACE (0xFFFF)
320 
321 #define MPS_DEBUG_IF(s, debug_level, debug_instruction) if (debug_level & s->debug_level) { \
322  debug_instruction; \
323  }
324 
325 MPS_END_DECLS
326 
327 #endif /* DEBUG_H */
Additional functions used to complete the GMP package with what is needed in MPSolve.
Header file for libmps.
this struct holds the state of the mps computation
Definition: context.h:55