File: vtkPartitionBalancer.h

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (141 lines) | stat: -rw-r--r-- 4,992 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
 * @class vtkPartitionBalancer
 * @brief Balances input partitioned data sets so each rank has the same number of data sets.
 *
 * This filter can be applied on `vtkPartitionedDataSet` or `vtkPartitionedDataSetCollection`.
 *
 * * Given an input `vtkPartitionedDataSet`, this filter adds
 * `nullptr` instances in the output `vtkPartitionedDataSet` following a pattern specified
 * as parameter. The output partitioned data set will have the same number of partitions across
 * all ranks.
 * * Given an input `vtkPartitionedDataSetCollection`, this filter is applied on each partitioned
 * data set separately, and is producing a `vtkPartitioneDataSetCollection`.
 *
 * If some input partitions are `nullptr`, the output will see this partition squeezed out.
 * The filter will treat the input partitioned data set as if this `nullptr` partition was non
 * existent.
 *
 * The way the output is laid out is driven by the parameter `Mode`;
 * * `Mode::Expand` generates, per partitioned data set, as many partitions as there are partitions
 * in the input across all ranks.
 * Given a valid partition (not `nullptr`) in the output partitioned data set at index
 * n in rank i, all partitioned data set of all ranks but i have a `nullptr` instance as index n.
 * Output partitions are sorted by rank number. i.e., for i < j, partition at rank i are indexed
 * before partitions of rank j. Here is an example. of what would be generated for a
 * given input. PDC holds for Partitioned Dataset Collection, and PD holds for Partitioned Dataset.
 * @verbatim
 * Input:
 * rank 0: PDC [ PD (DS0, DS1,     DS2) ] [PD (nullptr, DS100) ]
 * rank 1: PDC [ PD (DS3, nullptr, DS4) ] [PD ()               ]
 *
 * Output:
 * rank 0: PDC [ PD (DS0,     DS1,     DS2,     nullptr, nullptr) ] [PD (DS100)   ]
 * rank 1: PDC [ PD (nullptr, nullptr, nullptr, DS3,     DS4)     ] [PD (nullptr) ]
 * @endverbatim
 * * `Mode::Squash` generates, per input partitioned data set, the minimum number of partitions
 * possible, appending `nullptr` in ranks lacking partitions. Using the same example as above:
 * @verbatim
 * Input:
 * rank 0: PDC [ PD (DS0, DS1,     DS2) ] [PD (nullptr, DS100) ]
 * rank 1: PDC [ PD (DS3, nullptr, DS4) ] [PD ()               ]
 *
 * Output:
 * rank 0: PDC [ PD (DS0, DS1, DS2)     ] [PD (DS100)   ]
 * rank 1: PDC [ PD (DS3, DS4, nullptr) ] [PD (nullptr) ]
 * @endverbatim
 */

#ifndef vtkPartitionBalancer_h
#define vtkPartitionBalancer_h

#include "vtkFiltersParallelModule.h" // for export macros
#include "vtkPartitionedDataSetAlgorithm.h"

VTK_ABI_NAMESPACE_BEGIN
class vtkMultiProcessController;

class VTKFILTERSPARALLEL_EXPORT vtkPartitionBalancer : public vtkPartitionedDataSetAlgorithm
{
public:
  static vtkPartitionBalancer* New();
  vtkTypeMacro(vtkPartitionBalancer, vtkPartitionedDataSetAlgorithm);
  void PrintSelf(ostream& os, vtkIndent indent) override;

  ///@{
  /**
   * Get/Set the controller to use. By default
   * vtkMultiProcessController::GlobalController will be used.
   */
  void SetController(vtkMultiProcessController*);
  vtkGetObjectMacro(Controller, vtkMultiProcessController);
  ///@}

  /**
   * Modes defining the layout of the output.
   */
  enum Mode
  {
    Expand,
    Squash
  };

  ///@{
  /**
   * Set / Get current layout of the output. Default value is `vtkPartitionBalancer::Squash`.
   */
  vtkSetClampMacro(Mode, int, vtkPartitionBalancer::Expand, vtkPartitionBalancer::Squash);
  vtkGetMacro(Mode, int);
  ///@}

  /**
   * Sets filter to expand mode. See example below.
   *
   * @verbatim
   * Input:
   * rank 0: PDC [ PD (DS0, DS1,     DS2) ] [PD (nullptr, DS100) ]
   * rank 1: PDC [ PD (DS3, nullptr, DS4) ] [PD ()               ]
   *
   * Output:
   * rank 0: PDC [ PD (DS0,     DS1,     DS2,     nullptr, nullptr) ] [PD (DS100)   ]
   * rank 1: PDC [ PD (nullptr, nullptr, nullptr, DS3,     DS4)     ] [PD (nullptr) ]
   * @endverbatim
   */
  void SetModeToExpand() { this->SetMode(vtkPartitionBalancer::Expand); }

  /**
   * Sets filter to squash mode. See example below.
   *
   * @verbatim
   * Input:
   * rank 0: PDC [ PD (DS0, DS1,     DS2) ] [PD (nullptr, DS100) ]
   * rank 1: PDC [ PD (DS3, nullptr, DS4) ] [PD ()               ]
   *
   * Output:
   * rank 0: PDC [ PD (DS0, DS1, DS2)     ] [PD (DS100)   ]
   * rank 1: PDC [ PD (DS3, DS4, nullptr) ] [PD (nullptr) ]
   * @endverbatim
   */
  void SetModeToSquash() { this->SetMode(vtkPartitionBalancer::Squash); }

protected:
  vtkPartitionBalancer();
  ~vtkPartitionBalancer() override;

  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;

  /**
   * Local controller.
   */
  vtkMultiProcessController* Controller;

  int Mode;

private:
  vtkPartitionBalancer(const vtkPartitionBalancer&) = delete;
  void operator=(const vtkPartitionBalancer&) = delete;
};

VTK_ABI_NAMESPACE_END
#endif