Search code examples
pythonvtk

Multithreading with vtkSMPTools


I want to use vtkSMPTools to run my backend parallel (Python). Sample code is as follows:

import vtk

# Create an instance of vtkSMPTools
smpTools = vtk.vtkSMPTools()

# Use the For method to iterate over a range of indices in parallel
def func(i):
    # Code to execute in parallel goes here
    print(i)

smpTools.For(0, 100, func)

However, I am getting an error as follows: vtkmodules.vtkCommonCore.vtkSMPTools' object has no attribute 'For'.

I have checked the vtk documentation and can see For method is defined for vtkSMPTools.

I am unable to figure out what is the issue. Please help me with this.

I am able to import vtk.vtkSMPTools(). However, error comes when I am trying to use the For method.


Solution

  • I fear vtkSMPTools are not expected to work from python code, as templated methods (like the For method in the c++ code) are not wrappable (see this doc )