[SciPy-Dev] Using OpenMP in SciPy

Peter Bell PeterBell10 at live.co.uk
Fri Aug 2 15:38:41 EDT 2019


Apologies, the format stripping made my previous email quite hard to read so here it is again in plain text.

Hello all,
I'd like to revisit a discussion started a while ago in gh-10239: Can we build and use OpenMP in a portable way?

andyfaff's comment on the issue pointed out a number of portability issues that he's experienced that put him off of OpenMP. Summarising:
1.       1. macOS's apple clang doesn't support openmp and supporting OpenMP requires distributing a runtime with your library.
2.       2. On macOS, the openmp version crashes if mkl numpy is installed. This is a general problem because several different OpenMP runtimes exist.
3.       3. openmp doesn't play nicely with multiprocessing.Pool

To expand on that third point, some openmp runtimes aren't fork-safe. Most notably, this includes gcc's libgomp. Upon entering the first openmp parallel region, the runtime initializes a thread pool which won't be rebuilt in the child after fork. This means that any parallel regions in the child will deadlock. Single threaded openmp loops seem to be safe though.

Eric Larson has also recently had a chat with an sklearn maintainer which has been using OpenMP in the wild for ~6 months.  A few of the key take-aways from his discussion were:
*         * Packaging OpenMP code has many pitfalls but they think they've found a solution that works for them.
*         * They use joblib with the "loky" backend to avoid multiprocessing and the associated forking issues.
*         * They had issues related to incompatibility with macOS Accelerate for BLAS/LAPACK but SciPy has already dropped support for accelerate<https://github.com/scipy/scipy/wiki/Dropping-support-for-Accelerate>.
*         * Some macOS users still needed the option to compile the library without OpenMP. Although, this might have also been Accelerate related.
*
So, given these issues, are we willing to use OpenMP in SciPy?

Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20190802/a1db2a6f/attachment-0001.html>


More information about the SciPy-Dev mailing list