VTK  9.2.6
vtkMPIController.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMPIController.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 =========================================================================*/
49 #ifndef vtkMPIController_h
50 #define vtkMPIController_h
51 
53 #include "vtkParallelMPIModule.h" // For export macro
54 // Do not remove this header file. This class contains methods
55 // which take arguments defined in vtkMPICommunicator.h by
56 // reference.
57 #include "vtkMPICommunicator.h" // Needed for direct access to communicator
58 
59 class vtkIntArray;
60 
61 class VTKPARALLELMPI_EXPORT vtkMPIController : public vtkMultiProcessController
62 {
63 
64 public:
65  static vtkMPIController* New();
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
80  void Initialize(int* argc, char*** argv) override { this->Initialize(argc, argv, 0); }
81 
82  void Initialize(
83  int* vtkNotUsed(argc), char*** vtkNotUsed(argv), int initializedExternally) override;
84 
88  virtual void Initialize();
89 
95  void Finalize() override { this->Finalize(0); }
96 
97  void Finalize(int finalizedExternally) override;
98 
103  void SingleMethodExecute() override;
104 
110  void MultipleMethodExecute() override;
111 
117  void CreateOutputWindow() override;
118 
123  static char* ErrorString(int err);
124 
134  void SetCommunicator(vtkMPICommunicator* comm);
135 
137 
138  vtkMPIController* PartitionController(int localColor, int localKey) override;
139 
150  const int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
151  {
152  return ((vtkMPICommunicator*)this->Communicator)
153  ->NoBlockSend(data, length, remoteProcessId, tag, req);
154  }
155  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId, int tag,
157  {
158  return ((vtkMPICommunicator*)this->Communicator)
159  ->NoBlockSend(data, length, remoteProcessId, tag, req);
160  }
162  const char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
163  {
164  return ((vtkMPICommunicator*)this->Communicator)
165  ->NoBlockSend(data, length, remoteProcessId, tag, req);
166  }
167  int NoBlockSend(const unsigned char* data, int length, int remoteProcessId, int tag,
169  {
170  return ((vtkMPICommunicator*)this->Communicator)
171  ->NoBlockSend(data, length, remoteProcessId, tag, req);
172  }
174  const float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
175  {
176  return ((vtkMPICommunicator*)this->Communicator)
177  ->NoBlockSend(data, length, remoteProcessId, tag, req);
178  }
180  const double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
181  {
182  return ((vtkMPICommunicator*)this->Communicator)
183  ->NoBlockSend(data, length, remoteProcessId, tag, req);
184  }
185 #ifdef VTK_USE_64BIT_IDS
186  int NoBlockSend(const vtkIdType* data, int length, int remoteProcessId, int tag,
188  {
189  return ((vtkMPICommunicator*)this->Communicator)
190  ->NoBlockSend(data, length, remoteProcessId, tag, req);
191  }
192 #endif
193 
203  int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
204  {
205  return ((vtkMPICommunicator*)this->Communicator)
206  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
207  }
209  unsigned long* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
210  {
211  return ((vtkMPICommunicator*)this->Communicator)
212  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
213  }
215  char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
216  {
217  return ((vtkMPICommunicator*)this->Communicator)
218  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
219  }
221  unsigned char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
222  {
223  return ((vtkMPICommunicator*)this->Communicator)
224  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
225  }
227  float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
228  {
229  return ((vtkMPICommunicator*)this->Communicator)
230  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
231  }
233  double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
234  {
235  return ((vtkMPICommunicator*)this->Communicator)
236  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
237  }
238 #ifdef VTK_USE_64BIT_IDS
239  int NoBlockReceive(
240  vtkIdType* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
241  {
242  return ((vtkMPICommunicator*)this->Communicator)
243  ->NoBlockReceive(data, length, remoteProcessId, tag, req);
244  }
245 #endif
246 
257  int Iprobe(int source, int tag, int* flag, int* actualSource)
258  {
259  return ((vtkMPICommunicator*)this->Communicator)->Iprobe(source, tag, flag, actualSource);
260  }
261  int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, int* size)
262  {
263  return ((vtkMPICommunicator*)this->Communicator)
264  ->Iprobe(source, tag, flag, actualSource, type, size);
265  }
266  int Iprobe(int source, int tag, int* flag, int* actualSource, unsigned long* type, int* size)
267  {
268  return ((vtkMPICommunicator*)this->Communicator)
269  ->Iprobe(source, tag, flag, actualSource, type, size);
270  }
271  int Iprobe(int source, int tag, int* flag, int* actualSource, const char* type, int* size)
272  {
273  return ((vtkMPICommunicator*)this->Communicator)
274  ->Iprobe(source, tag, flag, actualSource, type, size);
275  }
276  int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, int* size)
277  {
278  return ((vtkMPICommunicator*)this->Communicator)
279  ->Iprobe(source, tag, flag, actualSource, type, size);
280  }
281  int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, int* size)
282  {
283  return ((vtkMPICommunicator*)this->Communicator)
284  ->Iprobe(source, tag, flag, actualSource, type, size);
285  }
286 
292  int WaitAll(const int count, vtkMPICommunicator::Request requests[])
293  {
294  return ((vtkMPICommunicator*)this->Communicator)->WaitAll(count, requests);
295  }
296 
303  int WaitAny(const int count, vtkMPICommunicator::Request requests[], int& idx)
304  VTK_SIZEHINT(requests, count)
305  {
306  return ((vtkMPICommunicator*)this->Communicator)->WaitAny(count, requests, idx);
307  }
308 
314  int WaitSome(const int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
315  VTK_SIZEHINT(requests, count);
316 
320  bool TestAll(const int count, vtkMPICommunicator::Request requests[]);
321 
328  bool TestAny(const int count, vtkMPICommunicator::Request requests[], int& idx)
329  VTK_SIZEHINT(requests, count);
330 
336  bool TestSome(const int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
337  VTK_SIZEHINT(requests, count);
338 
339  static const char* GetProcessorName();
340 
345  static void SetUseSsendForRMI(int use_send)
346  {
347  vtkMPIController::UseSsendForRMI = (use_send != 0) ? 1 : 0;
348  }
350 
351 protected:
353  ~vtkMPIController() override;
354 
355  // Set the communicator to comm and call InitializeNumberOfProcesses()
356  void InitializeCommunicator(vtkMPICommunicator* comm);
357 
358  // Duplicate the current communicator, creating RMICommunicator
359  void InitializeRMICommunicator();
360 
366  void TriggerRMIInternal(
367  int remoteProcessId, void* arg, int argLength, int rmiTag, bool propagate) override;
368 
369  // MPI communicator created when Initialize() called.
370  // This is a copy of MPI_COMM_WORLD but uses a new
371  // context, i.e. even if the tags are the same, the
372  // RMI messages will not interfere with user level
373  // messages.
375 
376  friend class vtkMPIOutputWindow;
377 
378  // Initialize only once.
379  static int Initialized;
380 
381  static char ProcessorName[];
382 
386  static int UseSsendForRMI;
387 
388 private:
389  vtkMPIController(const vtkMPIController&) = delete;
390  void operator=(const vtkMPIController&) = delete;
391 };
392 
393 #endif
int NoBlockSend(const double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int NoBlockSend(const unsigned char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int NoBlockSend(const unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int WaitAll(const int count, vtkMPICommunicator::Request requests[])
Given the request objects of a set of non-blocking operations (send and/or receive) this method block...
int WaitAny(const int count, vtkMPICommunicator::Request requests[], int &idx)
Blocks until one of the specified requests in the given request array completes.
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)
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 vtkIdType
Definition: vtkType.h:332
virtual void MultipleMethodExecute()=0
Execute the MultipleMethods (as define by calling SetMultipleMethod for each of the required this->Nu...
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)
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.
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:45
int NoBlockSend(const int *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
virtual void Initialize(int *vtkNotUsed(argc), char ***vtkNotUsed(argv))=0
This method is for setting up the processes.
int NoBlockReceive(unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
a simple class to control print indentation
Definition: vtkIndent.h:39
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static int Initialized
A subgroup of processes from a communicator.
Process communication using MPI.
static vtkMPICommunicator * WorldRMICommunicator
#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)
int Iprobe(int source, int tag, int *flag, int *actualSource, double *type, int *size)
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 char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int Iprobe(int source, int tag, int *flag, int *actualSource, unsigned long *type, int *size)
int NoBlockReceive(double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int NoBlockReceive(char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int Iprobe(int source, int tag, int *flag, int *actualSource, float *type, int *size)
static int GetUseSsendForRMI()
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)
int Iprobe(int source, int tag, int *flag, int *actualSource, int *type, int *size)
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.
virtual vtkMultiProcessController * CreateSubController(vtkProcessGroup *group)
Creates a new controller with the processes specified by the given group.
int Iprobe(int source, int tag, int *flag, int *actualSource)
Nonblocking test for a message.
Multiprocessing communication superclass.