ug4
progress.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3  * Author: Martin Rupp
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef PROGRESS_H_
34 #define PROGRESS_H_
35 
36 #include <iostream>
38 #include "common/log.h"
39 #include <ctime>
40 #include <string>
41 #include <sstream>
42 
43 #include "stopwatch.h"
44 #include "util/ostream_util.h"
45 
46 namespace ug
47 {
48 
49 class Progress
50 {
51 public:
52  Progress(int minSecondsUntilProgress=-1);
53 
55  {
56  stop();
57  totalDepth--;
58  }
59  void set_length(int l)
60  {
61  m_length = l;
62  }
63 
65  {
68  }
69  void start(double total, std::string msg="");
70 
71  inline void set(size_t now)
72  {
73  if(now < iNextValueToUpdate) return;
74  setD(now);
75  }
76  inline void set(int now)
77  {
78  if(now < 0 || (size_t)now < iNextValueToUpdate) return;
79  setD(now);
80  }
81 
82  inline void set(double now)
83  {
84  if(now < dNextValueToUpdate) return;
85  setD(now);
86  }
87  void setD(double now);
88 
89  void stop();
90 
91 private:
92 
94  double startS;
97  int posNow;
98  bool bStarted;
99  double m_total;
100  double m_now;
101  int m_length;
102  std::string m_msg;
103 
104  static int totalDepth;
105  static int lastUpdateDepth;
106  int myDepth;
107 };
108 
109 }
110 
111 #define PROGRESS_START(progVarName, dSize, msg) \
112  ug::Progress progVarName; { std::stringstream ss; ss << msg; progVarName.start(dSize, ss.str()); }
113 
114 #define PROGRESS_START_WITH(progVarName, dSize, msg) \
115  { std::stringstream ss; ss << msg; progVarName.start(dSize, ss.str()); }
116 
117 #define PROGRESS_UPDATE(progVarName, d) progVarName.set(d);
118 #define PROGRESS_FINISH(progVarName) progVarName.stop();
119 
120 
121 #endif /* PROCESS_H_ */
Definition: progress.h:50
void set(double now)
Definition: progress.h:82
void start(double total, std::string msg="")
Definition: progress.cpp:161
std::string m_msg
Definition: progress.h:102
int myDepth
Definition: progress.h:106
double dNextValueToUpdate
Definition: progress.h:95
void stop()
Definition: progress.cpp:141
~Progress()
Definition: progress.h:54
static int lastUpdateDepth
Definition: progress.h:105
int m_minSecondsUntilProgress
Definition: progress.h:93
void setD(double now)
Definition: progress.cpp:105
int m_length
Definition: progress.h:101
void set_length(int l)
Definition: progress.h:59
int posNow
Definition: progress.h:97
void calc_next_value()
Definition: progress.h:64
static int totalDepth
Definition: progress.h:104
size_t iNextValueToUpdate
Definition: progress.h:96
void set(size_t now)
Definition: progress.h:71
double m_total
Definition: progress.h:99
Progress(int minSecondsUntilProgress=-1)
Definition: progress.cpp:41
double m_now
Definition: progress.h:100
double startS
Definition: progress.h:94
bool bStarted
Definition: progress.h:98
void set(int now)
Definition: progress.h:76
the ug namespace
stopwatch class for quickly taking times