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=========================================================================*/
37#ifndef vtkSocketCommunicator_h
38#define vtkSocketCommunicator_h
39
40#include "vtkParallelCoreModule.h" // For export macro
41#include "vtkCommunicator.h"
42
43#include "vtkByteSwap.h" // Needed for vtkSwap macros
44
45#ifdef VTK_WORDS_BIGENDIAN
46# define vtkSwap4 vtkByteSwap::Swap4LE
47# define vtkSwap4Range vtkByteSwap::Swap4LERange
48# define vtkSwap8 vtkByteSwap::Swap8LE
49# define vtkSwap8Range vtkByteSwap::Swap8LERange
50#else
51# define vtkSwap4 vtkByteSwap::Swap4BE
52# define vtkSwap4Range vtkByteSwap::Swap4BERange
53# define vtkSwap8 vtkByteSwap::Swap8BE
54# define vtkSwap8Range vtkByteSwap::Swap8BERange
55#endif
56
57class vtkClientSocket;
58class vtkServerSocket;
59
60class VTKPARALLELCORE_EXPORT vtkSocketCommunicator : public vtkCommunicator
61{
62public:
65 void PrintSelf(ostream& os, vtkIndent indent);
66
68
72 virtual int WaitForConnection(int port);
74 unsigned long msec = 0);
76
80 virtual void CloseConnection();
81
85 virtual int ConnectTo(const char* hostName, int port);
86
88
91 vtkGetMacro(SwapBytesInReceivedData, int);
93
98
102 virtual void SetNumberOfProcesses(int num);
103
104 //------------------ Communication --------------------
105
107
111 virtual int SendVoidArray(const void *data, vtkIdType length, int type,
112 int remoteHandle, int tag);
113 virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
114 int remoteHandle, int tag);
116
121 virtual void Barrier();
122
124
129 virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
130 int srcProcessId);
131 virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
132 vtkIdType length, int type, int destProcessId);
133 virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
134 vtkIdType sendLength, vtkIdType *recvLengths,
135 vtkIdType *offsets, int type, int destProcessId);
136 virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
137 vtkIdType length, int type, int srcProcessId);
138 virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
139 vtkIdType *sendLengths, vtkIdType *offsets,
140 vtkIdType recvLength, int type,
141 int srcProcessId);
142 virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
143 vtkIdType length, int type);
144 virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
145 vtkIdType sendLength, vtkIdType *recvLengths,
146 vtkIdType *offsets, int type);
147 virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
148 vtkIdType length, int type,
149 int operation, int destProcessId);
150 virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
151 vtkIdType length, int type,
152 Operation *operation, int destProcessId);
153 virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
154 vtkIdType length, int type,
155 int operation);
156 virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
157 vtkIdType length, int type,
158 Operation *operation);
160
162
167 vtkSetClampMacro(PerformHandshake, int, 0, 1);
168 vtkBooleanMacro(PerformHandshake, int);
169 vtkGetMacro(PerformHandshake, int);
171
173
177 virtual void SetLogStream(ostream* stream);
178 virtual ostream* GetLogStream();
180
182
188 virtual int LogToFile(const char* name);
189 virtual int LogToFile(const char* name, int append);
191
193
196 vtkSetMacro(ReportErrors, int);
197 vtkGetMacro(ReportErrors, int);
199
201
204 vtkGetObjectMacro(Socket, vtkClientSocket);
207
213
220
227
229
233 vtkGetMacro(IsServer, int);
235
240 static int GetVersion();
241
251 { this->BufferMessage = true; }
252
257
258protected:
259
265
267
268 ofstream* LogFile;
269 ostream* LogStream;
270
273
274 // Wrappers around send/recv calls to implement loops. Return 1 for
275 // success, and 0 for failure.
276 int SendTagged(const void* data, int wordSize, int numWords, int tag,
277 const char* logName);
278 int ReceiveTagged(void* data, int wordSize, int numWords, int tag,
279 const char* logName);
280 int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag,
281 const char* logName);
282
284 void* data, int wordSize, int numWords, int tag, const char* logName);
285
289 void FixByteOrder(void* data, int wordSize, int numWords);
290
291 // Internal utility methods.
292 void LogTagged(const char* name, const void* data, int wordSize, int numWords,
293 int tag, const char* logName);
296private:
297 vtkSocketCommunicator(const vtkSocketCommunicator&) VTK_DELETE_FUNCTION;
298 void operator=(const vtkSocketCommunicator&) VTK_DELETE_FUNCTION;
299
300 int SelectSocket(int socket, unsigned long msec);
301
302 // SwapBytesInReceiveData needs an invalid / not set.
303 // This avoids checking length of endian handshake.
304 enum ErrorIds {
305 SwapOff = 0,
306 SwapOn,
307 SwapNotSet
308 };
309
310 // One may be tempted to change this to a vtkIdType, but really an int is
311 // enough since we split messages > VTK_INT_MAX.
312 int TagMessageLength;
313
314 // Buffer to save messages received with different tag than requested.
315 class vtkMessageBuffer;
316 vtkMessageBuffer* ReceivedMessageBuffer;
317
318};
319
320#endif
Encapsulates a client socket.
A custom operation to use in a reduce command.
Used to send/receive messages in a multiprocess environment.
a simple class to control print indentation
Definition: vtkIndent.h:40
Encapsulate a socket that accepts connections.
Process communication using Sockets.
virtual void SetNumberOfProcesses(int num)
Set the number of processes you will be using.
virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation, int destProcessId)
virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation, int destProcessId)
virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type)
int ClientSideHandshake()
Performs ClientSide handshake.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual int BroadcastVoidArray(void *data, vtkIdType length, int type, int srcProcessId)
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int Handshake()
Performs handshake.
virtual void Barrier()
This class foolishly breaks the conventions of the superclass, so this overload fixes the method.
virtual int LogToFile(const char *name, int append)
virtual int ConnectTo(const char *hostName, int port)
Open a connection to host.
int ServerSideHandshake()
Performs ServerSide handshake.
int GetIsConnected()
Is the communicator connected?.
int ReceivePartialTagged(void *data, int wordSize, int numWords, int tag, const char *logName)
virtual void CloseConnection()
Close a connection.
void FixByteOrder(void *data, int wordSize, int numWords)
Fix byte order for received data.
int SendTagged(const void *data, int wordSize, int numWords, int tag, const char *logName)
virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation)
void LogTagged(const char *name, const void *data, int wordSize, int numWords, int tag, const char *logName)
int ReceivedTaggedFromBuffer(void *data, int wordSize, int numWords, int tag, const char *logName)
virtual int WaitForConnection(vtkServerSocket *socket, unsigned long msec=0)
static int GetVersion()
Uniquely identifies the version of this class.
virtual int WaitForConnection(int port)
Wait for connection on a given port.
virtual int SendVoidArray(const void *data, vtkIdType length, int type, int remoteHandle, int tag)
Performs the actual communication.
virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type, int destProcessId)
virtual int ReceiveVoidArray(void *data, vtkIdType length, int type, int remoteHandle, int tag)
Subclasses have to supply this method to receive various arrays of data.
virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int destProcessId)
virtual ostream * GetLogStream()
virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType *sendLengths, vtkIdType *offsets, vtkIdType recvLength, int type, int srcProcessId)
int CheckForErrorInternal(int id)
virtual int LogToFile(const char *name)
Log messages to the given file.
static vtkSocketCommunicator * New()
virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation)
bool HasBufferredMessages()
Returns true if there are any messages in the receive buffer.
int ReceiveTagged(void *data, int wordSize, int numWords, int tag, const char *logName)
void SetSocket(vtkClientSocket *)
virtual void SetLogStream(ostream *stream)
Get/Set the output stream to which communications should be logged.
virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int srcProcessId)
virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type)
void BufferCurrentMessage()
This flag is cleared before vtkCommand::WrongTagEvent is fired when ever a message with mismatched ta...
@ length
Definition: vtkX3D.h:393
@ port
Definition: vtkX3D.h:447
@ type
Definition: vtkX3D.h:516
@ name
Definition: vtkX3D.h:219
@ data
Definition: vtkX3D.h:315
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287