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 //
38 #ifndef vtkParallelTimer_h
39 #define vtkParallelTimer_h
40 
41 #define vtkParallelTimerDEBUG -1
42 
43 #include "vtkObject.h"
44 #include "vtkRenderingParallelLICModule.h" // for export
45 
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 
53 class vtkParallelTimerBuffer;
54 
55 class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject
56 {
57 public:
58  static vtkParallelTimer *New();
59  vtkTypeMacro(vtkParallelTimer,vtkObject);
60  void PrintSelf(ostream& os, vtkIndent indent);
61 
63 
68  {
69  public:
70  template<typename T> LogHeaderType &operator<<(const T& s);
71  };
73 
75 
80  {
81  public:
82  template<typename T> LogBodyType &operator<<(const T& s);
83  };
85 
87 
90  vtkSetMacro(WriterRank,int);
91  vtkGetMacro(WriterRank,int);
93 
95 
100  vtkSetStringMacro(FileName);
101  vtkGetStringMacro(FileName);
103 
104  void SetFileName(const std::string &fileName)
105  { this->SetFileName(fileName.c_str()); }
106 
108 
116  void StartEvent(const char *event);
117  void StartEvent(int rank, const char *event);
118  void EndEvent(const char *event);
119  void EndEvent(int rank, const char *event);
120  void EndEventSynch(const char *event);
121  void EndEventSynch(int rank, const char *event);
123 
127  template<typename T>
128  vtkParallelTimer &operator<<(const T& s);
129 
134  { return vtkParallelTimer::LogHeaderType(); }
135 
140  { return vtkParallelTimer::LogBodyType(); }
141 
145  void Clear();
146 
155  void Update();
156 
160  int Write();
161 
169  static vtkParallelTimer *GetGlobalInstance();
170 
174  static void DeleteGlobalInstance();
175 
177 
181  vtkSetMacro(WriteOnClose, int);
182  vtkGetMacro(WriteOnClose, int);
184 
186 
190  vtkSetMacro(GlobalLevel, int);
191  vtkGetMacro(GlobalLevel, int);
193 
194 protected:
196  virtual ~vtkParallelTimer();
197 
198 private:
199  vtkParallelTimer(const vtkParallelTimer&) VTK_DELETE_FUNCTION;
200  void operator=(const vtkParallelTimer&) VTK_DELETE_FUNCTION;
201 
205  class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor
206  {
207  public:
208  vtkParallelTimerDestructor() : Log(0) {}
209  ~vtkParallelTimerDestructor();
210 
211  void SetLog(vtkParallelTimer *log){ this->Log = log; }
212 
213  private:
214  vtkParallelTimer *Log;
215  };
216 
217 private:
218  int GlobalLevel;
219  int Initialized;
220  int WorldRank;
221  int WriterRank;
222  char *FileName;
223  int WriteOnClose;
224  std::vector<double> StartTime;
225  #if vtkParallelTimerDEBUG < 0
226  std::vector<std::string> EventId;
227  #endif
228 
229  vtkParallelTimerBuffer *Log;
230 
231  static vtkParallelTimer *GlobalInstance;
232  static vtkParallelTimerDestructor GlobalInstanceDestructor;
233 
234  std::ostringstream HeaderBuffer;
235 
236  friend class LogHeaderType;
237  friend class LogBodyType;
238 };
239 
240 //-----------------------------------------------------------------------------
241 template<typename T>
243 {
244  if (this->WorldRank == this->WriterRank)
245  {
246  this->HeaderBuffer << s;
247  #if vtkParallelTimerDEBUG > 0
248  std::cerr << s;
249  #endif
250  }
251  return *this;
252 }
253 
254 //-----------------------------------------------------------------------------
255 template<typename T>
257 {
259 
260  if (log->WorldRank == log->WriterRank)
261  {
262  log->HeaderBuffer << s;
263  #if vtkParallelTimerDEBUG > 0
264  std::cerr << s;
265  #endif
266  }
267 
268  return *this;
269 }
270 
271 //-----------------------------------------------------------------------------
272 template<typename T>
274 {
276 
277  *(log->Log) << s;
278  #if vtkParallelTimerDEBUG > 0
279  std::cerr << s;
280  #endif
281 
282  return *this;
283 }
284 
285 #endif
LogHeaderType & operator<<(const T &s)
friend class LogHeaderType
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Type used to direct an output stream into the log's header.
virtual void Update()
Updates the extensions string.
friend class LogBodyType
a simple class to control print indentation
Definition: vtkIndent.h:39
LogBodyType & operator<<(const T &s)
Type used to direct an output stream into the log's body.
Provides ditributed log functionality.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
void SetFileName(const std::string &fileName)
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
static vtkParallelTimer * GetGlobalInstance()
The log class implements the singleton patern so that it may be shared accross class boundaries...
vtkParallelTimer::LogBodyType GetBody()
stream output to log body(all ranks).
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkIndent &o)
vtkParallelTimer::LogHeaderType GetHeader()
stream output to the log's header(root rank only).
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
vtkParallelTimer & operator<<(const T &s)
Insert text into the log header on the writer rank.