00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00039 #ifndef __vtkSocketCommunicator_h
00040 #define __vtkSocketCommunicator_h
00041
00042 #include "vtkCommunicator.h"
00043
00044 #include "vtkByteSwap.h"
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 vtkTypeMacro(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
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
00154
00156 virtual void SetLogStream(ostream* stream);
00157 virtual ostream* GetLogStream();
00158
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
00200
00201 protected:
00202
00203 vtkClientSocket* Socket;
00204 int SwapBytesInReceivedData;
00205 int RemoteHas64BitIds;
00206 int PerformHandshake;
00207 int IsServer;
00208
00209 int ReportErrors;
00210
00211 ofstream* LogFile;
00212 ostream* LogStream;
00213
00214 vtkSocketCommunicator();
00215 ~vtkSocketCommunicator();
00216
00217
00218
00219 int SendTagged(const void* data, int wordSize, int numWords, int tag,
00220 const char* logName);
00221 int ReceiveTagged(void* data, int wordSize, int numWords, int tag,
00222 const char* logName);
00223 int ReceivePartialTagged(void* data, int wordSize, int numWords, int tag,
00224 const char* logName);
00225
00226
00227 void LogTagged(const char* name, const void* data, int wordSize, int numWords,
00228 int tag, const char* logName);
00229 int CheckForErrorInternal(int id);
00230
00231 private:
00232 vtkSocketCommunicator(const vtkSocketCommunicator&);
00233 void operator=(const vtkSocketCommunicator&);
00234
00235 int SelectSocket(int socket, unsigned long msec);
00236
00237
00238
00239 enum ErrorIds {
00240 SwapOff = 0,
00241 SwapOn,
00242 SwapNotSet
00243 };
00244
00245
00246
00247 int TagMessageLength;
00248
00251 static int GetVersion();
00252
00253 };
00254
00255 #endif