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 
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 
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 
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
vtkParallelTimer::StartEvent
void StartEvent(const char *event)
The log works as an event stack.
vtkParallelTimer::LogBodyType
friend class LogBodyType
Definition: vtkParallelTimer.h:242
vtkParallelTimer::StartEvent
void StartEvent(int rank, const char *event)
The log works as an event stack.
vtkParallelTimer::Write
int Write()
Write the log contents to a file.
vtkParallelTimer
Provides distributed log functionality.
Definition: vtkParallelTimer.h:56
vtkParallelTimer::SetFileName
void SetFileName(VTK_FILEPATH const std::string &fileName)
Definition: vtkParallelTimer.h:106
VTK_FILEPATH
#define VTK_FILEPATH
Definition: vtkWrappingHints.h:46
vtkParallelTimer::GetGlobalInstance
static vtkParallelTimer * GetGlobalInstance()
The log class implements the singleton pattern so that it may be shared across class boundaries.
vtkParallelTimer::vtkSetFilePathMacro
vtkSetFilePathMacro(FileName)
Set the filename that is used during write when the object is used as a singleton.
vtkParallelTimer::~vtkParallelTimer
virtual ~vtkParallelTimer()
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkParallelTimer::LogBodyType::operator<<
LogBodyType & operator<<(const T &s)
vtkParallelTimer::LogHeaderType
Type used to direct an output stream into the log's header.
Definition: vtkParallelTimer.h:68
vtkParallelTimer::GetBody
vtkParallelTimer::LogBodyType GetBody()
stream output to log body(all ranks).
Definition: vtkParallelTimer.h:142
vtkParallelTimer::Update
void Update()
When an object is finished writing data to the log object it must call Update to send the data to the...
vtkParallelTimer::GetHeader
vtkParallelTimer::LogHeaderType GetHeader()
stream output to the log's header(root rank only).
Definition: vtkParallelTimer.h:137
vtkParallelTimer::operator<<
vtkParallelTimer & operator<<(const T &s)
Insert text into the log header on the writer rank.
Definition: vtkParallelTimer.h:247
vtkParallelTimer::Clear
void Clear()
Clear the log.
vtkParallelTimer::LogHeaderType
friend class LogHeaderType
Definition: vtkParallelTimer.h:241
vtkParallelTimer::DeleteGlobalInstance
static void DeleteGlobalInstance()
Explicitly delete the singleton.
vtkParallelTimer::vtkGetFilePathMacro
vtkGetFilePathMacro(FileName)
Set the filename that is used during write when the object is used as a singleton.
vtkParallelTimer::EndEvent
void EndEvent(const char *event)
The log works as an event stack.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkParallelTimer::LogHeaderType::operator<<
LogHeaderType & operator<<(const T &s)
vtkParallelTimer::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkParallelTimer::New
static vtkParallelTimer * New()
vtkObject.h
vtkParallelTimer::EndEvent
void EndEvent(int rank, const char *event)
The log works as an event stack.
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkObjectBase::operator<<
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
vtkParallelTimer::EndEventSynch
void EndEventSynch(const char *event)
The log works as an event stack.
vtkParallelTimer::LogBodyType
Type used to direct an output stream into the log's body.
Definition: vtkParallelTimer.h:81
vtkParallelTimer::vtkParallelTimer
vtkParallelTimer()
vtkParallelTimer::EndEventSynch
void EndEventSynch(int rank, const char *event)
The log works as an event stack.