VTK  9.7.1
vtkMPIController.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
37 #ifndef vtkMPIController_h
38 #define vtkMPIController_h
39 
41 #include "vtkParallelMPIModule.h" // For export macro
42 #include "vtkTypeList.h" // For vtkTypeList
43 // Do not remove this header file. This class contains methods
44 // which take arguments defined in vtkMPICommunicator.h by
45 // reference.
46 #include "vtkMPICommunicator.h" // Needed for direct access to communicator
47 
48 VTK_ABI_NAMESPACE_BEGIN
49 class vtkIntArray;
50 
51 class VTKPARALLELMPI_EXPORT vtkMPIController : public vtkMultiProcessController
52 {
53 
54 public:
55  static vtkMPIController* New();
57  void PrintSelf(ostream& os, vtkIndent indent) override;
58 
62  using ValueTypes =
64 
76  void Initialize(int* argc, char*** argv) override { this->Initialize(argc, argv, 0); }
77 
78  void Initialize(
79  int* vtkNotUsed(argc), char*** vtkNotUsed(argv), int initializedExternally) override;
80 
84  virtual void Initialize();
85 
91  void Finalize() override { this->Finalize(0); }
92 
93  void Finalize(int finalizedExternally) override;
94 
99  void SingleMethodExecute() override;
100 
106  void MultipleMethodExecute() override;
107 
113  void CreateOutputWindow() override;
114 
119  static char* ErrorString(int err);
120 
130  void SetCommunicator(vtkMPICommunicator* comm);
131 
133 
134  vtkMPIController* PartitionController(int localColor, int localKey) override;
135 
137 
147  const int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
148  {
149  return ((vtkMPICommunicator*)this->Communicator)
150  ->NoBlockSend(data, length, remoteProcessId, tag, req);
151  }
152  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId, int tag,
154  {
155  return ((vtkMPICommunicator*)this->Communicator)
156  ->NoBlockSend(data, length, remoteProcessId, tag, req);
157  }
159  const char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
160  {
161  return ((vtkMPICommunicator*)this->Communicator)
162  ->NoBlockSend(data, length, remoteProcessId, tag, req);
163  }
164  int NoBlockSend(const unsigned char* data, int length, int remoteProcessId, int tag,
166  {
167  return ((vtkMPICommunicator*)this->Communicator)
168  ->NoBlockSend(data, length, remoteProcessId, tag, req);
169  }
171  const float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
172  {
173  return ((vtkMPICommunicator*)this->Communicator)
174  ->NoBlockSend(data, length, remoteProcessId, tag, req);
175  }
177  const double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
178  {
179  return ((vtkMPICommunicator*)this->Communicator)
180  ->NoBlockSend(data, length, remoteProcessId, tag, req);
181  }
182  int NoBlockSend(const vtkTypeInt64* data, int length, int remoteProcessId, int tag,
184  {
185  return ((vtkMPICommunicator*)this->Communicator)
186  ->NoBlockSend(data, length, remoteProcessId, tag, req);
187  }
188  int NoBlockSend(const int* data, vtkTypeInt64 length, int remoteProcessId, int tag,
190  {
191  return ((vtkMPICommunicator*)this->Communicator)
192  ->NoBlockSend(data, length, remoteProcessId, tag, req);
193  }
194  int NoBlockSend(const unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag,
196  {
197  return ((vtkMPICommunicator*)this->Communicator)
198  ->NoBlockSend(data, length, remoteProcessId, tag, req);
199  }
200  int NoBlockSend(const char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
202  {
203  return ((vtkMPICommunicator*)this->Communicator)
204  ->NoBlockSend(data, length, remoteProcessId, tag, req);
205  }
206  int NoBlockSend(const unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
208  {
209  return ((vtkMPICommunicator*)this->Communicator)
210  ->NoBlockSend(data, length, remoteProcessId, tag, req);
211  }
212  int NoBlockSend(const float* data, vtkTypeInt64 length, int remoteProcessId, int tag,
214  {
215  return ((vtkMPICommunicator*)this->Communicator)
216  ->NoBlockSend(data, length, remoteProcessId, tag, req);
217  }
218  int NoBlockSend(const double* data, vtkTypeInt64 length, int remoteProcessId, int tag,
220  {
221  return ((vtkMPICommunicator*)this->Communicator)
222  ->NoBlockSend(data, length, remoteProcessId, tag, req);
223  }
224  int NoBlockSend(const vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag,
226  {
227  return ((vtkMPICommunicator*)this->Communicator)
228  ->NoBlockSend(data, length, remoteProcessId, tag, req);
229  }
231 
235  int NoBlockSend(const void* data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId,
236  int tag, vtkMPICommunicator::Request& req)
237  {
238  return ((vtkMPICommunicator*)this->Communicator)
239  ->NoBlockSend(data, length, mpiType, remoteProcessId, tag, req);
240  }
241 
243 
252  int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
253  {
254  return ((vtkMPICommunicator*)this->Communicator)
255  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
256  }
258  unsigned long* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
259  {
260  return ((vtkMPICommunicator*)this->Communicator)
261  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
262  }
264  char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
265  {
266  return ((vtkMPICommunicator*)this->Communicator)
267  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
268  }
270  unsigned char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
271  {
272  return ((vtkMPICommunicator*)this->Communicator)
273  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
274  }
276  float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
277  {
278  return ((vtkMPICommunicator*)this->Communicator)
279  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
280  }
282  double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
283  {
284  return ((vtkMPICommunicator*)this->Communicator)
285  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
286  }
288  vtkTypeInt64* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
289  {
290  return ((vtkMPICommunicator*)this->Communicator)
291  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
292  }
294  int* data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
295  {
296  return ((vtkMPICommunicator*)this->Communicator)
297  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
298  }
299  int NoBlockReceive(unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag,
301  {
302  return ((vtkMPICommunicator*)this->Communicator)
303  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
304  }
306  char* data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
307  {
308  return ((vtkMPICommunicator*)this->Communicator)
309  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
310  }
311  int NoBlockReceive(unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
313  {
314  return ((vtkMPICommunicator*)this->Communicator)
315  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
316  }
317  int NoBlockReceive(float* data, vtkTypeInt64 length, int remoteProcessId, int tag,
319  {
320  return ((vtkMPICommunicator*)this->Communicator)
321  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
322  }
323  int NoBlockReceive(double* data, vtkTypeInt64 length, int remoteProcessId, int tag,
325  {
326  return ((vtkMPICommunicator*)this->Communicator)
327  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
328  }
329  int NoBlockReceive(vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag,
331  {
332  return ((vtkMPICommunicator*)this->Communicator)
333  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
334  }
336 
338 
348  int Iprobe(int source, int tag, int* flag, int* actualSource)
349  {
350  return ((vtkMPICommunicator*)this->Communicator)->Iprobe(source, tag, flag, actualSource);
351  }
352  int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, int* size)
353  {
354  return ((vtkMPICommunicator*)this->Communicator)
355  ->Iprobe(source, tag, flag, actualSource, type, size);
356  }
357  int Iprobe(int source, int tag, int* flag, int* actualSource, unsigned long* type, int* size)
358  {
359  return ((vtkMPICommunicator*)this->Communicator)
360  ->Iprobe(source, tag, flag, actualSource, type, size);
361  }
362  int Iprobe(int source, int tag, int* flag, int* actualSource, const char* type, int* size)
363  {
364  return ((vtkMPICommunicator*)this->Communicator)
365  ->Iprobe(source, tag, flag, actualSource, type, size);
366  }
367  int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, int* size)
368  {
369  return ((vtkMPICommunicator*)this->Communicator)
370  ->Iprobe(source, tag, flag, actualSource, type, size);
371  }
372  int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, int* size)
373  {
374  return ((vtkMPICommunicator*)this->Communicator)
375  ->Iprobe(source, tag, flag, actualSource, type, size);
376  }
378 
382  bool CanProbe() override { return ((vtkMPICommunicator*)this->Communicator)->CanProbe(); }
383 
385 
394  int Probe(int source, int tag, int* actualSource) override
395  {
396  return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource);
397  }
398  int Probe(int source, int tag, int* actualSource, int* type, int* size)
399  {
400  return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
401  }
402  int Probe(int source, int tag, int* actualSource, unsigned long* type, int* size)
403  {
404  return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
405  }
406  int Probe(int source, int tag, int* actualSource, const char* type, int* size)
407  {
408  return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
409  }
410  int Probe(int source, int tag, int* actualSource, float* type, int* size)
411  {
412  return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
413  }
414  int Probe(int source, int tag, int* actualSource, double* type, int* size)
415  {
416  return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
417  }
419 
425  int WaitAll(int count, vtkMPICommunicator::Request requests[])
426  {
427  return ((vtkMPICommunicator*)this->Communicator)->WaitAll(count, requests);
428  }
429 
436  int WaitAny(int count, vtkMPICommunicator::Request requests[], int& idx)
437  VTK_SIZEHINT(requests, count)
438  {
439  return ((vtkMPICommunicator*)this->Communicator)->WaitAny(count, requests, idx);
440  }
441 
447  int WaitSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
448  VTK_SIZEHINT(requests, count);
449 
453  bool TestAll(int count, vtkMPICommunicator::Request requests[]);
454 
461  bool TestAny(int count, vtkMPICommunicator::Request requests[], int& idx)
462  VTK_SIZEHINT(requests, count);
463 
469  bool TestSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
470  VTK_SIZEHINT(requests, count);
471 
472  static const char* GetProcessorName();
473 
478  static void SetUseSsendForRMI(int use_send)
479  {
480  vtkMPIController::UseSsendForRMI = (use_send != 0) ? 1 : 0;
481  }
483 
484 protected:
486  ~vtkMPIController() override;
487 
491  void InitializeCommunicator(vtkMPICommunicator* comm);
492 
493  // Duplicate the current communicator, creating RMICommunicator
494  void InitializeRMICommunicator();
495 
501  void TriggerRMIInternal(
502  int remoteProcessId, void* arg, int argLength, int rmiTag, bool propagate) override;
503 
504  // MPI communicator created when Initialize() called.
505  // This is a copy of MPI_COMM_WORLD but uses a new
506  // context, i.e. even if the tags are the same, the
507  // RMI messages will not interfere with user level
508  // messages.
510 
511  friend class vtkMPIOutputWindow;
512 
513  // Initialize only once.
514  static int Initialized;
515 
516  static char ProcessorName[];
517 
521  static int UseSsendForRMI;
522 
523 private:
524  vtkMPIController(const vtkMPIController&) = delete;
525  void operator=(const vtkMPIController&) = delete;
526 };
527 
528 VTK_ABI_NAMESPACE_END
529 #endif
int NoBlockSend(const double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(double *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockSend(const unsigned char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int Probe(int source, int tag, int *actualSource, float *type, int *size)
Blocking test for a message.
int NoBlockReceive(unsigned char *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockSend(const unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int Probe(int source, int tag, int *actualSource, unsigned long *type, int *size)
Blocking test for a message.
int NoBlockReceive(vtkTypeInt64 *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(float *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
virtual void Finalize()=0
This method is for cleaning up.
Class for creating user defined MPI communicators.
int Iprobe(int source, int tag, int *flag, int *actualSource, const char *type, int *size)
Nonblocking test for a message.
int WaitAny(int count, vtkMPICommunicator::Request requests[], int &idx)
Blocks until one of the specified requests in the given request array completes.
virtual void TriggerRMIInternal(int remoteProcessId, void *arg, int argLength, int rmiTag, bool propagate)
Implementation for TriggerRMI() provides subclasses an opportunity to modify the behaviour eg...
int NoBlockSend(const unsigned long *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
virtual void Initialize(int *argc, char ***argv)=0
This method is for setting up the processes.
virtual void MultipleMethodExecute()=0
Execute the MultipleMethods (as define by calling SetMultipleMethod for each of the required this->Nu...
typename vtkTypeList::detail::CreateImpl< Ts... >::type Create
Definition: vtkTypeList.h:171
int NoBlockReceive(int *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
static int UseSsendForRMI
When set, TriggerRMI uses Ssend instead of Send.
int NoBlockReceive(unsigned char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
void Initialize(int *argc, char ***argv) override
This method is for setting up the processes.
static void SetUseSsendForRMI(int use_send)
When set to 1, TriggerRMI uses Ssend() instead of Send() calls.
int NoBlockSend(const double *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
void Finalize() override
This method is for cleaning up and has to be called before the end of the program if MPI was initiali...
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:35
int Probe(int source, int tag, int *actualSource, double *type, int *size)
Blocking test for a message.
int NoBlockSend(const int *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
a simple class to control print indentation
Definition: vtkIndent.h:28
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int NoBlockSend(const vtkTypeInt64 *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockSend(const void *data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
Variant that permits dynamic type sends, like those create by MPI_Type_create_subarray.
int NoBlockSend(const int *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
static int Initialized
vtkTypeList::Create< float, double, char, int, vtkTypeInt64, unsigned char, unsigned long > ValueTypes
The list of value types supported by MPIController.
int NoBlockSend(const float *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
A subgroup of processes from a communicator.
Process communication using MPI.
static vtkMPICommunicator * WorldRMICommunicator
int Probe(int source, int tag, int *actualSource) override
Blocking test for a message.
#define VTK_SIZEHINT(...)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int NoBlockReceive(float *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::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.
virtual void CreateOutputWindow()=0
This method can be used to tell the controller to create a special output window in which all message...
int NoBlockSend(const vtkTypeInt64 *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockSend(const char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int Iprobe(int source, int tag, int *flag, int *actualSource, unsigned long *type, int *size)
Nonblocking test for a message.
int WaitAll(int count, vtkMPICommunicator::Request requests[])
Given the request objects of a set of non-blocking operations (send and/or receive) this method block...
int NoBlockReceive(char *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int Probe(int source, int tag, int *actualSource, const char *type, int *size)
Blocking test for a message.
int NoBlockReceive(char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int Iprobe(int source, int tag, int *flag, int *actualSource, float *type, int *size)
Nonblocking test for a message.
static int GetUseSsendForRMI()
int NoBlockSend(const char *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(int *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
int NoBlockSend(const float *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::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.
virtual void SingleMethodExecute()=0
Execute the SingleMethod (as define by SetSingleMethod) using this->NumberOfProcesses processes...
virtual vtkMultiProcessController * PartitionController(int localColor, int localKey)
Partitions this controller based on a coloring.
int NoBlockReceive(vtkTypeInt64 *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
virtual vtkMultiProcessController * CreateSubController(vtkProcessGroup *group)
Creates a new controller with the processes specified by the given group.
int NoBlockReceive(unsigned long *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockSend(const unsigned char *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::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.
bool CanProbe() override
This controller does have probing capability.
int Probe(int source, int tag, int *actualSource, int *type, int *size)
Blocking test for a message.
Multiprocessing communication superclass.