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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
/**
* @class vtkRedistributeDataSetFilter
* @brief redistributes input dataset into requested number of partitions
*
* vtkRedistributeDataSetFilter is intended for redistributing data in a load
* balanced fashion.
*
* The filter allows users to pick how cells along the boundary of the cuts
* either automatically generated or explicitly specified are to be distributed
* using `BoundaryMode`. One can choose to assign those cells uniquely to one of
* those regions or duplicate then on all regions or split the cells (using
* vtkTableBasedClipDataSet filter). When cells are
* duplicated along the boundary, the filter will mark the duplicated cells as
* `vtkDataSetAttributes::DUPLICATECELL` correctly on all but one of the
* partitions using the ghost cell array (@sa `vtkDataSetAttributes::GhostArrayName`).
*
* @warning Generated duplicate ghost cells do not span entire layers of ghosts.
* They are sparse, only appearing where cells overlap at the new boundaries between
* partitions. If one wants to have full layers of ghost cells, one should use
* `vtkGhostCellsGenerator`.
*
* Besides redistributing the data, the filter can optionally generate global
* cell ids. This is provided since it relative easy to generate these
* on when it is known that the data is spatially partitioned as is the case
* after this filter has executed.
*
* @section vtkRedistributeDataSetFilter-SupportedDataTypes Supported Data Types
*
* vtkRedistributeDataSetFilter is primarily intended for unstructured datasets
* i.e. vtkUnstructuredGrid, vtkPolyData and composite datasets comprising of
* the same. It will work when applied to structured datasets as well, however,
* it results in conversion of the dataset to an unstructured grid -- which is
* often not suitable.
*
* For composite datasets, the filter supports `vtkPartitionedDataSet` and
* `vtkPartitionedDataSetCollection`. When input is a
* `vtkPartitionedDataSetCollection`, you can set `LoadBalanceAcrossAllBlocks`
* to true to build the load balancing KdTree using all vtkPartitionedDataSets
* in the collection. Default is load balance each `vtkPartitionedDataSet`
* separately.
*
* For `vtkMultiBlockDataSet`, the filter internally uses
* `vtkDataAssemblyUtilities` to convert the
* vtkMultiBlockDataSet to a vtkPartitionedDataSetCollection and back.
*/
#ifndef vtkRedistributeDataSetFilter_h
#define vtkRedistributeDataSetFilter_h
#include "vtkDataObjectAlgorithm.h"
#include "vtkFiltersParallelDIY2Module.h" // for export macros
#include "vtkPartitioningStrategy.h" // for PartitionInformation
#include "vtkSmartPointer.h" // for vtkSmartPointer
#include <memory> // for std::shared_ptr
#include <vector> // for std::vector
// clang-format off
#include "vtk_diy2.h" // for DIY2 APIs
#include VTK_DIY2(diy/assigner.hpp)
// clang-format on
VTK_ABI_NAMESPACE_BEGIN
class vtkMultiProcessController;
class vtkBoundingBox;
class vtkPartitionedDataSet;
class vtkMultiBlockDataSet;
class vtkMultiPieceDataSet;
class vtkDataObjectTree;
class VTKFILTERSPARALLELDIY2_EXPORT vtkRedistributeDataSetFilter : public vtkDataObjectAlgorithm
{
public:
static vtkRedistributeDataSetFilter* New();
vtkTypeMacro(vtkRedistributeDataSetFilter, vtkDataObjectAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Necessary to override this in order to take into account modifications to strategy
*/
vtkMTimeType GetMTime() override;
///@{
/**
* Get/Set the controller to use. By default
* vtkMultiProcessController::GlobalController will be used.
*/
void SetController(vtkMultiProcessController*);
vtkGetObjectMacro(Controller, vtkMultiProcessController);
///@}
enum BoundaryModes
{
ASSIGN_TO_ONE_REGION = 0,
ASSIGN_TO_ALL_INTERSECTING_REGIONS = 1,
SPLIT_BOUNDARY_CELLS = 2
};
///@{
/**
* Specify how cells on the boundaries are handled.
*
* \li `ASSIGN_TO_ONE_REGION` results in a cell on the boundary uniquely added
* to one of the ranks containing the region intersecting the cell.
* \li `ASSIGN_TO_ALL_INTERSECTING_REGIONS` results in a cell on the boundary
* added to all ranks containing the region intersecting the cell.
* \li `SPLIT_BOUNDARY_CELLS` results in cells along the boundary being
* clipped along the region boundaries.
*
* Default is `ASSIGN_TO_ONE_REGION`.
*/
vtkSetClampMacro(BoundaryMode, int, ASSIGN_TO_ONE_REGION, SPLIT_BOUNDARY_CELLS);
vtkGetMacro(BoundaryMode, int);
void SetBoundaryModeToAssignToOneRegion() { this->SetBoundaryMode(ASSIGN_TO_ONE_REGION); }
void SetBoundaryModeToAssignToAllIntersectingRegions()
{
this->SetBoundaryMode(ASSIGN_TO_ALL_INTERSECTING_REGIONS);
}
void SetBoundaryModeToSplitBoundaryCells() { this->SetBoundaryMode(SPLIT_BOUNDARY_CELLS); }
///@}
///@{
/**
* Specify whether to compute the load balancing automatically or use
* explicitly provided cuts. Set to false (default) to automatically compute
* the cuts to use for redistributing the dataset.
*/
void SetUseExplicitCuts(bool);
bool GetUseExplicitCuts() const;
vtkBooleanMacro(UseExplicitCuts, bool);
///@}
///@{
/**
* Specify the cuts to use when `UseExplicitCuts` is true.
*/
void SetExplicitCuts(const std::vector<vtkBoundingBox>& boxes);
const std::vector<vtkBoundingBox>& GetExplicitCuts() const;
void RemoveAllExplicitCuts();
void AddExplicitCut(const vtkBoundingBox& bbox);
void AddExplicitCut(const double bbox[6]);
int GetNumberOfExplicitCuts() const;
const vtkBoundingBox& GetExplicitCut(int index) const;
///@}
///@{
/**
* Specify the DIY assigner used for distributing cuts. If you use this API, you have to be
* careful and use an assigner matching your setup. For example, if you use explicit cuts (by
* calling SetExplicitCuts()), you want to assign all the cuts you provide.
*/
void SetAssigner(std::shared_ptr<diy::Assigner> assigner);
std::shared_ptr<diy::Assigner> GetAssigner();
std::shared_ptr<const diy::Assigner> GetAssigner() const;
///@{
/**
* When using explicit cuts, it possible that the bounding box defined by all
* the cuts is smaller than the input's bounds. In that case, the filter can
* automatically expand the edge boxes to include the input bounds to avoid
* clipping of the input dataset on the external faces of the combined
* bounding box.
*
* Default is true, that is explicit cuts will automatically be expanded.
*
*/
void SetExpandExplicitCuts(bool);
bool GetExpandExplicitCuts() const;
vtkBooleanMacro(ExpandExplicitCuts, bool);
///@}
///@{
/**
* Returns the cuts used by the most recent `RequestData` call. This is only
* valid after a successful `Update` request.
*/
const std::vector<vtkBoundingBox>& GetCuts() const;
///@}
///@{
/**
* Specify the number of partitions to split the input dataset into.
* Set to -1 to indicate that the partitions should match the number of
* ranks (processes) determined using vtkMultiProcessController provided.
* Setting to a non-zero positive number will result in the filter generating at
* least as many partitions.
*
* This is simply a hint and not an exact number of partitions the data will be
* split into.
*
* Default is -1.
*
* @sa PreservePartitionsInOutput
*/
void SetNumberOfPartitions(vtkIdType);
vtkIdType GetNumberOfPartitions() const;
///@}
///@{
/**
* When set to true (default is false), this filter will generate a vtkPartitionedDataSet as the
* output. The advantage of doing that is each partition that the input dataset was split
* into can be individually accessed. Otherwise, when the number of partitions generated is
* greater than the number of ranks, a rank with more than one partition will use
* `vtkAppendFilter` to merge the multiple partitions into a single unstructured grid.
*
* The output dataset type is always vtkUnstructuredGrid when
* PreservePartitionsInOutput is false and always a vtkPartitionedDataSet when
* PreservePartitionsInOutput is true.
*
* Default is false i.e. the filter will generate a single vtkUnstructuredGrid.
*/
vtkSetMacro(PreservePartitionsInOutput, bool);
vtkGetMacro(PreservePartitionsInOutput, bool);
vtkBooleanMacro(PreservePartitionsInOutput, bool);
///@}
///@{
/**
* Generate global cell ids if none present in the input. If global cell ids are present
* in the input then this flag is ignored. Default is true.
*/
vtkSetMacro(GenerateGlobalCellIds, bool);
vtkGetMacro(GenerateGlobalCellIds, bool);
vtkBooleanMacro(GenerateGlobalCellIds, bool);
///@}
///@{
/**
* Enable/disable debugging mode. In this mode internal arrays are preserved
* and ghost cells are not explicitly marked as such so that they can be inspected
* without risk of being dropped or removed by the pipeline.
*
* Default is false.
*/
vtkSetMacro(EnableDebugging, bool);
vtkGetMacro(EnableDebugging, bool);
vtkBooleanMacro(EnableDebugging, bool);
///@}
///@{
/**
* When UseExplicitCuts is false, and input is a
* `vtkPartitionedDataSetCollection`, set this to true to generate cuts for
* load balancing using all the datasets in the
* vtkPartitionedDataSetCollection.
*
* Default is true.
*/
void SetLoadBalanceAcrossAllBlocks(bool);
bool GetLoadBalanceAcrossAllBlocks();
vtkBooleanMacro(LoadBalanceAcrossAllBlocks, bool);
///@}
///@{
/**
* Setter/Getter for Strategy
*/
vtkPartitioningStrategy* GetStrategy();
void SetStrategy(vtkPartitioningStrategy*);
///@}
protected:
vtkRedistributeDataSetFilter();
~vtkRedistributeDataSetFilter() override;
int FillInputPortInformation(int port, vtkInformation* info) override;
int RequestDataObject(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
/*
* A method with this signature used to exist. With the refactoring of this filter to accept
* different partitioning strategies, this method no longer had any meaning in the generic
* sense.
*
* If you inherited this filter and overrid this method, please implement a new partitioning
* strategy instead.
*/
// virtual vtkSmartPointer<vtkPartitionedDataSet> SplitDataSet(
// vtkDataSet* dataset, const std::vector<vtkBoundingBox>& cuts);
private:
vtkRedistributeDataSetFilter(const vtkRedistributeDataSetFilter&) = delete;
void operator=(const vtkRedistributeDataSetFilter&) = delete;
/**
* This method is called to split a vtkDataSet into multiple datasets by the
* vector of partition information passed in. The returned vtkPartitionedDataSet
* must have exactly as many partitions as the number of information elements
* in the `info` vector.
*
* Note, this method may duplicate cells that lie on the boundaries and add cell
* arrays that indicate cell ownership and flag boundary cells.
*/
virtual vtkSmartPointer<vtkPartitionedDataSet> SplitDataSet(
vtkDataSet* dataset, const vtkPartitioningStrategy::PartitionInformation& info);
bool Redistribute(vtkPartitionedDataSetCollection* inputCollection,
vtkPartitionedDataSetCollection* outputCollection,
const std::vector<vtkPartitioningStrategy::PartitionInformation>& info,
bool preserve_input_hierarchy);
bool RedistributePTD(vtkPartitionedDataSet*, vtkPartitionedDataSet*,
const std::vector<vtkPartitioningStrategy::PartitionInformation>&, unsigned int*, vtkIdType*);
bool RedistributeDataSet(vtkDataSet* inputDS, vtkPartitionedDataSet* outputPDS,
const vtkPartitioningStrategy::PartitionInformation& info);
vtkSmartPointer<vtkDataSet> ClipDataSet(vtkDataSet* dataset, const vtkBoundingBox& bbox);
void MarkGhostCells(vtkPartitionedDataSet* pieces);
vtkSmartPointer<vtkPartitionedDataSet> AssignGlobalCellIds(
vtkPartitionedDataSet* input, vtkIdType* mb_offset = nullptr);
vtkSmartPointer<vtkDataSet> AssignGlobalCellIds(
vtkDataSet* input, vtkIdType* mb_offset = nullptr);
void MarkValidDimensions(const vtkBoundingBox& gbounds);
std::shared_ptr<diy::Assigner> Assigner;
vtkMultiProcessController* Controller;
int BoundaryMode;
bool PreservePartitionsInOutput;
bool GenerateGlobalCellIds;
bool EnableDebugging;
bool ValidDim[3];
vtkSmartPointer<vtkPartitioningStrategy> Strategy;
};
VTK_ABI_NAMESPACE_END
#endif
|