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 =========================================================================*/
39 #ifndef vtkMPICommunicator_h
40 #define vtkMPICommunicator_h
41 
42 #include "vtkParallelMPIModule.h" // For export macro
43 #include "vtkCommunicator.h"
44 
45 class vtkMPIController;
46 class vtkProcessGroup;
47 
48 class vtkMPICommunicatorOpaqueComm;
49 class vtkMPICommunicatorOpaqueRequest;
50 class vtkMPICommunicatorReceiveDataInfo;
51 
52 class VTKPARALLELMPI_EXPORT vtkMPICommunicator : public vtkCommunicator
53 {
54 public:
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 
70  void PrintSelf(ostream& os, vtkIndent indent) override;
71 
75  static vtkMPICommunicator* New();
76 
81  static vtkMPICommunicator* GetWorldCommunicator();
82 
83 
88  int Initialize(vtkProcessGroup *group);
89 
95  int SplitInitialize(vtkCommunicator *oldcomm, int color, int key);
96 
98 
103  virtual int SendVoidArray(const void *data, vtkIdType length, int type,
104  int remoteProcessId, int tag) override;
105  virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
106  int remoteProcessId, int tag) override;
108 
110 
118  int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
119  Request& req);
120  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
121  int tag, Request& req);
122  int NoBlockSend(const char* data, int length, int remoteProcessId,
123  int tag, Request& req);
124  int NoBlockSend(const unsigned char* data, int length, int remoteProcessId,
125  int tag, Request& req);
126  int NoBlockSend(const float* data, int length, int remoteProcessId,
127  int tag, Request& req);
128  int NoBlockSend(const double* data, int length, int remoteProcessId,
129  int tag, Request& req);
130 #ifdef VTK_USE_64BIT_IDS
131  int NoBlockSend(const vtkIdType* data, int length, int remoteProcessId,
132  int tag, Request& req);
133 #endif
134 
135 
137 
144  int NoBlockReceive(int* data, int length, int remoteProcessId,
145  int tag, Request& req);
146  int NoBlockReceive(unsigned long* data, int length,
147  int remoteProcessId, int tag, Request& req);
148  int NoBlockReceive(char* data, int length, int remoteProcessId,
149  int tag, Request& req);
150  int NoBlockReceive(unsigned char* data, int length, int remoteProcessId,
151  int tag, Request& req);
152  int NoBlockReceive(float* data, int length, int remoteProcessId,
153  int tag, Request& req);
154  int NoBlockReceive(double* data, int length, int remoteProcessId,
155  int tag, Request& req);
156 #ifdef VTK_USE_64BIT_IDS
157  int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
158  int tag, Request& req);
159 #endif
160 
161 
162 
164 
169  virtual void Barrier() override;
170  virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
171  int srcProcessId) override;
172  virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
173  vtkIdType length, int type, int destProcessId) override;
174  virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
175  vtkIdType sendLength, vtkIdType *recvLengths,
176  vtkIdType *offsets, int type, int destProcessId) override;
177  virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
178  vtkIdType length, int type, int srcProcessId) override;
179  virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
180  vtkIdType *sendLengths, vtkIdType *offsets,
181  vtkIdType recvLength, int type,
182  int srcProcessId) override;
183  virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
184  vtkIdType length, int type) override;
185  virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
186  vtkIdType sendLength, vtkIdType *recvLengths,
187  vtkIdType *offsets, int type) override;
188  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
189  vtkIdType length, int type,
190  int operation, int destProcessId) override;
191  virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
192  vtkIdType length, int type,
193  Operation *operation, int destProcessId) override;
194  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
195  vtkIdType length, int type,
196  int operation) override;
197  virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
198  vtkIdType length, int type,
199  Operation *operation) override;
201 
203 
212  int Iprobe(int source, int tag, int* flag, int* actualSource);
213  int Iprobe(int source, int tag, int* flag, int* actualSource,
214  int* type, int* size);
215  int Iprobe(int source, int tag, int* flag, int* actualSource,
216  unsigned long* type, int* size);
217  int Iprobe(int source, int tag, int* flag, int* actualSource,
218  const char* type, int* size);
219  int Iprobe(int source, int tag, int* flag, int* actualSource,
220  float* type, int* size);
221  int Iprobe(int source, int tag, int* flag, int* actualSource,
222  double* type, int* size);
224 
229  int WaitAll(const int count, Request requests[]);
230 
236  int WaitAny(const int count, Request requests[], int& idx) VTK_SIZEHINT(requests, count);
237 
243  int WaitSome(
244  const int count, Request requests[], int &NCompleted, int *completed ) VTK_SIZEHINT(requests, count);
245 
251  int TestAll( const int count, Request requests[], int& flag ) VTK_SIZEHINT(requests, count);
252 
256  int TestAny(const int count, Request requests[], int &idx, int &flag ) VTK_SIZEHINT(requests, count);
257 
264  int TestSome(const int count,Request requests[],
265  int& NCompleted,int *completed) VTK_SIZEHINT(requests, count);
266 
267  friend class vtkMPIController;
268 
269  vtkMPICommunicatorOpaqueComm *GetMPIComm()
270  {
271  return this->MPIComm;
272  }
273 
274  int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
275 
276  static char* Allocate(size_t size);
277  static void Free(char* ptr);
278 
279 
281 
285  vtkSetClampMacro(UseSsend, int, 0, 1);
286  vtkGetMacro(UseSsend, int);
287  vtkBooleanMacro(UseSsend, int);
289 
297  void CopyFrom(vtkMPICommunicator* source);
298 
299 protected:
302 
303  // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
304  // not be called if the current communicator does not include this process
305  int InitializeNumberOfProcesses();
306 
308 
318  vtkSetMacro(KeepHandle, int);
319  vtkBooleanMacro(KeepHandle, int);
321 
322 
324 
325  void InitializeCopy(vtkMPICommunicator* source);
326 
336  void Duplicate(vtkMPICommunicator* source);
337 
341  virtual int ReceiveDataInternal(
342  char* data, int length, int sizeoftype,
343  int remoteProcessId, int tag,
344  vtkMPICommunicatorReceiveDataInfo* info,
345  int useCopy, int& senderId);
346 
347  vtkMPICommunicatorOpaqueComm* MPIComm;
348 
351 
353  int UseSsend;
354  static int CheckForMPIError(int err);
355 
356 private:
357  vtkMPICommunicator(const vtkMPICommunicator&) = delete;
358  void operator=(const vtkMPICommunicator&) = delete;
359 };
360 
361 #endif
vtkMPICommunicator::Request
Definition: vtkMPICommunicator.h:56
vtkMPICommunicator::Initialized
int Initialized
Definition: vtkMPICommunicator.h:349
vtkX3D::type
Definition: vtkX3D.h:516
vtkCommunicator
Used to send/receive messages in a multiprocess environment.
Definition: vtkCommunicator.h:53
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkMPICommunicator::UseSsend
int UseSsend
Definition: vtkMPICommunicator.h:353
vtkX3D::data
Definition: vtkX3D.h:315
vtkCommunicator::Operation
A custom operation to use in a reduce command.
Definition: vtkCommunicator.h:107
vtkX3D::key
Definition: vtkX3D.h:257
vtkX3D::length
Definition: vtkX3D.h:393
vtkMPICommunicator::LastSenderId
int LastSenderId
Definition: vtkMPICommunicator.h:352
vtkMPICommunicator
Class for creating user defined MPI communicators.
Definition: vtkMPICommunicator.h:52
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:825
vtkX3D::color
Definition: vtkX3D.h:221
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
impl::Test
int Test(int argc, char *argv[], const char *dfile, const InitializationCallback &initCallback)
Definition: TestMotionFXCFGReaderCommon.h:108
vtkMPICommunicator::WorldCommunicator
static vtkMPICommunicator * WorldCommunicator
Definition: vtkMPICommunicator.h:319
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkX3D::size
Definition: vtkX3D.h:253
vtkX3D::info
Definition: vtkX3D.h:376
vtkProcessGroup
A subgroup of processes from a communicator.
Definition: vtkProcessGroup.h:57
vtkCommunicator.h
vtkMPICommunicator::KeepHandle
int KeepHandle
Definition: vtkMPICommunicator.h:350
vtkMPICommunicator::MPIComm
vtkMPICommunicatorOpaqueComm * MPIComm
Definition: vtkMPICommunicator.h:347
vtkMPICommunicator::GetMPIComm
vtkMPICommunicatorOpaqueComm * GetMPIComm()
Definition: vtkMPICommunicator.h:269
vtkMPIController
Process communication using MPI.
Definition: vtkMPIController.h:61
vtkMPICommunicator::Request::Req
vtkMPICommunicatorOpaqueRequest * Req
Definition: vtkMPICommunicator.h:66