VTK-m  2.0
MultiBlockContourTreeHelper.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 // Copyright (c) 2018, The Regents of the University of California, through
11 // Lawrence Berkeley National Laboratory (subject to receipt of any required approvals
12 // from the U.S. Dept. of Energy). All rights reserved.
13 //
14 // Redistribution and use in source and binary forms, with or without modification,
15 // are permitted provided that the following conditions are met:
16 //
17 // (1) Redistributions of source code must retain the above copyright notice, this
18 // list of conditions and the following disclaimer.
19 //
20 // (2) Redistributions in binary form must reproduce the above copyright notice,
21 // this list of conditions and the following disclaimer in the documentation
22 // and/or other materials provided with the distribution.
23 //
24 // (3) Neither the name of the University of California, Lawrence Berkeley National
25 // Laboratory, U.S. Dept. of Energy nor the names of its contributors may be
26 // used to endorse or promote products derived from this software without
27 // specific prior written permission.
28 //
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
36 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
38 // OF THE POSSIBILITY OF SUCH DAMAGE.
39 //
40 //=============================================================================
41 //
42 // This code is an extension of the algorithm presented in the paper:
43 // Parallel Peak Pruning for Scalable SMP Contour Tree Computation.
44 // Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
45 // Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
46 // (LDAV), October 2016, Baltimore, Maryland.
47 //
48 // The PPP2 algorithm and software were jointly developed by
49 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
50 // Oliver Ruebel (LBNL)
51 //==============================================================================
52 
53 #ifndef vtk_m_worklet_contourtree_distributed_multiblockcontourtreehelper_h
54 #define vtk_m_worklet_contourtree_distributed_multiblockcontourtreehelper_h
55 
58 
59 #include <vtkm/Types.h>
65 
66 namespace vtkm
67 {
68 namespace worklet
69 {
70 namespace contourtree_distributed
71 {
72 
73 //--- Helper class to help with the contstuction of the GlobalContourTree
75 {
76 public:
77  VTKM_CONT
79  const vtkm::cont::ArrayHandle<vtkm::Id3>& localBlockIndices)
80  : BlocksPerDimension(blocksPerDim)
81  , LocalBlockIndices(localBlockIndices)
82  , LocalContourTrees(static_cast<size_t>(localBlockIndices.GetNumberOfValues()))
83  , LocalSortOrders(static_cast<size_t>(localBlockIndices.GetNumberOfValues()))
84  {
85  }
86 
87  VTKM_CONT
89  : BlocksPerDimension(-1, -1, -1)
91  , LocalContourTrees(static_cast<size_t>(input.GetNumberOfPartitions()))
92  , LocalSortOrders(static_cast<size_t>(input.GetNumberOfPartitions()))
93  {
94  }
95 
96  VTKM_CONT
98  {
99  // FIXME: This shouldn't be necessary as arrays will get deleted anyway
100  LocalContourTrees.clear();
101  LocalSortOrders.clear();
102  }
103 
105  {
106  // Get the spatial bounds of a multi -block data set
108  return bounds;
109  }
110 
112  {
113  // Get the spatial bounds of a multi -block data set
114  vtkm::Bounds bounds = vtkm::cont::BoundsCompute(input);
115  return bounds;
116  }
117 
119  {
120  return static_cast<vtkm::Id>(this->LocalContourTrees.size());
121  }
122 
124  {
125  return this->BlocksPerDimension[0] * this->BlocksPerDimension[1] * this->BlocksPerDimension[2];
126  }
127 
128  // Used to compute the local contour tree mesh in after DoExecute. I.e., the function is
129  // used in PostExecute to construct the initial set of local ContourTreeMesh blocks for
130  // DIY. Subsequent construction of updated ContourTreeMeshes is handled separately.
131  template <typename T>
133  ComputeLocalContourTreeMesh(const vtkm::Id3 localBlockOrigin,
134  const vtkm::Id3 localBlockSize,
135  const vtkm::Id3 globalSize,
136  const vtkm::cont::ArrayHandle<T>& field,
139  unsigned int computeRegularStructure)
140 
141  {
142  // compute the global mesh index and initalize the local contour tree mesh
143  if (computeRegularStructure == 1)
144  {
145  // Compute the global mesh index
147  auto transformedIndex = vtkm::cont::ArrayHandleTransform<
150  sortOrder,
152  localBlockOrigin, localBlockSize, globalSize));
153  vtkm::cont::Algorithm::Copy(transformedIndex, localGlobalMeshIndex);
154  // Compute the local contour tree mesh
155  auto localContourTreeMesh = new vtkm::worklet::contourtree_augmented::ContourTreeMesh<T>(
156  contourTree.Arcs, sortOrder, field, localGlobalMeshIndex);
157  return localContourTreeMesh;
158  }
159  else if (computeRegularStructure == 2)
160  {
161  // Compute the global mesh index for the partially augmented contour tree. I.e., here we
162  // don't need the global mesh index for all nodes, but only for the augmented nodes from the
163  // tree. We, hence, permute the sortOrder by contourTree.augmentednodes and then compute the
164  // GlobalMeshIndex by tranforming those indices with our IdRelabler
168  permutedSortOrder(contourTree.Augmentnodes, sortOrder);
169  auto transformedIndex = vtkm::cont::make_ArrayHandleTransform(
170  permutedSortOrder,
172  localBlockOrigin, localBlockSize, globalSize));
173  vtkm::cont::Algorithm::Copy(transformedIndex, localGlobalMeshIndex);
174  // Compute the local contour tree mesh
175  auto localContourTreeMesh = new vtkm::worklet::contourtree_augmented::ContourTreeMesh<T>(
176  contourTree.Augmentnodes, contourTree.Augmentarcs, sortOrder, field, localGlobalMeshIndex);
177  return localContourTreeMesh;
178  }
179  else
180  {
181  // We should not be able to get here
183  "Parallel contour tree requires at least parial boundary augmentation");
184  }
185  }
186 
189  std::vector<vtkm::worklet::contourtree_augmented::ContourTree> LocalContourTrees;
190  std::vector<vtkm::worklet::contourtree_augmented::IdArrayType> LocalSortOrders;
191 }; // end MultiBlockContourTreeHelper
192 
193 } // namespace contourtree_distributed
194 } // namespace worklet
195 } // namespace vtkm
196 
197 #endif
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::GetLocalNumberOfBlocks
vtkm::Id GetLocalNumberOfBlocks() const
Definition: MultiBlockContourTreeHelper.h:118
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::BlocksPerDimension
vtkm::Id3 BlocksPerDimension
Definition: MultiBlockContourTreeHelper.h:187
vtkm::worklet::contourtree_augmented::ContourTree
Definition: augmented/ContourTree.h:106
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::MultiBlockContourTreeHelper
VTKM_CONT MultiBlockContourTreeHelper(const vtkm::cont::PartitionedDataSet &input)
Definition: MultiBlockContourTreeHelper.h:88
BoundsGlobalCompute.h
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::~MultiBlockContourTreeHelper
VTKM_CONT ~MultiBlockContourTreeHelper(void)
Definition: MultiBlockContourTreeHelper.h:97
vtkm::cont::ErrorFilterExecution
This class is primarily intended to filters to throw in the control environment to indicate an execut...
Definition: ErrorFilterExecution.h:27
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper
Definition: MultiBlockContourTreeHelper.h:74
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::LocalContourTrees
std::vector< vtkm::worklet::contourtree_augmented::ContourTree > LocalContourTrees
Definition: MultiBlockContourTreeHelper.h:189
vtkm::cont::Algorithm::Copy
static VTKM_CONT bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:410
BoundsCompute.h
ErrorFilterExecution.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh
Definition: ContourTreeMesh.h:129
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_augmented::ContourTree::Augmentarcs
IdArrayType Augmentarcs
Definition: augmented/ContourTree.h:133
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::LocalSortOrders
std::vector< vtkm::worklet::contourtree_augmented::IdArrayType > LocalSortOrders
Definition: MultiBlockContourTreeHelper.h:190
IdRelabeler.h
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::GetLocalBounds
static vtkm::Bounds GetLocalBounds(const vtkm::cont::PartitionedDataSet &input)
Definition: MultiBlockContourTreeHelper.h:111
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::LocalBlockIndices
vtkm::cont::ArrayHandle< vtkm::Id3 > LocalBlockIndices
Definition: MultiBlockContourTreeHelper.h:188
ContourTreeMesh.h
vtkm::cont::make_ArrayHandleTransform
VTKM_CONT vtkm::cont::ArrayHandleTransform< HandleType, FunctorType > make_ArrayHandleTransform(HandleType handle, FunctorType functor)
make_ArrayHandleTransform is convenience function to generate an ArrayHandleTransform.
Definition: ArrayHandleTransform.h:474
vtkm::cont::ArrayHandlePermutation
Implicitly permutes the values in an array.
Definition: ArrayHandlePermutation.h:227
vtkm::worklet::contourtree_augmented::IdArrayType
vtkm::cont::ArrayHandle< vtkm::Id > IdArrayType
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:90
Types.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandleTransform
Implicitly transform values of one array to another with a functor.
Definition: ArrayHandleTransform.h:437
vtkm::Bounds
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler
A utility class that converts Ids from local to global given a mesh.
Definition: IdRelabeler.h:79
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::MultiBlockContourTreeHelper
VTKM_CONT MultiBlockContourTreeHelper(vtkm::Id3 blocksPerDim, const vtkm::cont::ArrayHandle< vtkm::Id3 > &localBlockIndices)
Definition: MultiBlockContourTreeHelper.h:78
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::GetGlobalNumberOfBlocks
vtkm::Id GetGlobalNumberOfBlocks() const
Definition: MultiBlockContourTreeHelper.h:123
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::ComputeLocalContourTreeMesh
static vtkm::worklet::contourtree_augmented::ContourTreeMesh< T > * ComputeLocalContourTreeMesh(const vtkm::Id3 localBlockOrigin, const vtkm::Id3 localBlockSize, const vtkm::Id3 globalSize, const vtkm::cont::ArrayHandle< T > &field, const vtkm::worklet::contourtree_augmented::ContourTree &contourTree, const vtkm::worklet::contourtree_augmented::IdArrayType &sortOrder, unsigned int computeRegularStructure)
Definition: MultiBlockContourTreeHelper.h:133
PartitionedDataSet.h
vtkm::worklet::contourtree_augmented::ContourTree::Arcs
IdArrayType Arcs
Definition: augmented/ContourTree.h:115
vtkm::cont::BoundsGlobalCompute
VTKM_CONT_EXPORT VTKM_CONT vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::DataSet &dataset, vtkm::Id coordinate_system_index=0)
Functions to compute bounds for a single dataset or partitioned dataset globally.
vtkm::cont::BoundsCompute
VTKM_CONT_EXPORT VTKM_CONT vtkm::Bounds BoundsCompute(const vtkm::cont::DataSet &dataset, vtkm::Id coordinate_system_index=0)
Functions to compute bounds for a single dataSset or partition dataset.
vtkm::worklet::contourtree_distributed::MultiBlockContourTreeHelper::GetGlobalBounds
static vtkm::Bounds GetGlobalBounds(const vtkm::cont::PartitionedDataSet &input)
Definition: MultiBlockContourTreeHelper.h:104
vtkm::cont::PartitionedDataSet
Definition: PartitionedDataSet.h:25
vtkm::worklet::contourtree_augmented::ContourTree::Augmentnodes
IdArrayType Augmentnodes
Definition: augmented/ContourTree.h:132