VTK  9.3.20240424
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// Do not remove this header file. This class contains methods
43// which take arguments defined in vtkMPICommunicator.h by
44// reference.
45#include "vtkMPICommunicator.h" // Needed for direct access to communicator
46
47VTK_ABI_NAMESPACE_BEGIN
48class vtkIntArray;
49
50class VTKPARALLELMPI_EXPORT vtkMPIController : public vtkMultiProcessController
51{
52
53public:
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
69 void Initialize(int* argc, char*** argv) override { this->Initialize(argc, argv, 0); }
70
72 int* vtkNotUsed(argc), char*** vtkNotUsed(argv), int initializedExternally) override;
73
77 virtual void Initialize();
78
84 void Finalize() override { this->Finalize(0); }
85
86 void Finalize(int finalizedExternally) override;
87
92 void SingleMethodExecute() override;
93
99 void MultipleMethodExecute() override;
100
106 void CreateOutputWindow() override;
107
112 static char* ErrorString(int err);
113
124
126
127 vtkMPIController* PartitionController(int localColor, int localKey) override;
128
130
140 const int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
141 {
142 return ((vtkMPICommunicator*)this->Communicator)
143 ->NoBlockSend(data, length, remoteProcessId, tag, req);
144 }
145 int NoBlockSend(const unsigned long* data, int length, int remoteProcessId, int tag,
147 {
148 return ((vtkMPICommunicator*)this->Communicator)
149 ->NoBlockSend(data, length, remoteProcessId, tag, req);
150 }
152 const char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
153 {
154 return ((vtkMPICommunicator*)this->Communicator)
155 ->NoBlockSend(data, length, remoteProcessId, tag, req);
156 }
157 int NoBlockSend(const unsigned char* data, int length, int remoteProcessId, int tag,
159 {
160 return ((vtkMPICommunicator*)this->Communicator)
161 ->NoBlockSend(data, length, remoteProcessId, tag, req);
162 }
164 const float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
165 {
166 return ((vtkMPICommunicator*)this->Communicator)
167 ->NoBlockSend(data, length, remoteProcessId, tag, req);
168 }
170 const double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
171 {
172 return ((vtkMPICommunicator*)this->Communicator)
173 ->NoBlockSend(data, length, remoteProcessId, tag, req);
174 }
175 int NoBlockSend(const vtkTypeInt64* data, int length, int remoteProcessId, int tag,
177 {
178 return ((vtkMPICommunicator*)this->Communicator)
179 ->NoBlockSend(data, length, remoteProcessId, tag, req);
180 }
181 int NoBlockSend(const int* data, vtkTypeInt64 length, int remoteProcessId, int tag,
183 {
184 return ((vtkMPICommunicator*)this->Communicator)
185 ->NoBlockSend(data, length, remoteProcessId, tag, req);
186 }
187 int NoBlockSend(const unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag,
189 {
190 return ((vtkMPICommunicator*)this->Communicator)
191 ->NoBlockSend(data, length, remoteProcessId, tag, req);
192 }
193 int NoBlockSend(const char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
195 {
196 return ((vtkMPICommunicator*)this->Communicator)
197 ->NoBlockSend(data, length, remoteProcessId, tag, req);
198 }
199 int NoBlockSend(const unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
201 {
202 return ((vtkMPICommunicator*)this->Communicator)
203 ->NoBlockSend(data, length, remoteProcessId, tag, req);
204 }
205 int NoBlockSend(const float* data, vtkTypeInt64 length, int remoteProcessId, int tag,
207 {
208 return ((vtkMPICommunicator*)this->Communicator)
209 ->NoBlockSend(data, length, remoteProcessId, tag, req);
210 }
211 int NoBlockSend(const double* data, vtkTypeInt64 length, int remoteProcessId, int tag,
213 {
214 return ((vtkMPICommunicator*)this->Communicator)
215 ->NoBlockSend(data, length, remoteProcessId, tag, req);
216 }
217 int NoBlockSend(const vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag,
219 {
220 return ((vtkMPICommunicator*)this->Communicator)
221 ->NoBlockSend(data, length, remoteProcessId, tag, req);
222 }
224
228 int NoBlockSend(const void* data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId,
229 int tag, vtkMPICommunicator::Request& req)
230 {
231 return ((vtkMPICommunicator*)this->Communicator)
232 ->NoBlockSend(data, length, mpiType, remoteProcessId, tag, req);
233 }
234
236
245 int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
246 {
247 return ((vtkMPICommunicator*)this->Communicator)
248 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
249 }
251 unsigned long* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
252 {
253 return ((vtkMPICommunicator*)this->Communicator)
254 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
255 }
257 char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
258 {
259 return ((vtkMPICommunicator*)this->Communicator)
260 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
261 }
263 unsigned char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
264 {
265 return ((vtkMPICommunicator*)this->Communicator)
266 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
267 }
269 float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
270 {
271 return ((vtkMPICommunicator*)this->Communicator)
272 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
273 }
275 double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
276 {
277 return ((vtkMPICommunicator*)this->Communicator)
278 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
279 }
281 vtkTypeInt64* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
282 {
283 return ((vtkMPICommunicator*)this->Communicator)
284 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
285 }
287 int* data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
288 {
289 return ((vtkMPICommunicator*)this->Communicator)
290 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
291 }
292 int NoBlockReceive(unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag,
294 {
295 return ((vtkMPICommunicator*)this->Communicator)
296 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
297 }
299 char* data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
300 {
301 return ((vtkMPICommunicator*)this->Communicator)
302 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
303 }
304 int NoBlockReceive(unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
306 {
307 return ((vtkMPICommunicator*)this->Communicator)
308 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
309 }
310 int NoBlockReceive(float* data, vtkTypeInt64 length, int remoteProcessId, int tag,
312 {
313 return ((vtkMPICommunicator*)this->Communicator)
314 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
315 }
316 int NoBlockReceive(double* data, vtkTypeInt64 length, int remoteProcessId, int tag,
318 {
319 return ((vtkMPICommunicator*)this->Communicator)
320 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
321 }
322 int NoBlockReceive(vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag,
324 {
325 return ((vtkMPICommunicator*)this->Communicator)
326 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
327 }
329
331
341 int Iprobe(int source, int tag, int* flag, int* actualSource)
342 {
343 return ((vtkMPICommunicator*)this->Communicator)->Iprobe(source, tag, flag, actualSource);
344 }
345 int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, int* size)
346 {
347 return ((vtkMPICommunicator*)this->Communicator)
348 ->Iprobe(source, tag, flag, actualSource, type, size);
349 }
350 int Iprobe(int source, int tag, int* flag, int* actualSource, unsigned long* type, int* size)
351 {
352 return ((vtkMPICommunicator*)this->Communicator)
353 ->Iprobe(source, tag, flag, actualSource, type, size);
354 }
355 int Iprobe(int source, int tag, int* flag, int* actualSource, const char* type, int* size)
356 {
357 return ((vtkMPICommunicator*)this->Communicator)
358 ->Iprobe(source, tag, flag, actualSource, type, size);
359 }
360 int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, int* size)
361 {
362 return ((vtkMPICommunicator*)this->Communicator)
363 ->Iprobe(source, tag, flag, actualSource, type, size);
364 }
365 int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, int* size)
366 {
367 return ((vtkMPICommunicator*)this->Communicator)
368 ->Iprobe(source, tag, flag, actualSource, type, size);
369 }
371
375 bool CanProbe() override { return ((vtkMPICommunicator*)this->Communicator)->CanProbe(); }
376
378
387 int Probe(int source, int tag, int* actualSource) override
388 {
389 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource);
390 }
391 int Probe(int source, int tag, int* actualSource, int* type, int* size)
392 {
393 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
394 }
395 int Probe(int source, int tag, int* actualSource, unsigned long* type, int* size)
396 {
397 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
398 }
399 int Probe(int source, int tag, int* actualSource, const char* type, int* size)
400 {
401 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
402 }
403 int Probe(int source, int tag, int* actualSource, float* type, int* size)
404 {
405 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
406 }
407 int Probe(int source, int tag, int* actualSource, double* type, int* size)
408 {
409 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
410 }
412
418 int WaitAll(int count, vtkMPICommunicator::Request requests[])
419 {
420 return ((vtkMPICommunicator*)this->Communicator)->WaitAll(count, requests);
421 }
422
429 int WaitAny(int count, vtkMPICommunicator::Request requests[], int& idx)
430 VTK_SIZEHINT(requests, count)
431 {
432 return ((vtkMPICommunicator*)this->Communicator)->WaitAny(count, requests, idx);
433 }
434
440 int WaitSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
441 VTK_SIZEHINT(requests, count);
442
446 bool TestAll(int count, vtkMPICommunicator::Request requests[]);
447
454 bool TestAny(int count, vtkMPICommunicator::Request requests[], int& idx)
455 VTK_SIZEHINT(requests, count);
456
462 bool TestSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
463 VTK_SIZEHINT(requests, count);
464
465 static const char* GetProcessorName();
466
471 static void SetUseSsendForRMI(int use_send)
472 {
473 vtkMPIController::UseSsendForRMI = (use_send != 0) ? 1 : 0;
474 }
476
477protected:
480
481 // Set the communicator to comm and call InitializeNumberOfProcesses()
483
484 // Duplicate the current communicator, creating RMICommunicator
486
493 int remoteProcessId, void* arg, int argLength, int rmiTag, bool propagate) override;
494
495 // MPI communicator created when Initialize() called.
496 // This is a copy of MPI_COMM_WORLD but uses a new
497 // context, i.e. even if the tags are the same, the
498 // RMI messages will not interfere with user level
499 // messages.
501
502 friend class vtkMPIOutputWindow;
503
504 // Initialize only once.
505 static int Initialized;
506
507 static char ProcessorName[];
508
512 static int UseSsendForRMI;
513
514private:
515 vtkMPIController(const vtkMPIController&) = delete;
516 void operator=(const vtkMPIController&) = delete;
517};
518
519VTK_ABI_NAMESPACE_END
520#endif
a simple class to control print indentation
Definition vtkIndent.h:108
dynamic, self-adjusting array of int
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)
Nonblocking test for a message.
int Probe(int source, int tag, int *actualSource, int *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 NoBlockSend(const double *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
~vtkMPIController() override
bool TestSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray *completed)
Return true iff one or more of the communicator request objects is complete.
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 NoBlockSend(const int *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockSend(const unsigned long *data, vtkTypeInt64 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 Probe(int source, int tag, int *actualSource, float *type, int *size)
Blocking test for a message.
void InitializeCommunicator(vtkMPICommunicator *comm)
int Probe(int source, int tag, int *actualSource, double *type, int *size)
Blocking test for a message.
int NoBlockSend(const char *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
bool CanProbe() override
This controller does have probing capability.
int Iprobe(int source, int tag, int *flag, int *actualSource, double *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.
int NoBlockSend(const vtkTypeInt64 *data, vtkTypeInt64 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.
bool TestAll(int count, vtkMPICommunicator::Request requests[])
Returns true iff all of the communication request objects are complete.
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)
This method sends data to another process (non-blocking).
int Probe(int source, int tag, int *actualSource) override
Blocking test for a message.
int NoBlockReceive(char *data, vtkTypeInt64 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, const char *type, int *size)
Nonblocking test for a message.
bool TestAny(int count, vtkMPICommunicator::Request requests[], int &idx)
Returns true iff at least one of the communication request objects is complete.
void CreateOutputWindow() override
This method can be used to tell the controller to create a special output window in which all message...
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 NoBlockReceive(float *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 NoBlockSend(const unsigned char *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
static int UseSsendForRMI
When set, TriggerRMI uses Ssend instead of Send.
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)
This method sends data to another process (non-blocking).
int NoBlockReceive(unsigned char *data, vtkTypeInt64 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.
vtkMPIController * CreateSubController(vtkProcessGroup *group) override
Creates a new controller with the processes specified by the given group.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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 Iprobe(int source, int tag, int *flag, int *actualSource, float *type, int *size)
Nonblocking test for a message.
void Initialize(int *vtkNotUsed(argc), char ***vtkNotUsed(argv), int initializedExternally) override
This method is for setting up the processes.
vtkMPIController * PartitionController(int localColor, int localKey) override
Partitions this controller based on a coloring.
void Finalize(int finalizedExternally) override
This method is for cleaning up.
int NoBlockReceive(double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int NoBlockReceive(int *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
static const char * GetProcessorName()
int NoBlockReceive(unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
int WaitSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray *completed)
Blocks until one or more of the specified requests in the given request request array completes.
static char * ErrorString(int err)
Given an MPI error code, return a string which contains an error message.
void SingleMethodExecute() override
Execute the SingleMethod (as define by SetSingleMethod) using this->NumberOfProcesses processes.
int NoBlockReceive(vtkTypeInt64 *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
static vtkMPIController * New()
int NoBlockSend(const int *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
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 NoBlockSend(const float *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(unsigned 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)
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.
int NoBlockSend(const double *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
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 char *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
int NoBlockReceive(vtkTypeInt64 *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
virtual void Initialize()
Same as Initialize(0, 0, 1).
static int GetUseSsendForRMI()
int NoBlockSend(const unsigned long *data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method sends data to another process (non-blocking).
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)
Nonblocking test for a message.
void InitializeRMICommunicator()
int NoBlockReceive(float *data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request &req)
This method receives data from a corresponding send (non-blocking).
Multiprocessing communication superclass.
A subgroup of processes from a communicator.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_SIZEHINT(...)