vtkStaticCellLocator results into a segmentation fault when executed in parallel using OpenMP
I get a segmentation fault when I try to use vtkStaticCellLocator's FindCell in parallel using OpenMP. Sequentially runs just fine. I also tried to use vtkCellLocator, which is not thread-safe. Sequentially everything was okay like before, but in parallel, I got a segmentation fault (expected) at the same place with vtkStaticCellLocator (not expected).
// create cell locator
auto cellLocator = vtkSmartPointer<vtkStaticCellLocator>::New();
// auto cellLocator = vtkSmartPointer<vtkCellLocator>::New();
cellLocator->SetDataSet(inputMesh);
cellLocator->BuildLocator();
#pragma omp parallel for schedule(static) shared(cellLocator, pixels) default(none)
for (size_t i = 0; i < pixels.size(); ++i) {
// get pixel point
auto pixelPoint = pixelToPoint(pixels[i]);
double pixelPointForVtk[3] = {pixelPoint[0], pixelPoint[1], pixelPoint[2]};
// find cell that include point
auto cellId = cellLocator->FindCell(pixelPointForVtk);
}
I did a similar thing using vtkKdTreePointLocator and it worked both sequentially and in parallel just fine.
// create point locator
auto pointLocator = vtkSmartPointer<vtkKdTreePointLocator>::New();
pointLocator->SetDataSet(inputMesh);
pointLocator->BuildLocator();
#pragma omp parallel for schedule(static) shared(pointLocator, numberOfNearestPoints, pixels) default(none)
// set pixel values
for (size_t i = 0; i < pixels.size(); ++i) {
// get pixel point
auto pixelPoint = pixelToPoint(pixels[i]);
double pixelPointForVtk[3] = {pixelPoint[0], pixelPoint[1], pixelPoint[2]};
// find nearest points of pixelPoint
auto idList = vtkSmartPointer<vtkIdList>::New();
pointLocator->FindClosestNPoints(numberOfNearestPoints, pixelPointForVtk, idList);
}
Is vtkStaticCellLocator truly thread-safe like vtkKdTreePointLocator or it is thread-safe only if vtkSMPTools are used for parallelization?