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 "vtkParallelMPIModule.h" // For export macro
42 #include "vtkCommunicator.h"
43 
44 class vtkMPIController;
45 class vtkProcessGroup;
46 
47 class vtkMPICommunicatorOpaqueComm;
48 class vtkMPICommunicatorOpaqueRequest;
49 class vtkMPICommunicatorReceiveDataInfo;
50 
51 class VTKPARALLELMPI_EXPORT vtkMPICommunicator : public vtkCommunicator
52 {
53 public:
54 //BTX
55 
56  class VTKPARALLELMPI_EXPORT Request
57  {
58  public:
59  Request();
60  Request( const Request& );
61  ~Request();
62  Request& operator = ( const Request& );
63  int Test();
64  void Cancel();
65  void Wait();
66  vtkMPICommunicatorOpaqueRequest* Req;
67  };
68 
69 //ETX
70 
72  void PrintSelf(ostream& os, vtkIndent indent);
73 
75  static vtkMPICommunicator* New();
76 
79  static vtkMPICommunicator* GetWorldCommunicator();
80 
81 
85  int Initialize(vtkProcessGroup *group);
86 
90  int SplitInitialize(vtkCommunicator *oldcomm, int color, int key);
91 
93 
96  virtual int SendVoidArray(const void *data, vtkIdType length, int type,
97  int remoteProcessId, int tag);
98  virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
99  int remoteProcessId, int tag);
101 
103 
108  int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
109  Request& req);
110  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
111  int tag, Request& req);
112  int NoBlockSend(const char* data, int length, int remoteProcessId,
113  int tag, Request& req);
114  int NoBlockSend(const unsigned char* data, int length, int remoteProcessId,
115  int tag, Request& req);
116  int NoBlockSend(const float* data, int length, int remoteProcessId,
117  int tag, Request& req);
118  int NoBlockSend(const double* data, int length, int remoteProcessId,
119  int tag, Request& req);
120 #ifdef VTK_USE_64BIT_IDS
121  int NoBlockSend(const vtkIdType* data, int length, int remoteProcessId,
122  int tag, Request& req);
123 #endif
124 
125 
127 
131  int NoBlockReceive(int* data, int length, int remoteProcessId,
132  int tag, Request& req);
133  int NoBlockReceive(unsigned long* data, int length,
134  int remoteProcessId, int tag, Request& req);
135  int NoBlockReceive(char* data, int length, int remoteProcessId,
136  int tag, Request& req);
137  int NoBlockReceive(unsigned char* data, int length, int remoteProcessId,
138  int tag, Request& req);
139  int NoBlockReceive(float* data, int length, int remoteProcessId,
140  int tag, Request& req);
141  int NoBlockReceive(double* data, int length, int remoteProcessId,
142  int tag, Request& req);
143 #ifdef VTK_USE_64BIT_IDS
144  int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
145  int tag, Request& req);
146 #endif
147 
148 
149 
151 
154  virtual void Barrier();
155  virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
156  int srcProcessId);
157  virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
158  vtkIdType length, int type, int destProcessId);
159  virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
160  vtkIdType sendLength, vtkIdType *recvLengths,
161  vtkIdType *offsets, int type, int destProcessId);
162  virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
163  vtkIdType length, int type, int srcProcessId);
164  virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
165  vtkIdType *sendLengths, vtkIdType *offsets,
166  vtkIdType recvLength, int type,
167  int srcProcessId);
168  virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
169  vtkIdType length, int type);
170  virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
171  vtkIdType sendLength, vtkIdType *recvLengths,
172  vtkIdType *offsets, int type);
173  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
174  vtkIdType length, int type,
175  int operation, int destProcessId);
176  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
177  vtkIdType length, int type,
178  Operation *operation, int destProcessId);
179  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
180  vtkIdType length, int type,
181  int operation);
182  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
183  vtkIdType length, int type,
184  Operation *operation);
186 
188 
195  int Iprobe(int source, int tag, int* flag, int* actualSource);
196  int Iprobe(int source, int tag, int* flag, int* actualSource,
197  int* type, int* size);
198  int Iprobe(int source, int tag, int* flag, int* actualSource,
199  unsigned long* type, int* size);
200  int Iprobe(int source, int tag, int* flag, int* actualSource,
201  const char* type, int* size);
202  int Iprobe(int source, int tag, int* flag, int* actualSource,
203  float* type, int* size);
204  int Iprobe(int source, int tag, int* flag, int* actualSource,
205  double* type, int* size);
207 
210  int WaitAll(const int count, Request requests[]);
211 
215  int WaitAny(const int count, Request requests[], int& idx);
216 
218 
221  int WaitSome(
222  const int count, Request requests[], int &NCompleted, int *completed );
224 
228  int TestAll( const int count, Request requests[], int& flag );
229 
231  int TestAny(const int count, Request requests[], int &idx, int &flag );
232 
234 
238  int TestSome(const int count,Request requests[],
239  int& NCompleted,int *completed);
240 //BTX
242 
243  friend class vtkMPIController;
244 
245  vtkMPICommunicatorOpaqueComm *GetMPIComm()
246  {
247  return this->MPIComm;
248  }
249 
250  int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
251 
252 //ETX
253 
254  static char* Allocate(size_t size);
255  static void Free(char* ptr);
256 
257 
259 
261  vtkSetClampMacro(UseSsend, int, 0, 1);
262  vtkGetMacro(UseSsend, int);
263  vtkBooleanMacro(UseSsend, int);
265 
267 
271  void CopyFrom(vtkMPICommunicator* source);
272 protected:
276 
277  // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
278  // not be called if the current communicator does not include this process
279  int InitializeNumberOfProcesses();
280 
282 
289  vtkSetMacro(KeepHandle, int);
290  vtkBooleanMacro(KeepHandle, int);
292 
293 
295 
296  void InitializeCopy(vtkMPICommunicator* source);
297 
304  void Duplicate(vtkMPICommunicator* source);
305 
307 
308  virtual int ReceiveDataInternal(
309  char* data, int length, int sizeoftype,
310  int remoteProcessId, int tag,
311  vtkMPICommunicatorReceiveDataInfo* info,
312  int useCopy, int& senderId);
314 
315  vtkMPICommunicatorOpaqueComm* MPIComm;
316 
319 
321  int UseSsend;
322  static int CheckForMPIError(int err);
323 
324 private:
325  vtkMPICommunicator(const vtkMPICommunicator&); // Not implemented.
326  void operator=(const vtkMPICommunicator&); // Not implemented.
327 };
328 
329 #endif
vtkMPICommunicatorOpaqueRequest * Req
static vtkMPICommunicator * WorldCommunicator
Class for creating user defined MPI communicators.
int vtkIdType
Definition: vtkType.h:275
vtkMPICommunicatorOpaqueComm * MPIComm
a simple class to control print indentation
Definition: vtkIndent.h:38
A subgroup of processes from a communicator.
Process communication using MPI.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Used to send/receive messages in a multiprocess environment.
vtkMPICommunicatorOpaqueComm * GetMPIComm()