Skip to content

Commit

Permalink
Merge pull request #12487 from JuliaLang/amitm/tweak_preduce
Browse files Browse the repository at this point in the history
tweak @parallel for a small improvement in performance
  • Loading branch information
amitmurthy committed Aug 9, 2015
2 parents 7f4c2de + 9c48da1 commit 783f870
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1467,12 +1467,15 @@ function splitrange(N::Int, np::Int)
end

function preduce(reducer, f, N::Int)
chunks = splitrange(N, nworkers())
w=workers()
chunks = splitrange(N, length(w))
results = cell(length(chunks))
for i in 1:length(chunks)
results[i] = @spawn f(first(chunks[i]), last(chunks[i]))
@sync begin
for i in 1:length(chunks)
@async results[i] = remotecall_fetch(w[i], f, first(chunks[i]), last(chunks[i]))
end
end
mapreduce(fetch, reducer, results)
reduce(reducer, results)
end

function pfor(f, N::Int)
Expand Down

0 comments on commit 783f870

Please sign in to comment.