-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: cython_special: GIL free error handling #6722
Conversation
Errors are now tracked by a global errno-style variable; this variable is threadsafe for OpenMP threads.
88aafcd
to
d7d8c3d
Compare
df9c793
to
db78124
Compare
I'm running into a bit of a problem, and I wonder if anyone has any ideas. How things work now:
To make the necessary modifications to |
I have a bad feeling about this ....:
|
Yeah, pretty much me too. I don't like the other options either, which seem to be:
Not sure where to go; the current situation is undesirable enough that something should be done though. |
I think I'm inclined to say "let's turn off error reporting". The current method is buggy, and other methods have their own problems. Better to have nothing and add something if the situation improves than have something bad. Opinions? |
You could have the TLS flag owned by the C++ module, and export functions from there for toggling its value. I don't really like using openmp for this, and the fact that the flag becomes non-threadlocal if you don't have openmp on. We can always add |
Ok, let's close this then and I'll submit something which removes the current (buggy) error handling. (The relief I feel at not having to mess with distutils anymore is palpable!) |
a familiar feeling:) |
This changes the error handling in
cython_special
to be based on a global errno-style variable. With these changes error handling looks like:To achieve that effect with the old error handling system one would have to do something like:
Note that with the old error handling changing the flow of the program based on errors requires grabbing the GIL.
If SciPy is compiled by a C compiler with OpenMP support, then the new error handling is threadsafe for OpenMP threads. In particular this covers uses of
cython.parallel
; e.g. something like the following code:is fine.
See #6681 for more discussion.
Some aspects of this PR are ugly and could perhaps be done in a nicer way; in particular it currently implements a custom
build_ext
in the top-levelsetup.py
that tries to detect whether the C compiler supports OpenMP. A better way of doing this would be welcome. (Presumably changingnumpy.distutils
would be a better way of doing this, but ISTM it is expedient to get this figured out beforecython_special
is in a release.)