-
Notifications
You must be signed in to change notification settings - Fork 92
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
Avoid the zeros(nthreads())[threadid()]
buffering pattern
#293
Conversation
This is known issue: #10 |
Where do you think there might be other such algorithms? |
This should only be in Parallel, if it is somewhere else, I would be really worried. My concern is if we sufficiently advertise these Parallel algorithms as error-prone. For the moment, our take is: we never see the tests fail so we assume it works, though we know the code in clunky and might have race conditions that lead to potential errors. |
Hi folks and sorry for the delay in my reply. To clarify, this aims to fix an issue we might get into on 1.9.3 where multithreading behavior changed slightly in that julia> buf = zeros(Threads.nthreads())
7-element Vector{Float64}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
julia> Threads.@threads for i in 1:Threads.nthreads()
buf[Threads.threadid()] = Threads.threadid()
end
ERROR: TaskFailedException
nested task error: BoundsError: attempt to access 7-element Vector{Float64} at index [9]
Stacktrace:
[1] setindex!(A::Vector{Float64}, x::Int64, i1::Int64)
@ Base ./array.jl:969
[2] macro expansion
@ ./REPL[2]:2 [inlined]
[3] (::var"#26#threadsfor_fun#4"{var"#26#threadsfor_fun#3#5"{UnitRange{Int64}}})(tid::Int64; onethread::Bool)
@ Main ./threadingconstructs.jl:200
[4] #26#threadsfor_fun
@ ./threadingconstructs.jl:167 [inlined]
[5] (::Base.Threads.var"#1#2"{var"#26#threadsfor_fun#4"{var"#26#threadsfor_fun#3#5"{UnitRange{Int64}}}, Int64})()
@ Base.Threads ./threadingconstructs.jl:139
...and 1 more exception. To avoid that, instead of I don't know if this PR fixes any other, older known bugs or issues though. |
Thanks for the PR! Do you know why tests are failing? |
Codecov Report
@@ Coverage Diff @@
## master #293 +/- ##
==========================================
- Coverage 97.30% 97.27% -0.04%
==========================================
Files 115 115
Lines 6709 6778 +69
==========================================
+ Hits 6528 6593 +65
- Misses 181 185 +4 |
@gdalle I think I fixed the issue 👍 |
will review soon, thanks! |
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.
Looks good to me
As recommended in this blogpost https://julialang.org/blog/2023/07/PSA-dont-use-threadid/