VTK  9.3.1
vtkParallelTimer.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
26 #ifndef vtkParallelTimer_h
27 #define vtkParallelTimer_h
28 
29 #define vtkParallelTimerDEBUG -1
30 
31 #include "vtkObject.h"
32 #include "vtkRenderingParallelLICModule.h" // for export
33 
34 #include <sstream> // for sstream
35 #include <string> // for string
36 #include <vector> // for vector
37 #if vtkParallelTimerDEBUG > 0
38 #include <iostream> // for cerr
39 #endif
40 
41 VTK_ABI_NAMESPACE_BEGIN
42 class vtkParallelTimerBuffer;
43 
44 class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject
45 {
46 public:
47  static vtkParallelTimer* New();
48  vtkTypeMacro(vtkParallelTimer, vtkObject);
49  void PrintSelf(ostream& os, vtkIndent indent) override;
50 
52 
57  {
58  public:
59  template <typename T>
60  LogHeaderType& operator<<(const T& s);
61  };
63 
65 
70  {
71  public:
72  template <typename T>
73  LogBodyType& operator<<(const T& s);
74  };
76 
78 
81  vtkSetMacro(WriterRank, int);
82  vtkGetMacro(WriterRank, int);
84 
86 
91  vtkSetFilePathMacro(FileName);
92  vtkGetFilePathMacro(FileName);
94 
95  void SetFileName(VTK_FILEPATH const std::string& fileName)
96  {
97  this->SetFileName(fileName.c_str());
98  }
99 
101 
109  void StartEvent(const char* event);
110  void StartEvent(int rank, const char* event);
111  void EndEvent(const char* event);
112  void EndEvent(int rank, const char* event);
113  void EndEventSynch(const char* event);
114  void EndEventSynch(int rank, const char* event);
116 
120  template <typename T>
121  vtkParallelTimer& operator<<(const T& s);
122 
127 
132 
136  void Clear();
137 
146  void Update();
147 
151  int Write();
152 
160  static vtkParallelTimer* GetGlobalInstance();
161 
165  static void DeleteGlobalInstance();
166 
168 
172  vtkSetMacro(WriteOnClose, int);
173  vtkGetMacro(WriteOnClose, int);
175 
177 
181  vtkSetMacro(GlobalLevel, int);
182  vtkGetMacro(GlobalLevel, int);
184 
185 protected:
187  ~vtkParallelTimer() override;
188 
189 private:
190  vtkParallelTimer(const vtkParallelTimer&) = delete;
191  void operator=(const vtkParallelTimer&) = delete;
192 
196  class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor
197  {
198  public:
199  vtkParallelTimerDestructor()
200  : Log(nullptr)
201  {
202  }
203  ~vtkParallelTimerDestructor();
204 
205  void SetLog(vtkParallelTimer* log) { this->Log = log; }
206 
207  private:
208  vtkParallelTimer* Log;
209  };
210 
211  int GlobalLevel;
212  int Initialized;
213  int WorldRank;
214  int WriterRank;
215  char* FileName;
216  int WriteOnClose;
217  std::vector<double> StartTime;
218 #if vtkParallelTimerDEBUG < 0
219  std::vector<std::string> EventId;
220 #endif
221 
222  vtkParallelTimerBuffer* Log;
223 
224  static vtkParallelTimer* GlobalInstance;
225  static vtkParallelTimerDestructor GlobalInstanceDestructor;
226 
227  std::ostringstream HeaderBuffer;
228 
229  friend class LogHeaderType;
230  friend class LogBodyType;
231 };
232 
233 //-----------------------------------------------------------------------------
234 template <typename T>
236 {
237  if (this->WorldRank == this->WriterRank)
238  {
239  this->HeaderBuffer << s;
240 #if vtkParallelTimerDEBUG > 0
241  std::cerr << s;
242 #endif
243  }
244  return *this;
245 }
246 
247 //-----------------------------------------------------------------------------
248 template <typename T>
250 {
252 
253  if (log->WorldRank == log->WriterRank)
254  {
255  log->HeaderBuffer << s;
256 #if vtkParallelTimerDEBUG > 0
257  std::cerr << s;
258 #endif
259  }
260 
261  return *this;
262 }
263 
264 //-----------------------------------------------------------------------------
265 template <typename T>
267 {
269 
270  *(log->Log) << s;
271 #if vtkParallelTimerDEBUG > 0
272  std::cerr << s;
273 #endif
274 
275  return *this;
276 }
277 
278 VTK_ABI_NAMESPACE_END
279 #endif
LogHeaderType & operator<<(const T &s)
friend class LogHeaderType
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:28
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.