VTK-m  2.0
FindRegularByGlobal.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_find_regular_by_global_device_data_h
54 #define vtk_m_worklet_contourtree_distributed_find_regular_by_global_device_data_h
55 
56 #include <vtkm/Types.h>
58 
59 
60 namespace vtkm
61 {
62 namespace worklet
63 {
64 namespace contourtree_distributed
65 {
66 
67 
70 {
71 public:
72  using IndicesPortalType =
74 
75  VTKM_CONT
78  vtkm::cont::Token& token,
79  const vtkm::worklet::contourtree_augmented::IdArrayType& regularNodeSortOrder,
80  const vtkm::worklet::contourtree_augmented::IdArrayType& regularNodeGlobalIds)
81  {
82  // Prepare the arrays for input and store the array portals
83  // so that they can be used inside a workelt
84  this->RegularNodeSortOrder = regularNodeSortOrder.PrepareForInput(device, token);
85  this->RegularNodeGlobalIds = regularNodeGlobalIds.PrepareForInput(device, token);
86  }
87 
89  VTKM_EXEC
90  vtkm::Id operator()(vtkm::Id globalId) const { return this->FindRegularByGlobal(globalId); }
91 
92  // TODO: This is just a binary search. Does VTKm have an implementation we can use to replace this with?
94  VTKM_EXEC
96  { // FindRegularByGlobal()
97  // this is just a binary search, but the C++ STL doesn't seem to implement it . . .
98  vtkm::Id left = 0;
99  vtkm::Id right = this->RegularNodeSortOrder.GetNumberOfValues() - 1;
100 
101  // pull LHE into register & check whether target is in range
102  vtkm::Id leftId = this->RegularNodeGlobalIds.Get(this->RegularNodeSortOrder.Get(left));
103  if (leftId > globalId)
104  {
106  }
107 
108  // exact match on the left
109  if (leftId == globalId)
110  {
111  return this->RegularNodeSortOrder.Get(left);
112  }
113 
114  // pull RHE into register & check whether target is in range
115  vtkm::Id rightId = this->RegularNodeGlobalIds.Get(this->RegularNodeSortOrder.Get(right));
116  // RHE is less than target, so not present
117  if (rightId < globalId)
118  {
120  }
121 
122  // exact match on the right
123  if (rightId == globalId)
124  {
125  return this->RegularNodeSortOrder.Get(right);
126  }
127 
128  // loop until the two meet
129  while (left <= right)
130  { // while loop
131 
132  // compute the midpoint
133  vtkm::Id mid = (left + right) / 2;
134  vtkm::Id midId = this->RegularNodeGlobalIds.Get(this->RegularNodeSortOrder.Get(mid));
135 
136  // compare with the value
137  if (midId == globalId)
138  { // exact match
139  return this->RegularNodeSortOrder.Get(mid);
140  } // exact match
141 
142  if (midId < globalId)
143  { // mid is lower: global is in right half
144  left = mid + 1;
145  leftId = this->RegularNodeGlobalIds.Get(this->RegularNodeSortOrder.Get(left));
146  } // mid is lower: global is in right half
147 
148  if (midId > globalId)
149  { // mid is higher: global is in left half
150  right = mid - 1;
151  rightId = this->RegularNodeGlobalIds.Get(this->RegularNodeSortOrder.Get(right));
152  } // mid is higher: global is in left half
153  } // while loop
154 
155  // if we fell through, we didn't find it
157  } // FindRegularByGlobal()
158 
159 private:
160  // Array portals needed by FindRegularByGlobal
163 };
164 
165 
168 {
169 public:
171  VTKM_CONT
173  const vtkm::worklet::contourtree_augmented::IdArrayType& regularNodeGlobalIds)
174  : RegularNodeSortOrder(regularNodeSortOrder)
175  , RegularNodeGlobalIds(regularNodeGlobalIds)
176  {
177  }
178 
180  vtkm::cont::Token& token) const
181  {
183  device, token, this->RegularNodeSortOrder, this->RegularNodeGlobalIds);
184  }
185 
186 private:
187  // Array portals needed by FindRegularByGlobal
190 };
191 
192 
193 } // namespace contourtree_distributed
194 } // namespace worklet
195 } // namespace vtkm
196 
197 #endif
vtkm::worklet::contourtree_distributed::FindRegularByGlobal::RegularNodeGlobalIds
vtkm::worklet::contourtree_augmented::IdArrayType RegularNodeGlobalIds
Definition: FindRegularByGlobal.h:189
vtkm::worklet::contourtree_distributed::FindRegularByGlobal::FindRegularByGlobal
VTKM_CONT FindRegularByGlobal(const vtkm::worklet::contourtree_augmented::IdArrayType &regularNodeSortOrder, const vtkm::worklet::contourtree_augmented::IdArrayType &regularNodeGlobalIds)
constructor
Definition: FindRegularByGlobal.h:172
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData::IndicesPortalType
typename vtkm::worklet::contourtree_augmented::IdArrayType::ReadPortalType IndicesPortalType
Definition: FindRegularByGlobal.h:73
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
vtkm::cont::ArrayHandle::PrepareForInput
VTKM_CONT ReadPortalType PrepareForInput(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used as an input to an operation in the execution environment.
Definition: ArrayHandle.h:574
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData::RegularNodeSortOrder
IndicesPortalType RegularNodeSortOrder
Definition: FindRegularByGlobal.h:161
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData::FindRegularByGlobal
VTKM_EXEC vtkm::Id FindRegularByGlobal(vtkm::Id globalId) const
routine to search the array of regular nodes for a particular global ID
Definition: FindRegularByGlobal.h:95
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData::FindRegularByGlobalDeviceData
VTKM_CONT FindRegularByGlobalDeviceData(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token, const vtkm::worklet::contourtree_augmented::IdArrayType &regularNodeSortOrder, const vtkm::worklet::contourtree_augmented::IdArrayType &regularNodeGlobalIds)
Definition: FindRegularByGlobal.h:76
vtkm::cont::ArrayHandle< vtkm::Id >::ReadPortalType
typename StorageType::ReadPortalType ReadPortalType
Definition: ArrayHandle.h:294
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
Types.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::contourtree_distributed::FindRegularByGlobal::RegularNodeSortOrder
vtkm::worklet::contourtree_augmented::IdArrayType RegularNodeSortOrder
Definition: FindRegularByGlobal.h:188
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData
Device implementation of FindRegularByGlobal for the HierarchicalContourTree.
Definition: FindRegularByGlobal.h:69
vtkm::worklet::contourtree_distributed::FindRegularByGlobal
ExecutionObject to generate a device object to use FindRegularByGlobal for the HierarchicalContourTre...
Definition: FindRegularByGlobal.h:167
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData::operator()
VTKM_EXEC vtkm::Id operator()(vtkm::Id globalId) const
Define also as an operator so that we can use it in ArrayHandleTransform directly.
Definition: FindRegularByGlobal.h:90
vtkm::worklet::contourtree_distributed::FindRegularByGlobal::PrepareForExecution
VTKM_CONT FindRegularByGlobalDeviceData PrepareForExecution(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Definition: FindRegularByGlobal.h:179
vtkm::worklet::contourtree_distributed::FindRegularByGlobalDeviceData::RegularNodeGlobalIds
IndicesPortalType RegularNodeGlobalIds
Definition: FindRegularByGlobal.h:162
vtkm::worklet::contourtree_augmented::NO_SUCH_ELEMENT
constexpr vtkm::Id NO_SUCH_ELEMENT
Definition: filter/scalar_topology/worklet/contourtree_augmented/Types.h:73