VTK
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 =========================================================================*/
43 #ifndef vtkMPIController_h
44 #define vtkMPIController_h
45 
46 #include "vtkParallelMPIModule.h" // For export macro
48 // Do not remove this header file. This class contains methods
49 // which take arguments defined in vtkMPICommunicator.h by
50 // reference.
51 #include "vtkMPICommunicator.h" // Needed for direct access to communicator
52 
53 class vtkIntArray;
54 
55 class VTKPARALLELMPI_EXPORT vtkMPIController : public vtkMultiProcessController
56 {
57 
58 public:
59 
60  static vtkMPIController *New();
62  void PrintSelf(ostream& os, vtkIndent indent) override;
63 
75  virtual void Initialize(int* argc, char*** argv) override
76  { this->Initialize(argc, argv, 0); }
77 
78  virtual void Initialize(int* vtkNotUsed(argc), char*** vtkNotUsed(argv),
79  int initializedExternally) override;
80 
84  virtual void Initialize();
85 
91  virtual void Finalize() override { this->Finalize(0); }
92 
93  virtual void Finalize(int finalizedExternally) override;
94 
99  virtual void SingleMethodExecute() override;
100 
106  virtual void MultipleMethodExecute() override;
107 
113  virtual void CreateOutputWindow() override;
114 
119  static char* ErrorString(int err);
120 
121 
131  void SetCommunicator(vtkMPICommunicator* comm);
132 
133  virtual vtkMPIController *CreateSubController(vtkProcessGroup *group) override;
134 
135  virtual vtkMPIController *PartitionController(int localColor, int localKey) override;
136 
146  int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
148  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
149  (data ,length, remoteProcessId, tag, req); }
150  int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
151  int tag, vtkMPICommunicator::Request& req)
152  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
153  (data, length, remoteProcessId, tag, req); }
154  int NoBlockSend(const char* data, int length, int remoteProcessId,
155  int tag, vtkMPICommunicator::Request& req)
156  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
157  (data, length, remoteProcessId, tag, req); }
158  int NoBlockSend( const unsigned char* data, int length, int remoteProcessId,
159  int tag, vtkMPICommunicator::Request& req )
160  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
161  (data, length, remoteProcessId, tag, req);}
162  int NoBlockSend(const float* data, int length, int remoteProcessId,
163  int tag, vtkMPICommunicator::Request& req)
164  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
165  (data, length, remoteProcessId, tag, req); }
166  int NoBlockSend(const double* data, int length, int remoteProcessId,
167  int tag, vtkMPICommunicator::Request& req)
168  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
169  (data, length, remoteProcessId, tag, req); }
170 #ifdef VTK_USE_64BIT_IDS
171  int NoBlockSend(const vtkIdType* data, int length, int remoteProcessId,
172  int tag, vtkMPICommunicator::Request& req)
173  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockSend
174  (data, length, remoteProcessId, tag, req); }
175 #endif
176 
185  int NoBlockReceive(int* data, int length, int remoteProcessId,
186  int tag, vtkMPICommunicator::Request& req)
187  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
188  (data, length, remoteProcessId, tag, req); }
189  int NoBlockReceive(unsigned long* data, int length,
190  int remoteProcessId, int tag,
192  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
193  (data, length, remoteProcessId, tag, req); }
194  int NoBlockReceive(char* data, int length, int remoteProcessId,
195  int tag, vtkMPICommunicator::Request& req)
196  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
197  (data, length, remoteProcessId, tag, req); }
198  int NoBlockReceive(unsigned char* data, int length, int remoteProcessId,
199  int tag, vtkMPICommunicator::Request& req)
200  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
201  (data, length, remoteProcessId, tag, req); }
202  int NoBlockReceive(float* data, int length, int remoteProcessId,
203  int tag, vtkMPICommunicator::Request& req)
204  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
205  (data, length, remoteProcessId, tag, req); }
206  int NoBlockReceive(double* data, int length, int remoteProcessId,
207  int tag, vtkMPICommunicator::Request& req)
208  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
209  (data, length, remoteProcessId, tag, req); }
210 #ifdef VTK_USE_64BIT_IDS
211  int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
212  int tag, vtkMPICommunicator::Request& req)
213  { return ((vtkMPICommunicator*)this->Communicator)->NoBlockReceive
214  (data, length, remoteProcessId, tag, req); }
215 #endif
216 
227  int Iprobe(int source, int tag, int* flag, int* actualSource)
228  { return ((vtkMPICommunicator*)this->Communicator)->Iprobe(
229  source, tag, flag, actualSource); }
230  int Iprobe(int source, int tag, int* flag, int* actualSource,
231  int* type, int* size)
232  { return ((vtkMPICommunicator*)this->Communicator)->Iprobe(
233  source, tag, flag, actualSource, type, size); }
234  int Iprobe(int source, int tag, int* flag, int* actualSource,
235  unsigned long* type, int* size)
236  { return ((vtkMPICommunicator*)this->Communicator)->Iprobe(
237  source, tag, flag, actualSource, type, size); }
238  int Iprobe(int source, int tag, int* flag, int* actualSource,
239  const char* type, int* size)
240  { return ((vtkMPICommunicator*)this->Communicator)->Iprobe(
241  source, tag, flag, actualSource, type, size); }
242  int Iprobe(int source, int tag, int* flag, int* actualSource,
243  float* type, int* size)
244  { return ((vtkMPICommunicator*)this->Communicator)->Iprobe(
245  source, tag, flag, actualSource, type, size); }
246  int Iprobe(int source, int tag, int* flag, int* actualSource,
247  double* type, int* size)
248  { return ((vtkMPICommunicator*)this->Communicator)->Iprobe(
249  source, tag, flag, actualSource, type, size); }
250 
256  int WaitAll(const int count, vtkMPICommunicator::Request requests[])
257  { return ((vtkMPICommunicator*)this->Communicator)->WaitAll(count,requests);}
258 
265  int WaitAny(const int count,vtkMPICommunicator::Request requests[], int& idx) VTK_SIZEHINT(requests, count)
266  {return ((vtkMPICommunicator*)this->Communicator)->WaitAny(count,requests,idx);}
267 
273  int WaitSome(
274  const int count, vtkMPICommunicator::Request requests[],
275  vtkIntArray *completed ) VTK_SIZEHINT(requests, count);
276 
280  bool TestAll(const int count, vtkMPICommunicator::Request requests[] );
281 
288  bool TestAny(const int count,vtkMPICommunicator::Request requests[],int &idx) VTK_SIZEHINT(requests, count);
289 
295  bool TestSome(const int count,vtkMPICommunicator::Request requests[],
296  vtkIntArray *completed ) VTK_SIZEHINT(requests, count);
297 
298  static const char* GetProcessorName();
299 
304  static void SetUseSsendForRMI(int use_send)
305  { vtkMPIController::UseSsendForRMI = (use_send != 0)? 1: 0; }
307 
308 protected:
310  ~vtkMPIController();
311 
312  // Set the communicator to comm and call InitializeNumberOfProcesses()
313  void InitializeCommunicator(vtkMPICommunicator* comm);
314 
315  // Duplicate the current communicator, creating RMICommunicator
316  void InitializeRMICommunicator();
317 
323  virtual void TriggerRMIInternal(int remoteProcessId,
324  void* arg, int argLength, int rmiTag, bool propagate) override;
325 
326  // MPI communicator created when Initialize() called.
327  // This is a copy of MPI_COMM_WORLD but uses a new
328  // context, i.e. even if the tags are the same, the
329  // RMI messages will not interfere with user level
330  // messages.
332 
333  friend class vtkMPIOutputWindow;
334 
335  // Initialize only once.
336  static int Initialized;
337 
338  static char ProcessorName[];
339 
343  static int UseSsendForRMI;
344 
345 private:
346  vtkMPIController(const vtkMPIController&) = delete;
347  void operator=(const vtkMPIController&) = delete;
348 
349 };
350 
351 
352 #endif
353 
354 
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:347
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)
static void SetUseSsendForRMI(int use_send)
When set to 1, TriggerRMI uses Ssend() instead of Send() calls.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:39
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:33
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void Initialize(int *argc, char ***argv) override
This method is for setting up the processes.
static int Initialized
A subgroup of processes from a communicator.
Process communication using MPI.
static vtkMPICommunicator * WorldRMICommunicator
#define VTK_SIZEHINT(...)
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)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
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)
virtual 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 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.