-
Notifications
You must be signed in to change notification settings - Fork 48
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
Threading improvements #493
Conversation
Codecov Report
@@ Coverage Diff @@
## main #493 +/- ##
=======================================
Coverage 93.95% 93.96%
=======================================
Files 26 26
Lines 2152 2153 +1
=======================================
+ Hits 2022 2023 +1
Misses 130 130
Continue to review full report at Codecov.
|
mod = m_threads[Threads.threadid()] | ||
local βsc = βsc_threads[Threads.threadid()] | ||
local θsc = θsc_threads[Threads.threadid()] | ||
tidx = use_threads ? Threads.threadid() : 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch that the threadid()
can be other than 1 when nested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original error came from @behinger actually using this within a threaded for
loop.
* better safety in nested threading * SpinLock brings back the speeeed * NEWS entry (cherry picked from commit 624805c)
* the trunk is now called main (#494) (cherry picked from commit db2274d) * update standard tests to include 1.6 (#496) * update standard tests to include 1.6 * tweak readme (cherry picked from commit 50ea7a6) * Update Tier1.yml (#497) Upload codecov from version 1.6 (cherry picked from commit 5402ae5) * Disable ProgressBar for logs and when requested (#495) * Disable ProgressBar for logs and when requested * NEWS entry (cherry picked from commit b9c73da) * Threading improvements (#493) * better safety in nested threading * SpinLock brings back the speeeed * NEWS entry (cherry picked from commit 624805c) * minor version bump Co-authored-by: Douglas Bates <dmbates@gmail.com>
better safety in nested threading
If you used
use_threads=false
but nested that within aThreads.@threads for
, then you could be on a thread withid > 1
but with the shared resource arrays only 1 unit long. This problem was first detected by @behinger in a different context.potential performance increase in multithreading.
For this, I replaced the
ReentrantLock
with aSpinLock
. Spin locks are faster, but aren't re-entrant safe. We're not sharing this state anywhere and the RNG call is ideally quick, so we should be able to avoid the deadlock issues that the locks documentation warns about. Nonetheless, I've added a warning to the docstring discussing this.The "potential" performance improvements are a complicated story, but it looks like we do get a boost for many models (the sleepstudy example is the big outlier). Here are some timing metrics (with progress bars and NLopt warnings cut out) using 4 threads on a machine with 8 cores on Julia 1.6-rc1 and default OpenBLAS and number of OpenBLAS threads: