VTK  9.3.20240329
vtkMPICommunicator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
27 #ifndef vtkMPICommunicator_h
28 #define vtkMPICommunicator_h
29 
30 #include "vtkCommunicator.h"
31 #include "vtkMPI.h" // for MPI_Datatype
32 #include "vtkParallelMPIModule.h" // For export macro
33 
34 VTK_ABI_NAMESPACE_BEGIN
35 class vtkMPIController;
36 class vtkProcessGroup;
37 
38 class vtkMPICommunicatorOpaqueComm;
39 class vtkMPICommunicatorOpaqueRequest;
40 class vtkMPICommunicatorReceiveDataInfo;
41 
42 class VTKPARALLELMPI_EXPORT vtkMPICommunicator : public vtkCommunicator
43 {
44 public:
45  class VTKPARALLELMPI_EXPORT Request
46  {
47  public:
49  Request(const Request&);
52  int Test();
53  void Cancel();
54  void Wait();
55  vtkMPICommunicatorOpaqueRequest* Req;
56  };
57 
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
65 
71 
77 
83  int SplitInitialize(vtkCommunicator* oldcomm, int color, int key);
84 
86 
92  const void* data, vtkIdType length, int type, int remoteProcessId, int tag) override;
94  void* data, vtkIdType length, int type, int remoteProcessId, int tag) override;
96 
98 
106  int NoBlockSend(const int* data, int length, int remoteProcessId, int tag, Request& req);
108  const unsigned long* data, int length, int remoteProcessId, int tag, Request& req);
109  int NoBlockSend(const char* data, int length, int remoteProcessId, int tag, Request& req);
111  const unsigned char* data, int length, int remoteProcessId, int tag, Request& req);
112  int NoBlockSend(const float* data, int length, int remoteProcessId, int tag, Request& req);
113  int NoBlockSend(const double* data, int length, int remoteProcessId, int tag, Request& req);
114  int NoBlockSend(const vtkTypeInt64* data, int length, int remoteProcessId, int tag, Request& req);
115 
116  int NoBlockSend(const int* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
118  const unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
120  const char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
122  const unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
124  const float* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
126  const double* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
128  const vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
130 
134  int NoBlockSend(const void* data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId,
135  int tag, Request& req);
136 
138 
145  int NoBlockReceive(int* data, int length, int remoteProcessId, int tag, Request& req);
146  int NoBlockReceive(unsigned long* data, int length, int remoteProcessId, int tag, Request& req);
147  int NoBlockReceive(char* data, int length, int remoteProcessId, int tag, Request& req);
148  int NoBlockReceive(unsigned char* data, int length, int remoteProcessId, int tag, Request& req);
149  int NoBlockReceive(float* data, int length, int remoteProcessId, int tag, Request& req);
150  int NoBlockReceive(double* data, int length, int remoteProcessId, int tag, Request& req);
151  int NoBlockReceive(vtkTypeInt64* data, int length, int remoteProcessId, int tag, Request& req);
152 
153  int NoBlockReceive(int* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
155  unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
156  int NoBlockReceive(char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
158  unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
159  int NoBlockReceive(float* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
160  int NoBlockReceive(double* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
162  vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
164 
166 
171  void Barrier() override;
172  int BroadcastVoidArray(void* data, vtkIdType length, int type, int srcProcessId) override;
173  int GatherVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
174  int destProcessId) override;
175  int GatherVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType sendLength,
176  vtkIdType* recvLengths, vtkIdType* offsets, int type, int destProcessId) override;
177  int ScatterVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
178  int srcProcessId) override;
179  int ScatterVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType* sendLengths,
180  vtkIdType* offsets, vtkIdType recvLength, int type, int srcProcessId) override;
182  const void* sendBuffer, void* recvBuffer, vtkIdType length, int type) override;
183  int AllGatherVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType sendLength,
184  vtkIdType* recvLengths, vtkIdType* offsets, int type) override;
185  int ReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
186  int operation, int destProcessId) override;
187  int ReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
188  Operation* operation, int destProcessId) override;
190  const void* sendBuffer, void* recvBuffer, vtkIdType length, int type, int operation) override;
191  int AllReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
192  Operation* operation) override;
194 
196 
205  int Iprobe(int source, int tag, int* flag, int* actualSource);
206  int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, int* size);
207  int Iprobe(int source, int tag, int* flag, int* actualSource, unsigned long* type, int* size);
208  int Iprobe(int source, int tag, int* flag, int* actualSource, const char* type, int* size);
209  int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, int* size);
210  int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, int* size);
211 
212  int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, vtkTypeInt64* size);
213  int Iprobe(
214  int source, int tag, int* flag, int* actualSource, unsigned long* type, vtkTypeInt64* size);
215  int Iprobe(
216  int source, int tag, int* flag, int* actualSource, const char* type, vtkTypeInt64* size);
217  int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, vtkTypeInt64* size);
218  int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, vtkTypeInt64* size);
220 
224  bool CanProbe() override { return true; };
225 
227 
235  int Probe(int source, int tag, int* actualSource) override;
236  int Probe(int source, int tag, int* actualSource, int* type, int* size);
237  int Probe(int source, int tag, int* actualSource, unsigned long* type, int* size);
238  int Probe(int source, int tag, int* actualSource, const char* type, int* size);
239  int Probe(int source, int tag, int* actualSource, float* type, int* size);
240  int Probe(int source, int tag, int* actualSource, double* type, int* size);
241 
242  int Probe(int source, int tag, int* actualSource, int* type, vtkTypeInt64* size);
243  int Probe(int source, int tag, int* actualSource, unsigned long* type, vtkTypeInt64* size);
244  int Probe(int source, int tag, int* actualSource, const char* type, vtkTypeInt64* size);
245  int Probe(int source, int tag, int* actualSource, float* type, vtkTypeInt64* size);
246  int Probe(int source, int tag, int* actualSource, double* type, vtkTypeInt64* size);
248 
253  int WaitAll(int count, Request requests[]);
254 
260  int WaitAny(int count, Request requests[], int& idx) VTK_SIZEHINT(requests, count);
261 
267  int WaitSome(int count, Request requests[], int& NCompleted, int* completed)
268  VTK_SIZEHINT(requests, count);
269 
275  int TestAll(int count, Request requests[], int& flag) VTK_SIZEHINT(requests, count);
276 
280  int TestAny(int count, Request requests[], int& idx, int& flag) VTK_SIZEHINT(requests, count);
281 
288  int TestSome(int count, Request requests[], int& NCompleted, int* completed)
289  VTK_SIZEHINT(requests, count);
290 
291  friend class vtkMPIController;
292 
293  vtkMPICommunicatorOpaqueComm* GetMPIComm() { return this->MPIComm; }
294 
295  int InitializeExternal(vtkMPICommunicatorOpaqueComm* comm);
296 
297  static char* Allocate(size_t size);
298  static void Free(char* ptr);
299 
301 
305  vtkSetClampMacro(UseSsend, int, 0, 1);
306  vtkGetMacro(UseSsend, int);
307  vtkBooleanMacro(UseSsend, int);
309 
318 
319 protected:
322 
323  // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
324  // not be called if the current communicator does not include this process
326 
328 
338  vtkSetMacro(KeepHandle, int);
339  vtkBooleanMacro(KeepHandle, int);
341 
343 
345 
356 
358 
361  virtual int ReceiveDataInternal(char* data, int length, int sizeoftype, int remoteProcessId,
362  int tag, vtkMPICommunicatorReceiveDataInfo* info, int useCopy, int& senderId);
363  virtual int ReceiveDataInternal(char* data, vtkTypeInt64 length, int sizeoftype,
364  int remoteProcessId, int tag, vtkMPICommunicatorReceiveDataInfo* info, int useCopy,
365  int& senderId);
367 
368  vtkMPICommunicatorOpaqueComm* MPIComm;
369 
372 
374  int UseSsend;
375  static int CheckForMPIError(int err);
376 
377 private:
378  vtkMPICommunicator(const vtkMPICommunicator&) = delete;
379  void operator=(const vtkMPICommunicator&) = delete;
380 };
381 
382 VTK_ABI_NAMESPACE_END
383 #endif
A custom operation to use in a reduce command.
Used to send/receive messages in a multiprocess environment.
a simple class to control print indentation
Definition: vtkIndent.h:108
Request & operator=(const Request &)
Request(const Request &)
vtkMPICommunicatorOpaqueRequest * Req
Class for creating user defined MPI communicators.
bool CanProbe() override
Check if this communicator implements a probe operation (always true for MPI communicator)
int NoBlockReceive(vtkTypeInt64 *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(double *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(unsigned char *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
void InitializeCopy(vtkMPICommunicator *source)
static vtkMPICommunicator * WorldCommunicator
int Probe(int source, int tag, int *actualSource, const char *type, vtkTypeInt64 *size)
Blocking test for a message.
int Iprobe(int source, int tag, int *flag, int *actualSource, const char *type, vtkTypeInt64 *size)
Nonblocking test for a message.
int InitializeNumberOfProcesses()
int SplitInitialize(vtkCommunicator *oldcomm, int color, int key)
Used to initialize the communicator (i.e.
int Probe(int source, int tag, int *actualSource, double *type, vtkTypeInt64 *size)
Blocking test for a message.
int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm)
int Initialize(vtkProcessGroup *group)
Used to initialize the communicator (i.e.
virtual int ReceiveDataInternal(char *data, int length, int sizeoftype, int remoteProcessId, int tag, vtkMPICommunicatorReceiveDataInfo *info, int useCopy, int &senderId)
Implementation for receive data.
int NoBlockSend(const unsigned char *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
static vtkMPICommunicator * GetWorldCommunicator()
Returns the singleton which behaves as the global communicator (MPI_COMM_WORLD)
int Iprobe(int source, int tag, int *flag, int *actualSource, unsigned long *type, vtkTypeInt64 *size)
Nonblocking test for a message.
int NoBlockSend(const char *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int ScatterVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int srcProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int Iprobe(int source, int tag, int *flag, int *actualSource, double *type, vtkTypeInt64 *size)
Nonblocking test for a message.
int NoBlockReceive(int *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockSend(const double *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int NoBlockSend(const float *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(unsigned long *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
void Barrier() override
More efficient implementations of collective operations that use the equivalent MPI commands.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkMPICommunicatorOpaqueComm * MPIComm
int GatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type, int destProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int Iprobe(int source, int tag, int *flag, int *actualSource, float *type, vtkTypeInt64 *size)
Nonblocking test for a message.
int Probe(int source, int tag, int *actualSource, float *type, vtkTypeInt64 *size)
Blocking test for a message.
int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation, int destProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int Iprobe(int source, int tag, int *flag, int *actualSource, int *type, vtkTypeInt64 *size)
Nonblocking test for a message.
int Probe(int source, int tag, int *actualSource, double *type, int *size)
Blocking test for a message.
int NoBlockSend(const char *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int Probe(int source, int tag, int *actualSource, unsigned long *type, vtkTypeInt64 *size)
Blocking test for a message.
int NoBlockSend(const int *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int Iprobe(int source, int tag, int *flag, int *actualSource)
Nonblocking test for a message.
int SendVoidArray(const void *data, vtkIdType length, int type, int remoteProcessId, int tag) override
Performs the actual communication.
static void Free(char *ptr)
int WaitAny(int count, Request requests[], int &idx)
Blocks until one of the specified requests in the given request array completes.
int NoBlockSend(const void *data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId, int tag, Request &req)
Variant that permits dynamic type sends, like those create by MPI_Type_create_subarray.
int NoBlockReceive(double *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(unsigned long *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType *sendLengths, vtkIdType *offsets, vtkIdType recvLength, int type, int srcProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
virtual int ReceiveDataInternal(char *data, vtkTypeInt64 length, int sizeoftype, int remoteProcessId, int tag, vtkMPICommunicatorReceiveDataInfo *info, int useCopy, int &senderId)
Implementation for receive data.
int NoBlockSend(const vtkTypeInt64 *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(int *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockSend(const int *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int Iprobe(int source, int tag, int *flag, int *actualSource, int *type, int *size)
Nonblocking test for a message.
int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int Probe(int source, int tag, int *actualSource, int *type, int *size)
Blocking test for a message.
int NoBlockSend(const vtkTypeInt64 *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int NoBlockSend(const unsigned long *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
vtkMPICommunicatorOpaqueComm * GetMPIComm()
int TestAny(int count, Request requests[], int &idx, int &flag)
Check if at least one of the specified requests has completed.
void CopyFrom(vtkMPICommunicator *source)
Copies all the attributes of source, deleting previously stored data.
int Probe(int source, int tag, int *actualSource, const char *type, int *size)
Blocking test for a message.
int Iprobe(int source, int tag, int *flag, int *actualSource, unsigned long *type, int *size)
Nonblocking test for a message.
int NoBlockSend(const float *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int ReceiveVoidArray(void *data, vtkIdType length, int type, int remoteProcessId, int tag) override
Performs the actual communication.
int NoBlockSend(const unsigned long *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int NoBlockSend(const double *data, int length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int ReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, Operation *operation, int destProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
static char * Allocate(size_t size)
int BroadcastVoidArray(void *data, vtkIdType length, int type, int srcProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int NoBlockReceive(float *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockSend(const unsigned char *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method sends data to another process (non-blocking).
int TestSome(int count, Request requests[], int &NCompleted, int *completed)
Checks the status of all the given request communication object handles.
int Probe(int source, int tag, int *actualSource, unsigned long *type, int *size)
Blocking test for a message.
int NoBlockReceive(char *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType sendLength, vtkIdType *recvLengths, vtkIdType *offsets, int type) override
More efficient implementations of collective operations that use the equivalent MPI commands.
int Probe(int source, int tag, int *actualSource, float *type, int *size)
Blocking test for a message.
~vtkMPICommunicator() override
int WaitAll(int count, Request requests[])
Given the request objects of a set of non-blocking operations (send and/or receive) this method block...
int Iprobe(int source, int tag, int *flag, int *actualSource, float *type, int *size)
Nonblocking test for a message.
int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int operation) override
More efficient implementations of collective operations that use the equivalent MPI commands.
static int CheckForMPIError(int err)
int Probe(int source, int tag, int *actualSource) override
Blocking test for a message.
int WaitSome(int count, Request requests[], int &NCompleted, int *completed)
Blocks until one or more of the specified requests in the given request request array completes.
static vtkMPICommunicator * New()
Creates an empty communicator.
int NoBlockReceive(vtkTypeInt64 *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int GatherVoidArray(const void *sendBuffer, void *recvBuffer, vtkIdType length, int type, int destProcessId) override
More efficient implementations of collective operations that use the equivalent MPI commands.
void Duplicate(vtkMPICommunicator *source)
Copies all the attributes of source, deleting previously stored data EXCEPT the MPI communicator hand...
int NoBlockReceive(float *data, int length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int Iprobe(int source, int tag, int *flag, int *actualSource, const char *type, int *size)
Nonblocking test for a message.
int NoBlockReceive(char *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(unsigned char *data, vtkTypeInt64 length, int remoteProcessId, int tag, Request &req)
This method receives data from a corresponding send (non-blocking).
int Iprobe(int source, int tag, int *flag, int *actualSource, double *type, int *size)
Nonblocking test for a message.
int TestAll(int count, Request requests[], int &flag)
Checks if the given communication request objects are complete.
int Probe(int source, int tag, int *actualSource, int *type, vtkTypeInt64 *size)
Blocking test for a message.
Process communication using MPI.
A subgroup of processes from a communicator.
@ key
Definition: vtkX3D.h:257
@ info
Definition: vtkX3D.h:376
@ length
Definition: vtkX3D.h:393
@ type
Definition: vtkX3D.h:516
@ color
Definition: vtkX3D.h:221
@ size
Definition: vtkX3D.h:253
@ data
Definition: vtkX3D.h:315
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:315
#define VTK_SIZEHINT(...)