Alps 1.5.12
Loading...
Searching...
No Matches
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 * Ted Ralphs, Lehigh University *
11 * *
12 * Conceptual Design: *
13 * *
14 * Yan Xu, Lehigh University *
15 * Ted Ralphs, Lehigh University *
16 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17 * Matthew Saltzman, Clemson University *
18 * *
19 * *
20 * Copyright (C) 2001-2023, Lehigh University, Yan Xu, and Ted Ralphs. *
21 *===========================================================================*/
22
23#ifndef AlpsTime_
24#define AlpsTime_
25
26//#############################################################################
27
28#undef SEEK_SET
29#undef SEEK_END
30#undef SEEK_CUR
31#include "Alps.h"
32#include "AlpsConfig.h"
33
34#include "CoinTime.hpp"
35
36#ifdef COIN_HAS_MPI
37# include "mpi.h"
38#endif
39
40//#############################################################################
41
42#define AlpsCpuTime CoinCpuTime
43
44//#############################################################################
45
46static inline double AlpsGetTimeOfDay()
47{
48
49#ifndef COIN_HAS_MPI
50 return CoinGetTimeOfDay();
51#else
52 // COIN_HAS_MPI
53 return MPI_Wtime();
54#endif
55}
56
57//#############################################################################
58
59/* A timer used to record cpu and wallclock time. */
61{
62 public: /* Public for parallecl gather. */
63
65
67 double limit_;
68
69 double startCpu_;
70 double startWall_;
71 double finishCpu_;
73
75 double cpu_;
76
78 double wall_;
79
80 public:
82 AlpsTimer(double lt) : limit_(lt) { reset(); }
84
86 void reset() {
87 startCpu_ = 0.0;
88 startWall_ = 0.0;
89 finishCpu_ = 0.0;
90 finishWall_ = 0.0;
91 cpu_ = 0.0;
92 wall_ = 0.0;
93 }
94
96 void start() {
99 }
100
108
109 //{@
110 void setLimit(double lm) { limit_ = lm; }
111 double getLimit() const { return limit_; }
113
115 double getCpuTime() {
118 return cpu_;
119 }
120
122 double getWallClock() {
125 return wall_;
126 }
127
129 double getTime() {
130 assert( (clockType_ == AlpsClockTypeCpu) ||
135 return cpu_;
136 }
137 else {
140 return wall_;
141 }
142 }
143
145 int getClockType(){ return clockType_; }
146 void setClockType(int ct){ clockType_ = ct; }
147
152 if (finishCpu_ - startCpu_ > limit_) {
153 return true;
154 }
155 else {
156 return false;
157 }
158 }
159
164 if (finishWall_ - startWall_ > limit_) {
165 return true;
166 }
167 else {
168 return false;
169 }
170 }
171};
172
173#endif
static double AlpsGetTimeOfDay()
Definition AlpsTime.h:46
#define AlpsCpuTime
Definition AlpsTime.h:42
@ AlpsClockTypeCpu
Definition Alps.h:44
@ AlpsClockTypeWallClock
Definition Alps.h:45
#define ALPS_DBL_MAX
Definition Alps.h:143
double getWallClock()
Get cpu timee.
Definition AlpsTime.h:122
double limit_
Time limit.
Definition AlpsTime.h:67
void setClockType(int ct)
Definition AlpsTime.h:146
double wall_
Wall clock time.
Definition AlpsTime.h:78
double cpu_
Cpu time.
Definition AlpsTime.h:75
~AlpsTimer()
Definition AlpsTime.h:83
int getClockType()
Get/Set clock type.
Definition AlpsTime.h:145
double finishWall_
Definition AlpsTime.h:72
double startCpu_
Definition AlpsTime.h:69
bool reachCpuLimit()
Check if cpu time reach limit.
Definition AlpsTime.h:149
double finishCpu_
Definition AlpsTime.h:71
void setLimit(double lm)
Definition AlpsTime.h:110
double startWall_
Definition AlpsTime.h:70
void reset()
Reset.
Definition AlpsTime.h:86
void stop()
Stop timer and computing times.
Definition AlpsTime.h:102
AlpsTimer(double lt)
Definition AlpsTime.h:82
AlpsTimer()
Definition AlpsTime.h:81
double getLimit() const
Definition AlpsTime.h:111
bool reachWallLimit()
Check if wallclock time reach limit.
Definition AlpsTime.h:161
int clockType_
Definition AlpsTime.h:64
void start()
Start to count times.
Definition AlpsTime.h:96
double getTime()
Get time depends on clock type.
Definition AlpsTime.h:129
double getCpuTime()
Get cpu timee.
Definition AlpsTime.h:115