VTK
vtkMPICommunicator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMPICommunicator.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 =========================================================================*/
38 #ifndef __vtkMPICommunicator_h
39 #define __vtkMPICommunicator_h
40 
41 #include "vtkCommunicator.h"
42 
43 class vtkMPIController;
44 class vtkProcessGroup;
45 
46 class vtkMPICommunicatorOpaqueComm;
47 class vtkMPICommunicatorOpaqueRequest;
48 class vtkMPICommunicatorReceiveDataInfo;
49 
51 {
52 public:
53 //BTX
54 
56  {
57  public:
58  Request();
59  Request( const Request& );
60  ~Request();
61  Request& operator = ( const Request& );
62  int Test();
63  void Cancel();
64  void Wait();
65  vtkMPICommunicatorOpaqueRequest* Req;
66  };
67 
68 //ETX
69 
71  void PrintSelf(ostream& os, vtkIndent indent);
72 
74  static vtkMPICommunicator* New();
75 
78  static vtkMPICommunicator* GetWorldCommunicator();
79 
80 
84  int Initialize(vtkProcessGroup *group);
85 
89  int SplitInitialize(vtkCommunicator *oldcomm, int color, int key);
90 
92 
95  virtual int SendVoidArray(const void *data, vtkIdType length, int type,
96  int remoteProcessId, int tag);
97  virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
98  int remoteProcessId, int tag);
100 
102 
107  int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
108  Request& req);
109  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
110  int tag, Request& req);
111  int NoBlockSend(const char* data, int length, int remoteProcessId,
112  int tag, Request& req);
113  int NoBlockSend(const float* data, int length, int remoteProcessId,
114  int tag, Request& req);
115  int NoBlockSend(const double* data, int length, int remoteProcessId,
116  int tag, Request& req);
118 
120 
124  int NoBlockReceive(int* data, int length, int remoteProcessId,
125  int tag, Request& req);
126  int NoBlockReceive(unsigned long* data, int length,
127  int remoteProcessId, int tag, Request& req);
128  int NoBlockReceive(char* data, int length, int remoteProcessId,
129  int tag, Request& req);
130  int NoBlockReceive(float* data, int length, int remoteProcessId,
131  int tag, Request& req);
132  int NoBlockReceive(double* data, int length, int remoteProcessId,
133  int tag, Request& req);
134 #ifdef VTK_USE_64BIT_IDS
135  int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
136  int tag, Request& req);
137 #endif
138 
139 
140 
142 
145  virtual void Barrier();
146  virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
147  int srcProcessId);
148  virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
149  vtkIdType length, int type, int destProcessId);
150  virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
151  vtkIdType sendLength, vtkIdType *recvLengths,
152  vtkIdType *offsets, int type, int destProcessId);
153  virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
154  vtkIdType length, int type, int srcProcessId);
155  virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
156  vtkIdType *sendLengths, vtkIdType *offsets,
157  vtkIdType recvLength, int type,
158  int srcProcessId);
159  virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
160  vtkIdType length, int type);
161  virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
162  vtkIdType sendLength, vtkIdType *recvLengths,
163  vtkIdType *offsets, int type);
164  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
165  vtkIdType length, int type,
166  int operation, int destProcessId);
167  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
168  vtkIdType length, int type,
169  Operation *operation, int destProcessId);
170  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
171  vtkIdType length, int type,
172  int operation);
173  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
174  vtkIdType length, int type,
175  Operation *operation);
177 
179 
186  int Iprobe(int source, int tag, int* flag, int* actualSource);
187  int Iprobe(int source, int tag, int* flag, int* actualSource,
188  int* type, int* size);
189  int Iprobe(int source, int tag, int* flag, int* actualSource,
190  unsigned long* type, int* size);
191  int Iprobe(int source, int tag, int* flag, int* actualSource,
192  const char* type, int* size);
193  int Iprobe(int source, int tag, int* flag, int* actualSource,
194  float* type, int* size);
195  int Iprobe(int source, int tag, int* flag, int* actualSource,
196  double* type, int* size);
198 
199 //BTX
200 
201  friend class vtkMPIController;
202 
203  vtkMPICommunicatorOpaqueComm *GetMPIComm()
204  {
205  return this->MPIComm;
206  }
207 
208  int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
209 
210 //ETX
211 
212  static char* Allocate(size_t size);
213  static void Free(char* ptr);
214 
215 
217 
219  vtkSetClampMacro(UseSsend, int, 0, 1);
220  vtkGetMacro(UseSsend, int);
221  vtkBooleanMacro(UseSsend, int);
223 
225 
229  void CopyFrom(vtkMPICommunicator* source);
230 protected:
234 
235  // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
236  // not be called if the current communicator does not include this process
237  int InitializeNumberOfProcesses();
238 
240 
247  vtkSetMacro(KeepHandle, int);
248  vtkBooleanMacro(KeepHandle, int);
250 
251 
253 
254  void InitializeCopy(vtkMPICommunicator* source);
255 
262  void Duplicate(vtkMPICommunicator* source);
263 
265 
266  virtual int ReceiveDataInternal(
267  char* data, int length, int sizeoftype,
268  int remoteProcessId, int tag,
269  vtkMPICommunicatorReceiveDataInfo* info,
270  int useCopy, int& senderId);
272 
273  vtkMPICommunicatorOpaqueComm* MPIComm;
274 
277 
279  int UseSsend;
280  static int CheckForMPIError(int err);
281 
282 private:
283  vtkMPICommunicator(const vtkMPICommunicator&); // Not implemented.
284  void operator=(const vtkMPICommunicator&); // Not implemented.
285 };
286 
287 #endif