Mercurial > repos > public > sbplib_julia
changeset 78:fbf7398f8154 cell_based_test
Inline and inbounds everything
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Thu, 24 Jan 2019 14:38:14 +0100 |
parents | e4fa13137d12 |
children | b795ec7f9ca0 |
files | diffOp.jl sbpD2.jl stencil.jl |
diffstat | 3 files changed, 9 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/diffOp.jl Fri Jan 18 13:51:32 2019 +0100 +++ b/diffOp.jl Thu Jan 24 14:38:14 2019 +0100 @@ -61,7 +61,7 @@ end # u = L*v -function apply(L::Laplace{2}, v::AbstractVector, i::Int) +@inline function apply(L::Laplace{2}, v::AbstractVector, i::Int) h = Grid.spacings(L.grid) li = LinearIndices(L.grid.numberOfPointsPerDim) @@ -69,10 +69,10 @@ I = ci[i] # 2nd x-derivative - vx = view(v, view(li,:,I[2])) + vx = @inbounds view(v, view(li,:,I[2])) uᵢ = apply(L.op, h[1], vx , I[1]) # 2nd y-derivative - vy = view(v, view(li,I[1],:)) + vy = @inbounds view(v, view(li,I[1],:)) uᵢ += apply(L.op, h[2], vy, I[2]) return uᵢ
--- a/sbpD2.jl Fri Jan 18 13:51:32 2019 +0100 +++ b/sbpD2.jl Thu Jan 24 14:38:14 2019 +0100 @@ -1,15 +1,15 @@ abstract type ConstantStencilOperator end -function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) +@inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Int) cSize = closureSize(op) N = length(v) if i ∈ range(1; length=cSize) - uᵢ = apply(op.closureStencils[i], v, i)/h^2 + uᵢ = @inbounds apply(op.closureStencils[i], v, i)/h^2 elseif i ∈ range(N - cSize+1, length=cSize) - uᵢ = Int(op.parity)*apply(flip(op.closureStencils[N-i+1]), v, i)/h^2 + uᵢ = @inbounds Int(op.parity)*apply(flip(op.closureStencils[N-i+1]), v, i)/h^2 else - uᵢ = apply(op.innerStencil, v, i)/h^2 + uᵢ = @inbounds apply(op.innerStencil, v, i)/h^2 end return uᵢ
--- a/stencil.jl Fri Jan 18 13:51:32 2019 +0100 +++ b/stencil.jl Thu Jan 24 14:38:14 2019 +0100 @@ -25,10 +25,10 @@ end end -function apply(s::Stencil, v::AbstractVector, i::Int) +@inline function apply(s::Stencil, v::AbstractVector, i::Int) w = zero(eltype(v)) for j ∈ s.range[1]:s.range[2] - w += s[j]*v[i+j] + @inbounds w += s[j]*v[i+j] end return w end