Skip to content

Avoid recursive parallel_for callback invocations with TBB

Yasushi Saito requested to merge yasushi.saito/vtk:saito-tbbfix into master

This change prevent TBB threads from making recursive calls during nested parallel_for calls. For more details:

https://software.intel.com/content/www/us/en/develop/blogs/the-work-isolation-functionality-in-intel-threading-building-blocks-intel-tbb.html

This change fixes a problem in which a mesh consisting of many vtkPolyhedrons SEGVs during CellCenters or RedistributeDataSet. More specifically: below is a call stack of CellCenterFunctor being called recursively. CellCenterFunctor and many other parallel_for callbacks uses thread-local vtkGenericCell variables, so they aren't reentrant.

Perhaps a real fix is to avoid running nested parallel_for loops, but this change is a safer fix.

==1102320==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60c0002b203f at pc 0x7f0c451b8025 bp 0x7f0c03661440 sp 0x7f0c03661430
WRITE of size 1 at 0x60c0002b203f thread T10
    #0 0x7f0c451b8024 in vtkCellArray::Reset() /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkCellArray.cxx:1227
    #1 0x7f0c45748c99 in vtkPolyhedron::Initialize() /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkPolyhedron.cxx:427
    #2 0x7f0c45307111 in vtkGenericCell::Initialize() /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkGenericCell.cxx:161
    #3 0x7f0c459cfceb in vtkUnstructuredGrid::GetCell(long long, vtkGenericCell*) /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkUnstructuredGrid.cxx:1025
    #4 0x7f0c2cfd3ccf in operator() /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Filters/Core/vtkCellCenters.cxx:72
    #5 0x7f0c2cfd70ec in Execute /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/Core/vtkSMPTools.h:90
    #6 0x7f0c2cfd6d41 in operator() VTK/Common/Core/vtkSMPToolsInternal.h:48
    #7 0x7f0c2cfd6c3a in run_body /usr/include/tbb/parallel_for.h:115
    #8 0x7f0c2cfd69a2 in work_balance<tbb::interface9::internal::start_for<tbb::blocked_range<long long int>, vtk::detail::smp::FuncCall<vtk::detail::smp::vtkSMPTools_FunctorInternal<(anonymous namespace)::CellCenterFunctor, false> >, const tbb::auto_partitioner>, tbb::blocked_range<long long int> > /usr/include/tbb/partitioner.h:438
    #9 0x7f0c2cfd6683 in execute<tbb::interface9::internal::start_for<tbb::blocked_range<long long int>, vtk::detail::smp::FuncCall<vtk::detail::smp::vtkSMPTools_FunctorInternal<(anonymous namespace)::CellCenterFunctor, false> >, const tbb::auto_partitioner>, tbb::blocked_range<long long int> > /usr/include/tbb/partitioner.h:256
    #10 0x7f0c2cfd64bd in execute /usr/include/tbb/parallel_for.h:142
    #11 0x7f0c43149544  (/lib/x86_64-linux-gnu/libtbb.so.2+0x2c544)
    #12 0x7f0c4314980e  (/lib/x86_64-linux-gnu/libtbb.so.2+0x2c80e)
    #13 0x7f0c43146b67  (/lib/x86_64-linux-gnu/libtbb.so.2+0x29b67)
    #14 0x7f0c4517ea1d in tbb::task::spawn_root_and_wait(tbb::task&) /usr/include/tbb/task.h:798
    #15 0x7f0c451c358c in run /usr/include/tbb/parallel_for.h:95
    #16 0x7f0c451c25c5 in parallel_for<tbb::blocked_range<long long int>, vtk::detail::smp::FuncCall<vtk::detail::smp::vtkSMPTools_FunctorInternal<(anonymous namespace)::FindMaxCell, true> > > /usr/include/tbb/parallel_for.h:201
    #17 0x7f0c451c016c in vtkSMPTools_Impl_For<vtk::detail::smp::vtkSMPTools_FunctorInternal<(anonymous namespace)::FindMaxCell, true> > VTK/Common/Core/vtkSMPToolsInternal.h:88
    #18 0x7f0c451bf2e5 in For /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/Core/vtkSMPTools.h:122
    #19 0x7f0c451bb7b6 in For<(anonymous namespace)::FindMaxCell> /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/Core/vtkSMPTools.h:170
    #20 0x7f0c451b8cb3 in For<(anonymous namespace)::FindMaxCell> /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/Core/vtkSMPTools.h:204
    #21 0x7f0c451b6a2b in vtkCellArray::GetMaxCellSize() /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkCellArray.cxx:1095
    #22 0x7f0c455da1f4 in vtkMVCPolyIterator::vtkMVCPolyIterator(vtkCellArray*) /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkMeanValueCoordinatesInterpolator.cxx:104
    #23 0x7f0c455c801f in vtkMeanValueCoordinatesInterpolator::ComputeInterpolationWeights(double const*, vtkPoints*, vtkCellArray*, double*) /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkMeanValueCoordinatesInterpolator.cxx:609
    #24 0x7f0c457503e1 in vtkPolyhedron::InterpolateFunctions(double const*, double*) /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkPolyhedron.cxx:1267
    #25 0x7f0c4574f0f2 in vtkPolyhedron::EvaluateLocation(int&, double const*, double*, double*) /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkPolyhedron.cxx:1160
    #26 0x7f0c453075c7 in vtkGenericCell::EvaluateLocation(int&, double const*, double*, double*) /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/DataModel/vtkGenericCell.cxx:205
    #27 0x7f0c2cfd3f3c in operator() /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Filters/Core/vtkCellCenters.cxx:78
    #28 0x7f0c2cfd70ec in Execute /home/saito/src/paraview-5.9.0-RC4-20210127_asan/VTK/Common/Core/vtkSMPTools.h:90
    #29 0x7f0c2cfd6d41 in operator() VTK/Common/Core/vtkSMPToolsInternal.h:48
    #30 0x7f0c2cfd6c3a in run_body /usr/include/tbb/parallel_for.h:115
    #31 0x7f0c2cfd6877 in work_balance<tbb::interface9::internal::start_for<tbb::blocked_range<long long int>, vtk::detail::smp::FuncCall<vtk::detail::smp::vtkSMPTools_FunctorInternal<(anonymous namespace)::CellCenterFunctor, false> >, const tbb::auto_partitioner>, tbb::blocked_range<long long int> > /usr/include/tbb/partitioner.h:423
    #32 0x7f0c2cfd6683 in execute<tbb::interface9::internal::start_for<tbb::blocked_range<long long int>, vtk::detail::smp::FuncCall<vtk::detail::smp::vtkSMPTools_FunctorInternal<(anonymous namespace)::CellCenterFunctor, false> >, const tbb::auto_partitioner>, tbb::blocked_range<long long int> > /usr/include/tbb/partitioner.h:256
    #33 0x7f0c2cfd64bd in execute /usr/include/tbb/parallel_for.h:142
    #34 0x7f0c43149544  (/lib/x86_64-linux-gnu/libtbb.so.2+0x2c544)
    #35 0x7f0c4314980e  (/lib/x86_64-linux-gnu/libtbb.so.2+0x2c80e)
    #36 0x7f0c43142bd6  (/lib/x86_64-linux-gnu/libtbb.so.2+0x25bd6)
    #37 0x7f0c43141497  (/lib/x86_64-linux-gnu/libtbb.so.2+0x24497)
    #38 0x7f0c4313d87f  (/lib/x86_64-linux-gnu/libtbb.so.2+0x2087f)
    #39 0x7f0c4313da8c  (/lib/x86_64-linux-gnu/libtbb.so.2+0x20a8c)
    #40 0x7f0c42ce2608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
    #41 0x7f0c4b326292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)

Merge request reports