Giter Club home page Giter Club logo

Comments (4)

da-woods avatar da-woods commented on May 28, 2024

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.

ameli avatar ameli commented on May 28, 2024

I added lapack_api.pxi to the original post. Thanks for noting the missing file.

from cython.

mattip avatar mattip commented on May 28, 2024

This is happening on linux, so probably not related directly to scipy/scipy#20294 which is windows-specific

from cython.

da-woods avatar da-woods commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.