VTK-m  2.0
IdentifyLeafHyperarcsWorklet.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_tree_grafter_identify_leaf_hyperarcs_worklet_h
54 #define vtk_m_worklet_contourtree_distributed_tree_grafter_identify_leaf_hyperarcs_worklet_h
55 
56 
59 
60 namespace vtkm
61 {
62 namespace worklet
63 {
64 namespace contourtree_distributed
65 {
66 namespace tree_grafter
67 {
68 
86 {
87 public:
88  using ControlSignature = void(
89  FieldIn
90  activeSuperarcs, // input iteration index. loop to one less than ContourTree->Supernodes.GetNumberOfValues()
91  WholeArrayIn supernodeType, // input
92  WholeArrayIn upNeighbour, // input
93  WholeArrayIn downNeighbour, // input
94  WholeArrayOut hierarchicalHyperparent, //output
95  WholeArrayOut hierarchicalHyperarcPortal, // output
96  WholeArrayOut whenTransferredPortal // output
97  );
98 
99  using ExecutionSignature = void(_1, _2, _3, _4, _5, _6, _7);
100  using InputDomain = _1;
101 
102  // Default Constructor
104  IdentifyLeafHyperarcsWorklet(const vtkm::Id& numTransferIterations)
105  : NumTransferIterations(numTransferIterations)
106  {
107  }
108 
109  template <typename InFieldPortalType, typename OutFieldPortalType>
111  const InFieldPortalType supernodeTypePortal,
112  const InFieldPortalType upNeighbourPortal,
113  const InFieldPortalType downNeighbourPortal,
114  const OutFieldPortalType& hierarchicalHyperparentPortal,
115  const OutFieldPortalType& hierarchicalHyperarcPortal,
116  const OutFieldPortalType& whenTransferredPortal) const
117  { // operator ()
118  // per active superarc
119  // retrieve the supernode IDs for the two ends
120  vtkm::Id low = activeSuperarc.first;
121  vtkm::Id high = activeSuperarc.second;
122 
123  // test whether the top end is an upper leaf
124  switch (supernodeTypePortal.Get(high))
125  { // switch on upper end
127  { // upper end is a leaf
128  // in lower leaf rounds, never recognise these
129  hierarchicalHyperparentPortal.Set(high, high);
130  hierarchicalHyperarcPortal.Set(
131  high, vtkm::worklet::contourtree_augmented::MaskedIndex(downNeighbourPortal.Get(high)));
132  whenTransferredPortal.Set(
134  break;
135  } // upper end is a leaf
137  { // upper end is regular
138  // notice that this is redundant, so will be set from both arcs
139  // this is parallel safe, because it sets the same value anyway
140  // testing would be more complex
141  // find the up & down neighbours
142  vtkm::Id upNbr =
143  vtkm::worklet::contourtree_augmented::MaskedIndex(upNeighbourPortal.Get(high));
144  vtkm::Id downNbr =
145  vtkm::worklet::contourtree_augmented::MaskedIndex(downNeighbourPortal.Get(high));
146 
147  // test the up neighbour first for leaf-hood
148  // but only if the corresponding flag is true
149  if (supernodeTypePortal.Get(upNbr) ==
151  { // up neighbour is an upper leaf
152  hierarchicalHyperparentPortal.Set(high, upNbr);
153  whenTransferredPortal.Set(high,
154  this->NumTransferIterations |
156  } // up neighbour is an upper leaf
157  // then the down neighbour (cannot both be true)
158  else if (supernodeTypePortal.Get(downNbr) ==
160  { // down neighbour is a lower leaf
161  hierarchicalHyperparentPortal.Set(high, downNbr);
162  whenTransferredPortal.Set(high,
163  this->NumTransferIterations |
165  } // down neighbour is a lower leaf
166  break;
167  } // case: upper end is regular
168  // all other cases do nothing
172  default:
173  break;
174  } // switch on upper end
175 
176  // test whether the bottom end is a lower leaf
177  switch (supernodeTypePortal.Get(low))
178  { // switch on lower end
180  { // lower end is a leaf
181  hierarchicalHyperparentPortal.Set(low, low);
182  hierarchicalHyperarcPortal.Set(
183  low,
184  vtkm::worklet::contourtree_augmented::MaskedIndex(upNeighbourPortal.Get(low)) |
186  whenTransferredPortal.Set(low,
187  this->NumTransferIterations |
189  break;
190  } // lower end is a leaf
192  { // lower end is regular
193  // notice that this is redundant, so will be set from both arcs
194  // this is parallel safe, because it sets the same value anyway
195  // testing would be more complex
196  // find the up & down neighbours
197  vtkm::Id upNbr =
198  vtkm::worklet::contourtree_augmented::MaskedIndex(upNeighbourPortal.Get(low));
199  vtkm::Id downNbr =
200  vtkm::worklet::contourtree_augmented::MaskedIndex(downNeighbourPortal.Get(low));
201 
202  // test the up neighbour first for leaf-hood
203  if (supernodeTypePortal.Get(upNbr) ==
205  { // up neighbour is an upper leaf
206  hierarchicalHyperparentPortal.Set(low, upNbr);
207  whenTransferredPortal.Set(low,
208  this->NumTransferIterations |
210  } // up neighbour is an upper leaf
211  // then the down neighbour (cannot both be true)
212  else if (supernodeTypePortal.Get(downNbr) ==
214  { // down neighbour is a lower leaf
215  hierarchicalHyperparentPortal.Set(low, downNbr);
216  whenTransferredPortal.Set(low,
217  this->NumTransferIterations |
219  } // down neighbour is a lower leaf
220  break;
221  } // lower end is regular
222  // all other cases do nothing
226  default:
227  break;
228  } // switch on lower end
229 
230  // In serial this worklet implements the following operation
231  /*
232  #pragma omp parallel for
233  for (indexType activeSuper = 0; activeSuper < activeSuperarcs.size(); activeSuper++)
234  { // per active superarc
235  // retrieve the supernode IDs for the two ends
236  indexType low = activeSuperarcs[activeSuper].low;
237  indexType high = activeSuperarcs[activeSuper].high;
238 
239  // test whether the top end is an upper leaf
240  switch (supernodeType[high])
241  { // switch on upper end
242  case IS_UPPER_LEAF:
243  { // upper end is a leaf
244  // in lower leaf rounds, never recognise these
245  hierarchicalHyperparent[high] = high;
246  hierarchicalHyperarc[high] = maskedIndex(downNeighbour[high]);
247  whenTransferred[high] = nTransferIterations | IS_HYPERNODE;
248  break;
249  } // upper end is a leaf
250  case IS_REGULAR:
251  { // upper end is regular
252  // notice that this is redundant, so will be set from both arcs
253  // this is parallel safe, because it sets the same value anyway
254  // testing would be more complex
255  // find the up & down neighbours
256  indexType upNbr = maskedIndex(upNeighbour[high]);
257  indexType downNbr = maskedIndex(downNeighbour[high]);
258 
259  // test the up neighbour first for leaf-hood
260  // but only if the corresponding flag is true
261  if (supernodeType[upNbr] == IS_UPPER_LEAF)
262  { // up neighbour is an upper leaf
263  hierarchicalHyperparent[high] = upNbr;
264  whenTransferred[high] = nTransferIterations | IS_SUPERNODE;
265  } // up neighbour is an upper leaf
266  // then the down neighbour (cannot both be true)
267  else if (supernodeType[downNbr] == IS_LOWER_LEAF)
268  { // down neighbour is a lower leaf
269  hierarchicalHyperparent[high] = downNbr;
270  whenTransferred[high] = nTransferIterations | IS_SUPERNODE;
271  } // down neighbour is a lower leaf
272  break;
273  } // upper end is regular
274  // all other cases do nothing
275  case IS_SADDLE:
276  case IS_ATTACHMENT:
277  case IS_LOWER_LEAF:
278  default:
279  break;
280  } // switch on upper end
281 
282  // test whether the bottom end is a lower leaf
283  switch (supernodeType[low])
284  { // switch on lower end
285  case IS_LOWER_LEAF:
286  { // lower end is a leaf
287  hierarchicalHyperparent[low] = low;
288  hierarchicalHyperarc[low] = maskedIndex(upNeighbour[low]) | IS_ASCENDING;
289  whenTransferred[low] = nTransferIterations | IS_HYPERNODE;
290  break;
291  } // lower end is a leaf
292  case IS_REGULAR:
293  { // lower end is regular
294  // notice that this is redundant, so will be set from both arcs
295  // this is parallel safe, because it sets the same value anyway
296  // testing would be more complex
297  // find the up & down neighbours
298  indexType upNbr = maskedIndex(upNeighbour[low]);
299  indexType downNbr = maskedIndex(downNeighbour[low]);
300 
301  // test the up neighbour first for leaf-hood
302  if (supernodeType[upNbr] == IS_UPPER_LEAF)
303  { // up neighbour is an upper leaf
304  hierarchicalHyperparent[low] = upNbr;
305  whenTransferred[low] = nTransferIterations | IS_SUPERNODE;
306  } // up neighbour is an upper leaf
307  // then the down neighbour (cannot both be true)
308  else if (supernodeType[downNbr] == IS_LOWER_LEAF)
309  { // down neighbour is a lower leaf
310  hierarchicalHyperparent[low] = downNbr;
311  whenTransferred[low] = nTransferIterations | IS_SUPERNODE;
312  } // down neighbour is a lower leaf
313  break;
314  } // lower end is regular
315  // all other cases do nothing
316  case IS_SADDLE:
317  case IS_ATTACHMENT:
318  case IS_UPPER_LEAF:
319  default:
320  break;
321  } // switch on lower end
322  } // per active superarc
323  */
324  } // operator ()
325 
326 private:
328 
329 }; // IdentifyLeafHyperarcsWorklet
330 
331 } // namespace tree_grafter
332 } // namespace contourtree_distributed
333 } // namespace worklet
334 } // namespace vtkm
335 
336 #endif
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::worklet::contourtree_augmented::IS_SADDLE
constexpr vtkm::Id IS_SADDLE
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:86
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet::ControlSignature
void(FieldIn activeSuperarcs, WholeArrayIn supernodeType, WholeArrayIn upNeighbour, WholeArrayIn downNeighbour, WholeArrayOut hierarchicalHyperparent, WholeArrayOut hierarchicalHyperarcPortal, WholeArrayOut whenTransferredPortal) ControlSignature
Definition: IdentifyLeafHyperarcsWorklet.h:97
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet
Worklet implementing the TreeGrafter.IdentifyLeafHyperarcs function.
Definition: IdentifyLeafHyperarcsWorklet.h:85
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet::IdentifyLeafHyperarcsWorklet
VTKM_EXEC_CONT IdentifyLeafHyperarcsWorklet(const vtkm::Id &numTransferIterations)
Definition: IdentifyLeafHyperarcsWorklet.h:104
vtkm::worklet::contourtree_augmented::MaskedIndex
VTKM_EXEC_CONT vtkm::Id MaskedIndex(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:127
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet::InputDomain
_1 InputDomain
Definition: IdentifyLeafHyperarcsWorklet.h:100
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:50
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet::ExecutionSignature
void(_1, _2, _3, _4, _5, _6, _7) ExecutionSignature
Definition: IdentifyLeafHyperarcsWorklet.h:99
Types.h
vtkm::worklet::contourtree_augmented::IS_LOWER_LEAF
constexpr vtkm::Id IS_LOWER_LEAF
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:83
vtkm::worklet::contourtree_augmented::IS_SUPERNODE
constexpr vtkm::Id IS_SUPERNODE
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:75
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet::operator()
VTKM_EXEC void operator()(const vtkm::worklet::contourtree_augmented::EdgePair &activeSuperarc, const InFieldPortalType supernodeTypePortal, const InFieldPortalType upNeighbourPortal, const InFieldPortalType downNeighbourPortal, const OutFieldPortalType &hierarchicalHyperparentPortal, const OutFieldPortalType &hierarchicalHyperarcPortal, const OutFieldPortalType &whenTransferredPortal) const
Definition: IdentifyLeafHyperarcsWorklet.h:110
vtkm::worklet::contourtree_augmented::IS_ASCENDING
constexpr vtkm::Id IS_ASCENDING
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:77
vtkm::worklet::contourtree_augmented::IS_UPPER_LEAF
constexpr vtkm::Id IS_UPPER_LEAF
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:84
vtkm::worklet::contourtree_augmented::IS_REGULAR
constexpr vtkm::Id IS_REGULAR
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:85
vtkm::worklet::contourtree_augmented::IS_ATTACHMENT
constexpr vtkm::Id IS_ATTACHMENT
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:87
vtkm::worklet::contourtree_distributed::tree_grafter::IdentifyLeafHyperarcsWorklet::NumTransferIterations
vtkm::Id NumTransferIterations
Definition: IdentifyLeafHyperarcsWorklet.h:327
vtkm::Pair
A vtkm::Pair is essentially the same as an STL pair object except that the methods (constructors and ...
Definition: Pair.h:29
vtkm::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:55
vtkm::worklet::contourtree_augmented::IS_HYPERNODE
constexpr vtkm::Id IS_HYPERNODE
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:76
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38