VTK  9.1.0
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
53class vtkParallelTimerBuffer;
54
55class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject
56{
57public:
60 void PrintSelf(ostream& os, vtkIndent indent) override;
61
63
68 {
69 public:
70 template <typename T>
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
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
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
196protected:
199
200private:
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
222private:
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//-----------------------------------------------------------------------------
246template <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//-----------------------------------------------------------------------------
260template <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//-----------------------------------------------------------------------------
277template <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
a simple class to control print indentation
Definition: vtkIndent.h:113
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
abstract base class for most VTK objects
Definition: vtkObject.h:82
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()
virtual ~vtkParallelTimer()
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