VTK
vtkSocketCommunicator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSocketCommunicator.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
39 #ifndef vtkSocketCommunicator_h
40 #define vtkSocketCommunicator_h
41 
42 #include "vtkParallelCoreModule.h" // For export macro
43 #include "vtkCommunicator.h"
44 
45 #include "vtkByteSwap.h" // Needed for vtkSwap macros
46 
47 #ifdef VTK_WORDS_BIGENDIAN
48 # define vtkSwap4 vtkByteSwap::Swap4LE
49 # define vtkSwap4Range vtkByteSwap::Swap4LERange
50 # define vtkSwap8 vtkByteSwap::Swap8LE
51 # define vtkSwap8Range vtkByteSwap::Swap8LERange
52 #else
53 # define vtkSwap4 vtkByteSwap::Swap4BE
54 # define vtkSwap4Range vtkByteSwap::Swap4BERange
55 # define vtkSwap8 vtkByteSwap::Swap8BE
56 # define vtkSwap8Range vtkByteSwap::Swap8BERange
57 #endif
58 
59 class vtkClientSocket;
60 class vtkServerSocket;
61 
63 {
64 public:
67  void PrintSelf(ostream& os, vtkIndent indent);
68 
70 
72  virtual int WaitForConnection(int port);
73  virtual int WaitForConnection(vtkServerSocket* socket,
74  unsigned long msec = 0);
76 
78  virtual void CloseConnection();
79 
81  virtual int ConnectTo(const char* hostName, int port);
82 
84 
85  vtkGetMacro(SwapBytesInReceivedData, int);
87 
90 
92  virtual void SetNumberOfProcesses(int num);
93 
94  //------------------ Communication --------------------
95 
97 
99  virtual int SendVoidArray(const void *data, vtkIdType length, int type,
100  int remoteHandle, int tag);
101  virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
102  int remoteHandle, int tag);
104 
107  virtual void Barrier();
108 
110 
113  virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
114  int srcProcessId);
115  virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
116  vtkIdType length, int type, int destProcessId);
117  virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
118  vtkIdType sendLength, vtkIdType *recvLengths,
119  vtkIdType *offsets, int type, int destProcessId);
120  virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
121  vtkIdType length, int type, int srcProcessId);
122  virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
123  vtkIdType *sendLengths, vtkIdType *offsets,
124  vtkIdType recvLength, int type,
125  int srcProcessId);
126  virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
127  vtkIdType length, int type);
128  virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
129  vtkIdType sendLength, vtkIdType *recvLengths,
130  vtkIdType *offsets, int type);
131  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
132  vtkIdType length, int type,
133  int operation, int destProcessId);
134  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
135  vtkIdType length, int type,
136  Operation *operation, int destProcessId);
137  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
138  vtkIdType length, int type,
139  int operation);
140  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
141  vtkIdType length, int type,
142  Operation *operation);
144 
146 
148  vtkSetClampMacro(PerformHandshake, int, 0, 1);
149  vtkBooleanMacro(PerformHandshake, int);
150  vtkGetMacro(PerformHandshake, int);
152 
153  //BTX
155 
157  virtual void SetLogStream(ostream* stream);
158  virtual ostream* GetLogStream();
159  //ETX
161 
163 
167  virtual int LogToFile(const char* name);
168  virtual int LogToFile(const char* name, int append);
170 
172 
173  vtkSetMacro(ReportErrors, int);
174  vtkGetMacro(ReportErrors, int);
176 
178 
182 
185  int Handshake();
186 
190 
194 
196 
198  vtkGetMacro(IsServer, int);
200 
203  static int GetVersion();
204 
206 
213  { this->BufferMessage = true; }
215 
218 
219 //BTX
220 protected:
221 
226  int IsServer;
227 
229 
230  ofstream* LogFile;
231  ostream* LogStream;
232 
235 
236  // Wrappers around send/recv calls to implement loops. Return 1 for
237  // success, and 0 for failure.
238  int SendTagged(const void* data, int wordSize, int numWords, int tag,
239  const char* logName);
240  int ReceiveTagged(void* data, int wordSize, int numWords, int tag,
241  const char* logName);
242  int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag,
243  const char* logName);
244 
246  void* data, int wordSize, int numWords, int tag, const char* logName);
247 
249  void FixByteOrder(void* data, int wordSize, int numWords);
250 
251  // Internal utility methods.
252  void LogTagged(const char* name, const void* data, int wordSize, int numWords,
253  int tag, const char* logName);
256 private:
257  vtkSocketCommunicator(const vtkSocketCommunicator&); // Not implemented.
258  void operator=(const vtkSocketCommunicator&); // Not implemented.
259 
260  int SelectSocket(int socket, unsigned long msec);
261 
262  // SwapBytesInReceiveData needs an invalid / not set.
263  // This avoids checking length of endian handshake.
264  enum ErrorIds {
265  SwapOff = 0,
266  SwapOn,
267  SwapNotSet
268  };
269 
270  // One may be tempted to change this to a vtkIdType, but really an int is
271  // enough since we split messages > VTK_INT_MAX.
272  int TagMessageLength;
273 
274  // Buffer to save messages received with different tag than requested.
275  class vtkMessageBuffer;
276  vtkMessageBuffer* ReceivedMessageBuffer;
277 
278 //ETX
279 };
280 
281 #endif
vtkSocketCommunicator::LogToFile
virtual int LogToFile(const char *name)
vtkSocketCommunicator::LogFile
ofstream * LogFile
Definition: vtkSocketCommunicator.h:230
vtkSocketCommunicator::ReduceVoidArray
virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation, int destProcessId)
vtkgl::data
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkSocketCommunicator::New
static vtkSocketCommunicator * New()
vtkSocketCommunicator::RemoteHas64BitIds
int RemoteHas64BitIds
Definition: vtkSocketCommunicator.h:224
vtkSocketCommunicator::ScatterVoidArray
virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int srcProcessId)
vtkCommunicator
Used to send/receive messages in a multiprocess environment.
Definition: vtkCommunicator.h:52
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkSocketCommunicator
Process communication using Sockets.
Definition: vtkSocketCommunicator.h:63
vtkSocketCommunicator::LogToFile
virtual int LogToFile(const char *name, int append)
vtkCommunicator::Operation
Definition: vtkCommunicator.h:103
vtkSocketCommunicator::AllReduceVoidArray
virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkgl::stream
GLuint GLuint stream
Definition: vtkgl.h:14154
vtkSocketCommunicator::BufferMessage
bool BufferMessage
Definition: vtkSocketCommunicator.h:255
vtkSocketCommunicator::CheckForErrorInternal
int CheckForErrorInternal(int id)
vtkSocketCommunicator::SendVoidArray
virtual int SendVoidArray(const void *data, vtkIdType length, int type, int remoteHandle, int tag)
vtkgl::length
GLuint GLsizei GLsizei * length
Definition: vtkgl.h:11992
vtkSocketCommunicator::GetLogStream
virtual ostream * GetLogStream()
vtkSocketCommunicator::Barrier
virtual void Barrier()
vtkSocketCommunicator::SetSocket
void SetSocket(vtkClientSocket *)
vtkSocketCommunicator::ReceiveTagged
int ReceiveTagged(void *data, int wordSize, int numWords, int tag, const char *logName)
vtkSocketCommunicator::ReduceVoidArray
virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation, int destProcessId)
vtkX3D::port
@ port
Definition: vtkX3D.h:447
vtkSetClampMacro
#define vtkSetClampMacro(name, type, min, max)
Definition: vtkSetGet.h:143
vtkgl::name
GLuint const GLchar * name
Definition: vtkgl.h:11983
vtkSocketCommunicator::vtkSocketCommunicator
vtkSocketCommunicator()
vtkSocketCommunicator::ConnectTo
virtual int ConnectTo(const char *hostName, int port)
vtkSocketCommunicator::ReceivePartialTagged
int ReceivePartialTagged(void *data, int wordSize, int numWords, int tag, const char *logName)
vtkSocketCommunicator::WaitForConnection
virtual int WaitForConnection(int port)
vtkSocketCommunicator::HasBufferredMessages
bool HasBufferredMessages()
vtkServerSocket
Encapsulate a socket that accepts connections.
Definition: vtkServerSocket.h:29
vtkByteSwap.h
vtkSocketCommunicator::GetVersion
static int GetVersion()
vtkSocketCommunicator::ReceiveVoidArray
virtual int ReceiveVoidArray(void *data, vtkIdType length, int type, int remoteHandle, int tag)
vtkSocketCommunicator::IsServer
int IsServer
Definition: vtkSocketCommunicator.h:226
vtkgl::num
GLuint GLuint num
Definition: vtkgl.h:16907
vtkSocketCommunicator::PerformHandshake
int PerformHandshake
Definition: vtkSocketCommunicator.h:225
vtkSocketCommunicator::ReceivedTaggedFromBuffer
int ReceivedTaggedFromBuffer(void *data, int wordSize, int numWords, int tag, const char *logName)
vtkSocketCommunicator::FixByteOrder
void FixByteOrder(void *data, int wordSize, int numWords)
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkParallelCoreModule.h
VTKPARALLELCORE_EXPORT
#define VTKPARALLELCORE_EXPORT
Definition: vtkParallelCoreModule.h:15
vtkSocketCommunicator::Handshake
int Handshake()
vtkSocketCommunicator::SendTagged
int SendTagged(const void *data, int wordSize, int numWords, int tag, const char *logName)
vtkSocketCommunicator::Socket
vtkClientSocket * Socket
Definition: vtkSocketCommunicator.h:222
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkSocketCommunicator::SwapBytesInReceivedData
int SwapBytesInReceivedData
Definition: vtkSocketCommunicator.h:223
vtkBooleanMacro
vtkBooleanMacro(IgnoreDriverBugs, bool)
vtkSocketCommunicator::SetLogStream
virtual void SetLogStream(ostream *stream)
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkSocketCommunicator::AllReduceVoidArray
virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation)
vtkClientSocket
Encapsulates a client socket.
Definition: vtkClientSocket.h:27
vtkSocketCommunicator::AllGatherVVoidArray
virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type)
vtkSocketCommunicator::GetIsConnected
int GetIsConnected()
vtkSocketCommunicator::GatherVoidArray
virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int destProcessId)
vtkSocketCommunicator::ScatterVVoidArray
virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType *sendLengths, vtkIdType *offsets, vtkIdType recvLength, int type, int srcProcessId)
vtkCommunicator.h
vtkSocketCommunicator::ClientSideHandshake
int ClientSideHandshake()
vtkSocketCommunicator::BufferCurrentMessage
void BufferCurrentMessage()
Definition: vtkSocketCommunicator.h:212
vtkSocketCommunicator::GatherVVoidArray
virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type, int destProcessId)
vtkSocketCommunicator::CloseConnection
virtual void CloseConnection()
vtkSocketCommunicator::SetNumberOfProcesses
virtual void SetNumberOfProcesses(int num)
vtkSocketCommunicator::ReportErrors
int ReportErrors
Definition: vtkSocketCommunicator.h:228
vtkSocketCommunicator::BroadcastVoidArray
virtual int BroadcastVoidArray(void *data, vtkIdType length, int type, int srcProcessId)
vtkSocketCommunicator::AllGatherVoidArray
virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type)
vtkSocketCommunicator::ServerSideHandshake
int ServerSideHandshake()
vtkgl::type
GLuint GLuint GLsizei GLenum type
Definition: vtkgl.h:11315
vtkSocketCommunicator::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkSocketCommunicator::LogTagged
void LogTagged(const char *name, const void *data, int wordSize, int numWords, int tag, const char *logName)
vtkSocketCommunicator::~vtkSocketCommunicator
~vtkSocketCommunicator()
vtkSocketCommunicator::WaitForConnection
virtual int WaitForConnection(vtkServerSocket *socket, unsigned long msec=0)
vtkSocketCommunicator::LogStream
ostream * LogStream
Definition: vtkSocketCommunicator.h:231