Accelerating VTK processing

The following code loads a .vtk file, does some processing, and exports the output as a .vtp file:

# Read VTK
reader = vtkStructuredGridReader()
reader.SetFileName(filename + ".vtk")

# Extract surface
surface_filter = vtkDataSetSurfaceFilter()
surface_filter.SetInputConnection(reader.GetOutputPort())

clean_filter = vtkCleanPolyData()
clean_filter.SetInputConnection(surface_filter.GetOutputPort())

# Save output to a VTP file
writer = vtkXMLPolyDataWriter()
writer.SetFileName(filename + ".vtp")
writer.SetInputConnection(clean_filter.GetOutputPort())
writer.Write()

While this code works perfectly, I have to run this for about 50 VTK files, so the conversion can take a while. Is there a way to somehow accelerate this by running this for multiple files in parallel? Any other ideas?

You can use make -j$(nproc) to do this:

outputs := $(patsubst %.vtk,%.vtp,$(wildcard *.vtk))

.PHONY: all
all: $(outputs)

%.vtp: %.vtk convert.py
	vtkpython convert.py $<

though this will pass foo.vtk as the argument, not foo

Is there a way to do everything within the Python script itself?

You could use a ProcessPoolExecutor see example here.