VTK  9.2.6
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  vtkSetFilePathMacro(FileName);
103  vtkGetFilePathMacro(FileName);
105 
106  void SetFileName(VTK_FILEPATH const std::string& fileName)
107  {
108  this->SetFileName(fileName.c_str());
109  }
110 
112 
120  void StartEvent(const char* event);
121  void StartEvent(int rank, const char* event);
122  void EndEvent(const char* event);
123  void EndEvent(int rank, const char* event);
124  void EndEventSynch(const char* event);
125  void EndEventSynch(int rank, const char* event);
127 
131  template <typename T>
132  vtkParallelTimer& operator<<(const T& s);
133 
138 
143 
147  void Clear();
148 
157  void Update();
158 
162  int Write();
163 
171  static vtkParallelTimer* GetGlobalInstance();
172 
176  static void DeleteGlobalInstance();
177 
179 
183  vtkSetMacro(WriteOnClose, int);
184  vtkGetMacro(WriteOnClose, int);
186 
188 
192  vtkSetMacro(GlobalLevel, int);
193  vtkGetMacro(GlobalLevel, int);
195 
196 protected:
198  virtual ~vtkParallelTimer();
199 
200 private:
201  vtkParallelTimer(const vtkParallelTimer&) = delete;
202  void operator=(const vtkParallelTimer&) = delete;
203 
207  class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor
208  {
209  public:
210  vtkParallelTimerDestructor()
211  : Log(0)
212  {
213  }
214  ~vtkParallelTimerDestructor();
215 
216  void SetLog(vtkParallelTimer* log) { this->Log = log; }
217 
218  private:
219  vtkParallelTimer* Log;
220  };
221 
222 private:
223  int GlobalLevel;
224  int Initialized;
225  int WorldRank;
226  int WriterRank;
227  char* FileName;
228  int WriteOnClose;
229  std::vector<double> StartTime;
230 #if vtkParallelTimerDEBUG < 0
231  std::vector<std::string> EventId;
232 #endif
233 
234  vtkParallelTimerBuffer* Log;
235 
236  static vtkParallelTimer* GlobalInstance;
237  static vtkParallelTimerDestructor GlobalInstanceDestructor;
238 
239  std::ostringstream HeaderBuffer;
240 
241  friend class LogHeaderType;
242  friend class LogBodyType;
243 };
244 
245 //-----------------------------------------------------------------------------
246 template <typename T>
248 {
249  if (this->WorldRank == this->WriterRank)
250  {
251  this->HeaderBuffer << s;
252 #if vtkParallelTimerDEBUG > 0
253  std::cerr << s;
254 #endif
255  }
256  return *this;
257 }
258 
259 //-----------------------------------------------------------------------------
260 template <typename T>
262 {
264 
265  if (log->WorldRank == log->WriterRank)
266  {
267  log->HeaderBuffer << s;
268 #if vtkParallelTimerDEBUG > 0
269  std::cerr << s;
270 #endif
271  }
272 
273  return *this;
274 }
275 
276 //-----------------------------------------------------------------------------
277 template <typename T>
279 {
281 
282  *(log->Log) << s;
283 #if vtkParallelTimerDEBUG > 0
284  std::cerr << s;
285 #endif
286 
287  return *this;
288 }
289 
290 #endif
LogHeaderType & operator<<(const T &s)
friend class LogHeaderType
abstract base class for most VTK objects
Definition: vtkObject.h:62
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.
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 distributed log functionality.
void SetFileName(VTK_FILEPATH const std::string &fileName)
#define VTK_FILEPATH
static vtkParallelTimer * GetGlobalInstance()
The log class implements the singleton pattern so that it may be shared across 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.