VTK  9.7.20260818
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
36
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
48VTK_ABI_NAMESPACE_BEGIN
49class vtkIntArray;
50
51class VTKPARALLELMPI_EXPORT vtkMPIController : public vtkMultiProcessController
52{
53
54public:
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
62 using ValueTypes =
63 vtkTypeList::Create<float, double, char, int, vtkTypeInt64, unsigned char, unsigned long>;
64
76 void Initialize(int* argc, char*** argv) override { this->Initialize(argc, argv, 0); }
77
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
131
133
134 vtkMPIController* PartitionController(int localColor, int localKey) override;
135
137
160
187 vtkMPIController* PartitionControllerByCount(int numberOfGroups) override;
188
190
200 const int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
201 {
202 return ((vtkMPICommunicator*)this->Communicator)
203 ->NoBlockSend(data, length, remoteProcessId, tag, req);
204 }
205 int NoBlockSend(const unsigned long* data, int length, int remoteProcessId, int tag,
207 {
208 return ((vtkMPICommunicator*)this->Communicator)
209 ->NoBlockSend(data, length, remoteProcessId, tag, req);
210 }
212 const char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
213 {
214 return ((vtkMPICommunicator*)this->Communicator)
215 ->NoBlockSend(data, length, remoteProcessId, tag, req);
216 }
217 int NoBlockSend(const unsigned char* data, int length, int remoteProcessId, int tag,
219 {
220 return ((vtkMPICommunicator*)this->Communicator)
221 ->NoBlockSend(data, length, remoteProcessId, tag, req);
222 }
224 const float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
225 {
226 return ((vtkMPICommunicator*)this->Communicator)
227 ->NoBlockSend(data, length, remoteProcessId, tag, req);
228 }
230 const double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
231 {
232 return ((vtkMPICommunicator*)this->Communicator)
233 ->NoBlockSend(data, length, remoteProcessId, tag, req);
234 }
235 int NoBlockSend(const vtkTypeInt64* data, int length, int remoteProcessId, int tag,
237 {
238 return ((vtkMPICommunicator*)this->Communicator)
239 ->NoBlockSend(data, length, remoteProcessId, tag, req);
240 }
241 int NoBlockSend(const int* data, vtkTypeInt64 length, int remoteProcessId, int tag,
243 {
244 return ((vtkMPICommunicator*)this->Communicator)
245 ->NoBlockSend(data, length, remoteProcessId, tag, req);
246 }
247 int NoBlockSend(const unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag,
249 {
250 return ((vtkMPICommunicator*)this->Communicator)
251 ->NoBlockSend(data, length, remoteProcessId, tag, req);
252 }
253 int NoBlockSend(const char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
255 {
256 return ((vtkMPICommunicator*)this->Communicator)
257 ->NoBlockSend(data, length, remoteProcessId, tag, req);
258 }
259 int NoBlockSend(const unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
261 {
262 return ((vtkMPICommunicator*)this->Communicator)
263 ->NoBlockSend(data, length, remoteProcessId, tag, req);
264 }
265 int NoBlockSend(const float* data, vtkTypeInt64 length, int remoteProcessId, int tag,
267 {
268 return ((vtkMPICommunicator*)this->Communicator)
269 ->NoBlockSend(data, length, remoteProcessId, tag, req);
270 }
271 int NoBlockSend(const double* data, vtkTypeInt64 length, int remoteProcessId, int tag,
273 {
274 return ((vtkMPICommunicator*)this->Communicator)
275 ->NoBlockSend(data, length, remoteProcessId, tag, req);
276 }
277 int NoBlockSend(const vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag,
279 {
280 return ((vtkMPICommunicator*)this->Communicator)
281 ->NoBlockSend(data, length, remoteProcessId, tag, req);
282 }
283
284
288 int NoBlockSend(const void* data, vtkTypeInt64 length, MPI_Datatype mpiType, int remoteProcessId,
289 int tag, vtkMPICommunicator::Request& req)
290 {
291 return ((vtkMPICommunicator*)this->Communicator)
292 ->NoBlockSend(data, length, mpiType, remoteProcessId, tag, req);
293 }
294
296
305 int* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
306 {
307 return ((vtkMPICommunicator*)this->Communicator)
308 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
309 }
311 unsigned long* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
312 {
313 return ((vtkMPICommunicator*)this->Communicator)
314 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
315 }
317 char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
318 {
319 return ((vtkMPICommunicator*)this->Communicator)
320 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
321 }
323 unsigned char* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
324 {
325 return ((vtkMPICommunicator*)this->Communicator)
326 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
327 }
329 float* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
330 {
331 return ((vtkMPICommunicator*)this->Communicator)
332 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
333 }
335 double* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
336 {
337 return ((vtkMPICommunicator*)this->Communicator)
338 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
339 }
341 vtkTypeInt64* data, int length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
342 {
343 return ((vtkMPICommunicator*)this->Communicator)
344 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
345 }
347 int* data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
348 {
349 return ((vtkMPICommunicator*)this->Communicator)
350 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
351 }
352 int NoBlockReceive(unsigned long* data, vtkTypeInt64 length, int remoteProcessId, int tag,
354 {
355 return ((vtkMPICommunicator*)this->Communicator)
356 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
357 }
359 char* data, vtkTypeInt64 length, int remoteProcessId, int tag, vtkMPICommunicator::Request& req)
360 {
361 return ((vtkMPICommunicator*)this->Communicator)
362 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
363 }
364 int NoBlockReceive(unsigned char* data, vtkTypeInt64 length, int remoteProcessId, int tag,
366 {
367 return ((vtkMPICommunicator*)this->Communicator)
368 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
369 }
370 int NoBlockReceive(float* data, vtkTypeInt64 length, int remoteProcessId, int tag,
372 {
373 return ((vtkMPICommunicator*)this->Communicator)
374 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
375 }
376 int NoBlockReceive(double* data, vtkTypeInt64 length, int remoteProcessId, int tag,
378 {
379 return ((vtkMPICommunicator*)this->Communicator)
380 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
381 }
382 int NoBlockReceive(vtkTypeInt64* data, vtkTypeInt64 length, int remoteProcessId, int tag,
384 {
385 return ((vtkMPICommunicator*)this->Communicator)
386 ->NoBlockReceive(data, length, remoteProcessId, tag, req);
387 }
388
389
391
401 int Iprobe(int source, int tag, int* flag, int* actualSource)
402 {
403 return ((vtkMPICommunicator*)this->Communicator)->Iprobe(source, tag, flag, actualSource);
404 }
405 int Iprobe(int source, int tag, int* flag, int* actualSource, int* type, int* size)
406 {
407 return ((vtkMPICommunicator*)this->Communicator)
408 ->Iprobe(source, tag, flag, actualSource, type, size);
409 }
410 int Iprobe(int source, int tag, int* flag, int* actualSource, unsigned long* type, int* size)
411 {
412 return ((vtkMPICommunicator*)this->Communicator)
413 ->Iprobe(source, tag, flag, actualSource, type, size);
414 }
415 int Iprobe(int source, int tag, int* flag, int* actualSource, const char* type, int* size)
416 {
417 return ((vtkMPICommunicator*)this->Communicator)
418 ->Iprobe(source, tag, flag, actualSource, type, size);
419 }
420 int Iprobe(int source, int tag, int* flag, int* actualSource, float* type, int* size)
421 {
422 return ((vtkMPICommunicator*)this->Communicator)
423 ->Iprobe(source, tag, flag, actualSource, type, size);
424 }
425 int Iprobe(int source, int tag, int* flag, int* actualSource, double* type, int* size)
426 {
427 return ((vtkMPICommunicator*)this->Communicator)
428 ->Iprobe(source, tag, flag, actualSource, type, size);
429 }
430
431
435 bool CanProbe() override { return ((vtkMPICommunicator*)this->Communicator)->CanProbe(); }
436
438
447 int Probe(int source, int tag, int* actualSource) override
448 {
449 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource);
450 }
451 int Probe(int source, int tag, int* actualSource, int* type, int* size)
452 {
453 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
454 }
455 int Probe(int source, int tag, int* actualSource, unsigned long* type, int* size)
456 {
457 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
458 }
459 int Probe(int source, int tag, int* actualSource, const char* type, int* size)
460 {
461 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
462 }
463 int Probe(int source, int tag, int* actualSource, float* type, int* size)
464 {
465 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
466 }
467 int Probe(int source, int tag, int* actualSource, double* type, int* size)
468 {
469 return ((vtkMPICommunicator*)this->Communicator)->Probe(source, tag, actualSource, type, size);
470 }
471
472
478 int WaitAll(int count, vtkMPICommunicator::Request requests[])
479 {
480 return ((vtkMPICommunicator*)this->Communicator)->WaitAll(count, requests);
481 }
482
489 int WaitAny(int count, vtkMPICommunicator::Request requests[], int& idx)
490 VTK_SIZEHINT(requests, count)
491 {
492 return ((vtkMPICommunicator*)this->Communicator)->WaitAny(count, requests, idx);
493 }
494
500 int WaitSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
501 VTK_SIZEHINT(requests, count);
502
506 bool TestAll(int count, vtkMPICommunicator::Request requests[]);
507
514 bool TestAny(int count, vtkMPICommunicator::Request requests[], int& idx)
515 VTK_SIZEHINT(requests, count);
516
522 bool TestSome(int count, vtkMPICommunicator::Request requests[], vtkIntArray* completed)
523 VTK_SIZEHINT(requests, count);
524
525 static const char* GetProcessorName();
526
531 static void SetUseSsendForRMI(int use_send)
532 {
533 vtkMPIController::UseSsendForRMI = (use_send != 0) ? 1 : 0;
534 }
536
537protected:
540
545
546 // Duplicate the current communicator, creating RMICommunicator
548
555 int remoteProcessId, void* arg, int argLength, int rmiTag, bool propagate) override;
556
557 // MPI communicator created when Initialize() called.
558 // This is a copy of MPI_COMM_WORLD but uses a new
559 // context, i.e. even if the tags are the same, the
560 // RMI messages will not interfere with user level
561 // messages.
563
564 friend class vtkMPIOutputWindow;
565
566 // Initialize only once.
567 static int Initialized;
568
569 static char ProcessorName[];
570
574 static int UseSsendForRMI;
575
576private:
577 vtkMPIController(const vtkMPIController&) = delete;
578 void operator=(const vtkMPIController&) = delete;
579};
580
581VTK_ABI_NAMESPACE_END
582#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.
int Iprobe(int source, int tag, int *flag, int *actualSource, int *type, int *size)
Nonblocking test for a message.
static char ProcessorName[]
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).
vtkTypeList::Create< float, double, char, int, vtkTypeInt64, unsigned char, unsigned long > ValueTypes
The list of value types supported by MPIController.
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)
Set the communicator to comm.
friend class vtkMPIOutputWindow
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 Initialize(int *argc, char ***argv, int initializedExternally) override
This method is for setting up the processes.
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 GetNumberOfSharedMemoryNodes()
Returns the number of disjoint groups of processes that can share memory (e.g.
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.
int GetSharedMemoryNodeId()
Returns the number of disjoint groups of processes that can share memory (e.g.
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).
vtkMPIController * PartitionControllerByCount(int numberOfGroups) override
Groups processes into numberOfGroups groups, balancing group membership by physical node rather than ...
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).
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(...)