VTK  9.2.5
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 
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()
357 
358  // Duplicate the current communicator, creating RMICommunicator
360 
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
a simple class to control print indentation
Definition: vtkIndent.h:119
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:155
Class for creating user defined MPI communicators.
Process communication using MPI.
int Iprobe(int source, int tag, int *flag, int *actualSource, int *type, int *size)
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 NoBlockReceive(char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
~vtkMPIController() override
int WaitSome(const int count, vtkMPICommunicator::Request requests[], vtkIntArray *completed)
Blocks until one or more of the specified requests in the given request request array completes.
void InitializeCommunicator(vtkMPICommunicator *comm)
int NoBlockSend(const char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int Iprobe(int source, int tag, int *flag, int *actualSource, double *type, int *size)
void Finalize() override
This method is for cleaning up and has to be called before the end of the program if MPI was initiali...
int NoBlockSend(const unsigned char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int Iprobe(int source, int tag, int *flag, int *actualSource, const char *type, int *size)
void CreateOutputWindow() override
This method can be used to tell the controller to create a special output window in which all message...
int NoBlockReceive(float *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
static vtkMPIController * New()
static int UseSsendForRMI
When set, TriggerRMI uses Ssend instead of Send.
bool TestSome(const int count, vtkMPICommunicator::Request requests[], vtkIntArray *completed)
Return true iff one or more of the communicator request objects is complete.
bool TestAny(const int count, vtkMPICommunicator::Request requests[], int &idx)
Returns true iff at least one of the communication request objects is complete.
static vtkMPICommunicator * WorldRMICommunicator
void SetCommunicator(vtkMPICommunicator *comm)
MPIController uses this communicator in all sends and receives.
int NoBlockSend(const float *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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Iprobe(int source, int tag, int *flag, int *actualSource, float *type, int *size)
void Initialize(int *vtkNotUsed(argc), char ***vtkNotUsed(argv), int initializedExternally) override
This method is for setting up the processes.
void Finalize(int finalizedExternally) override
This method is for cleaning up.
int NoBlockReceive(double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
static const char * GetProcessorName()
int NoBlockReceive(unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
void SingleMethodExecute() override
Execute the SingleMethod (as define by SetSingleMethod) using this->NumberOfProcesses processes.
vtkMPIController * PartitionController(int localColor, int localKey) override
Partitions this controller based on a coloring.
int NoBlockSend(const int *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int WaitAny(const int count, vtkMPICommunicator::Request requests[], int &idx)
Blocks until one of the specified requests in the given request array completes.
static void SetUseSsendForRMI(int use_send)
When set to 1, TriggerRMI uses Ssend() instead of Send() calls.
int NoBlockReceive(int *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(unsigned char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
int Iprobe(int source, int tag, int *flag, int *actualSource)
Nonblocking test for a message.
void TriggerRMIInternal(int remoteProcessId, void *arg, int argLength, int rmiTag, bool propagate) override
Implementation for TriggerRMI() provides subclasses an opportunity to modify the behaviour eg.
vtkMPIController * CreateSubController(vtkProcessGroup *group) override
Creates a new controller with the processes specified by the given group.
int NoBlockSend(const double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
bool TestAll(const int count, vtkMPICommunicator::Request requests[])
Returns true iff all of the communication request objects are complete.
static int Initialized
virtual void Initialize()
Same as Initialize(0, 0, 1).
static int GetUseSsendForRMI()
static char * ErrorString(int err)
Given an MPI error code, return a string which contains an error message.
int NoBlockSend(const unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
void MultipleMethodExecute() override
Execute the MultipleMethods (as define by calling SetMultipleMethod for each of the required this->Nu...
int Iprobe(int source, int tag, int *flag, int *actualSource, unsigned long *type, int *size)
void InitializeRMICommunicator()
Multiprocessing communication superclass.
A subgroup of processes from a communicator.
@ length
Definition: vtkX3D.h:399
@ type
Definition: vtkX3D.h:522
@ size
Definition: vtkX3D.h:259
@ data
Definition: vtkX3D.h:321
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:332
#define VTK_SIZEHINT(...)