VTK-m  2.0
CombineHyperSweepBlockFunctor.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_combinehypersweepblockfunctor_h
54 #define vtk_m_worklet_contourtree_distributed_combinehypersweepblockfunctor_h
55 
56 #include <vtkm/Types.h>
58 #include <vtkm/cont/ArrayHandle.h>
60 
61 // clang-format off
62 VTKM_THIRDPARTY_PRE_INCLUDE
63 #include <vtkm/thirdparty/diy/diy.h>
64 VTKM_THIRDPARTY_POST_INCLUDE
65 // clang-format on
66 
67 // #define DEBUG_PRINT_COMBINED_BLOCK_IDS
68 
69 namespace vtkm
70 {
71 namespace worklet
72 {
73 namespace contourtree_distributed
74 {
75 
76 template <typename ContourTreeDataFieldType>
78 {
79  void operator()(
81  const vtkmdiy::ReduceProxy& rp, // communication proxy
82  const vtkmdiy::RegularSwapPartners& // partners of the current block (unused)
83  ) const
84  {
85  // Get our rank and DIY id
86  //const vtkm::Id rank = vtkm::cont::EnvironmentTracker::GetCommunicator().rank();
87  const auto selfid = rp.gid();
88 
89  std::vector<int> incoming;
90  rp.incoming(incoming);
91 
92  for (const int ingid : incoming)
93  {
94  auto roundNo = rp.round() - 1; // We are processing incoming data from the previous round
95 
96  // NOTE/IMPORTANT: In each round we should have only one swap partner (despite for-loop here).
97  // If that assumption does not hold, it will break things.
98  // NOTE/IMPORTANT: This assumption only holds if the number of blocks is a power of two.
99  // Otherwise, we may need to process more than one incoming block
100  if (ingid != selfid)
101  {
102 #ifdef DEBUG_PRINT_COMBINED_BLOCK_IDS
103  int incomingGlobalBlockId;
104  rp.dequeue(ingid, incomingGlobalBlockId);
106  "Combining local block " << b->GlobalBlockId << " with incomoing block "
107  << incomingGlobalBlockId);
108 #endif
109  vtkm::cont::ArrayHandle<vtkm::Id> incomingIntrinsicVolume;
110  rp.dequeue(ingid, incomingIntrinsicVolume);
111  vtkm::cont::ArrayHandle<vtkm::Id> incomingDependentVolume;
112  rp.dequeue(ingid, incomingDependentVolume);
113 
114  vtkm::Id numSupernodesToProcess = vtkm::cont::ArrayGetValue(
116 
117  auto intrinsicVolumeView =
118  make_ArrayHandleView(b->IntrinsicVolume, 0, numSupernodesToProcess);
119  VTKM_ASSERT(incomingIntrinsicVolume.GetNumberOfValues() ==
120  intrinsicVolumeView.GetNumberOfValues());
121 
123  intrinsicVolumeView, incomingIntrinsicVolume, intrinsicVolumeView, vtkm::Sum());
124 
125  auto dependentVolumeView =
126  make_ArrayHandleView(b->DependentVolume, 0, numSupernodesToProcess);
127  VTKM_ASSERT(incomingDependentVolume.GetNumberOfValues() ==
128  dependentVolumeView.GetNumberOfValues());
130  dependentVolumeView, incomingDependentVolume, dependentVolumeView, vtkm::Sum());
131  }
132  }
133 
134  for (int cc = 0; cc < rp.out_link().size(); ++cc)
135  {
136  auto target = rp.out_link().target(cc);
137  if (target.gid != selfid)
138  {
139 #ifdef DEBUG_PRINT_COMBINED_BLOCK_IDS
140  rp.enqueue(target, b->GlobalBlockId);
141 #endif
142 
143  // Create views for data we need to send
144  vtkm::Id numSupernodesToProcess = vtkm::cont::ArrayGetValue(
146  auto intrinsicVolumeView =
147  make_ArrayHandleView(b->IntrinsicVolume, 0, numSupernodesToProcess);
148  auto dependentVolumeView =
149  make_ArrayHandleView(b->DependentVolume, 0, numSupernodesToProcess);
150  // TODO/FIXME: Currently a copy is required, as ArrayHandleView does not
151  // have a serialization function (and even serializing it would not avoid
152  // sending portions outside the "view"). At the moment, copying the data
153  // inside its view to an extra array seems to be the best approach. Possibly
154  // revisit this, if vtk-m adds additional functions that can help avoiding the
155  // extra copy.
156  vtkm::cont::ArrayHandle<vtkm::Id> sendIntrinsicVolume;
157  vtkm::cont::ArrayCopy(intrinsicVolumeView, sendIntrinsicVolume);
158  vtkm::cont::ArrayHandle<vtkm::Id> sendDependentVolume;
159  vtkm::cont::ArrayCopy(dependentVolumeView, sendDependentVolume);
160 
161  // Send necessary data portions
162  rp.enqueue(target, sendIntrinsicVolume);
163  rp.enqueue(target, sendDependentVolume);
164  }
165  }
166  }
167 };
168 
169 } // namespace contourtree_distributed
170 } // namespace worklet
171 } // namespace vtkm
172 
173 #endif
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle< vtkm::Id >
ArrayHandle.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::make_ArrayHandleView
ArrayHandleView< ArrayHandleType > make_ArrayHandleView(const ArrayHandleType &array, vtkm::Id startIndex, vtkm::Id numValues)
Definition: ArrayHandleView.h:222
Types.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::worklet::contourtree_distributed::CobmineHyperSweepBlockFunctor::operator()
void operator()(vtkm::worklet::contourtree_distributed::HyperSweepBlock< ContourTreeDataFieldType > *b, const vtkmdiy::ReduceProxy &rp, const vtkmdiy::RegularSwapPartners &) const
Definition: CombineHyperSweepBlockFunctor.h:79
vtkm::cont::ArrayGetValue
VTKM_CONT T ArrayGetValue(vtkm::Id id, const vtkm::cont::ArrayHandle< T, S > &data)
Obtain a small set of values from an ArrayHandle with minimal device transfers.
Definition: ArrayGetValues.h:264
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_distributed::HyperSweepBlock::HierarchicalContourTree
const vtkm::worklet::contourtree_distributed::HierarchicalContourTree< ContourTreeDataFieldType > & HierarchicalContourTree
Definition: HyperSweepBlock.h:96
vtkm::Sum
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:33
vtkm::cont::LogLevel::Info
@ Info
Information messages (detected hardware, etc) and temporary debugging output.
vtkm::worklet::contourtree_distributed::HierarchicalContourTree::FirstSupernodePerIteration
std::vector< vtkm::worklet::contourtree_augmented::IdArrayType > FirstSupernodePerIteration
vectors tracking the segments used in each iteration of the hypersweep
Definition: HierarchicalContourTree.h:169
vtkm::worklet::contourtree_distributed::HyperSweepBlock::DependentVolume
vtkm::cont::ArrayHandle< vtkm::Id > DependentVolume
Definition: HyperSweepBlock.h:100
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::worklet::contourtree_distributed::CobmineHyperSweepBlockFunctor
Definition: CombineHyperSweepBlockFunctor.h:77
ArrayGetValues.h
HyperSweepBlock.h
vtkm::worklet::contourtree_distributed::HyperSweepBlock::IntrinsicVolume
vtkm::cont::ArrayHandle< vtkm::Id > IntrinsicVolume
Definition: HyperSweepBlock.h:99
VTKM_LOG_S
#define VTKM_LOG_S(level,...)
Writes a message using stream syntax to the indicated log level.
Definition: Logging.h:261
vtkm::cont::Algorithm::Transform
static VTKM_CONT void Transform(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, StorageT > &input1, const vtkm::cont::ArrayHandle< U, StorageU > &input2, vtkm::cont::ArrayHandle< V, StorageV > &output, BinaryFunctor binaryFunctor)
Definition: Algorithm.h:1037
vtkm::worklet::contourtree_distributed::HyperSweepBlock::GlobalBlockId
int GlobalBlockId
Definition: HyperSweepBlock.h:89
vtkm::worklet::contourtree_distributed::HyperSweepBlock
Definition: HyperSweepBlock.h:68