C++ mpi module for stochmagnet_main Package
MPI_Chrono.h
1 #ifndef MPI_Chrono_H
2 #define MPI_Chrono_H
3 
4 //inherited class object
5 #include "MPI_Object.h"
6 
7 //MPI types header
8 #include "MPI_Type.h"
9 
20 class MPI_Chrono : public MPI_Object {
21 
22  //attributes
23 private :
24 
25  tULLInt mStartTime=0;
26  tULLInt mDuration;
27 public:
28  // CONSTRUCTORS
29 
33  mStartTime=(tULLInt) GetTime();
34  mDuration=0;
35  }
36 
37 
38  // DESTRUCTORS
41  virtual ~MPI_Chrono(void) {
42 
43 
44  }
45 
46 public:
47  //New methods
48  //------------
52  inline static CORE_UniquePointer<MPI_Chrono> New() {
53  CORE_UniquePointer<MPI_Chrono> p(new MPI_Chrono(),
55 
56  return p;
57  };
58 
59 public:
60  //memory management
61  //=================
64  virtual tMemSize getMemorySize() const override {
65  return sizeof(*this)+getContentsMemorySize();
66  }
67 
76  virtual tMemSize getContentsMemorySize() const override {
77  tMemSize mem=MPI_Object::getContentsMemorySize();
78  return mem;
79  }
80 
81 public:
82 
86  inline MPI_Chrono& operator=(const tULLInt& t) {
87  mDuration=t;
88  return *this;
89  }
93  inline MPI_Chrono& operator+=(const tULLInt& t) {
94  mDuration+=t;
95  return *this;
96  }
97 
101  inline static tReal GetTime() {
102  return MPI_Wtime();
103  }
104 
105 
106 
107 
108 public:
109  //chrono methods
110  //-------------
111 
114  inline void start() {
115  mStartTime=(tULLInt)MPI_Wtime();
116  }
117 
121  inline tULLInt stop() const {
122  return ((tULLInt)MPI_Wtime())-mStartTime;
123  }
124 
128  inline void addToDuration(const tULLInt& t) {
129  mDuration+=t;
130  }
131 
132 
133 
137  inline const tULLInt& getDuration() const {
138  return mDuration;
139  }
140 
144  inline void setDuration(const tULLInt& d) {
145  mDuration=d;
146  }
147 
151  inline static tString ConvertDurationToString(tULLInt duration) {
152  tString ret;
153  ret.reserve(30);
154  //duration=s+60*(m+60*(h+24*d)))
155  ret.insert(0,std::to_string((duration%60))+"s ");
156  duration/=60;
157 
158  ret.insert(0,std::to_string((duration%60))+"m ");
159  duration/=60;
160 
161  ret.insert(0,std::to_string((duration%24))+"h ");
162  duration/=24;
163 
164  ret.insert(0,std::to_string((duration))+"d ");
165  return ret;
166  }
176  inline static tULLInt ConvertDuration(tULLInt duration,
177  tUInt& d,
178  tUInt& h,
179  tUInt& m,
180  tUInt& s) {
181 
182  tULLInt w=duration;
183  //duration=s+60*(m+60*(h+24*d)))
184  s=duration%60;
185  duration/=60;
186  m=duration%60;
187  duration/=60;
188  h=duration%24;
189  duration/=24;
190  d=duration;
191  return w;
192  }
193 
194 };
195 
196 
197 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
This class is a time class to manage time within an environment.
Definition: MPI_Chrono.h:20
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_Chrono.h:76
static tULLInt ConvertDuration(tULLInt duration, tUInt &d, tUInt &h, tUInt &m, tUInt &s)
convert the duration as days,hours,minutes,second,milliseconds,microseconds
Definition: MPI_Chrono.h:176
const tULLInt & getDuration() const
get the duration in second
Definition: MPI_Chrono.h:137
MPI_Chrono & operator+=(const tULLInt &t)
operator +=
Definition: MPI_Chrono.h:93
void start()
start the chrono
Definition: MPI_Chrono.h:114
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: MPI_Chrono.h:64
virtual ~MPI_Chrono(void)
destroy
Definition: MPI_Chrono.h:41
static CORE_UniquePointer< MPI_Chrono > New()
create a new instance of class within an unique pointer
Definition: MPI_Chrono.h:52
tULLInt stop() const
stop the chrono
Definition: MPI_Chrono.h:121
static tString ConvertDurationToString(tULLInt duration)
convert the duration the duration to string
Definition: MPI_Chrono.h:151
static tReal GetTime()
get the time
Definition: MPI_Chrono.h:101
void setDuration(const tULLInt &d)
set the duration in second
Definition: MPI_Chrono.h:144
MPI_Chrono & operator=(const tULLInt &t)
operator =
Definition: MPI_Chrono.h:86
void addToDuration(const tULLInt &t)
add to duration
Definition: MPI_Chrono.h:128
MPI_Chrono()
create a root environment
Definition: MPI_Chrono.h:32
This class is a base class of E-MicromM core package.
Definition: MPI_Object.h:32