Skip to content

Commit

Permalink
Use in-place operations and BLAS inf-norm in inner loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadlinger committed Oct 22, 2015
1 parent c2f33b4 commit 7b141b2
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/expmv_fun.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export expmv

norm_inf(v) = abs(v[Base.LinAlg.BLAS.iamax(v)])

function expmv(t, A, b; M::Array{Float64, 2} = Array(Float64, 0, 0), prec = "double", shift = false, full_term = false, prnt = false)
# bal = false,

Expand Down Expand Up @@ -82,34 +84,37 @@ function expmv(t, A, b; M::Array{Float64, 2} = Array(Float64, 0, 0), prec = "dou
if shift
eta = exp(t * mu / s)
end

f = b;

# if prnt
# fprintf("m = %2.0f, s = %g, m_actual = ", m, s)
# end

for i = 1:s
c1 = norm(b,Inf);

f = copy(b)
b1 = copy(b)
b2 = similar(b)
@inbounds for i = 1:s
c1 = norm_inf(b1)
for k = 1:m
b = (t/(s*k))*(A*b);
f = f + b;
c2 = norm(b,Inf);
A_mul_B!(b2, A, b1)
@simd for l in 1:n
b2[l] *= (t / (s * k))
end
(b1, b2) = (b2, b1)

@simd for l in 1:n
f[l] = f[l] + b1[l]
end
c2 = norm_inf(b1)
if !full_term
if c1 + c2 <= tol*norm(f,Inf)
if c1 + c2 <= tol * norm_inf(f)
# if prnt
# fprintf(" %2.0f, ", k)
# end
break
end
c1 = c2;
c1 = c2
end

end
if shift
f = eta*f
scale!(f, eta)
end
b = f
copy!(b1, f)
end

# if prnt
Expand Down

0 comments on commit 7b141b2

Please sign in to comment.