-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
Intermittent segfaults with map_rect and TBB #1637
Comments
Does this mean any map_rect model is affected when threading is on? |
See here: stan-dev/cmdstan#802 (comment) It's not a severe problem from my view. All inferences are still correct. I can probably fix it by tomorrow (assuming my understanding is all correct, which I think it is). |
If you point me in the general direction I can take a stab at it today. |
You should compile and link the TBB in debug mode (a flag for the TBB makefiles). Then it's a matter of ensuring that the tbb scheduler and the observer which we create are deallocated in the right order. At worst we have static de-allocation catastrophe which requires a bit more thinking as to how and where we instantiate our global management stuff of the TBB. |
This is probably stating the obvious but yeah, commenting out this line https://github.com/stan-dev/math/blob/develop/stan/math/rev/core/init_chainablestack.hpp#L52 does it. But that is obviously not the solution, the erase is the cause. |
There is probably a circular dependency and we need to write a destructor to handle things in the right order. The thing is that when the tbb scheduler is torn down it will run the exit functions of the observers...but the observers are also going out of scope...hmmm...we can try to write a destructor which uses the lock mutex to ensure proper ordering...which hopefully does not cause another mess |
Description
Running a model with map_rect and multithreading enabled results in segfaults in around 5% of the cases. The issue only occurs on v2.21.0, not on v2.20.0 and could be reproduced by @wds15.
When the segfault occurs, results are still written to disk.
Example
To reproduce, compile the attached model (taken from the stan user manual) and repeatedly run it with the attached data (though the segfaults seem to occur independently of the model or data).
Observed output (~5% of the runs):
Link to discourse thread: https://discourse.mc-stan.org/t/intermittent-segfaults-with-map-rect-and-tbb/12750
g++ -v
Expected Output
No intermittent segfaults
map_rect_model.stan.txt
data.Rdump.txt
The text was updated successfully, but these errors were encountered: