VTK  9.7.20260908
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
26
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
34VTK_ABI_NAMESPACE_BEGIN
36class vtkProcessGroup;
37
38class vtkMPICommunicatorOpaqueComm;
39class vtkMPICommunicatorOpaqueRequest;
40class vtkMPICommunicatorReceiveDataInfo;
41
42class VTKPARALLELMPI_EXPORT vtkMPICommunicator : public vtkCommunicator
43{
44public:
45 class VTKPARALLELMPI_EXPORT Request
46 {
47 public:
52
58 int Test();
59
65 void Cancel();
66
72 void Wait();
73
74 vtkMPICommunicatorOpaqueRequest* Req;
75 };
76
78 void PrintSelf(ostream& os, vtkIndent indent) override;
79
84
90
96
103
109 int SplitInitialize(vtkCommunicator* oldcomm, int color, int key);
110
112
129 int SplitInitializeByType(vtkCommunicator* oldcomm, int splitType, int key);
131
133
139 const void* data, vtkIdType length, int type, int remoteProcessId, int tag) override;
141 void* data, vtkIdType length, int type, int remoteProcessId, int tag) override;
143
145
153 int NoBlockSend(const int* data, int length, int remoteProcessId, int tag, Request& req);
155 const unsigned long* data, int length, int remoteProcessId, int tag, Request& req);
156 int NoBlockSend(const char* data, int length, int remoteProcessId, int tag, Request& req);
158 const unsigned char* data, int length, int remoteProcessId, int tag, Request& req);
159 int NoBlockSend(const float* data, int length, int remoteProcessId, int tag, Request& req);
160 int NoBlockSend(const double* data, int length, int remoteProcessId, int tag, Request& req);
161 int NoBlockSend(const vtkTypeInt64* data, int length, int remoteProcessId, int tag, Request& req);
162
163 int NoBlockSend(const int* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
165 const unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
167 const char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
169 const unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
171 const float* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
173 const double* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
175 const vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
177
181 int NoBlockSend(const void* data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId,
182 int tag, Request& req);
183
185
192 int NoBlockReceive(int* data, int length, int remoteProcessId, int tag, Request& req);
193 int NoBlockReceive(unsigned long* data, int length, int remoteProcessId, int tag, Request& req);
194 int NoBlockReceive(char* data, int length, int remoteProcessId, int tag, Request& req);
195 int NoBlockReceive(unsigned char* data, int length, int remoteProcessId, int tag, Request& req);
196 int NoBlockReceive(float* data, int length, int remoteProcessId, int tag, Request& req);
197 int NoBlockReceive(double* data, int length, int remoteProcessId, int tag, Request& req);
198 int NoBlockReceive(vtkTypeInt64* data, int length, int remoteProcessId, int tag, Request& req);
199
200 int NoBlockReceive(int* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
202 unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
203 int NoBlockReceive(char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
205 unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
206 int NoBlockReceive(float* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
207 int NoBlockReceive(double* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
209 vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag, Request& req);
211
215 int AllToAllVVoidArray(const void* sendBuffer, const int* sendCounts, const int* sendOffsets,
216 void* recvBuffer, const int* recvCounts, const int* recvOffsets, int type) override;
217
219
224 void Barrier() override;
225 int BroadcastVoidArray(void* data, vtkIdType length, int type, int srcProcessId) override;
226 int GatherVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
227 int destProcessId) override;
228 int GatherVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType sendLength,
229 vtkIdType* recvLengths, vtkIdType* offsets, int type, int destProcessId) override;
230 int ScatterVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
231 int srcProcessId) override;
232 int ScatterVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType* sendLengths,
233 vtkIdType* offsets, vtkIdType recvLength, int type, int srcProcessId) override;
235 const void* sendBuffer, void* recvBuffer, vtkIdType length, int type) override;
236 int AllGatherVVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType sendLength,
237 vtkIdType* recvLengths, vtkIdType* offsets, int type) override;
238 int ReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
239 int operation, int destProcessId) override;
240 int ReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
241 Operation* operation, int destProcessId) override;
243 const void* sendBuffer, void* recvBuffer, vtkIdType length, int type, int operation) override;
244 int AllReduceVoidArray(const void* sendBuffer, void* recvBuffer, vtkIdType length, int type,
245 Operation* operation) override;
247
249
258 int Iprobe(int source, int tag, int* flag, int* actualSource);
259 int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, int* size);
260 int Iprobe(int source, int tag, int* flag, int* actualSource, unsigned long* type, int* size);
261 int Iprobe(int source, int tag, int* flag, int* actualSource, const char* type, int* size);
262 int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, int* size);
263 int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, int* size);
264
265 int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, vtkTypeInt64* size);
267 int source, int tag, int* flag, int* actualSource, unsigned long* type, vtkTypeInt64* size);
269 int source, int tag, int* flag, int* actualSource, const char* type, vtkTypeInt64* size);
270 int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, vtkTypeInt64* size);
271 int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, vtkTypeInt64* size);
273
277 bool CanProbe() override { return true; };
278
280
288 int Probe(int source, int tag, int* actualSource) override;
289 int Probe(int source, int tag, int* actualSource, int* type, int* size);
290 int Probe(int source, int tag, int* actualSource, unsigned long* type, int* size);
291 int Probe(int source, int tag, int* actualSource, const char* type, int* size);
292 int Probe(int source, int tag, int* actualSource, float* type, int* size);
293 int Probe(int source, int tag, int* actualSource, double* type, int* size);
294
295 int Probe(int source, int tag, int* actualSource, int* type, vtkTypeInt64* size);
296 int Probe(int source, int tag, int* actualSource, unsigned long* type, vtkTypeInt64* size);
297 int Probe(int source, int tag, int* actualSource, const char* type, vtkTypeInt64* size);
298 int Probe(int source, int tag, int* actualSource, float* type, vtkTypeInt64* size);
299 int Probe(int source, int tag, int* actualSource, double* type, vtkTypeInt64* size);
301
306 int WaitAll(int count, Request requests[]);
307
313 int WaitAny(int count, Request requests[], int& idx) VTK_SIZEHINT(requests, count);
314
320 int WaitSome(int count, Request requests[], int& NCompleted, int* completed)
321 VTK_SIZEHINT(requests, count);
322
328 int TestAll(int count, Request requests[], int& flag) VTK_SIZEHINT(requests, count);
329
333 int TestAny(int count, Request requests[], int& idx, int& flag) VTK_SIZEHINT(requests, count);
334
341 int TestSome(int count, Request requests[], int& NCompleted, int* completed)
342 VTK_SIZEHINT(requests, count);
343
344 friend class vtkMPIController;
345
346 vtkMPICommunicatorOpaqueComm* GetMPIComm() { return this->MPIComm; }
347
348 int InitializeExternal(vtkMPICommunicatorOpaqueComm* comm);
349
350 static char* Allocate(size_t size);
351 static void Free(char* ptr);
352
354
358 vtkSetClampMacro(UseSsend, int, 0, 1);
359 vtkGetMacro(UseSsend, int);
360 vtkBooleanMacro(UseSsend, int);
362
371
372protected:
375
376 // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
377 // not be called if the current communicator does not include this process
379
381
391 vtkSetMacro(KeepHandle, int);
392 vtkBooleanMacro(KeepHandle, int);
394
396
398
409
411
414 virtual int ReceiveDataInternal(char* data, int length, int sizeoftype, int remoteProcessId,
415 int tag, vtkMPICommunicatorReceiveDataInfo* info, int useCopy, int& senderId);
416 virtual int ReceiveDataInternal(char* data, vtkTypeInt64 length, int sizeoftype,
417 int remoteProcessId, int tag, vtkMPICommunicatorReceiveDataInfo* info, int useCopy,
418 int& senderId);
420
428 int GetTagMaxValue() const override { return this->TagMaxValue; }
429
430 static int CheckForMPIError(int err);
431
432 vtkMPICommunicatorOpaqueComm* MPIComm;
433
436
439
441
442private:
443 vtkMPICommunicator(const vtkMPICommunicator&) = delete;
444 void operator=(const vtkMPICommunicator&) = delete;
445};
446
447VTK_ABI_NAMESPACE_END
448#endif
A custom operation to use in a reduce command.
a simple class to control print indentation
Definition vtkIndent.h:108
int Test()
Forward to MPI_Test and return 1 if the request completed successfully This should not be called befo...
void Wait()
Forward to MPI_Wait This should not be called before the request is used properly (eg: NoBlockSend/No...
Request(const Request &)
void Cancel()
Forward to MPI_Cancel and then call MPI_Request_free This should not be called before the request is ...
vtkMPICommunicatorOpaqueRequest * Req
Request & operator=(const Request &)
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)
static vtkMPICommunicator * New()
Creates an empty communicator.
int GetTagMaxValue() const override
Overrides the base function to return the maximum value for a tag supported by MPI.
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.
friend class vtkMPIController
int AllToAllVVoidArray(const void *sendBuffer, const int *sendCounts, const int *sendOffsets, void *recvBuffer, const int *recvCounts, const int *recvOffsets, int type) override
Exchange variable-sized messages between all processes.
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.
static char * Allocate(size_t size)
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 SplitInitializeByType(vtkCommunicator *oldcomm, int splitType, int key)
Similar to SplitInitialize(), but partitions using MPI_Comm_split_type instead of MPI_Comm_split.
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).
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.
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.
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.
vtkMPICommunicatorOpaqueComm * GetMPIComm()
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.
void InitializeAttributes()
Used to initialize MPI attributes.
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.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:363
#define VTK_INT_MAX
Definition vtkType.h:192
#define VTK_SIZEHINT(...)