New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] OpenMP does not work anymore with function call on cython 3.0 #5573
Comments
I finaly found that the It fix this issue. |
This isn't true I think... ignore |
Essentially the problem is that a `nogil` function just promises that the function *can* be called without the GIL, not that it actually doesn't have the GIL. If you call `prange`/`parallel` inside that function while still holding the GIL, if any thread has finished the GIL will be held (... I think it's probably more of a mess than this, but mostly you get away with it...). If a thread is still running and tries to acquire the GIL then it'll deadlock permenantly. I've solved this by adding an implicit `with nogil` around any `prange`/`parallel` that's in a `nogil` block but isn't certain that it has the GIL. Fixes cython#5573 and cython#5564.
Got to the bottom of this. I believe there's a subtle error in your code: a Frankly that's so subtle that I'm not sure anyone can be expected to spot it. Therefore my proposed fix is to get rid of the requirement and make absolutely 100% sure that the GIL is released before entering a |
Thanks for your answer and your fix. However thinking a little bit more on this, do we really want to implicitly add I am not saying there is a perfect solution. I just want to explore all the possible fixes and improve my code 😀 |
I think if I was starting from scratch that might be how I'd do it. However, making it a compiler error now would break quite a bit of existing code, and probably require us to create a way to annotate a function to say "this function MUST be called without the GIL".
Yes, that's very true. I think it's likely low cost compared to setting up a parallel/prange block. But I could be wrong. Again, we could provide some way for the user to turn off the check, but that makes it more complicated. |
* Fix issues with parallel/exception checked functions Essentially the problem is that a `nogil` function just promises that the function *can* be called without the GIL, not that it actually doesn't have the GIL. If you call `prange`/`parallel` inside that function while still holding the GIL, if any thread has finished the GIL will be held (... I think it's probably more of a mess than this, but mostly you get away with it...). If a thread is still running and tries to acquire the GIL then it'll deadlock permenantly. I've solved this by adding an implicit `with nogil` around any `prange`/`parallel` that's in a `nogil` block but isn't certain that it has the GIL. Fixes #5573 and #5564. * Add extra field in pxd * Separate comment
Describe the bug
After upgrading from Cython 0.29.36 to Cython 3.0.0 produced code just hang infinitly when OpenMP is used and sub-function are called.
Looking at produced code for bellow lines:
Using Cython 0.29.36 produced code is:
Using Cython 3.0 produced code is:
I am not expecting any GIL check / any other check in
prange
body.Code to reproduce the behaviour:
my_ext.pyx :
setup.py :
Expected behaviour
I am expecting code produced code that:
OS
Linux
Python version
3.10.6
Cython version
3.0.0
Additional context
No response
The text was updated successfully, but these errors were encountered: