Mercurial > repos > public > sbplib_julia
changeset 88:170e5447bc19 patch_based_test
Reduce allocations
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 25 Jan 2019 15:10:41 +0100 |
parents | 38733e84ef1a |
children | c0729ade65da |
files | diffOp.jl sbpD2.jl stencil.jl |
diffstat | 3 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/diffOp.jl Fri Jan 25 13:40:15 2019 +0100 +++ b/diffOp.jl Fri Jan 25 15:10:41 2019 +0100 @@ -50,7 +50,7 @@ # u = L*v using UnsafeArrays @inline function apply!(L::Laplace{2}, u::AbstractVector, v::AbstractVector) - u .= 0*u # Fix this? + fill!(u,0) h = Grid.spacings(L.grid) li = LinearIndices(L.grid.numberOfPointsPerDim) @@ -77,7 +77,9 @@ end end - u .= L.a*u + for i ∈ eachindex(u) + @inbounds u[i] = L.a*u[i] + end return nothing end
--- a/sbpD2.jl Fri Jan 25 13:40:15 2019 +0100 +++ b/sbpD2.jl Fri Jan 25 15:10:41 2019 +0100 @@ -15,7 +15,7 @@ end for i ∈ range(innerEnd+1, length=cSize) - @inbounds u[i] = Int(op.parity)*apply(flip(op.closureStencils[N-i+1]), v, i)/h^2 + @inbounds u[i] = Int(op.parity)*applybackwards(op.closureStencils[N-i+1], v, i)/h^2 end return nothing
--- a/stencil.jl Fri Jan 25 13:40:15 2019 +0100 +++ b/stencil.jl Fri Jan 25 15:10:41 2019 +0100 @@ -31,3 +31,12 @@ end return w end + +Base.@propagate_inbounds function applybackwards(s::Stencil, v::AbstractVector, i::Int) + w = zero(eltype(v)) + for j ∈ s.range[1]:s.range[2] + @inbounds weight = s[j] + w += weight*v[i-j] + end + return w +end