Comments (4)
I've install Scipy 1.10.1 in a virtual environment and I'm struggling to find "lapack_api.pxi" so I think there's some details I'm missing.
However - here's my working theory:
in compute_wrapper
the nogil
says that it can run without the GIL, not that it actually releases the GIL. You don't release the GIL and thus the whole thing runs with the GIL locked..
I wouldn't be surprised if it worked if you changed
cpdef void compute_wrapper(
double[:] d, double[:] e, double[:] v, int n) noexcept:
cdef double* dp = &d[0];
cdef double* ep = &e[0];
cdef double* vp = &v[0];
with nogil:
compute(dp, ep, vp, n);
to explicitly release the GIL.
I'm not sure what's going on beyond that (since I think the mystery .pxi file is important). But it might be that in Cython 3 the implementation of lapack_dstev
has added an exception check somewhere which tries to reacquire the GIL.
from cython.
I added lapack_api.pxi
to the original post. Thanks for noting the missing file.
from cython.
This is happening on linux, so probably not related directly to scipy/scipy#20294 which is windows-specific
from cython.
So:
In that version of scipy dstev
is written as:
cdef void dstev(char *jobz, int *n, d *d, d *e, d *z, int *ldz, d *work, int *info) nogil
(I'm fairly sure it has noexcept
in more recent versions of Scipy). Cython 3 interprets the definition without noexcept
to mean "might throw a Python exception". Therefore, the call to dstev
generates to code
__pyx_f_5scipy_6linalg_13cython_lapack_dstev(__pyx_v_jobz, __pyx_v_n, __pyx_v_d, __pyx_v_e, __pyx_v_z, __pyx_v_ldz, __pyx_v_work, __pyx_v_info); if (unlikely(__Pyx_ErrOccurredWithGIL()))
i.e. it always re-acquires the GIL in order to check for an exception.
As I said earlier, compute_wrapper
doesn't release the GIL - it can simply run without the GIL. Therefore the deadlock is that all your OpenMP threads are trying to acquire the GIL when something else already holds it, hence the block.
If you modify compute_wrapper
as I suggested to explicitly release the GIL then it works correctly.
We ran into a few issues like this with the release of Cython 3. The one differs because the parallel loop isn't Cython-generated, so it can't be fixed by changing the GIL handling from Cython.
from cython.
Related Issues (20)
- [BUG] Random Segfault HOT 4
- [BUG] Cython master crashes analysing division of int by float HOT 3
- source code string cannot contain null bytes HOT 2
- [BUG] Cannot cythonize C++ source if function isn't explicitly used in a new Python function in the same file
- Coverage measurement of Cython code in a meson build HOT 18
- [BUG] Build dependency that is NOT a runtime compulsory dependency HOT 7
- Handling of Python element access in free-threading Python HOT 4
- [BUG] Possible regression in handling of default function arguments HOT 3
- [BUG] Unknown object types PyComplexObject, incomplete types PyTypeObject, PyLongObject when use -DCYTHON_LIMITED_API HOT 2
- prange/OpenMP issues under the free-threading CPython build HOT 10
- [BUG] Test test_parallel_numpy_arrays fails on 32bits with Cython 3.0.10 and numpy 1.26.0
- [BUG] Large pyqt file causes compile to stall [Mac OS arm] HOT 9
- [BUG] Invalid C code from simple parallel example HOT 1
- [BUG] Seg-fault calling class method accessing object member on class object HOT 1
- [BUG] Nested double quotes supported by python 3.12 not supported in cython HOT 1
- [BUG] cython to C translation error on array of structs as struct field HOT 2
- [BUG] Function pointer casting not working properly HOT 1
- Lock memoryviewslice struct in free-threading mode
- [BUG] Unnecessary refnanny gil handling in __init__/__del__ (and maybe other slots)
- [BUG] Possible regression on master branch, __class__ not available in class body during cythonize HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cython.