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

Parallel/vtkSharedMemoryCommunicator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSharedMemoryCommunicator.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00060 #ifndef __vtkSharedMemoryCommunicator_h
00061 #define __vtkSharedMemoryCommunicator_h
00062 
00063 #include "vtkCommunicator.h"
00064 #include "vtkMultiProcessController.h"
00065 #include "vtkCriticalSection.h"
00066 
00067 class vtkThreadedController;
00068 class vtkSharedMemoryCommunicatorMessage;
00069 
00070 class VTK_PARALLEL_EXPORT vtkSharedMemoryCommunicator : public vtkCommunicator
00071 {
00072 
00073 public:
00074 
00075   vtkTypeMacro( vtkSharedMemoryCommunicator,vtkObject);
00076   
00078   static vtkSharedMemoryCommunicator* New();
00079 
00080   virtual void PrintSelf(ostream& os, vtkIndent indent);
00081 
00083 
00085   virtual int Send(int* data, int length, int remoteThreadId, int tag);
00086   virtual int Send(unsigned long* data, int length, int remoteThreadId, 
00087                    int tag);
00088   virtual int Send(char* data, int length, int remoteThreadId, int tag);
00089   virtual int Send(unsigned char* data, int length, int remoteThreadId, int tag);
00090   virtual int Send(float* data, int length, int remoteThreadId, int tag);
00091   virtual int Send(double* data, int length, int remoteThreadId, int tag);
00092 #ifdef VTK_USE_64BIT_IDS
00093   virtual int Send(vtkIdType* data, int length, int remoteThreadId, int tag);
00095 #endif
00096   virtual int Send(vtkDataObject* data, int remoteThreadId, int tag);
00097   virtual int Send(vtkDataArray* data, int remoteThreadId, int tag);
00098 
00100 
00103   virtual int Receive(int* data, int length, int remoteThreadId, 
00104                       int tag);
00105   virtual int Receive(unsigned long* data, int length, 
00106                       int remoteThreadId, int tag);
00107   virtual int Receive(char* data, int length, int remoteThreadId, 
00108                       int tag);
00109   virtual int Receive(unsigned char* data, int length, int remoteThreadId, 
00110                       int tag);
00111   virtual int Receive(float* data, int length, int remoteThreadId, 
00112                       int tag);
00113   virtual int Receive(double* data, int length, int remoteThreadId, 
00114                       int tag);
00115 #ifdef VTK_USE_64BIT_IDS
00116   virtual int Receive(vtkIdType* data, int length, int remoteThreadId, 
00117                       int tag);
00119 #endif
00120   virtual int Receive(vtkDataObject *data, int remoteThreadId, int tag);
00121   virtual int Receive(vtkDataArray *data, int remoteThreadId, int tag);
00122 
00123 //BTX
00124 
00125   friend class vtkThreadedController;
00126 
00127 //ETX
00128 
00129 protected:
00130 
00131   int NumberOfThreads;
00132   int Initialized;
00133   void Initialize(int nThreads, int forceDeepCopy);
00134 
00135   int LocalThreadId;
00136   int WaitingForId;
00137 
00138   int ForceDeepCopy;
00139 
00140   // It is not enough to block on the messages, we have to mutex 
00141   // the whole send interaction.  I was trying to avoid a central 
00142   // mutex (oh well).
00143   vtkSimpleCriticalSection* MessageListLock;
00144 
00145 
00146   // Each thread has its own communicator.
00147   vtkSharedMemoryCommunicator** Communicators;
00148 
00149   vtkSharedMemoryCommunicator* Parent;
00150   
00151   // Double linked list.
00152   vtkSharedMemoryCommunicatorMessage *MessageListStart;
00153   vtkSharedMemoryCommunicatorMessage *MessageListEnd;
00154 
00155   vtkSharedMemoryCommunicator();
00156   ~vtkSharedMemoryCommunicator();
00157 
00158   // The generic send and receive methods.
00159   int Send(vtkDataObject* object, void *data, int dataLength, 
00160            int remoteThreadId, int tag);
00161   int Receive(vtkDataObject* object, void *data, int dataLength, 
00162               int remoteThreadId, int tag);
00163 
00164   int Send(vtkDataArray* object, int dataLength, 
00165            int remoteThreadId, int tag);
00166   int Receive(vtkDataArray* object, int dataLength, 
00167               int remoteThreadId, int tag);
00168 
00169   vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataObject* object,
00170                                                  void* data, 
00171                                                  int dataLength);
00172   vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataArray* object,
00173                                                  void* data, 
00174                                                  int dataLength);
00175   void DeleteMessage(vtkSharedMemoryCommunicatorMessage *message);
00176   void AddMessage(vtkSharedMemoryCommunicatorMessage *message);
00177   vtkSharedMemoryCommunicatorMessage* FindMessage(int sendId, int tag);
00178 
00179 #ifdef _WIN32
00180   // Event signaling the arrival of a new message.
00181   // Windows implementation only.
00182   HANDLE MessageSignal;
00183 #else
00184   // This mutex is normally locked.  It is used to block the execution 
00185   // of the receiving process when the send has not been called yet.
00186   vtkSimpleCriticalSection* Gate;
00187 #endif
00188 
00189   void SignalNewMessage(vtkSharedMemoryCommunicator* receiveCommunicator)
00190     {
00191 #ifdef _WIN32
00192     SetEvent( receiveCommunicator->MessageSignal );
00193 #else
00194     receiveCommunicator->Gate->Unlock();
00195 #endif
00196     }
00197 
00198   void WaitForNewMessage()
00199     {
00200 #ifdef _WIN32
00201       WaitForSingleObject( this->MessageSignal, INFINITE );
00202 #else
00203       this->Gate->Lock();
00204 #endif
00205     }
00206 
00207 private:
00208   vtkSharedMemoryCommunicator(const vtkSharedMemoryCommunicator&);  // Not implemented.
00209   void operator=(const vtkSharedMemoryCommunicator&);  // Not implemented.
00210 };
00211 
00212 #endif //  __vtkSharedMemoryCommunicator_h

Generated on Thu Mar 28 14:19:30 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001