Skip to content
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

More uniform reduce chunk sizes #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,12 @@ function _reduce_threads_for(rf, init, reducible::SizedReducible{<:AbstractArray
if nthreads == 1
return foldl_basecase(rf, start(rf, init), arr)
else
w = length(arr) ÷ nthreads
mylen = length(arr)
results = Vector{Any}(undef, nthreads)
Threads.@threads for i in 1:nthreads
if i == nthreads
chunk = @view arr[(i - 1) * w + 1:end]
else
chunk = @view arr[(i - 1) * w + 1:i * w]
end
rangeini = ((i - 1) * mylen) ÷ nthreads + 1
rangeend = (i * mylen) ÷ nthreads
chunk = @view arr[rangeini, rangeend]
results[i] = foldl_basecase(rf, start(rf, init), chunk)
end
# It can be done in `log2(n)` for loops but it's not clear if
Expand Down