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   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 =========================================================================*/
    00048 #ifndef __vtkSharedMemoryCommunicator_h
    00049 #define __vtkSharedMemoryCommunicator_h
    00050
    00051 #include "vtkCommunicator.h"
    00052
    00053 class vtkThreadedController;
    00054 class vtkSharedMemoryCommunicatorMessage;
    00055 class vtkSimpleCriticalSection;
    00056
    00057 class VTK_PARALLEL_EXPORT vtkSharedMemoryCommunicator : public vtkCommunicator
    00058 {
    00059 public:
    00060   vtkTypeRevisionMacro( vtkSharedMemoryCommunicator,vtkCommunicator);
    00061
    00063   static vtkSharedMemoryCommunicator* New();
    00064
    00065   virtual void PrintSelf(ostream& os, vtkIndent indent);
    00066
    00068
    00070   virtual int Send(int* data, int length, int remoteThreadId, int tag);
    00071   virtual int Send(unsigned long* data, int length, int remoteThreadId,
    00072                    int tag);
    00073   virtual int Send(char* data, int length, int remoteThreadId, int tag);
    00074   virtual int Send(unsigned char* data, int length, int remoteThreadId, int tag);
    00075   virtual int Send(float* data, int length, int remoteThreadId, int tag);
    00076   virtual int Send(double* data, int length, int remoteThreadId, int tag);
    00077 #ifdef VTK_USE_64BIT_IDS
    00078   virtual int Send(vtkIdType* data, int length, int remoteThreadId, int tag);
    00080 #endif
    00081   virtual int Send(vtkDataObject* data, int remoteThreadId, int tag);
    00082   virtual int Send(vtkDataArray* data, int remoteThreadId, int tag);
    00083
    00085
    00088   virtual int Receive(int* data, int length, int remoteThreadId,
    00089                       int tag);
    00090   virtual int Receive(unsigned long* data, int length,
    00091                       int remoteThreadId, int tag);
    00092   virtual int Receive(char* data, int length, int remoteThreadId,
    00093                       int tag);
    00094   virtual int Receive(unsigned char* data, int length, int remoteThreadId,
    00095                       int tag);
    00096   virtual int Receive(float* data, int length, int remoteThreadId,
    00097                       int tag);
    00098   virtual int Receive(double* data, int length, int remoteThreadId,
    00099                       int tag);
    00100 #ifdef VTK_USE_64BIT_IDS
    00101   virtual int Receive(vtkIdType* data, int length, int remoteThreadId,
    00102                       int tag);
    00104 #endif
    00105   virtual int Receive(vtkDataObject *data, int remoteThreadId, int tag);
    00106   virtual int Receive(vtkDataArray *data, int remoteThreadId, int tag);
    00107
    00108 //BTX
    00109
    00110   friend class vtkThreadedController;
    00111
    00112 //ETX
    00113
    00114 protected:
    00115
    00116   int NumberOfThreads;
    00117   int Initialized;
    00118   void Initialize(int nThreads, int forceDeepCopy);
    00119
    00120   int LocalThreadId;
    00121   int WaitingForId;
    00122
    00123   int ForceDeepCopy;
    00124
    00125   // It is not enough to block on the messages, we have to mutex
    00126   // the whole send interaction.  I was trying to avoid a central
    00127   // mutex (oh well).
    00128   vtkSimpleCriticalSection* MessageListLock;
    00129
    00130
    00131   // Each thread has its own communicator.
    00132   vtkSharedMemoryCommunicator** Communicators;
    00133
    00134   vtkSharedMemoryCommunicator* Parent;
    00135
    00136   // Double linked list.
    00137   vtkSharedMemoryCommunicatorMessage *MessageListStart;
    00138   vtkSharedMemoryCommunicatorMessage *MessageListEnd;
    00139
    00140   vtkSharedMemoryCommunicator();
    00141   ~vtkSharedMemoryCommunicator();
    00142
    00143   // The generic send and receive methods.
    00144   int Send(vtkDataObject* object, void *data, int dataLength,
    00145            int remoteThreadId, int tag);
    00146   int Receive(vtkDataObject* object, void *data, int dataLength,
    00147               int remoteThreadId, int tag);
    00148
    00149   int Send(vtkDataArray* object, int dataLength,
    00150            int remoteThreadId, int tag);
    00151   int Receive(vtkDataArray* object, int dataLength,
    00152               int remoteThreadId, int tag);
    00153
    00154   vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataObject* object,
    00155                                                  void* data,
    00156                                                  int dataLength);
    00157   vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataArray* object,
    00158                                                  void* data,
    00159                                                  int dataLength);
    00160   void DeleteMessage(vtkSharedMemoryCommunicatorMessage *message);
    00161   void AddMessage(vtkSharedMemoryCommunicatorMessage *message);
    00162   vtkSharedMemoryCommunicatorMessage* FindMessage(int sendId, int tag);
    00163
    00164 #ifdef _WIN32
    00165   // Event signaling the arrival of a new message.
    00166   // Windows implementation only.
    00167   HANDLE MessageSignal;
    00168 #else
    00169   // This mutex is normally locked.  It is used to block the execution
    00170   // of the receiving process when the send has not been called yet.
    00171   vtkSimpleCriticalSection* Gate;
    00172 #endif
    00173
    00174   void SignalNewMessage(vtkSharedMemoryCommunicator* receiveCommunicator);
    00175
    00176   void WaitForNewMessage();
    00177
    00178 private:
    00179   vtkSharedMemoryCommunicator(const vtkSharedMemoryCommunicator&);  // Not implemented.
    00180   void operator=(const vtkSharedMemoryCommunicator&);  // Not implemented.
    00181 };
    00182
    00183 #endif //  __vtkSharedMemoryCommunicator_h