# Accelerating VTK processing

**URL:** https://discourse.paraview.org/t/accelerating-vtk-processing/14503
**Category:** ParaView Support
**Tags:** vtk
**Created:** [April 27, 2024, 11:11am UTC](https://discourse.paraview.org/t/accelerating-vtk-processing/14503 "2024-04-27T11:11:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [April 27, 2024, 11:11am UTC](https://discourse.paraview.org/t/accelerating-vtk-processing/14503/1 "2024-04-27T11:11:06Z")

</div>

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

```python
# 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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [April 27, 2024, 6:05pm UTC](https://discourse.paraview.org/t/accelerating-vtk-processing/14503/2 "2024-04-27T18:05:05Z")

</div>

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

```make
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`

---

<div class="post-metadata">

### Author: ![WarinSpace\_Game](https://discourse.paraview.org/user_avatar/discourse.paraview.org/warinspace_game/32/9808_2.png) [@WarinSpace\_Game](https://discourse.paraview.org/u/WarinSpace_Game)
#### Post date: [June 12, 2024, 4:06am UTC](https://discourse.paraview.org/t/accelerating-vtk-processing/14503/3 "2024-06-12T04:06:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.paraview.org/user_avatar/discourse.paraview.org/christos_tsolakis/32/4450_2.png) [@Christos\_Tsolakis](https://discourse.paraview.org/u/Christos_Tsolakis)
#### Post date: [June 12, 2024, 1:37pm UTC](https://discourse.paraview.org/t/accelerating-vtk-processing/14503/4 "2024-06-12T13:37:27Z")

</div>

> [@WarinSpace\_Game](#):
>
> Is there a way to do everything within the Python script itself?

You could use a `ProcessPoolExecutor` see example [here](https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor-example).
