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

bench mapreduce with array accesses #63

Merged
merged 10 commits into from
May 19, 2017
Merged

Conversation

felixrehren
Copy link
Contributor

Cf. JuliaLang/julia#20517:
mapreduce can be much slower than the equivalent for-loop, currently mostly coming from an inference bug JuliaLang/julia#15276 related to Core.box.

This benchmark would allow keeping an eye on this realistic code pattern. If that is what you had in mind, @stevengj ?

test performance of mapreduce with array accesses
z = zero(eltype(A))
zz = z*z
n = Base.LinAlg.checksquare(A)
B = Vector{typeof(zz)}(n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the benchmark is testing the performance of mapreduce, it'd be better not to benchmark this setup step, no? See BenchmarkTools' setup/teardown phase functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

@@ -59,6 +59,9 @@ for (A, str) in (arrays_iter..., ranges_iter...)
g["sumeach_view", str] = @benchmarkable perf_sumeach_view($A)
g["sumlinear_view", str] = @benchmarkable perf_sumlinear_view($A)
g["sumcartesian_view", str] = @benchmarkable perf_sumcartesian_view($A)
if ndims(A) == 2
g["mapr_access", str] = @benchmarkable perf_mapr_access(A, B, zz, n) setup = $setup_mapr_access #20517
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this is failing is due to the weird scoping rules of setup; you'd need to interpolate A into the expression for it to work. It's pretty ugly, unfortunately. For example:

julia> for a in 1:3
           @benchmark sin(b) setup=(println(a); b = 1 + a) samples=1 evals=1
       end
ERROR: UndefVarError: a not defined

vs.

# this one should work
julia> for a in 1:3
           @benchmark sin(b) setup=(println($a); b = 1 + $a) samples=1 evals=1
       end
1
1
2
2
3
3

Anyway, instead of interpolating an expression here, I would just make setup_mapr_access a function and write setup = (B, zz, n = setup_mapr_access()).

@@ -59,6 +59,9 @@ for (A, str) in (arrays_iter..., ranges_iter...)
g["sumeach_view", str] = @benchmarkable perf_sumeach_view($A)
g["sumlinear_view", str] = @benchmarkable perf_sumlinear_view($A)
g["sumcartesian_view", str] = @benchmarkable perf_sumcartesian_view($A)
if ndims(A) == 2
g["mapr_access", str] = @benchmarkable perf_mapr_access(A, B, zz, n) setup = (B, zz, n = setup_mapr_access($A)) #20517
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, looks like you've discovered a new BenchmarkTools bug. I just posted an issue for it in the BenchmarkTools repo. Sorry about this.

You should be able to fix this by using begin...end instead of parens for setup, e.g. setup = begin B, zz, n = setup_mapr_access($A) end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, no worries for me -- thanks for your patience with this. Fix incoming

@@ -59,6 +59,9 @@ for (A, str) in (arrays_iter..., ranges_iter...)
g["sumeach_view", str] = @benchmarkable perf_sumeach_view($A)
g["sumlinear_view", str] = @benchmarkable perf_sumlinear_view($A)
g["sumcartesian_view", str] = @benchmarkable perf_sumcartesian_view($A)
if ndims(A) == 2
g["mapr_access", str] = @benchmarkable perf_mapr_access(A, B, zz, n) setup = begin B, zz, n = setup_mapr_access($A) end #20517
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A here needs to be interpolated since it's coming from the loop scope rather than the setup scope.

for `IntX` with `X` less than the system size, `mapreduce` over a collection with `eltype` `IntX` may promote its result to a wider type.
@jrevels
Copy link
Member

jrevels commented Feb 15, 2017

Awesome, looks like tests are passing now! Let me know once you're ready to merge.

@felixrehren
Copy link
Contributor Author

LGTM but would like to make sure someone else, like @stevengj, has looked at this ?

@jrevels jrevels merged commit e3e89ca into JuliaCI:master May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants