From 70d76737c3a81f3ca1930c7633b45d6c791716ee Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Wed, 21 Dec 2016 17:11:43 -0500 Subject: [PATCH] update laplace benchmark to use fused dotops --- src/broadcast/BroadcastBenchmarks.jl | 20 +++----------------- src/problem/Laplacian.jl | 12 ++++++++++-- src/shootout/nbody_vec.jl | 16 ++-------------- src/utils/CompatUtils.jl | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 src/utils/CompatUtils.jl diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl index 1cadf64c..778c74ba 100644 --- a/src/broadcast/BroadcastBenchmarks.jl +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -1,28 +1,14 @@ module BroadcastBenchmarks -include(joinpath(dirname(@__FILE__), "..", "utils", "RandUtils.jl")) +include(joinpath("..", "utils", "RandUtils.jl")) +include(joinpath("..", "utils", "CompatUtils.jl")) -using .RandUtils +using .RandUtils, .CompatUtils using BenchmarkTools using Compat const SUITE = BenchmarkGroup() -# work around lack of Compat support for .= (Compat.jl issue #285) -if VERSION < v"0.5.0-dev+5575" #17510 - macro dotcompat(ex) - if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.= - :(copy!($(esc(ex.args[1])), $(esc(ex.args[3])))) - else - esc(ex) - end - end -else - macro dotcompat(ex) - esc(ex) - end -end - ########################################################################### g = addgroup!(SUITE, "fusion", ["broadcast!", "array"]) diff --git a/src/problem/Laplacian.jl b/src/problem/Laplacian.jl index f676c374..b5ef76aa 100644 --- a/src/problem/Laplacian.jl +++ b/src/problem/Laplacian.jl @@ -4,6 +4,9 @@ using Compat import Compat: UTF8String, view +include(joinpath("..", "utils", "CompatUtils.jl")) +using .CompatUtils + ################################ # Sparse Matrix * Dense Vector # ################################ @@ -76,7 +79,7 @@ function perf_laplace_iter_vec(N) Niter = 2^10 dx2 = dy2 = 0.1*0.1 for i = 1:Niter - u[2:N-1, 2:N-1] = ((u[1:N-2, 2:N-1] + u[3:N, 2:N-1])*dy2 + (u[2:N-1, 1:N-2] + u[2:N-1, 3:N])*dx2) * (1 / (2*(dx2+dy2))) + @dotcompat u[2:N-1, 2:N-1] .= ((u[1:N-2, 2:N-1] .+ u[3:N, 2:N-1]).*dy2 .+ (u[2:N-1, 1:N-2] .+ u[2:N-1, 3:N]).*dx2) .* (1 / (2*(dx2+dy2))) end return u end @@ -86,8 +89,13 @@ function perf_laplace_iter_sub(N) u[1,:] = 1 Niter = 2^10 dx2 = dy2 = 0.1*0.1 + u0 = view(u, 2:N-1, 2:N-1) + u1 = view(u, 1:N-2, 2:N-1) + u2 = view(u, 3:N, 2:N-1) + u3 = view(u, 2:N-1, 1:N-2) + u4 = view(u, 2:N-1, 3:N) for i = 1:Niter - u[2:N-1, 2:N-1] = ((view(u, 1:N-2, 2:N-1) + view(u,3:N, 2:N-1))*dy2 + (view(u,2:N-1, 1:N-2) + view(u, 2:N-1, 3:N))*dx2) * (1 / (2*(dx2+dy2))) + @dotcompat u0 .= ((u1 .+ u2).*dy2 .+ (u3 .+ u4).*dx2) .* (1 / (2*(dx2+dy2))) end return u end diff --git a/src/shootout/nbody_vec.jl b/src/shootout/nbody_vec.jl index a069eb4f..02b51d9d 100644 --- a/src/shootout/nbody_vec.jl +++ b/src/shootout/nbody_vec.jl @@ -6,20 +6,8 @@ module NBodyVec -# work around lack of Compat support for .= (Compat.jl issue #285) -if VERSION < v"0.5.0-dev+5575" #17510 - macro dotcompat(ex) - if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.= - :(copy!($(esc(ex.args[1])), $(esc(ex.args[3])))) - else - esc(ex) - end - end -else - macro dotcompat(ex) - esc(ex) - end -end +include(joinpath("..", "utils", "CompatUtils.jl")) +using .CompatUtils # Constants const solar_mass = 4 * pi * pi diff --git a/src/utils/CompatUtils.jl b/src/utils/CompatUtils.jl new file mode 100644 index 00000000..3d79de04 --- /dev/null +++ b/src/utils/CompatUtils.jl @@ -0,0 +1,20 @@ +module CompatUtils + +export @dotcompat + +# work around lack of Compat support for .= (Compat.jl issue #285) +if VERSION < v"0.5.0-dev+5575" #17510 + macro dotcompat(ex) + if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.= + :(copy!($(esc(ex.args[1])), $(esc(ex.args[3])))) + else + esc(ex) + end + end +else + macro dotcompat(ex) + esc(ex) + end +end + +end