Alps  2.0.2
AlpsTime.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Abstract Library for Parallel Search (ALPS). *
3  * *
4  * ALPS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Aykut Bulut, Lehigh University *
11  * Ted Ralphs, Lehigh University *
12  * *
13  * Conceptual Design: *
14  * *
15  * Yan Xu, Lehigh University *
16  * Ted Ralphs, Lehigh University *
17  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
18  * Matthew Saltzman, Clemson University *
19  * *
20  * *
21  * Copyright (C) 2001-2023, Lehigh University, Yan Xu, Aykut Bulut, and *
22  * Ted Ralphs. *
23  * All Rights Reserved. *
24  *===========================================================================*/
25 
26 
27 #ifndef AlpsTime_h_
28 #define AlpsTime_h_
29 
30 //#############################################################################
31 
32 // #undef SEEK_SET
33 // #undef SEEK_END
34 // #undef SEEK_CUR
35 #include "Alps.h"
36 #include "AlpsConfig.h"
37 
38 #include "CoinTime.hpp"
39 
40 #ifdef COIN_HAS_MPI
41  #include <mpi.h>
42 #endif
43 
44 //#############################################################################
45 
46 #define AlpsCpuTime CoinCpuTime
47 
48 //#############################################################################
49 
50 static inline double AlpsGetTimeOfDay()
51 {
52 
53 #ifndef COIN_HAS_MPI
54  return CoinGetTimeOfDay();
55 #else
56  // COIN_HAS_MPI
57  return MPI_Wtime();
58 #endif
59 }
60 
61 //#############################################################################
62 
63 /* A timer used to record cpu and wallclock time. */
64 class AlpsTimer
65 {
66  public: /* Public for parallecl gather. */
67 
69 
71  double limit_;
72 
73  double startCpu_;
74  double startWall_;
75  double finishCpu_;
76  double finishWall_;
77 
79  double cpu_;
80 
82  double wall_;
83 
84  public:
86  AlpsTimer(double lt) : limit_(lt) { reset(); }
88 
90  void reset() {
91  startCpu_ = 0.0;
92  startWall_ = 0.0;
93  finishCpu_ = 0.0;
94  finishWall_ = 0.0;
95  cpu_ = 0.0;
96  wall_ = 0.0;
97  }
98 
100  void start() {
103  }
104 
106  void stop() {
111  }
112 
113  //{@
114  void setLimit(double lm) { limit_ = lm; }
115  double getLimit() const { return limit_; }
117 
119  double getCpuTime() {
122  return cpu_;
123  }
124 
126  double getWallClockTime() {
129  return wall_;
130  }
131 
133  double getTime() {
134  assert( (clockType_ == AlpsClockTypeCpu) ||
136  if (clockType_ == AlpsClockTypeCpu) {
139  return cpu_;
140  }
141  else {
144  return wall_;
145  }
146  }
147 
149  int getClockType(){ return clockType_; }
150  void setClockType(int ct){ clockType_ = ct; }
151 
153  bool reachCpuLimit() {
156  if (finishCpu_ - startCpu_ > limit_) {
157  return true;
158  }
159  else {
160  return false;
161  }
162  }
163 
165  bool reachWallLimit() {
168  if (finishWall_ - startWall_ > limit_) {
169  return true;
170  }
171  else {
172  return false;
173  }
174  }
175 };
176 
177 #endif
AlpsClockTypeWallClock
@ AlpsClockTypeWallClock
Definition: Alps.h:182
AlpsTimer::cpu_
double cpu_
Cpu time.
Definition: AlpsTime.h:79
AlpsTimer::start
void start()
Start to count times.
Definition: AlpsTime.h:100
AlpsTimer::finishCpu_
double finishCpu_
Definition: AlpsTime.h:75
AlpsTimer::setClockType
void setClockType(int ct)
Definition: AlpsTime.h:150
AlpsTimer::setLimit
void setLimit(double lm)
Definition: AlpsTime.h:114
AlpsCpuTime
#define AlpsCpuTime
Definition: AlpsTime.h:46
AlpsTimer
Definition: AlpsTime.h:64
AlpsTimer::wall_
double wall_
Wall clock time.
Definition: AlpsTime.h:82
AlpsTimer::getWallClockTime
double getWallClockTime()
Get wallclock timee.
Definition: AlpsTime.h:126
AlpsTimer::AlpsTimer
AlpsTimer(double lt)
Definition: AlpsTime.h:86
AlpsTimer::clockType_
int clockType_
Definition: AlpsTime.h:68
ALPS_DBL_MAX
#define ALPS_DBL_MAX
Definition: Alps.h:286
AlpsTimer::startCpu_
double startCpu_
Definition: AlpsTime.h:73
AlpsClockTypeCpu
@ AlpsClockTypeCpu
Definition: Alps.h:181
AlpsTimer::reachWallLimit
bool reachWallLimit()
Check if wallclock time reach limit.
Definition: AlpsTime.h:165
AlpsTimer::getCpuTime
double getCpuTime()
Get cpu timee.
Definition: AlpsTime.h:119
Alps.h
AlpsTimer::startWall_
double startWall_
Definition: AlpsTime.h:74
AlpsTimer::finishWall_
double finishWall_
Definition: AlpsTime.h:76
AlpsTimer::reachCpuLimit
bool reachCpuLimit()
Check if cpu time reach limit.
Definition: AlpsTime.h:153
AlpsConfig.h
AlpsTimer::getLimit
double getLimit() const
Definition: AlpsTime.h:115
AlpsTimer::getClockType
int getClockType()
Get/Set clock type.
Definition: AlpsTime.h:149
AlpsTimer::getTime
double getTime()
Get time depends on clock type.
Definition: AlpsTime.h:133
AlpsGetTimeOfDay
static double AlpsGetTimeOfDay()
Definition: AlpsTime.h:50
AlpsTimer::stop
void stop()
Stop timer and computing times.
Definition: AlpsTime.h:106
AlpsTimer::~AlpsTimer
~AlpsTimer()
Definition: AlpsTime.h:87
AlpsTimer::reset
void reset()
Reset.
Definition: AlpsTime.h:90
AlpsTimer::AlpsTimer
AlpsTimer()
Definition: AlpsTime.h:85
AlpsTimer::limit_
double limit_
Time limit.
Definition: AlpsTime.h:71