Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Parallel/vtkThreadedController.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkThreadedController.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00047 #ifndef __vtkThreadedController_h
00048 #define __vtkThreadedController_h
00049 
00050 #include "vtkMultiProcessController.h"
00051 #include "vtkCriticalSection.h" // For vtkSimpleCriticalSection
00052 
00053 class vtkMultiThreader;
00054 
00055 class VTK_PARALLEL_EXPORT vtkThreadedController : public vtkMultiProcessController
00056 {
00057 public:
00058   static vtkThreadedController *New();
00059   vtkTypeRevisionMacro(vtkThreadedController,vtkMultiProcessController);
00060   void PrintSelf(ostream& os, vtkIndent indent);
00061 
00063 
00064   virtual void Initialize(int* argc, char*** argv, int)
00065     { this->Initialize(argc, argv); }
00066   virtual void Initialize(int* argc, char*** argv);
00067   virtual void Finalize();
00068   virtual void Finalize(int) {this->Finalize();}
00070 
00072 
00077   vtkGetMacro(LocalProcessId, int);
00079 
00083   virtual void SingleMethodExecute();
00084   
00088   virtual void MultipleMethodExecute();
00089 
00091   virtual void Barrier();
00092 
00095   virtual void CreateOutputWindow();
00096 
00097 protected:
00098   vtkThreadedController();
00099   ~vtkThreadedController();
00100   
00101   void CreateProcessControllers();
00102   
00104   void Start(int threadIdx);
00105 
00106   void ResetControllers();
00107 
00108   static VTK_THREAD_RETURN_TYPE vtkThreadedControllerStart( void *arg );
00109 
00110   // Each Process/Thread has its own controller.
00111   vtkThreadedController** Controllers;
00112 
00113 //BTX
00114 
00115 // Required only for static access to threadId (GetLocalController).
00116 #ifdef VTK_USE_PTHREADS
00117   typedef pthread_t ThreadIdType;
00118 #elif defined VTK_USE_SPROC
00119   typedef pid_t ThreadIdType;
00120 #elif defined VTK_USE_WIN32_THREADS
00121   typedef DWORD ThreadIdType;
00122 #else
00123   typedef int ThreadIdType;
00124 #endif
00125 
00126 //ETX
00127  
00128   // Used in barrier
00129   static vtkSimpleCriticalSection CounterLock;
00130   static int Counter;
00131   static int IsBarrierInProgress;
00132   static void WaitForPreviousBarrierToEnd();
00133   static void BarrierStarted();
00134   static void BarrierEnded();
00135   static void SignalNextThread();
00136   static void InitializeBarrier();
00137   static void WaitForNextThread();
00138 #ifdef VTK_USE_WIN32_THREADS
00139   static HANDLE BarrierEndedEvent;
00140   static HANDLE NextThread;
00141 #else
00142   static vtkSimpleCriticalSection* BarrierLock;
00143   static vtkSimpleCriticalSection* BarrierInProgress;
00144 #endif
00145   
00146   ThreadIdType ThreadId;
00147 
00148   int LastNumberOfProcesses;
00149 
00150   vtkMultiThreader *MultiThreader;
00151   // Used internally to switch between multiple and single method execution.
00152   int MultipleMethodFlag;
00153   
00154   // For static GetGlobalController.  Translates controller for thread0
00155   // to controller for local thread.
00156   vtkMultiProcessController *GetLocalController();
00157 
00158 private:
00159   vtkThreadedController(const vtkThreadedController&);  // Not implemented.
00160   void operator=(const vtkThreadedController&);  // Not implemented.
00161 };
00162 
00163 #endif
00164 
00165