Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkSharedMemoryCommunicator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSharedMemoryCommunicator.h,v $
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 =========================================================================*/
00044 #ifndef __vtkSharedMemoryCommunicator_h
00045 #define __vtkSharedMemoryCommunicator_h
00046 
00047 #include "vtkCommunicator.h"
00048 
00049 class vtkThreadedController;
00050 class vtkSharedMemoryCommunicatorMessage;
00051 class vtkSimpleCriticalSection;
00052 class vtkThreadMessager;
00053 
00054 class VTK_PARALLEL_EXPORT vtkSharedMemoryCommunicator : public vtkCommunicator
00055 {
00056 public:
00057   vtkTypeRevisionMacro( vtkSharedMemoryCommunicator,vtkCommunicator);
00058   
00060   static vtkSharedMemoryCommunicator* New();
00061 
00062   virtual void PrintSelf(ostream& os, vtkIndent indent);
00063 
00065 
00067   virtual int Send(int* data, int length, int remoteThreadId, int tag);
00068   virtual int Send(unsigned long* data, int length, int remoteThreadId, 
00069                    int tag);
00070   virtual int Send(char* data, int length, int remoteThreadId, int tag);
00071   virtual int Send(unsigned char* data, int length, int remoteThreadId, int tag);
00072   virtual int Send(float* data, int length, int remoteThreadId, int tag);
00073   virtual int Send(double* data, int length, int remoteThreadId, int tag);
00074 #ifdef VTK_USE_64BIT_IDS
00075   virtual int Send(vtkIdType* data, int length, int remoteThreadId, int tag);
00077 #endif
00078   virtual int Send(vtkDataObject* data, int remoteThreadId, int tag);
00079   virtual int Send(vtkDataArray* data, int remoteThreadId, int tag);
00080 
00082 
00085   virtual int Receive(int* data, int length, int remoteThreadId, 
00086                       int tag);
00087   virtual int Receive(unsigned long* data, int length, 
00088                       int remoteThreadId, int tag);
00089   virtual int Receive(char* data, int length, int remoteThreadId, 
00090                       int tag);
00091   virtual int Receive(unsigned char* data, int length, int remoteThreadId, 
00092                       int tag);
00093   virtual int Receive(float* data, int length, int remoteThreadId, 
00094                       int tag);
00095   virtual int Receive(double* data, int length, int remoteThreadId, 
00096                       int tag);
00097 #ifdef VTK_USE_64BIT_IDS
00098   virtual int Receive(vtkIdType* data, int length, int remoteThreadId, 
00099                       int tag);
00101 #endif
00102   virtual int Receive(vtkDataObject *data, int remoteThreadId, int tag);
00103   virtual int Receive(vtkDataArray *data, int remoteThreadId, int tag);
00104 
00105 //BTX
00106 
00107   friend class vtkThreadedController;
00108 
00109 //ETX
00110 
00111 protected:
00112 
00113   int NumberOfThreads;
00114   int Initialized;
00115   void Initialize(int nThreads, int forceDeepCopy);
00116 
00117   int LocalThreadId;
00118   int WaitingForId;
00119 
00120   int ForceDeepCopy;
00121 
00122   // It is not enough to block on the messages, we have to mutex 
00123   // the whole send interaction.  I was trying to avoid a central 
00124   // mutex (oh well).
00125   vtkSimpleCriticalSection* MessageListLock;
00126 
00127 
00128   // Each thread has its own communicator.
00129   vtkSharedMemoryCommunicator** Communicators;
00130 
00131   vtkSharedMemoryCommunicator* Parent;
00132   
00133   // Double linked list.
00134   vtkSharedMemoryCommunicatorMessage *MessageListStart;
00135   vtkSharedMemoryCommunicatorMessage *MessageListEnd;
00136 
00137   vtkSharedMemoryCommunicator();
00138   ~vtkSharedMemoryCommunicator();
00139 
00140   // The generic send and receive methods.
00141   int Send(vtkDataObject* object, void *data, int dataLength, 
00142            int remoteThreadId, int tag);
00143   int Receive(vtkDataObject* object, void *data, int dataLength, 
00144               int remoteThreadId, int tag);
00145 
00146   int Send(vtkDataArray* object, int dataLength, 
00147            int remoteThreadId, int tag);
00148   int Receive(vtkDataArray* object, int dataLength, 
00149               int remoteThreadId, int tag);
00150 
00151   vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataObject* object,
00152                                                  void* data, 
00153                                                  int dataLength);
00154   vtkSharedMemoryCommunicatorMessage* NewMessage(vtkDataArray* object,
00155                                                  void* data, 
00156                                                  int dataLength);
00157   void DeleteMessage(vtkSharedMemoryCommunicatorMessage *message);
00158   void AddMessage(vtkSharedMemoryCommunicatorMessage *message);
00159   vtkSharedMemoryCommunicatorMessage* FindMessage(int sendId, int tag);
00160 
00161   vtkThreadMessager* Messager;
00162 
00163   void SignalNewMessage(vtkSharedMemoryCommunicator* receiveCommunicator);
00164 
00165   void WaitForNewMessage();
00166 
00167 private:
00168   vtkSharedMemoryCommunicator(const vtkSharedMemoryCommunicator&);  // Not implemented.
00169   void operator=(const vtkSharedMemoryCommunicator&);  // Not implemented.
00170 };
00171 
00172 #endif //  __vtkSharedMemoryCommunicator_h