ESyS-Particle  2.3.2
Timer.h
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2003-2014 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef __MPI_TIMER_H_
14 #define __MPI_TIMER_H_
15 
16 //--- MPI includes ---
17 #include <mpi.h>
18 
19 //--- STL includes ---
20 #include <string>
21 #include <map>
22 
23 #include <boost/shared_ptr.hpp>
24 
28 class MpiWTimer
29 {
30 public:
31  MpiWTimer();
32 
33  MpiWTimer(const std::string &name);
34  void setStart(const double &wTime);
35  void pause(const double &wTime);
36  void resume(const double &wTime);
37  void setStop(const double &wTime, bool elapseIsStopMinusStart=false);
38  double getTiming() const;
39  const std::string &getName() const;
40 
41  bool isPaused() const;
42 
43  void zeroise();
44 protected:
45  void isPaused(bool paused);
46 
47 private:
48  std::string m_name;
49  double m_startTime;
50  double m_stopTime;
51  bool m_isPaused;
52  double m_pauseTime;
53  double m_resumeTime;
54  double m_elapsedTime;
55 };
56 
57 class MpiWTimers;
58 
63 {
64 public:
65  TimingDataWriter(const std::string &fileName, MpiWTimers &timers);
66 
67  std::ostream &getOStream();
68 
69  const std::string &getFileName() const;
70 
71  void writeHeader();
72 
73  void appendData();
74 
75 private:
76  std::string m_fileName;
79  typedef boost::shared_ptr<std::ofstream> OFStreamPtr;
81 };
82 
87 {
88 public:
89  MpiWTimers();
90 
91  void start(const std::string &name);
92  void stop(const std::string &name, bool elapseIsStopMinusStart=false);
93  void pause(const std::string &name);
94  void resume(const std::string &name);
95  void zeroise(const std::string &name);
96  void zeroise();
97  bool timerExists(const std::string &name) const;
98  double getTiming(const std::string &name) const;
99 
100  void writeHeader(std::ostream &oStream);
101  void appendData(std::ostream &oStream);
102  void appendData(const std::string &fileName);
103  void clear();
104 
105 protected:
106  //void createTimer(const std::string &timerName);
107 
108  MpiWTimer *findTimer(const std::string &timerName);
109  const MpiWTimer *findTimer(const std::string &timerName) const;
110 
111  MpiWTimer &findOrCreateTimer(const std::string &timerName);
112 
113  TimingDataWriter &getWriter(const std::string &fileName);
114 
115 private:
116  typedef std::map<std::string, MpiWTimer> NameMpiWTimerMap;
118 
119  typedef std::map<std::string, TimingDataWriter> FileNameWriterMap;
121 };
122 
123 #endif //__MPI_TIMER_H_