Skip to content

Segfault at runtime with openmp on macOS #790

@dcoeurjo

Description

@dcoeurjo

Describe the bug

The POT build with openmp on macOS is fine with the recent #789 PR. However, at runtime, threads cannot be initialized and the overall python interpreter crashes with a segfault

To Reproduce

Steps to reproduce the behavior:

  1. build POT (master) on MacOS
  2. run (snippet from test/test_OT.py)
import ot
import numpy as np

def test_omp_emd2():
    # test emd2 and emd2 with openmp for simple identity
    n = 100
    rng = np.random.RandomState(0)

    x = rng.randn(n, 2)
    u = ot.utils.unif(n)

    M = ot.dist(x, x)

    w = ot.emd2(u, u, M)
    w2 = ot.emd2(u, u, M, numThreads=2)

test_omp_emd2()

The code produces a segfault. Using a simple debugger, it seems to be related to the thread initialization.
It could be related to weird GIL / Threads / Cpython interference but I can't say more.

Screenshots

Code sample

Expected behavior

Environment (please complete the following information):

  • OS (e.g. MacOS, Windows, Linux): macOS26
  • Python version: 3.12.7
  • How was POT installed (source, pip, conda): build from master
  • Build command you used (if compiling from source): pip install -e .
  • Only for GPU related bugs:
    • CUDA version:
    • GPU models and configuration:
    • Any other relevant information: openmp with libomp on macOS

Output of the following code snippet:

import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import ot; print("POT", ot.__version__)
>>> import sys; print("Python", sys.version)
Python 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 08:22:19) [Clang 14.0.6 ]
>>> import numpy; print("NumPy", numpy.__version__)
NumPy 1.26.4
>>> import scipy; print("SciPy", scipy.__version__)
SciPy 1.14.1
>>> import ot; print("POT", ot.__version__)
POT 0.9.7.dev0
``` 

### Additional context
<!-- Add any other context about the problem here. -->

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions