Mercurial > repos > public > sbplib_julia
comparison sbpD2.jl @ 129:1aaeb46ba5f4 cell_based_test
Improve efficiency of apply by the following:
- Remove divisions in interior loop by storing and multiplying by the reciprocal of grid spacing instead.
- Add @inline to apply(::Laplace
- Remove initialization of w = 0 in apply(::Stencil) by manually unrolling first iteration of the loop.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 14 Feb 2019 16:25:22 +0100 |
parents | 6c6979ff17f4 |
children | 6b6d921e8f05 |
comparison
equal
deleted
inserted
replaced
128:7c0b9bb7ab4d | 129:1aaeb46ba5f4 |
---|---|
1 abstract type ConstantStencilOperator end | 1 abstract type ConstantStencilOperator end |
2 | 2 |
3 # Apply for different regions Lower/Interior/Upper or Unknown region | 3 # Apply for different regions Lower/Interior/Upper or Unknown region |
4 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower}) | 4 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Lower}) |
5 return @inbounds apply(op.closureStencils[Int(i)], v, Int(i))/h^2 | 5 return @inbounds h*h*apply(op.closureStencils[Int(i)], v, Int(i)) |
6 end | 6 end |
7 | 7 |
8 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Interior}) | 8 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Interior}) |
9 return @inbounds apply(op.innerStencil, v, Int(i))/h^2 | 9 return @inbounds h*h*apply(op.innerStencil, v, Int(i)) |
10 end | 10 end |
11 | 11 |
12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Upper}) | 12 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, i::Index{Upper}) |
13 N = length(v) | 13 N = length(v) |
14 return @inbounds Int(op.parity)*apply_backwards(op.closureStencils[N-Int(i)+1], v, Int(i))/h^2 | 14 return @inbounds h*h*Int(op.parity)*apply_backwards(op.closureStencils[N-Int(i)+1], v, Int(i)) |
15 end | 15 end |
16 | 16 |
17 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, index::Index{Unknown}) | 17 @inline function apply(op::ConstantStencilOperator, h::Real, v::AbstractVector, index::Index{Unknown}) |
18 cSize = closureSize(op) | 18 cSize = closureSize(op) |
19 N = length(v) | 19 N = length(v) |