77 #ifndef vtk_m_worklet_contourtree_distributed_hierarchical_hyper_sweeper_h
78 #define vtk_m_worklet_contourtree_distributed_hierarchical_hyper_sweeper_h
101 namespace contourtree_distributed
105 template <
typename SweepValueType,
typename ContourTreeFieldType>
154 template <
typename MeshType>
157 const MeshType& baseBlock,
170 std::string
DebugPrint(std::string message,
const char* fileName,
long lineNum)
const;
205 template <
typename SweepValueType,
typename ContourTreeFieldType>
211 : HierarchicalTree(hierarchicalTree)
213 , IntrinsicValues(intrinsicValues)
214 , DependentValues(dependentValues)
215 , NumOwnedRegularVertices(
vtkm::
Id{ 0 })
218 this->ValuePrefixSum.AllocateAndFill(this->HierarchicalTree.Supernodes.GetNumberOfValues(), 0);
219 this->TransferTarget.AllocateAndFill(this->HierarchicalTree.Supernodes.GetNumberOfValues(), 0);
220 this->SortedTransferTarget.AllocateAndFill(this->HierarchicalTree.Supernodes.GetNumberOfValues(),
224 this->HierarchicalTree.Supernodes.GetNumberOfValues());
230 template <
typename SweepValueType,
typename ContourTreeFieldType>
231 template <
typename MeshType>
234 const MeshType& baseBlock,
244 baseBlock.GetOwnedVerticesByGlobalId(localToGlobalIdRelabeler, globalIds);
251 std::stringstream debugStream;
252 debugStream << std::endl <<
"Owned Regular Vertex List" << std::endl;
263 auto computeSuperparentIdsWorklet = vtkm::worklet::contourtree_distributed::
264 hierarchical_hyper_sweeper::InitializeIntrinsicVertexCountComputeSuperparentIdsWorklet();
265 Invoke(computeSuperparentIdsWorklet,
276 std::stringstream debugStream;
278 "Superparents", superparents, -1, debugStream);
288 std::stringstream debugStream;
295 superarcRegularCounts.
AllocateAndFill(this->HierarchicalTree.Supernodes.GetNumberOfValues(), 0);
299 InitializeIntrinsicVertexCountInitalizeCountsWorklet{},
301 superarcRegularCounts
306 InitializeIntrinsicVertexCountSubtractLowEndWorklet{},
308 superarcRegularCounts
313 std::stringstream debugStream;
315 "SuperarcRegularCounts", superarcRegularCounts, -1, debugStream);
323 template <
typename SweepValueType,
typename ContourTreeFieldType>
328 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
329 std::string(
" Starting Local HyperSweep"),
335 for (
vtkm::Id round = 0; round <= this->HierarchicalTree.NumRounds; round++)
339 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
340 std::string(
" Round ") + std::to_string(round) +
341 std::string(
" Step 0 Starting Round"),
346 auto numIterationsPortal =
347 this->HierarchicalTree.NumIterations
349 for (
vtkm::Id iteration = 0; iteration < numIterationsPortal.Get(round); iteration++)
353 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
354 std::string(
" Round ") + std::to_string(round) +
355 std::string(
" Step 1 Iteration ") + std::to_string(iteration) +
356 std::string(
" Step A Starting Iteration"),
362 auto firstSupernodePerIterationPortal =
363 this->HierarchicalTree.FirstSupernodePerIteration[round].ReadPortal();
364 vtkm::Id firstSupernode = firstSupernodePerIterationPortal.Get(iteration);
365 vtkm::Id lastSupernode = firstSupernodePerIterationPortal.Get(iteration + 1);
368 this->ComputeSuperarcDependentWeights(round, iteration, firstSupernode, lastSupernode);
372 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
373 std::string(
" Round ") + std::to_string(round) +
374 std::string(
" Step 1 Iteration ") + std::to_string(iteration) +
375 std::string(
" Step B Dependent Weights Computed"),
380 this->ComputeSuperarcTransferWeights(round, iteration, firstSupernode, lastSupernode);
384 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
385 std::string(
" Round ") + std::to_string(round) +
386 std::string(
" Step 1 Iteration ") + std::to_string(iteration) +
387 std::string(
" Step C Transfer Weights Computed"),
393 this->TransferWeights(round, iteration, firstSupernode, lastSupernode);
397 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
398 std::string(
" Round ") + std::to_string(round) +
399 std::string(
" Step 1 Iteration ") + std::to_string(iteration) +
400 std::string(
" Step D Weights Transferred"),
408 DebugPrint(std::string(
"Hypersweep Block ") + std::to_string(BlockId) +
409 std::string(
" Round ") + std::to_string(round) +
410 std::string(
" Step 2 Ending Round"),
419 template <
typename SweepValueType,
typename ContourTreeFieldType>
427 vtkm::Id numSupernodesToProcess = lastSupernode - firstSupernode;
434 dependentValuesView(this->DependentValues,
436 numSupernodesToProcess);
439 valuePrefixSumView(this->ValuePrefixSum,
441 numSupernodesToProcess);
459 firstSupernode,
vtkm::Id{ 1 }, numSupernodesToProcess);
461 hierarchicalTreeSuperarcsView(
462 this->HierarchicalTree.Superarcs, firstSupernode, numSupernodesToProcess);
464 hierarchicalTreeHyperparentsView(
465 this->HierarchicalTree.Hyperparents, firstSupernode, numSupernodesToProcess);
467 hierarchicalTreeHypernodesView(
468 this->HierarchicalTree.Hypernodes, firstSupernode, numSupernodesToProcess);
470 dependentValuesView(this->DependentValues, firstSupernode, numSupernodesToProcess);
472 vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::
473 ComputeSuperarcDependentWeightsWorklet<SweepValueType>
474 computeSuperarcDependentWeightsWorklet(
475 firstSupernode, round, this->HierarchicalTree.NumRounds);
478 computeSuperarcDependentWeightsWorklet,
480 hierarchicalTreeSuperarcsView,
481 hierarchicalTreeHyperparentsView,
482 this->HierarchicalTree.Hypernodes,
483 this->ValuePrefixSum,
491 template <
typename SweepValueType,
typename ContourTreeFieldType>
501 vtkm::Id numSupernodesToProcess = lastSupernode - firstSupernode;
508 firstSupernode,
vtkm::Id{ 1 }, numSupernodesToProcess);
510 hierarchicalTreeSupernodesView(
511 this->HierarchicalTree.Supernodes, firstSupernode, numSupernodesToProcess);
513 hierarchicalTreeSuperarcsView(
514 this->HierarchicalTree.Superarcs, firstSupernode, numSupernodesToProcess);
516 transferTargetView(this->TransferTarget, firstSupernode, numSupernodesToProcess);
518 vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::
519 ComputeSuperarcTransferWeightsWorklet computeSuperarcTransferWeightsWorklet(
520 round, this->HierarchicalTree.NumRounds, lastSupernode);
523 computeSuperarcTransferWeightsWorklet,
525 hierarchicalTreeSupernodesView,
526 this->HierarchicalTree.Superparents,
527 this->HierarchicalTree.Hyperparents,
528 hierarchicalTreeSuperarcsView,
537 superSortPermuteView(this->SuperSortPermute, firstSupernode, numSupernodesToProcess);
540 transferTargetComperator(this->TransferTarget);
555 sortedTransferTargetView(this->SortedTransferTarget, firstSupernode, numSupernodesToProcess);
557 superSortPermuteView(this->SuperSortPermute, firstSupernode, numSupernodesToProcess);
558 auto permutedTransferTarget =
560 this->TransferTarget);
565 valuePrefixSumView(this->ValuePrefixSum, firstSupernode, numSupernodesToProcess);
566 auto permutedDependentValues =
568 this->DependentValues);
575 template <
typename SweepValueType,
typename ContourTreeFieldType>
583 vtkm::Id numSupernodesToProcess = lastSupernode - firstSupernode;
588 valuePrefixSumView(this->ValuePrefixSum,
590 numSupernodesToProcess);
596 tempScanInclusiveTarget.
Allocate(numSupernodesToProcess);
599 tempScanInclusiveTarget);
609 auto supernodeIndex =
611 VTKM_ASSERT(firstSupernode + numSupernodesToProcess <=
612 this->ValuePrefixSum.GetNumberOfValues());
614 this->ValuePrefixSum, firstSupernode, numSupernodesToProcess);
616 vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::
617 TransferWeightsUpdateRHEWorklet transferWeightsUpdateRHEWorklet(lastSupernode);
619 this->Invoke(transferWeightsUpdateRHEWorklet,
621 this->SortedTransferTarget,
623 this->DependentValues);
627 VTKM_ASSERT(firstSupernode + 1 + numSupernodesToProcess - 1 <=
628 this->SortedTransferTarget.GetNumberOfValues());
630 this->SortedTransferTarget, firstSupernode + 1, numSupernodesToProcess - 1);
631 VTKM_ASSERT(firstSupernode + 1 + numSupernodesToProcess - 1 <=
632 this->SortedTransferTarget.GetNumberOfValues());
634 this->SortedTransferTarget, firstSupernode, numSupernodesToProcess - 1);
636 this->ValuePrefixSum, firstSupernode, numSupernodesToProcess - 1);
639 vtkm::worklet::contourtree_distributed::hierarchical_hyper_sweeper::
640 TransferWeightsUpdateLHEWorklet transferWeightsUpdateLHEWorklet;
641 this->Invoke(transferWeightsUpdateLHEWorklet,
642 sortedTransferTargetView,
643 sortedTransferTargetShiftedView,
644 valuePrefixSumPreviousValueView,
645 this->DependentValues);
651 template <
typename SweepValueType,
typename ContourTreeFieldType>
654 const char* fileName,
657 std::stringstream resultStream;
658 resultStream << std::endl;
659 resultStream <<
"----------------------------------------" << std::endl;
660 resultStream << std::setw(30) << std::left << fileName <<
":" << std::right << std::setw(4)
661 << lineNum << std::endl;
662 resultStream << std::left << message << std::endl;
663 resultStream <<
"Hypersweep Value Array Contains: " << std::endl;
664 resultStream <<
"----------------------------------------" << std::endl;
665 resultStream << std::endl;
670 "Intrinsic", this->IntrinsicValues, -1, resultStream);
672 "Dependent", this->DependentValues, -1, resultStream);
674 "Prefix Sum", this->ValuePrefixSum, -1, resultStream);
676 "Transfer To", this->TransferTarget, -1, resultStream);
678 "Sorted Transfer", this->SortedTransferTarget, -1, resultStream);
680 "Sort Permute", this->SuperSortPermute, -1, resultStream);
681 return resultStream.str();
686 template <
typename SweepValueType,
typename ContourTreeFieldType>
689 const char* outFileName)
const
691 std::string hierarchicalTreeDotString =
692 HierarchicalContourTreeDotGraphPrint<vtkm::worklet::contourtree_augmented::IdArrayType>(
694 this->HierarchicalTree,
698 this->DependentValues);
699 std::ofstream hierarchicalTreeFile(outFileName);
700 hierarchicalTreeFile << hierarchicalTreeDotString;