VTK
vtkParallelTimer.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkParallelTimer.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 //
37 #ifndef vtkParallelTimer_h
38 #define vtkParallelTimer_h
39 
40 #define vtkParallelTimerDEBUG -1
41 
42 #include "vtkObject.h"
43 #include "vtkRenderingParallelLICModule.h" // for export
44 
45 //BTX
46 #include <vector> // for vector
47 #include <string> // for string
48 #include <sstream> // for sstream
49 #if vtkParallelTimerDEBUG > 0
50 #include <iostream> // for cerr
51 #endif
52 //ETX
53 
54 class vtkParallelTimerBuffer;
55 
56 class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject
57 {
58 public:
59  static vtkParallelTimer *New();
60  vtkTypeMacro(vtkParallelTimer,vtkObject);
61  void PrintSelf(ostream& os, vtkIndent indent);
62 
64 
67  {
68  public:
69  template<typename T> LogHeaderType &operator<<(const T& s);
70  };
72 
74 
77  {
78  public:
79  template<typename T> LogBodyType &operator<<(const T& s);
80  };
82 
84 
85  vtkSetMacro(WriterRank,int);
86  vtkGetMacro(WriterRank,int);
88 
90 
92  vtkSetStringMacro(FileName);
93  vtkGetStringMacro(FileName);
94  //BTX
95  void SetFileName(const std::string &fileName)
96  { this->SetFileName(fileName.c_str()); }
97  //ETX
99 
101 
107  void StartEvent(const char *event);
108  void StartEvent(int rank, const char *event);
109  void EndEvent(const char *event);
110  void EndEvent(int rank, const char *event);
111  void EndEventSynch(const char *event);
112  void EndEventSynch(int rank, const char *event);
114 
115  //BTX
117 
118  template<typename T>
119  vtkParallelTimer &operator<<(const T& s);
121 
123 
125  { return vtkParallelTimer::LogHeaderType(); }
127 
129 
131  { return vtkParallelTimer::LogBodyType(); }
132  //ETX
134 
136  void Clear();
137 
143  void Update();
144 
146  int Write();
147 
153  static vtkParallelTimer *GetGlobalInstance();
154 
156  static void DeleteGlobalInstance();
157 
159 
161  vtkSetMacro(WriteOnClose, int);
162  vtkGetMacro(WriteOnClose, int);
164 
166 
168  vtkSetMacro(GlobalLevel, int);
169  vtkGetMacro(GlobalLevel, int);
171 
172 protected:
174  virtual ~vtkParallelTimer();
175 
176 private:
177  vtkParallelTimer(const vtkParallelTimer&); // Not implemented
178  void operator=(const vtkParallelTimer&); // Not implemented
179 
180 //BTX
182 
183  class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor
184  {
185  public:
186  vtkParallelTimerDestructor() : Log(0) {}
187  ~vtkParallelTimerDestructor();
189 
190  void SetLog(vtkParallelTimer *log){ this->Log = log; }
191 
192  private:
193  vtkParallelTimer *Log;
194  };
195 //ETX
196 
197 private:
198  int GlobalLevel;
199  int Initialized;
200  int WorldRank;
201  int WriterRank;
202  char *FileName;
203  int WriteOnClose;
204  std::vector<double> StartTime;
205  #if vtkParallelTimerDEBUG < 0
206  std::vector<std::string> EventId;
207  #endif
208 
209  vtkParallelTimerBuffer *Log;
210 
211  static vtkParallelTimer *GlobalInstance;
212  static vtkParallelTimerDestructor GlobalInstanceDestructor;
213 
214  std::ostringstream HeaderBuffer;
215 
216  friend class LogHeaderType;
217  friend class LogBodyType;
218 };
219 
220 //BTX
221 //-----------------------------------------------------------------------------
222 template<typename T>
224 {
225  if (this->WorldRank == this->WriterRank)
226  {
227  this->HeaderBuffer << s;
228  #if vtkParallelTimerDEBUG > 0
229  std::cerr << s;
230  #endif
231  }
232  return *this;
233 }
234 
235 //-----------------------------------------------------------------------------
236 template<typename T>
238 {
240 
241  if (log->WorldRank == log->WriterRank)
242  {
243  log->HeaderBuffer << s;
244  #if vtkParallelTimerDEBUG > 0
245  std::cerr << s;
246  #endif
247  }
248 
249  return *this;
250 }
251 
252 //-----------------------------------------------------------------------------
253 template<typename T>
255 {
257 
258  *(log->Log) << s;
259  #if vtkParallelTimerDEBUG > 0
260  std::cerr << s;
261  #endif
262 
263  return *this;
264 }
265 //ETX
266 
267 #endif
LogHeaderType & operator<<(const T &s)
friend class LogHeaderType
abstract base class for most VTK objects
Definition: vtkObject.h:61
virtual void Update()
friend class LogBodyType
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
LogBodyType & operator<<(const T &s)
void SetFileName(const std::string &fileName)
static vtkParallelTimer * GetGlobalInstance()
vtkParallelTimer::LogBodyType GetBody()
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkIndent &o)
vtkParallelTimer::LogHeaderType GetHeader()
static vtkObject * New()
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
vtkParallelTimer & operator<<(const T &s)