VTK-m  2.0
ComputeSuperarcDependentWeightsWorklet.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 // The PPP2 algorithm and software were jointly developed by
43 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
44 // Oliver Ruebel (LBNL)
45 //==============================================================================
46 
47 #ifndef vtk_m_worklet_contourtree_distributed_hierarchical_hyper_sweeper_compute_superarc_dependent_weights_worklet_h
48 #define vtk_m_worklet_contourtree_distributed_hierarchical_hyper_sweeper_compute_superarc_dependent_weights_worklet_h
49 
52 
53 namespace vtkm
54 {
55 namespace worklet
56 {
57 namespace contourtree_distributed
58 {
59 namespace hierarchical_hyper_sweeper
60 {
61 
64 template <typename FieldType>
66 {
67 public:
68  using ControlSignature = void(
69  FieldIn supernodeIndex, // counting index [firstSupernode, lastSupernode)
70  FieldIn
71  hierarchicalTreeSuperarcsView, // view of hierarchicalTree.Superarcs[firstSupernode, lastSupernode)
72  FieldIn
73  hierarchicalTreeHyperparentsView, // view of hierarchicalTree.Hyperparents[firstSupernode, lastSupernode)
74  WholeArrayIn hierarchicalTreeHypernodes, // whole hierarchicalTree.Hypernodes array
75  WholeArrayIn valuePrefixSum, // whole valuePrefixSum array
76  FieldInOut dependentValuesView // output view of dependentValues[firstSupernode, lastSupernode)
77  );
78  using ExecutionSignature = void(_1, _2, _3, _4, _5, _6);
79 
80  // Default Constructor
83  const vtkm::Id& round,
84  const vtkm::Id& hierarchicalTreeNumRounds)
85  : FirstSupernode(firstSupernode)
86  , Round(round)
87  , HierarchicalTreeNumRounds(hierarchicalTreeNumRounds)
88  {
89  }
90 
91  template <typename InFieldPortalType>
93  const vtkm::Id& supernode,
94  const vtkm::Id& superarcTo, // same as hierarchicalTree.superarcs[supernode];
95  const vtkm::Id& hyperparent, // same as hierarchicalTree.hyperparents[supernode];
96  const InFieldPortalType& hierarchicalTreeHypernodesPortal,
97  const InFieldPortalType& valuePrefixSumPortal,
98  vtkm::Id& dependentValue) const
99  {
100  // per supernode
101  // if there is no superarc, it is either the root of the tree or an attachment point
103  { // null superarc
104  // next we test for whether it is the global root
105  if (this->Round == this->HierarchicalTreeNumRounds)
106  { // global root
107  // this is guaranteed to be the only element in it's iteration
108  // so the prefix sum is good as it stands
109  dependentValue = valuePrefixSumPortal.Get(supernode);
110  } // global root
111  else
112  { // attachment point
113  // could be the first in the iteration, in which case it is correct
114  if (supernode == this->FirstSupernode)
115  {
116  dependentValue = valuePrefixSumPortal.Get(supernode);
117  }
118  // otherwise, we are guaranteed that it's a length one chain, so subtract predecessor
119  else
120  {
121  dependentValue =
122  valuePrefixSumPortal.Get(supernode) - valuePrefixSumPortal.Get(supernode - 1);
123  }
124  } // attachment point
125  } // null superarc
126  else
127  { // actual superarc
128  // use the hyperparent to find the hypernode at the beginning of the chain
129  vtkm::Id hyperparentSuperId = hierarchicalTreeHypernodesPortal.Get(hyperparent);
130 
131  // now we check to see which value we subtract
132  FieldType baseValue = 0;
133  if (hyperparentSuperId != this->FirstSupernode)
134  {
135  baseValue = valuePrefixSumPortal.Get(hyperparentSuperId - 1);
136  }
137  // for all others, remove the hyperparent's prefix sum to get the "relative" prefix sum
138  dependentValue = valuePrefixSumPortal.Get(supernode) - baseValue;
139  } // actual superarc
140 
141  // In serial this worklet implements the following operation
142  /*
143  for (vtkm::Id supernode = firstSupernode; supernode < lastSupernode; supernode++)
144  { // per supernode
145  // we need to know the superarc first
146  vtkm::Id superarcTo = hierarchicalTree.superarcs[supernode];
147 
148  // if there is no superarc, it is either the root of the tree or an attachment point
149  if (noSuchElement(superarcTo))
150  { // null superarc
151  // next we test for whether it is the global root
152  if (round == hierarchicalTree.nRounds)
153  { // global root
154  // this is guaranteed to be the only element in it's iteration
155  // so the prefix sum is good as it stands
156  dependentValues[supernode] = valuePrefixSum[supernode];
157  } // global root
158  else
159  { // attachment point
160  // could be the first in the iteration, in which case it is correct
161  if (supernode == firstSupernode)
162  dependentValues[supernode] = valuePrefixSum[supernode];
163  // otherwise, we are guaranteed that it's a length one chain, so subtract predecessor
164  else
165  dependentValues[supernode] = valuePrefixSum[supernode] - valuePrefixSum[supernode-1];
166  } // attachment point
167  } // null superarc
168  else
169  { // actual superarc
170  // use the hyperparent to find the hypernode at the beginning of the chain
171  vtkm::Id hyperparent = hierarchicalTree.hyperparents[supernode];
172  vtkm::Id hyperparentSuperId = hierarchicalTree.hypernodes[hyperparent];
173 
174  // now we check to see which value we subtract
175  dataType baseValue = 0;
176  if (hyperparentSuperId != firstSupernode)
177  baseValue = valuePrefixSum[hyperparentSuperId - 1];
178 
179  // for all others, remove the hyperparent's prefix sum to get the "relative" prefix sum
180  dependentValues[supernode] = valuePrefixSum[supernode] - baseValue;
181  } // actual superarc
182  } // per supernode
183  */
184  } // operator()()
185 
186 private:
190 
191 }; // ComputeSuperarcDependentWeightsWorklet
192 
193 } // namespace hierarchical_hyper_sweeper
194 } // namespace contourtree_distributed
195 } // namespace worklet
196 } // namespace vtkm
197 
198 #endif
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::ComputeSuperarcDependentWeightsWorklet
VTKM_EXEC_CONT ComputeSuperarcDependentWeightsWorklet(const vtkm::Id &firstSupernode, const vtkm::Id &round, const vtkm::Id &hierarchicalTreeNumRounds)
Definition: ComputeSuperarcDependentWeightsWorklet.h:82
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
WorkletMapField.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::ExecutionSignature
void(_1, _2, _3, _4, _5, _6) ExecutionSignature
Definition: ComputeSuperarcDependentWeightsWorklet.h:78
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::HierarchicalTreeNumRounds
const vtkm::Id HierarchicalTreeNumRounds
Definition: ComputeSuperarcDependentWeightsWorklet.h:189
vtkm::worklet::contourtree_augmented::NoSuchElement
VTKM_EXEC_CONT bool NoSuchElement(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:97
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet
Worklet used in HierarchicalHyperSweeper.ComputeSuperarcDependentWeightsWorklet(.....
Definition: ComputeSuperarcDependentWeightsWorklet.h:65
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::Round
const vtkm::Id Round
Definition: ComputeSuperarcDependentWeightsWorklet.h:188
Types.h
vtkm::worklet::WorkletMapField::FieldInOut
A control signature tag for input-output (in-place) fields.
Definition: WorkletMapField.h:71
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Id &supernode, const vtkm::Id &superarcTo, const vtkm::Id &hyperparent, const InFieldPortalType &hierarchicalTreeHypernodesPortal, const InFieldPortalType &valuePrefixSumPortal, vtkm::Id &dependentValue) const
Definition: ComputeSuperarcDependentWeightsWorklet.h:92
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::FirstSupernode
const vtkm::Id FirstSupernode
Definition: ComputeSuperarcDependentWeightsWorklet.h:187
vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::ComputeSuperarcDependentWeightsWorklet::ControlSignature
void(FieldIn supernodeIndex, FieldIn hierarchicalTreeSuperarcsView, FieldIn hierarchicalTreeHyperparentsView, WholeArrayIn hierarchicalTreeHypernodes, WholeArrayIn valuePrefixSum, FieldInOut dependentValuesView) ControlSignature
Definition: ComputeSuperarcDependentWeightsWorklet.h:77
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38