-
Notifications
You must be signed in to change notification settings - Fork 107
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
Thread safety #385
Comments
I have used the fortran routines with openmp in the past without any problems. Could you give me more info about when this fails and when it doesn't? Or does it fail for even the most simply tasks? |
If the problem is indeed FFTW-related, it's most likely not connected with ducc, since ducc doesn't use FFTW internally. |
Oh interesting! I had it fail when multiple threads were trying to execute SHExpandGLQ calls on different datasets (with the same dimensions) at the same time. The failure was then a segmentation fault without clear error codes. I found the FFTW thread safety information, and saw that the variables they talk about there were edited in the SHExpandGLQ code. The threading implementation i'm using is a python-rewrite of Java threading that is implemented in the bigger software i'm writing in, so this may also have specific vulnerabilities? I managed to fix it in my code by encapsulating the SHExpandGLQ in an RLock - so it's not very pressing for me, but weird that it happens especially if it's stable with openMP |
I don't use openmp very often, so I'll need to investigate... |
OK, I have an idea why the Fortran code cannot be called concurrently: in the function you linked there are arrays with the "save" attribute, which means that they are equivalent to static variables in C/C++, i.e. global state. Calling into such a function concurrently will almost certainly lead to undesired effects. Not sure why you also encounter this with the ducc back-end as well though ... it shouldn't have any global state. Semi-related question: how do you manage to execute concurrent calls from Python? Doesn't the GIL prevent this? |
Sorry, I thake that back: all variables marked On the other hand, |
I had to look it up to figure out how the software im using is doing this: I'm never releasing the GIL, I call |
Sure! I was just wondering how you can call the SHTOOLS Python interface from two concurrently running Python threads. I most likely have an oversimplified picture in my mind of what you are actually doing. |
To get a clearer picture: which function from the SHTOOLS Python interface are you calling exactly? |
the only function i have isssues with is |
And i have to say i dont fully understand your question on having multiple concurrent python threads, this is something that does not require the release of the GIL (such as the multiprocessing.ThreadPool implementation) |
I'll try to make a minimal working example soon 😄 |
Thanks, that will certainly be very helpful! |
This breaks with a segmentation fault for me, but works with |
OK, I can reproduce the segmentation fault when the standard shtools backend is used, but not with ducc. Do you have the |
Ah okay, i did not notice because |
OK, might be good to add a function like |
I tried to now implement this in my main project, but there i seem to (currently) be limited to pyshtools v4.9.1 and ducc0 v0.26.0 due to other dependencies. Here the segmentation faults still happen with preferred_backend ducc. Is this not correctly setting the backend, or is the thread safety of ducc a newer thing? |
As far as I know, there shouldn't have been any relevant |
Currently the SHTOOLS SHExpandGLQ function i regularly use fails in multithreaded applications. I think this comes from the modulation of fftw3.3.3 plans as only the fftw execute calls are thread-safe: https://www.fftw.org/fftw3_doc/Thread-safety.html
This probably affects (almost) all fftw calls in SHTOOLS.
Would it be an idea to implement the brute fftw_make_planner_thread_safe call and force fft expansions to be thread safe?
The text was updated successfully, but these errors were encountered: