How to create vtkPartitionedDataSet in parallel using SMP?

I need to create a number of vtkPartitionedDataSet object which is completely independent of each other.
Then, they will be added to vtkPartitionedDataSetCollection. How do I parallelize this process? Are there any out of box class I can use?
I was looking into vtkThreadedCompositeDataPipeline but it seems I still need to implement ThreadedExecute() method?

Thanks,
Cam

Use SMPTools:
https://www.kitware.com/simple-parallel-computing-with-vtksmptools/

1 Like

Hi Dan,

I am able to use vtkSMPTools to parallelize my computation in some scenarios. But I am stuck at using it for pipeline. E.g.

class Slice
{
public:
    vtkAppendPolyData* AppendFilter;
    vtkDataSet* Input;
    double Center[3];
    double N0[3];
    double Spacing;
    int SortType;

    Slice(vtkAppendPolyData* appendFilter, vtkDataSet* input, const double* center,
          const double* n0, double spacing, int sortType) : 
        AppendFilter(appendFilter),
        Input(input),
        Spacing(spacing),
        SortType(sortType)
    {
        Center[0] = center[0];
        Center[1] = center[1];
        Center[2] = center[2];
        N0[0] = n0[0];
        N0[1] = n0[1];
        N0[2] = n0[2];
    } 

    void operator()(vtkIdType id, vtkIdType endId)
    {
        for (; id < endId; id++)
        {
            vtkNew<vtkPlane> plane;
            double origin[3] {this->Center[0] + id * this->N0[0] * this->Spacing,
                            this->Center[1] + id * this->N0[1] * this->Spacing,
                            this->Center[2] + id * this->N0[2] * this->Spacing};

            plane->SetOrigin(origin);
            plane->SetNormal(N0);
            // vtkNew<vtkPolyData> contour;
            vtkNew<vtkCutter> cutter;
            cutter->SetCutFunction(plane);
            cutter->SetInputData(this->Input);
            cutter->SetSortBy(this->SortType);
            this->AppendFilter->AddInputConnection(cutter->GetOutputPort());
        }
    }
};

There is Critical error detected c0000374. Is using vtkObject inside operator() method not thread safe? What is causing this to fail?

Thanks,
Cam

Shared data between threads has to be considered very carefully. Seems like AppendFilter is shared between threads - that is certain to cause problems. Advanced Capabilities and Future Work section in the linked articles gives you suggestions on how to use shared data and how to use VTK objects inside your threads. I would also browse the VTK source to see examples on how SMPTools is used.

1 Like

Also, see the following presentation with several examples of how to use SMPTools

https://data.kitware.com/#item/610a923c2fa25629b9c9616a

1 Like