Dip  0.92.4
sym_timemeas.h
Go to the documentation of this file.
1 /*===========================================================================*/
2 /* */
3 /* This file is part of the SYMPHONY MILP Solver Framework. */
4 /* */
5 /* SYMPHONY was jointly developed by Ted Ralphs (ted@lehigh.edu) and */
6 /* Laci Ladanyi (ladanyi@us.ibm.com). */
7 /* */
8 /* (c) Copyright 2000-2019 Ted Ralphs. All Rights Reserved. */
9 /* */
10 /* This software is licensed under the Eclipse Public License. Please see */
11 /* accompanying file for terms. */
12 /* */
13 /*===========================================================================*/
14 
15 #ifndef __TIMEMEAS_H
16 #define __TIMEMEAS_H
17 
18 #if defined (_MSC_VER) || defined (__MNO_CYGWIN)
19 #include "sym_win32_time.h"
20 #else
21 #include <sys/time.h>
22 #endif
23 
24 #ifdef __DARWIN
25 #include <sys/resource.h>
26 #endif
27 
28 #include "sym_proto.h"
29 
30 #define PRINT_TIME(tm, f) { /* Print the elapsed time in vbctool format*/ \
31  double elapsed = wall_clock(NULL) - tm->start_time; \
32  int hours, minutes, seconds, msec; \
33  hours = (int)(elapsed/3600.0); \
34  elapsed -= hours*3600.0; \
35  minutes = (int)(elapsed/60.0); \
36  elapsed -= minutes*60.0; \
37  seconds = (int)elapsed; \
38  elapsed -= (double)seconds; \
39  msec = (int)(elapsed*100.0); \
40  fprintf(f, "%.2d:%.2d:%.2d:%.2d ", hours, minutes, seconds, msec); \
41 }
42 
43 /* PRINT_TIME function when vbc_emulation = 3 */
44 #define PRINT_TIME2(tm, f) { /* Print the elapsed time in vbctool format*/ \
45  double elapsed_t = wall_clock(NULL) - tm->start_time; \
46  fprintf(f, "%10.6f ", elapsed_t); \
47 }
48 
49 #define TVCLEAR(tvp) (tvp.tv_sec = tvp.tv_usec = 0)
50 #define PTVCLEAR(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
51 
52 #define TVISSET(tvp) (tvp.tv_sec || tvp.tv_usec)
53 #define PTVISSET(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
54 
55 #define TVXLTY(xtv, ytv) \
56  ( (xtv.tv_sec < ytv.tv_sec) || \
57  (xtv.tv_sec == ytv.tv_sec && xtv.tv_usec < ytv.tv_usec))
58 #define PTVXLTY(xtv, ytv) \
59  ( ((xtv)->tv_sec < (ytv)->tv_sec) || \
60  ((xtv)->tv_sec == (ytv)->tv_sec && (xtv)->tv_usec < (ytv)->tv_usec))
61 
62 #define TVXADDY(ztv, xtv, ytv) \
63  if ((ztv.tv_usec = xtv.tv_usec + ytv.tv_usec) < 1000000) { \
64  ztv.tv_sec = xtv.tv_sec + ytv.tv_sec; \
65  } else { \
66  ztv.tv_usec -= 1000000; \
67  ztv.tv_sec = xtv.tv_sec + ytv.tv_sec + 1; \
68  }
69 #define PTVXADDY(ztv, xtv, ytv) \
70  if (((ztv)->tv_usec = (xtv)->tv_usec + (ytv)->tv_usec) < 1000000) { \
71  (ztv)->tv_sec = (xtv)->tv_sec + (ytv)->tv_sec; \
72  } else { \
73  (ztv)->tv_usec -= 1000000; \
74  (ztv)->tv_sec = (xtv)->tv_sec + (ytv)->tv_sec + 1; \
75  }
76 
77 #define TVXSUBY(ztv, xtv, ytv) \
78  if (xtv.tv_usec >= ytv.tv_usec) { \
79  ztv.tv_sec = xtv.tv_sec - ytv.tv_sec; \
80  ztv.tv_usec = xtv.tv_usec - ytv.tv_usec; \
81  } else { \
82  ztv.tv_sec = xtv.tv_sec - ytv.tv_sec - 1; \
83  ztv.tv_usec = xtv.tv_usec + 1000000 - ytv.tv_usec; \
84  }
85 #define PTVXSUBY(ztv, xtv, ytv) \
86  if ((xtv)->tv_usec >= (ytv)->tv_usec) { \
87  (ztv)->tv_sec = (xtv)->tv_sec - (ytv)->tv_sec; \
88  (ztv)->tv_usec = (xtv)->tv_usec - (ytv)->tv_usec; \
89  } else { \
90  (ztv)->tv_sec = (xtv)->tv_sec - (ytv)->tv_sec - 1; \
91  (ztv)->tv_usec = (xtv)->tv_usec + 1000000 - (ytv)->tv_usec; \
92  }
93 
94 #define TVTODBL(tvp) ((double)tvp.tv_sec + ((double)tvp.tv_usec)/1000000 )
95 #define TVPTODBL(tvp) ((double)(tvp)->tv_sec+((double)(tvp)->tv_usec)/1000000)
96 
97 #define DBLTOTV(x, tv) \
98  tv.tv_sec = (int) floor(x); \
99  tv.tv_usec = (int) floor(1000000 * (x - (double)tv.tv_sec));
100 #define DBLTOPTV(x, tvp) \
101  (tvp)->tv_sec = (int) floor(x); \
102  (tvp)->tv_usec = (int) floor(1000000 * (x - (tvp)->tv_sec));
103 
104 void start_time PROTO((void));
105 double used_time PROTO((double *T));
106 double wall_clock PROTO((double *T));
107 
108 #endif
#define PROTO(x)
Definition: sym_proto.h:27