VTK  9.3.20240424
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
41VTK_ABI_NAMESPACE_BEGIN
42class vtkParallelTimerBuffer;
43
44class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject
45{
46public:
49 void PrintSelf(ostream& os, vtkIndent indent) override;
50
52
57 {
58 public:
59 template <typename T>
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
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
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
185protected:
188
189private:
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//-----------------------------------------------------------------------------
234template <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//-----------------------------------------------------------------------------
248template <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//-----------------------------------------------------------------------------
265template <typename T>
267{
269
270 *(log->Log) << s;
271#if vtkParallelTimerDEBUG > 0
272 std::cerr << s;
273#endif
274
275 return *this;
276}
277
278VTK_ABI_NAMESPACE_END
279#endif
a simple class to control print indentation
Definition vtkIndent.h:108
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
abstract base class for most VTK objects
Definition vtkObject.h:162
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.
void Update()
When an object is finished writing data to the log object it must call Update to send the data to the...
vtkGetFilePathMacro(FileName)
Set the filename that is used during write when the object is used as a singleton.
int Write()
Write the log contents to a file.
void EndEventSynch(int rank, const char *event)
The log works as an event stack.
static vtkParallelTimer * GetGlobalInstance()
The log class implements the singleton pattern so that it may be shared across class boundaries.
void SetFileName(VTK_FILEPATH const std::string &fileName)
void Clear()
Clear the log.
void EndEvent(int rank, const char *event)
The log works as an event stack.
static void DeleteGlobalInstance()
Explicitly delete the singleton.
void EndEventSynch(const char *event)
The log works as an event stack.
void StartEvent(int rank, const char *event)
The log works as an event stack.
void EndEvent(const char *event)
The log works as an event stack.
vtkParallelTimer::LogBodyType GetBody()
stream output to log body(all ranks).
static vtkParallelTimer * New()
~vtkParallelTimer() override
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.
vtkSetFilePathMacro(FileName)
Set the filename that is used during write when the object is used as a singleton.
#define VTK_FILEPATH