VTK  9.2.6
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=========================================================================*/
36
37#ifndef vtkSocketCommunicator_h
38#define vtkSocketCommunicator_h
39
40#include "vtkCommunicator.h"
41#include "vtkEndian.h" // for VTK_WORDS_BIGENDIAN
42#include "vtkParallelCoreModule.h" // For export macro
43
44#include "vtkByteSwap.h" // Needed for vtkSwap macros
45
46#ifdef VTK_WORDS_BIGENDIAN
47#define vtkSwap4 vtkByteSwap::Swap4LE
48#define vtkSwap4Range vtkByteSwap::Swap4LERange
49#define vtkSwap8 vtkByteSwap::Swap8LE
50#define vtkSwap8Range vtkByteSwap::Swap8LERange
51#else
52#define vtkSwap4 vtkByteSwap::Swap4BE
53#define vtkSwap4Range vtkByteSwap::Swap4BERange
54#define vtkSwap8 vtkByteSwap::Swap8BE
55#define vtkSwap8Range vtkByteSwap::Swap8BERange
56#endif
57
58class vtkClientSocket;
59class vtkServerSocket;
60
61class VTKPARALLELCORE_EXPORT vtkSocketCommunicator : public vtkCommunicator
62{
63public:
66 void PrintSelf(ostream& os, vtkIndent indent) override;
67
69
73 virtual int WaitForConnection(int port);
74 virtual int WaitForConnection(vtkServerSocket* socket, 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 void SetNumberOfProcesses(int num) override;
103
104 //------------------ Communication --------------------
105
107
112 const void* data, vtkIdType length, int type, int remoteHandle, int tag) override;
113 int ReceiveVoidArray(void* data, vtkIdType length, int type, int remoteHandle, int tag) override;
115
120 void Barrier() override;
121
123
128 int BroadcastVoidArray(void* data, vtkIdType length, int type, int srcProcessId) override;
129 int GatherVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
130 int destProcessId) override;
131 int GatherVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType sendLength,
132 vtkIdType* recvLengths, vtkIdType* offsets, int type, int destProcessId) override;
133 int ScatterVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
134 int srcProcessId) override;
135 int ScatterVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType* sendLengths,
136 vtkIdType* offsets, vtkIdType recvLength, int type, int srcProcessId) override;
138 const void* sendBuffer, void* recvBuffer, vtkIdType length, int type) override;
139 int AllGatherVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType sendLength,
140 vtkIdType* recvLengths, vtkIdType* offsets, int type) override;
141 int ReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
142 int operation, int destProcessId) override;
143 int ReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
144 Operation* operation, int destProcessId) override;
146 const void* sendBuffer, void* recvBuffer, vtkIdType length, int type, int operation) override;
147 int AllReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
148 Operation* operation) override;
150
152
157 vtkSetClampMacro(PerformHandshake, vtkTypeBool, 0, 1);
158 vtkBooleanMacro(PerformHandshake, vtkTypeBool);
161
163
167 virtual void SetLogStream(ostream* stream);
168 virtual ostream* GetLogStream();
170
172
178 virtual int LogToFile(const char* name);
179 virtual int LogToFile(const char* name, int append);
181
183
186 vtkSetMacro(ReportErrors, int);
187 vtkGetMacro(ReportErrors, int);
189
191
194 vtkGetObjectMacro(Socket, vtkClientSocket);
197
203
210
217
219
223 vtkGetMacro(IsServer, int);
225
230 static int GetVersion();
231
240 void BufferCurrentMessage() { this->BufferMessage = true; }
241
246
247protected:
253
255
256 ostream* LogFile;
257 ostream* LogStream;
258
261
262 // Wrappers around send/recv calls to implement loops. Return 1 for
263 // success, and 0 for failure.
264 int SendTagged(const void* data, int wordSize, int numWords, int tag, const char* logName);
265 int ReceiveTagged(void* data, int wordSize, int numWords, int tag, const char* logName);
266 int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag, const char* logName);
267
269 void* data, int wordSize, int numWords, int tag, const char* logName);
270
274 void FixByteOrder(void* data, int wordSize, int numWords);
275
276 // Internal utility methods.
278 const char* name, const void* data, int wordSize, int numWords, int tag, const char* logName);
281
282private:
284 void operator=(const vtkSocketCommunicator&) = delete;
285
286 int SelectSocket(int socket, unsigned long msec);
287
288 // SwapBytesInReceiveData needs an invalid / not set.
289 // This avoids checking length of endian handshake.
290 enum ErrorIds
291 {
292 SwapOff = 0,
293 SwapOn,
294 SwapNotSet
295 };
296
297 // One may be tempted to change this to a vtkIdType, but really an int is
298 // enough since we split messages > VTK_INT_MAX.
299 int TagMessageLength;
300
301 // Buffer to save messages received with different tag than requested.
302 class vtkMessageBuffer;
303 vtkMessageBuffer* ReceivedMessageBuffer;
304};
305
306#endif
Encapsulates a client socket.
A custom operation to use in a reduce command.
a simple class to control print indentation
Definition vtkIndent.h:34
Encapsulate a socket that accepts connections.
int ReceiveVoidArray(void *data, vtkIdType length, int type, int remoteHandle, int tag) override
Performs the actual communication.
int ClientSideHandshake()
Performs ClientSide handshake.
int BroadcastVoidArray(void *data, vtkIdType length, int type, int srcProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int Handshake()
Performs handshake.
int GatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int destProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
virtual int LogToFile(const char *name, int append)
Log messages to the given file.
virtual int ConnectTo(const char *hostName, int port)
Open a connection to host.
int ServerSideHandshake()
Performs ServerSide handshake.
void Barrier() override
This class foolishly breaks the conventions of the superclass, so this overload fixes the method.
int GetIsConnected()
Is the communicator connected?
int SendVoidArray(const void *data, vtkIdType length, int type, int remoteHandle, int tag) override
Performs the actual communication.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int GatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type, int destProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
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)
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)
Wait for connection on a given port.
int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation, int destProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
static int GetVersion()
Uniquely identifies the version of this class.
virtual int WaitForConnection(int port)
Wait for connection on a given port.
void SetNumberOfProcesses(int num) override
Set the number of processes you will be using.
virtual ostream * GetLogStream()
Get/Set the output stream to which communications should be logged.
int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType *sendLengths, vtkIdType *offsets, vtkIdType recvLength, int type, int srcProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int ScatterVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int srcProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int CheckForErrorInternal(int id)
int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation, int destProcessId) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
virtual int LogToFile(const char *name)
Log messages to the given file.
~vtkSocketCommunicator() override
static vtkSocketCommunicator * New()
bool HasBufferredMessages()
Returns true if there are any messages in the receive buffer.
int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int ReceiveTagged(void *data, int wordSize, int numWords, int tag, const char *logName)
void SetSocket(vtkClientSocket *)
Get/Set the actual socket used for communication.
virtual void SetLogStream(ostream *stream)
Get/Set the output stream to which communications should be logged.
int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation) override
This class foolishly breaks the conventions of the superclass, so the default implementations of thes...
void BufferCurrentMessage()
This flag is cleared before vtkCommand::WrongTagEvent is fired when ever a message with mismatched ta...
int vtkTypeBool
Definition vtkABI.h:69
int vtkIdType
Definition vtkType.h:332