# CMake flags used to compile Python wheel

**URL:** https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940
**Category:** Support
**Created:** [March 10, 2023, 5:39pm UTC](https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940 "2023-03-10T17:39:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ffrancesco94](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ffrancesco94/32/6710_2.png) [@ffrancesco94](https://discourse.vtk.org/u/ffrancesco94)
#### Post date: [March 10, 2023, 5:39pm UTC](https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940/1 "2023-03-10T17:39:36Z")

</div>

Hi,  
I was trying to go through the .ci/\*.cmake files to understand how exactly the Python3 wheels (mainly interested in Linux) are generated, but I found that many optional flags are not mentioned (thus I’m assuming set to off?). I’m mainly looking at VTK\_PYTHON\_FULL\_THREADSAFE (that I’m assuming is off) and VTK\_SMP\_IMPLEMENTATION\_TYPE (also sequential?). I have been wondering why, considering how hard it is to achieve multithreading in Python due to the GIL, these flags are not turned on by default to have multithreaded code on the C++ side of things.

Francesco

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 10, 2023, 10:10pm UTC](https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940/2 "2023-03-10T22:10:20Z")

</div>

Oddly enough, the `VTK_PYTHON_FULL_THREADSAFE` setting can only be configured when building Paraview. It doesn’t appear when building VTK itself.

I agree that `VTK_PYTHON_FULL_THREADSAFE` should be `ON` by default, and last year I submitted a patch ([!9223](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9223)) to VTK. The same patch also releases the GIL during long stretches of C++ code execution, in order to unblock the execution of python threads. If you’re willing to read through the patch and give your opinion, that might help to give it enough momentum to actually get fully reviewed and merged.

Regarding C++ threading, the wheels provide both Sequential and STDThreads as SMP backends. The `VTK_SMP_IMPLEMENTATION_TYPE` only indicates the _default_ backend. The full set of defaults for VTK (and the wheels) is as follows:

```plaintext
VTK_SMP_IMPLEMENTATION_TYPE=Sequential
VTK_SMP_ENABLE_SEQUENTIAL=ON
VTK_SMP_ENABLE_STDTHREAD=ON
VTK_SMP_ENABLE_TBB=OFF
VTK_SMP_ENABLE_OPENMP=OFF

```

The STDThread backend can be turned on at runtime like so:

```python
>>> vtkSMPTools.SetBackend('STDThread')

```

It isn’t the default because it has performance issues (and potential stability issues) which are being worked on in [!10027](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10027).

The VTK imaging pipeline, at least, is parallel on all platforms/configurations because it falls back to native threads (e.g. posix threads on linux).

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 24, 2023, 3:10am UTC](https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940/3 "2023-04-24T03:10:08Z")

</div>

> [@dgobbi](#):
>
> Oddly enough, the `VTK_PYTHON_FULL_THREADSAFE` setting can only be configured when building Paraview. It doesn’t appear when building VTK itself.

That is strange…though it was added in 2015 (MR 582) in just the code. I suspect it was pushed from the ParaView side, never got a VTK exposure, and got missed when I rewrote things in ParaView to have a `PARAVIEW_` prefix…

Anyways, exposing it to VTK probably isn’t the worst thing, though I do remember someone trying to do it and I wondered why it should be an option at all…

---

<div class="post-metadata">

### Author: ![ffrancesco94](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ffrancesco94/32/6710_2.png) [@ffrancesco94](https://discourse.vtk.org/u/ffrancesco94)
#### Post date: [April 25, 2023, 9:29am UTC](https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940/4 "2023-04-25T09:29:14Z")

</div>

Thank you for your replies!  
The VTK\_PYTHON\_FULL\_THREADSAFE was discussed in a pipermail thread of VTK many years ago, but I can’t seem to find it…  
I’ll give a look at the patch and comment about it. I don’t really see many reasons why it shouldn’t be the default. And good to know that the multithreading can be enabled at runtime, reading VTK\_SMP\_IMPLEMENTATION\_TYPE sounds very “definitive” for a given build. Thank you!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 25, 2023, 12:02pm UTC](https://discourse.vtk.org/t/cmake-flags-used-to-compile-python-wheel/10940/5 "2023-04-25T12:02:13Z")

</div>

> [@ffrancesco94](#):
>
> And good to know that the multithreading can be enabled at runtime

Yes, I pushed for that to avoid adding yet another axis to VTK’s build configuration.
