VTK  9.0.1
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 <sstream> // for sstream
47 #include <string> // for string
48 #include <vector> // for vector
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) override;
61 
63 
68  {
69  public:
70  template <typename T>
71  LogHeaderType& operator<<(const T& s);
72  };
74 
76 
81  {
82  public:
83  template <typename T>
84  LogBodyType& operator<<(const T& s);
85  };
87 
89 
92  vtkSetMacro(WriterRank, int);
93  vtkGetMacro(WriterRank, int);
95 
97 
102  vtkSetStringMacro(FileName);
103  vtkGetStringMacro(FileName);
105 
106  void SetFileName(const std::string& fileName) { this->SetFileName(fileName.c_str()); }
107 
109 
117  void StartEvent(const char* event);
118  void StartEvent(int rank, const char* event);
119  void EndEvent(const char* event);
120  void EndEvent(int rank, const char* event);
121  void EndEventSynch(const char* event);
122  void EndEventSynch(int rank, const char* event);
124 
128  template <typename T>
129  vtkParallelTimer& operator<<(const T& s);
130 
135 
140 
144  void Clear();
145 
154  void Update();
155 
159  int Write();
160 
169 
173  static void DeleteGlobalInstance();
174 
176 
180  vtkSetMacro(WriteOnClose, int);
181  vtkGetMacro(WriteOnClose, int);
183 
185 
189  vtkSetMacro(GlobalLevel, int);
190  vtkGetMacro(GlobalLevel, int);
192 
193 protected:
195  virtual ~vtkParallelTimer();
196 
197 private:
198  vtkParallelTimer(const vtkParallelTimer&) = delete;
199  void operator=(const vtkParallelTimer&) = delete;
200 
204  class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor
205  {
206  public:
207  vtkParallelTimerDestructor()
208  : Log(0)
209  {
210  }
211  ~vtkParallelTimerDestructor();
212 
213  void SetLog(vtkParallelTimer* log) { this->Log = log; }
214 
215  private:
216  vtkParallelTimer* Log;
217  };
218 
219 private:
220  int GlobalLevel;
221  int Initialized;
222  int WorldRank;
223  int WriterRank;
224  char* FileName;
225  int WriteOnClose;
226  std::vector<double> StartTime;
227 #if vtkParallelTimerDEBUG < 0
228  std::vector<std::string> EventId;
229 #endif
230 
231  vtkParallelTimerBuffer* Log;
232 
233  static vtkParallelTimer* GlobalInstance;
234  static vtkParallelTimerDestructor GlobalInstanceDestructor;
235 
236  std::ostringstream HeaderBuffer;
237 
238  friend class LogHeaderType;
239  friend class LogBodyType;
240 };
241 
242 //-----------------------------------------------------------------------------
243 template <typename T>
245 {
246  if (this->WorldRank == this->WriterRank)
247  {
248  this->HeaderBuffer << s;
249 #if vtkParallelTimerDEBUG > 0
250  std::cerr << s;
251 #endif
252  }
253  return *this;
254 }
255 
256 //-----------------------------------------------------------------------------
257 template <typename T>
259 {
261 
262  if (log->WorldRank == log->WriterRank)
263  {
264  log->HeaderBuffer << s;
265 #if vtkParallelTimerDEBUG > 0
266  std::cerr << s;
267 #endif
268  }
269 
270  return *this;
271 }
272 
273 //-----------------------------------------------------------------------------
274 template <typename T>
276 {
278 
279  *(log->Log) << s;
280 #if vtkParallelTimerDEBUG > 0
281  std::cerr << s;
282 #endif
283 
284  return *this;
285 }
286 
287 #endif
a simple class to control print indentation
Definition: vtkIndent.h:34
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
abstract base class for most VTK objects
Definition: vtkObject.h:63
Type used to direct an output stream into the log's body.
LogBodyType & operator<<(const T &s)
Type used to direct an output stream into the log's header.
LogHeaderType & operator<<(const T &s)
Provides distributed log functionality.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
friend class LogBodyType
void Update()
When an object is finished writing data to the log object it must call Update to send the data to the...
int Write()
Write the log contents to a file.
void EndEventSynch(int rank, const char *event)
void Clear()
Clear the log.
void EndEvent(int rank, const char *event)
static void DeleteGlobalInstance()
Explicitly delete the singleton.
void EndEventSynch(const char *event)
static vtkParallelTimer * GetGlobalInstance()
The log class implements the singleton pattern so that it may be shared across class boundaries.
void StartEvent(int rank, const char *event)
void EndEvent(const char *event)
void SetFileName(const std::string &fileName)
vtkParallelTimer::LogBodyType GetBody()
stream output to log body(all ranks).
virtual ~vtkParallelTimer()
friend class LogHeaderType
vtkParallelTimer::LogHeaderType GetHeader()
stream output to the log's header(root rank only).
void StartEvent(const char *event)
The log works as an event stack.
static vtkParallelTimer * New()
vtkParallelTimer & operator<<(const T &s)
Insert text into the log header on the writer rank.
@ string
Definition: vtkX3D.h:496