• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

dox/Parallel/vtkSocketCommunicator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSocketCommunicator.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 =========================================================================*/
00039 #ifndef __vtkSocketCommunicator_h
00040 #define __vtkSocketCommunicator_h
00041 
00042 #include "vtkCommunicator.h"
00043 
00044 #include "vtkByteSwap.h" // Needed for vtkSwap macros
00045 
00046 #ifdef VTK_WORDS_BIGENDIAN
00047 # define vtkSwap4 vtkByteSwap::Swap4LE
00048 # define vtkSwap4Range vtkByteSwap::Swap4LERange
00049 # define vtkSwap8 vtkByteSwap::Swap8LE
00050 # define vtkSwap8Range vtkByteSwap::Swap8LERange
00051 #else
00052 # define vtkSwap4 vtkByteSwap::Swap4BE
00053 # define vtkSwap4Range vtkByteSwap::Swap4BERange
00054 # define vtkSwap8 vtkByteSwap::Swap8BE
00055 # define vtkSwap8Range vtkByteSwap::Swap8BERange
00056 #endif
00057 
00058 class vtkClientSocket;
00059 class vtkServerSocket;
00060 
00061 class VTK_PARALLEL_EXPORT vtkSocketCommunicator : public vtkCommunicator
00062 {
00063 public:
00064   static vtkSocketCommunicator *New();
00065   vtkTypeRevisionMacro(vtkSocketCommunicator,vtkCommunicator);
00066   void PrintSelf(ostream& os, vtkIndent indent);
00067 
00069 
00071   virtual int WaitForConnection(int port);
00072   virtual int WaitForConnection(vtkServerSocket* socket,
00073     unsigned  long msec = 0);
00075 
00077   virtual void CloseConnection();
00078 
00080   virtual int ConnectTo( char* hostName, int port);
00081 
00083 
00084   vtkGetMacro(SwapBytesInReceivedData, int);
00086 
00088   int GetIsConnected();
00089 
00091   virtual void SetNumberOfProcesses(int num);
00092 
00093   //------------------ Communication --------------------
00094 
00096 
00098   virtual int SendVoidArray(const void *data, vtkIdType length, int type,
00099                             int remoteHandle, int tag);
00100   virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
00101                                int remoteHandle, int tag);
00103 
00106   virtual void Barrier();
00107 
00109 
00112   virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
00113                                  int srcProcessId);
00114   virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
00115                               vtkIdType length, int type, int destProcessId);
00116   virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
00117                                vtkIdType sendLength, vtkIdType *recvLengths,
00118                                vtkIdType *offsets, int type, int destProcessId);
00119   virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
00120                                vtkIdType length, int type, int srcProcessId);
00121   virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
00122                                 vtkIdType *sendLengths, vtkIdType *offsets,
00123                                 vtkIdType recvLength, int type,
00124                                 int srcProcessId);
00125   virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
00126                                  vtkIdType length, int type);
00127   virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
00128                                   vtkIdType sendLength, vtkIdType *recvLengths,
00129                                   vtkIdType *offsets, int type);
00130   virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00131                               vtkIdType length, int type,
00132                               int operation, int destProcessId);
00133   virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00134                               vtkIdType length, int type,
00135                               Operation *operation, int destProcessId);
00136   virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00137                                  vtkIdType length, int type,
00138                                  int operation);
00139   virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00140                                  vtkIdType length, int type,
00141                                  Operation *operation);
00143 
00145 
00147   vtkSetClampMacro(PerformHandshake, int, 0, 1);
00148   vtkBooleanMacro(PerformHandshake, int);
00149   vtkGetMacro(PerformHandshake, int);
00151 
00152   //BTX
00154 
00156   virtual void SetLogStream(ostream* stream);
00157   virtual ostream* GetLogStream();
00158   //ETX
00160   
00162 
00166   virtual int LogToFile(const char* name);
00167   virtual int LogToFile(const char* name, int append);
00169 
00171 
00172   vtkSetMacro(ReportErrors, int);
00173   vtkGetMacro(ReportErrors, int);
00175 
00177 
00178   vtkGetObjectMacro(Socket, vtkClientSocket);
00179   void SetSocket(vtkClientSocket*);
00181 
00184   int Handshake();
00185 
00188   int ServerSideHandshake();
00189 
00192   int ClientSideHandshake();
00193 
00195 
00197   vtkGetMacro(IsServer, int);
00199 
00202   static int GetVersion();
00203 //BTX
00204 protected:
00205 
00206   vtkClientSocket* Socket;
00207   int SwapBytesInReceivedData;
00208   int RemoteHas64BitIds;
00209   int PerformHandshake;
00210   int IsServer;
00211   
00212   int ReportErrors;
00213 
00214   ofstream* LogFile;
00215   ostream* LogStream;
00216   
00217   vtkSocketCommunicator();
00218   ~vtkSocketCommunicator();
00219   
00220   // Wrappers around send/recv calls to implement loops.  Return 1 for
00221   // success, and 0 for failure.
00222   int SendTagged(const void* data, int wordSize, int numWords, int tag,
00223                  const char* logName);
00224   int ReceiveTagged(void* data, int wordSize, int numWords, int tag,
00225                     const char* logName);
00226   int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag,
00227                     const char* logName);
00228   
00229   // Internal utility methods.
00230   void LogTagged(const char* name, const void* data, int wordSize, int numWords,
00231                  int tag, const char* logName);
00232   int CheckForErrorInternal(int id);
00233 private:
00234   vtkSocketCommunicator(const vtkSocketCommunicator&);  // Not implemented.
00235   void operator=(const vtkSocketCommunicator&);  // Not implemented.
00236 
00237   int SelectSocket(int socket, unsigned long msec);
00238 
00239   // SwapBytesInReceiveData needs an invalid / not set.
00240   // This avoids checking length of endian handshake.
00241   enum ErrorIds {
00242     SwapOff = 0,
00243     SwapOn,
00244     SwapNotSet
00245   };
00246 
00247   // One may be tempted to change this to a vtkIdType, but really an int is
00248   // enough since we split messages > VTK_INT_MAX.
00249   int TagMessageLength;
00250 //ETX
00251 };
00252 
00253 #endif

Generated by  doxygen 1.7.1