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 =========================================================================*/
36 #ifndef vtkMPICommunicator_h
37 #define vtkMPICommunicator_h
38 
39 #include "vtkParallelMPIModule.h" // For export macro
40 #include "vtkCommunicator.h"
41 
42 class vtkMPIController;
43 class vtkProcessGroup;
44 
45 class vtkMPICommunicatorOpaqueComm;
46 class vtkMPICommunicatorOpaqueRequest;
47 class vtkMPICommunicatorReceiveDataInfo;
48 
49 class VTKPARALLELMPI_EXPORT vtkMPICommunicator : public vtkCommunicator
50 {
51 public:
52 
53  class VTKPARALLELMPI_EXPORT Request
54  {
55  public:
56  Request();
57  Request( const Request& );
58  ~Request();
59  Request& operator = ( const Request& );
60  int Test();
61  void Cancel();
62  void Wait();
63  vtkMPICommunicatorOpaqueRequest* Req;
64  };
65 
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
72  static vtkMPICommunicator* New();
73 
78  static vtkMPICommunicator* GetWorldCommunicator();
79 
80 
85  int Initialize(vtkProcessGroup *group);
86 
92  int SplitInitialize(vtkCommunicator *oldcomm, int color, int key);
93 
95 
100  virtual int SendVoidArray(const void *data, vtkIdType length, int type,
101  int remoteProcessId, int tag) override;
102  virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
103  int remoteProcessId, int tag) override;
105 
107 
115  int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
116  Request& req);
117  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
118  int tag, Request& req);
119  int NoBlockSend(const char* data, int length, int remoteProcessId,
120  int tag, Request& req);
121  int NoBlockSend(const unsigned char* data, int length, int remoteProcessId,
122  int tag, Request& req);
123  int NoBlockSend(const float* data, int length, int remoteProcessId,
124  int tag, Request& req);
125  int NoBlockSend(const double* data, int length, int remoteProcessId,
126  int tag, Request& req);
127 #ifdef VTK_USE_64BIT_IDS
128  int NoBlockSend(const vtkIdType* data, int length, int remoteProcessId,
129  int tag, Request& req);
130 #endif
131 
132 
134 
141  int NoBlockReceive(int* data, int length, int remoteProcessId,
142  int tag, Request& req);
143  int NoBlockReceive(unsigned long* data, int length,
144  int remoteProcessId, int tag, Request& req);
145  int NoBlockReceive(char* data, int length, int remoteProcessId,
146  int tag, Request& req);
147  int NoBlockReceive(unsigned char* data, int length, int remoteProcessId,
148  int tag, Request& req);
149  int NoBlockReceive(float* data, int length, int remoteProcessId,
150  int tag, Request& req);
151  int NoBlockReceive(double* data, int length, int remoteProcessId,
152  int tag, Request& req);
153 #ifdef VTK_USE_64BIT_IDS
154  int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
155  int tag, Request& req);
156 #endif
157 
158 
159 
161 
166  virtual void Barrier() override;
167  virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
168  int srcProcessId) override;
169  virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
170  vtkIdType length, int type, int destProcessId) override;
171  virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
172  vtkIdType sendLength, vtkIdType *recvLengths,
173  vtkIdType *offsets, int type, int destProcessId) override;
174  virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
175  vtkIdType length, int type, int srcProcessId) override;
176  virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
177  vtkIdType *sendLengths, vtkIdType *offsets,
178  vtkIdType recvLength, int type,
179  int srcProcessId) override;
180  virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
181  vtkIdType length, int type) override;
182  virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
183  vtkIdType sendLength, vtkIdType *recvLengths,
184  vtkIdType *offsets, int type) override;
185  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
186  vtkIdType length, int type,
187  int operation, int destProcessId) override;
188  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
189  vtkIdType length, int type,
190  Operation *operation, int destProcessId) override;
191  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
192  vtkIdType length, int type,
193  int operation) override;
194  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
195  vtkIdType length, int type,
196  Operation *operation) override;
198 
200 
209  int Iprobe(int source, int tag, int* flag, int* actualSource);
210  int Iprobe(int source, int tag, int* flag, int* actualSource,
211  int* type, int* size);
212  int Iprobe(int source, int tag, int* flag, int* actualSource,
213  unsigned long* type, int* size);
214  int Iprobe(int source, int tag, int* flag, int* actualSource,
215  const char* type, int* size);
216  int Iprobe(int source, int tag, int* flag, int* actualSource,
217  float* type, int* size);
218  int Iprobe(int source, int tag, int* flag, int* actualSource,
219  double* type, int* size);
221 
226  int WaitAll(const int count, Request requests[]);
227 
233  int WaitAny(const int count, Request requests[], int& idx);
234 
240  int WaitSome(
241  const int count, Request requests[], int &NCompleted, int *completed );
242 
248  int TestAll( const int count, Request requests[], int& flag );
249 
253  int TestAny(const int count, Request requests[], int &idx, int &flag );
254 
261  int TestSome(const int count,Request requests[],
262  int& NCompleted,int *completed);
263 
264  friend class vtkMPIController;
265 
266  vtkMPICommunicatorOpaqueComm *GetMPIComm()
267  {
268  return this->MPIComm;
269  }
270 
271  int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
272 
273  static char* Allocate(size_t size);
274  static void Free(char* ptr);
275 
276 
278 
282  vtkSetClampMacro(UseSsend, int, 0, 1);
283  vtkGetMacro(UseSsend, int);
284  vtkBooleanMacro(UseSsend, int);
286 
294  void CopyFrom(vtkMPICommunicator* source);
295 
296 protected:
299 
300  // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
301  // not be called if the current communicator does not include this process
302  int InitializeNumberOfProcesses();
303 
305 
315  vtkSetMacro(KeepHandle, int);
316  vtkBooleanMacro(KeepHandle, int);
318 
319 
321 
322  void InitializeCopy(vtkMPICommunicator* source);
323 
333  void Duplicate(vtkMPICommunicator* source);
334 
338  virtual int ReceiveDataInternal(
339  char* data, int length, int sizeoftype,
340  int remoteProcessId, int tag,
341  vtkMPICommunicatorReceiveDataInfo* info,
342  int useCopy, int& senderId);
343 
344  vtkMPICommunicatorOpaqueComm* MPIComm;
345 
348 
350  int UseSsend;
351  static int CheckForMPIError(int err);
352 
353 private:
354  vtkMPICommunicator(const vtkMPICommunicator&) = delete;
355  void operator=(const vtkMPICommunicator&) = delete;
356 };
357 
358 #endif
A custom operation to use in a reduce command.
vtkMPICommunicatorOpaqueRequest * Req
static vtkMPICommunicator * WorldCommunicator
Class for creating user defined MPI communicators.
Tests instantiations of the vtkNew class template.
int vtkIdType
Definition: vtkType.h:345
vtkMPICommunicatorOpaqueComm * MPIComm
a simple class to control print indentation
Definition: vtkIndent.h:33
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()