Fix OpenMP backend crashes by avoiding unnecessary computations and zero-length copying.

This commit is contained in:
Gunther H. Weber 2020-10-22 15:54:36 -07:00
parent 4594c1e4c6
commit d42916ba39
2 changed files with 57 additions and 3 deletions

@ -439,13 +439,24 @@ void BoundaryTreeMaker<MeshType, MeshBoundaryExecObjType>::PropagateBoundaryCoun
// i. Pull the array bounds into register
vtkm::Id firstSupernode = firstSupernodePerIterationReadPortal.Get(iteration);
vtkm::Id lastSupernode = firstSupernodePerIterationReadPortal.Get(iteration + 1);
if (lastSupernode == firstSupernode)
{
#ifdef DEBUG_PRINT
VTKM_LOG_S(vtkm::cont::LogLevel::Info,
"BoundaryTreeMaker::PropagateBoundaryCounts(): lastSupernode == firstSupernode "
" -> Skipping iteration");
#endif
continue;
}
vtkm::Id firstHypernode = firstHypernodePerIterationReadPortal.Get(iteration);
vtkm::Id lastHypernode = firstHypernodePerIterationReadPortal.Get(iteration + 1);
// ii. Add xfer + int & store in dependent count
// Compute the sum of this->SupernodeTransferBoundaryCount and this->SuperarcIntrinsicBoundaryCount
// for the [firstSupernodex, lastSupernode) subrange and copy to the this->SuperarcDependentBoundaryCount
{ // make local context ot fancyTempSumArray gets deleted
{ // make local context so fancyTempSumArray gets deleted
auto fancyTempSumArray = vtkm::cont::make_ArrayHandleImplicit(
bract_maker::ArraySumFunctor(this->SupernodeTransferBoundaryCount,
this->SuperarcIntrinsicBoundaryCount),
@ -701,6 +712,15 @@ void BoundaryTreeMaker<MeshType,
// We need to grow the arrays, without loosing our original data, so we need
// to create new arrays of the approbriate size, copy our data in and then
// assign. TODO: Would be great if VTKm allow resize without losing the values
if (this->NumNecessary == 0)
{
#ifdef DEBUG_PRINT
VTKM_LOG_S(vtkm::cont::LogLevel::Info,
"BoundaryTreeMaker::AugmentBoundaryWithNecessaryInteriorSupernodes():"
"No additional nodes necessary. Returning.");
#endif
return;
}
{
// Create a new resized array and copy the original values to the array
vtkm::worklet::contourtree_augmented::IdArrayType tempBractVertexSuperset;

@ -875,6 +875,15 @@ void TreeGrafter<MeshType, FieldType>::ListNewHypernodes(
this->WhenTransferred);
vtkm::cont::Algorithm::Sort(this->NewHypernodes, hyperNodeWhenComparator);
if (this->NewHypernodes.GetNumberOfValues() == 0)
{
#ifdef DEBUG_PRINT
VTKM_LOG_S(vtkm::cont::LogLevel::Info,
"TreeGrafter::ListNewHypernodes(): No new hypernodes. Returning.");
#endif
return;
}
// D. Use this sorted array to set the hierarchical hyper index for each supernode that is a new hypernode
vtkm::Id nOldHypernodes = hierarchicalTree.Hypernodes.GetNumberOfValues();
// VTKm copy can't allocate for transformed arrays, but this->HierarchicalHyperId.Allocate(nOldHypernodes) has already been allocate earlier.
@ -926,6 +935,16 @@ void TreeGrafter<MeshType, FieldType>::ListNewSupernodes(
notANewSupernodePredicate // unary predicate for deciding which supernodes are considered true
);
this->NewSupernodes = compressedNewSupernodes; // swap in the compressed array
if (this->NewSupernodes.GetNumberOfValues() == 0)
{
#ifdef DEBUG_PRINT
VTKM_LOG_S(vtkm::cont::LogLevel::Info,
"TreeGrafter::ListNewSupernodes(): No new supernodes. Returning.");
#endif
return;
}
// C. Sort them to match the hyperarc sort: note that the supernodes array ALWAYS holds a sort index into the nodes
auto superNodeWhenComparator =
vtkm::worklet::contourtree_distributed::tree_grafter::SuperNodeWhenComparator(
@ -1011,6 +1030,15 @@ void TreeGrafter<MeshType, FieldType>::ListNewNodes(
// swap in the compressed array
this->NewNodes = compressedNewNodes;
if (this->NewNodes.GetNumberOfValues() == 0)
{
#ifdef DEBUG_PRINT
VTKM_LOG_S(vtkm::cont::LogLevel::Info,
"TreeGrafter::ListNewNodes(): No noew nodes. Returning.");
#endif
return;
}
// E. And set their new ID for future use
vtkm::Id nOldNodes = hierarchicalTree.RegularNodeGlobalIds.GetNumberOfValues();
// VTKm copy can't allocate for transformed arrays, but this->HierarchicalTreeId has already been allocate earlier.
@ -1181,7 +1209,10 @@ void TreeGrafter<MeshType, FieldType>::CopyNewSupernodes(
vtkm::cont::make_ArrayHandlePermutation(newHypernodeIndex, hierarchicalTree.Hypernodes);
auto permutedSuper2hypernode =
vtkm::cont::make_ArrayHandlePermutation(permutedHypernodes, hierarchicalTree.Super2Hypernode);
vtkm::cont::Algorithm::Copy(newHypernodeIndex, permutedSuper2hypernode);
if (newHypernodeIndex.GetNumberOfValues())
{ // TODO/FIXME: Can we detect this earlier and save computation time?
vtkm::cont::Algorithm::Copy(newHypernodeIndex, permutedSuper2hypernode);
}
#ifdef DEBUG_PRINT
VTKM_LOG_S(vtkm::cont::LogLevel::Info, DebugPrint("New Supernodes Copied", __FILE__, __LINE__));
@ -1301,7 +1332,10 @@ void TreeGrafter<MeshType, FieldType>::CopyNewNodes(
auto regular2SupernodePermuted = vtkm::cont::make_ArrayHandlePermutation(
vtkm::cont::make_ArrayHandlePermutation(tempNewSupernodeIndex, hierarchicalTree.Supernodes),
hierarchicalTree.Regular2Supernode);
vtkm::cont::Algorithm::Copy(tempNewSupernodeIndex, regular2SupernodePermuted);
if (tempNewSupernodeIndex.GetNumberOfValues())
{ // TODO/FIXME: Can we detect this earlier and save computation time?
vtkm::cont::Algorithm::Copy(tempNewSupernodeIndex, regular2SupernodePermuted);
}
}
// E. Now we sort out the superparents