VTK-m  2.0
CopyNewNodesSetSuperparentsWorklet.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_copy_new_nodes_set_superparents_worklet_h
54 #define vtk_m_worklet_contourtree_distributed_tree_grafter_copy_new_nodes_set_superparents_worklet_h
55 
56 
59 
60 namespace vtkm
61 {
62 namespace worklet
63 {
64 namespace contourtree_distributed
65 {
66 namespace tree_grafter
67 {
68 
69 // Worklet implementing the sorting out the superparents as part of TreeGrafter::CopyNewNodes
71 {
72 public:
73  // TODO: Some WholeArrayIn could potentially be made FieldIn if we reshuffeled the arrays via newNodes beforehand
74  using ControlSignature = void(FieldIn newNodes, // input and iteration index
75  WholeArrayIn meshSortIndex, // input
76  WholeArrayIn meshSortOrder, // input
77  WholeArrayIn contourTreeSuperparents, // input
78  WholeArrayIn contourTreeSuperarcs, // input
79  WholeArrayIn contourTreeSupernodes, // input
80  WholeArrayIn hierarchicalRegularId, // input
81  WholeArrayIn hierarchicalTreeId, // input
82  WholeArrayIn hierarchicalTreeRegularNodeGlobalIds, // input
83  WholeArrayIn hierarchicalTreeDataValues, // input
84  ExecObject findSuperArcForUnknownNode, // input
85  WholeArrayOut hierarchicalTreeSuperparents // output
86  );
87 
88  using ExecutionSignature = void(InputIndex, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12);
89  using InputDomain = _1;
90 
91  // Default Constructor
94  : NumOldNodes(numOldNodes)
95  {
96  }
97 
98  template <typename InFieldPortalType,
99  typename MeshSortIndexPortalType,
100  typename MeshSortOrderPortalType,
101  typename DataValuePortalType,
102  typename FindSuperExecType,
103  typename OutFieldPortalType>
105  const vtkm::Id& newNode,
106  const vtkm::Id&
107  oldNodeId, // convert to a node Id in the current level's tree when calling the worklet
108  const MeshSortIndexPortalType& meshSortIndexPortal,
109  const MeshSortOrderPortalType& meshSortOrderPortal,
110  const InFieldPortalType& contourTreeSuperparentsPortal,
111  const InFieldPortalType& contourTreeSuperarcsPortal,
112  const InFieldPortalType& contourTreeSupernodesPortal,
113  const InFieldPortalType& hierarchicalRegularIdPortal,
114  const InFieldPortalType& hierarchicalTreeIdPortal,
115  const InFieldPortalType& hierarchicalTreeRegularNodeGlobalIdsPortal,
116  const DataValuePortalType& hierarchicalTreeDataValuesPortal,
117  const FindSuperExecType& findSuperArcForUnknownNode,
118  const OutFieldPortalType& hierarchicalTreeSuperparentsPortal
119 
120  ) const
121  { // operator ()
122  // per new node
123  // index into hierarchical tree
124  vtkm::Id newNodeId = this->NumOldNodes + newNode;
125  // retrieve the old parent superarc
126  vtkm::Id oldSortIndex = meshSortIndexPortal.Get(oldNodeId);
127  vtkm::Id oldSuperparent = contourTreeSuperparentsPortal.Get(oldSortIndex);
128  // and to a regular Id
129  vtkm::Id oldSuperparentNewRegularId = hierarchicalRegularIdPortal.Get(oldSuperparent);
130 
131  // Assuming that the new supernodes & hypernodes have been transferred, EVERY supernode in the old tree
132  // now has hierarchicalRegularId set correctly. Since every regular node belongs on a superarc in the old tree,
133  // we can use the ends of the superarc to invoke a search in the hierarchical tree for the superparent.
134  // This is therefore logically dependent on having the superstructure & hyperstructure updated first
135 
136  // supernodes will already have their superparent set in CopyNewSupernodes()
138  hierarchicalTreeSuperparentsPortal.Get(newNodeId)))
139  { // it's not a supernode
140  // retrieve the end of the superarc & convert to hierarchical regular Id, plus identify whether it ascends
141  vtkm::Id oldSupertargetSuperId = contourTreeSuperarcsPortal.Get(oldSuperparent);
142  bool oldSuperarcAscends =
144  oldSupertargetSuperId =
146  vtkm::Id oldSupertargetOldSortId = contourTreeSupernodesPortal.Get(oldSupertargetSuperId);
147  vtkm::Id oldSupertargetOldRegularId = meshSortOrderPortal.Get(oldSupertargetOldSortId);
148  vtkm::Id oldSupertargetNewRegularId =
149  hierarchicalTreeIdPortal.Get(oldSupertargetOldRegularId);
150 
151  // set up variables for our pruning search
152  // collect the low end's values
153  vtkm::Id lowEndRegularId =
154  oldSuperarcAscends ? oldSuperparentNewRegularId : oldSupertargetNewRegularId;
155  vtkm::Id highEndRegularId =
156  oldSuperarcAscends ? oldSupertargetNewRegularId : oldSuperparentNewRegularId;
157 
158  // pull the data value at the node
159  vtkm::Id nodeGlobalId = hierarchicalTreeRegularNodeGlobalIdsPortal.Get(newNodeId);
160  auto nodeValue = hierarchicalTreeDataValuesPortal.Get(newNodeId);
161 
162  // now ask the hierarchical tree for the correct superparent
163  hierarchicalTreeSuperparentsPortal.Set(
164  newNodeId,
165  findSuperArcForUnknownNode.FindSuperArcForUnknownNode(
166  nodeGlobalId, nodeValue, highEndRegularId, lowEndRegularId));
167  } // it's not a supernode
168 
169 
170  // In serial this worklet implements the following operation
171  /*
172  for (indexType newNode = 0; newNode < newNodes.size(); newNode++)
173  { // per new node
174  // convert to a node ID in the current level's tree
175  indexType oldNodeID = newNodes[newNode];
176  // index into hierarchical tree
177  indexType newNodeID = nOldNodes + newNode;
178  // retrieve the old parent superarc
179  indexType oldSortIndex = mesh->SortIndex(oldNodeID);
180  indexType oldSuperparent = contourTree->superparents[oldSortIndex];
181  // and to a regular ID
182  indexType oldSuperparentNewRegularID = hierarchicalRegularID[oldSuperparent];
183 
184  // Assuming that the new supernodes & hypernodes have been transferred, EVERY supernode in the old tree
185  // now has hierarchicalRegularID set correctly. Since every regular node belongs on a superarc in the old tree,
186  // we can use the ends of the superarc to invoke a search in the hierarchical tree for the superparent.
187  // This is therefore logically dependent on having the superstructure & hyperstructure updated first
188 
189  // supernodes will already have their superparent set in CopyNewSupernodes()
190  if (noSuchElement(hierarchicalTree.superparents[newNodeID]))
191  { // it's not a supernode
192  // retrieve the end of the superarc & convert to hierarchical regular ID, plus identify whether it ascends
193  indexType oldSupertargetSuperID = contourTree->superarcs[oldSuperparent];
194  bool oldSuperarcAscends = isAscending(oldSupertargetSuperID);
195  oldSupertargetSuperID = maskedIndex(oldSupertargetSuperID);
196  indexType oldSupertargetOldSortID = contourTree->supernodes[oldSupertargetSuperID];
197  indexType oldSupertargetOldRegularID = mesh->SortOrder(oldSupertargetOldSortID);
198  indexType oldSupertargetNewRegularID = hierarchicalTreeID[oldSupertargetOldRegularID];
199 
200  // set up variables for our pruning search
201  // collect the low end's values
202  indexType lowEndRegularID = oldSuperarcAscends ? oldSuperparentNewRegularID : oldSupertargetNewRegularID;
203  indexType highEndRegularID = oldSuperarcAscends ? oldSupertargetNewRegularID : oldSuperparentNewRegularID;
204 
205  // pull the data value at the node
206  indexType nodeGlobalID = hierarchicalTree.regularNodeGlobalIDs[newNodeID];
207  dataType nodeValue = hierarchicalTree.dataValues[newNodeID];
208 
209  // now ask the hierarchical tree for the correct superparent
210  hierarchicalTree.superparents[newNodeID] = hierarchicalTree.FindSuperArcForUnknownNode(nodeGlobalID, nodeValue, highEndRegularID, lowEndRegularID);
211  } // it's not a supernode
212  } // per new node
213  */
214  } // operator ()
215 
216 private:
218 
219 }; // CopyNewHypernodes
220 
221 } // namespace tree_grafter
222 } // namespace contourtree_distributed
223 } // namespace worklet
224 } // namespace vtkm
225 
226 #endif
vtkm::worklet::contourtree_augmented::IsAscending
VTKM_EXEC_CONT bool IsAscending(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:121
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::MaskedIndex
VTKM_EXEC_CONT vtkm::Id MaskedIndex(vtkm::Id flaggedIndex)
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:127
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Id &newNode, const vtkm::Id &oldNodeId, const MeshSortIndexPortalType &meshSortIndexPortal, const MeshSortOrderPortalType &meshSortOrderPortal, const InFieldPortalType &contourTreeSuperparentsPortal, const InFieldPortalType &contourTreeSuperarcsPortal, const InFieldPortalType &contourTreeSupernodesPortal, const InFieldPortalType &hierarchicalRegularIdPortal, const InFieldPortalType &hierarchicalTreeIdPortal, const InFieldPortalType &hierarchicalTreeRegularNodeGlobalIdsPortal, const DataValuePortalType &hierarchicalTreeDataValuesPortal, const FindSuperExecType &findSuperArcForUnknownNode, const OutFieldPortalType &hierarchicalTreeSuperparentsPortal) const
Definition: CopyNewNodesSetSuperparentsWorklet.h:104
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet::CopyNewNodesSetSuperparentsWorklet
VTKM_EXEC_CONT CopyNewNodesSetSuperparentsWorklet(const vtkm::Id &numOldNodes)
Definition: CopyNewNodesSetSuperparentsWorklet.h:93
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet::InputDomain
_1 InputDomain
Definition: CopyNewNodesSetSuperparentsWorklet.h:89
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::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
Types.h
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet::ExecutionSignature
void(InputIndex, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) ExecutionSignature
Definition: CopyNewNodesSetSuperparentsWorklet.h:88
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet::NumOldNodes
vtkm::Id NumOldNodes
Definition: CopyNewNodesSetSuperparentsWorklet.h:217
vtkm::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet
Definition: CopyNewNodesSetSuperparentsWorklet.h:70
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::contourtree_distributed::tree_grafter::CopyNewNodesSetSuperparentsWorklet::ControlSignature
void(FieldIn newNodes, WholeArrayIn meshSortIndex, WholeArrayIn meshSortOrder, WholeArrayIn contourTreeSuperparents, WholeArrayIn contourTreeSuperarcs, WholeArrayIn contourTreeSupernodes, WholeArrayIn hierarchicalRegularId, WholeArrayIn hierarchicalTreeId, WholeArrayIn hierarchicalTreeRegularNodeGlobalIds, WholeArrayIn hierarchicalTreeDataValues, ExecObject findSuperArcForUnknownNode, WholeArrayOut hierarchicalTreeSuperparents) ControlSignature
Definition: CopyNewNodesSetSuperparentsWorklet.h:86