VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkParallelTimer.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 // 00037 #ifndef __vtkParallelTimer_h 00038 #define __vtkParallelTimer_h 00039 00040 #define vtkParallelTimerDEBUG -1 00041 00042 #include "vtkObject.h" 00043 #include "vtkRenderingParallelLICModule.h" // for export 00044 00045 //BTX 00046 #include <vector> // for vector 00047 #include <string> // for string 00048 #include <sstream> // for sstream 00049 #if vtkParallelTimerDEBUG > 0 00050 #include <iostream> // for cerr 00051 #endif 00052 //ETX 00053 00054 class vtkParallelTimerBuffer; 00055 00056 class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject 00057 { 00058 public: 00059 static vtkParallelTimer *New(); 00060 vtkTypeMacro(vtkParallelTimer,vtkObject); 00061 void PrintSelf(ostream& os, vtkIndent indent); 00062 00064 00066 class LogHeaderType 00067 { 00068 public: 00069 template<typename T> LogHeaderType &operator<<(const T& s); 00070 }; 00072 00074 00076 class LogBodyType 00077 { 00078 public: 00079 template<typename T> LogBodyType &operator<<(const T& s); 00080 }; 00082 00084 00085 vtkSetMacro(WriterRank,int); 00086 vtkGetMacro(WriterRank,int); 00088 00090 00092 vtkSetStringMacro(FileName); 00093 vtkGetStringMacro(FileName); 00094 //BTX 00095 void SetFileName(const std::string &fileName) 00096 { this->SetFileName(fileName.c_str()); } 00097 //ETX 00099 00101 00107 void StartEvent(const char *event); 00108 void StartEvent(int rank, const char *event); 00109 void EndEvent(const char *event); 00110 void EndEvent(int rank, const char *event); 00111 void EndEventSynch(const char *event); 00112 void EndEventSynch(int rank, const char *event); 00114 00115 //BTX 00117 00118 template<typename T> 00119 vtkParallelTimer &operator<<(const T& s); 00121 00123 00124 vtkParallelTimer::LogHeaderType GetHeader() 00125 { return vtkParallelTimer::LogHeaderType(); } 00127 00129 00130 vtkParallelTimer::LogBodyType GetBody() 00131 { return vtkParallelTimer::LogBodyType(); } 00132 //ETX 00134 00136 void Clear(); 00137 00143 void Update(); 00144 00146 int Write(); 00147 00153 static vtkParallelTimer *GetGlobalInstance(); 00154 00156 static void DeleteGlobalInstance(); 00157 00159 00161 vtkSetMacro(WriteOnClose, int); 00162 vtkGetMacro(WriteOnClose, int); 00164 00166 00168 vtkSetMacro(GlobalLevel, int); 00169 vtkGetMacro(GlobalLevel, int); 00171 00172 protected: 00173 vtkParallelTimer(); 00174 virtual ~vtkParallelTimer(); 00175 00176 private: 00177 vtkParallelTimer(const vtkParallelTimer&); // Not implemented 00178 void operator=(const vtkParallelTimer&); // Not implemented 00179 00180 //BTX 00182 00183 class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor 00184 { 00185 public: 00186 vtkParallelTimerDestructor() : Log(0) {} 00187 ~vtkParallelTimerDestructor(); 00189 00190 void SetLog(vtkParallelTimer *log){ this->Log = log; } 00191 00192 private: 00193 vtkParallelTimer *Log; 00194 }; 00195 //ETX 00196 00197 private: 00198 int GlobalLevel; 00199 int Initialized; 00200 int WorldRank; 00201 int WriterRank; 00202 char *FileName; 00203 int WriteOnClose; 00204 std::vector<double> StartTime; 00205 #if vtkParallelTimerDEBUG < 0 00206 std::vector<std::string> EventId; 00207 #endif 00208 00209 vtkParallelTimerBuffer *Log; 00210 00211 static vtkParallelTimer *GlobalInstance; 00212 static vtkParallelTimerDestructor GlobalInstanceDestructor; 00213 00214 std::ostringstream HeaderBuffer; 00215 00216 friend class LogHeaderType; 00217 friend class LogBodyType; 00218 }; 00219 00220 //BTX 00221 //----------------------------------------------------------------------------- 00222 template<typename T> 00223 vtkParallelTimer &vtkParallelTimer::operator<<(const T& s) 00224 { 00225 if (this->WorldRank == this->WriterRank) 00226 { 00227 this->HeaderBuffer << s; 00228 #if vtkParallelTimerDEBUG > 0 00229 std::cerr << s; 00230 #endif 00231 } 00232 return *this; 00233 } 00234 00235 //----------------------------------------------------------------------------- 00236 template<typename T> 00237 vtkParallelTimer::LogHeaderType &vtkParallelTimer::LogHeaderType::operator<<(const T& s) 00238 { 00239 vtkParallelTimer *log = vtkParallelTimer::GetGlobalInstance(); 00240 00241 if (log->WorldRank == log->WriterRank) 00242 { 00243 log->HeaderBuffer << s; 00244 #if vtkParallelTimerDEBUG > 0 00245 std::cerr << s; 00246 #endif 00247 } 00248 00249 return *this; 00250 } 00251 00252 //----------------------------------------------------------------------------- 00253 template<typename T> 00254 vtkParallelTimer::LogBodyType &vtkParallelTimer::LogBodyType::operator<<(const T& s) 00255 { 00256 vtkParallelTimer *log = vtkParallelTimer::GetGlobalInstance(); 00257 00258 *(log->Log) << s; 00259 #if vtkParallelTimerDEBUG > 0 00260 std::cerr << s; 00261 #endif 00262 00263 return *this; 00264 } 00265 //ETX 00266 00267 #endif