VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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);
121 
123 
127  int NoBlockReceive(int* data, int length, int remoteProcessId,
128  int tag, Request& req);
129  int NoBlockReceive(unsigned long* data, int length,
130  int remoteProcessId, int tag, Request& req);
131  int NoBlockReceive(char* data, int length, int remoteProcessId,
132  int tag, Request& req);
133  int NoBlockReceive(unsigned char* data, int length, int remoteProcessId,
134  int tag, Request& req);
135  int NoBlockReceive(float* data, int length, int remoteProcessId,
136  int tag, Request& req);
137  int NoBlockReceive(double* data, int length, int remoteProcessId,
138  int tag, Request& req);
139 #ifdef VTK_USE_64BIT_IDS
140  int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
141  int tag, Request& req);
142 #endif
143 
144 
145 
147 
150  virtual void Barrier();
151  virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
152  int srcProcessId);
153  virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
154  vtkIdType length, int type, int destProcessId);
155  virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
156  vtkIdType sendLength, vtkIdType *recvLengths,
157  vtkIdType *offsets, int type, int destProcessId);
158  virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
159  vtkIdType length, int type, int srcProcessId);
160  virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
161  vtkIdType *sendLengths, vtkIdType *offsets,
162  vtkIdType recvLength, int type,
163  int srcProcessId);
164  virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
165  vtkIdType length, int type);
166  virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
167  vtkIdType sendLength, vtkIdType *recvLengths,
168  vtkIdType *offsets, int type);
169  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
170  vtkIdType length, int type,
171  int operation, int destProcessId);
172  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
173  vtkIdType length, int type,
174  Operation *operation, int destProcessId);
175  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
176  vtkIdType length, int type,
177  int operation);
178  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
179  vtkIdType length, int type,
180  Operation *operation);
182 
184 
191  int Iprobe(int source, int tag, int* flag, int* actualSource);
192  int Iprobe(int source, int tag, int* flag, int* actualSource,
193  int* type, int* size);
194  int Iprobe(int source, int tag, int* flag, int* actualSource,
195  unsigned long* type, int* size);
196  int Iprobe(int source, int tag, int* flag, int* actualSource,
197  const char* type, int* size);
198  int Iprobe(int source, int tag, int* flag, int* actualSource,
199  float* type, int* size);
200  int Iprobe(int source, int tag, int* flag, int* actualSource,
201  double* type, int* size);
203 
206  int WaitAll(const int count, Request requests[]);
207 
211  int WaitAny(const int count, Request requests[], int& idx);
212 
214 
217  int WaitSome(
218  const int count, Request requests[], int &NCompleted, int *completed );
220 
224  int TestAll( const int count, Request requests[], int& flag );
225 
227  int TestAny(const int count, Request requests[], int &idx, int &flag );
228 
230 
234  int TestSome(const int count,Request requests[],
235  int& NCompleted,int *completed);
236 //BTX
238 
239  friend class vtkMPIController;
240 
241  vtkMPICommunicatorOpaqueComm *GetMPIComm()
242  {
243  return this->MPIComm;
244  }
245 
246  int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
247 
248 //ETX
249 
250  static char* Allocate(size_t size);
251  static void Free(char* ptr);
252 
253 
255 
257  vtkSetClampMacro(UseSsend, int, 0, 1);
258  vtkGetMacro(UseSsend, int);
259  vtkBooleanMacro(UseSsend, int);
261 
263 
267  void CopyFrom(vtkMPICommunicator* source);
268 protected:
272 
273  // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
274  // not be called if the current communicator does not include this process
275  int InitializeNumberOfProcesses();
276 
278 
285  vtkSetMacro(KeepHandle, int);
286  vtkBooleanMacro(KeepHandle, int);
288 
289 
291 
292  void InitializeCopy(vtkMPICommunicator* source);
293 
300  void Duplicate(vtkMPICommunicator* source);
301 
303 
304  virtual int ReceiveDataInternal(
305  char* data, int length, int sizeoftype,
306  int remoteProcessId, int tag,
307  vtkMPICommunicatorReceiveDataInfo* info,
308  int useCopy, int& senderId);
310 
311  vtkMPICommunicatorOpaqueComm* MPIComm;
312 
315 
317  int UseSsend;
318  static int CheckForMPIError(int err);
319 
320 private:
321  vtkMPICommunicator(const vtkMPICommunicator&); // Not implemented.
322  void operator=(const vtkMPICommunicator&); // Not implemented.
323 };
324 
325 #endif
vtkMPICommunicatorOpaqueRequest * Req
static vtkMPICommunicator * WorldCommunicator
Class for creating user defined MPI communicators.
int vtkIdType
Definition: vtkType.h:268
vtkMPICommunicatorOpaqueComm * MPIComm
a simple class to control print indentation
Definition: vtkIndent.h:38
A subgroup of processes from a communicator.
Process communication using MPI.
Used to send/receive messages in a multiprocess environment.
vtkMPICommunicatorOpaqueComm * GetMPIComm()