Skip to content

Commit b8056b2

Browse files
authored
Merge pull request #187 from samuelpowell/idrsalloc
Reduce allocation in IDRS inner loop
2 parents 7103a27 + d97012a commit b8056b2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/idrs.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function idrs!(x, A, b;
4545
history = ConvergenceHistory(partial=!log)
4646
history[:tol] = tol
4747
reserve!(history,:resnorm, maxiter)
48-
idrs_method!(history, x, linsys_op, (A,), b, s, tol, maxiter; kwargs...)
48+
idrs_method!(history, x, A, b, s, tol, maxiter; kwargs...)
4949
log && shrink!(history)
5050
log ? (x, history) : x
5151
end
@@ -67,14 +67,12 @@ end
6767
om
6868
end
6969

70-
@inline linsys_op(x, A) = A*x
71-
72-
function idrs_method!(log::ConvergenceHistory, X, op, args, C::T,
70+
function idrs_method!(log::ConvergenceHistory, X, A, C::T,
7371
s::Number, tol::Number, maxiter::Number; smoothing::Bool=false, verbose::Bool=false
7472
) where {T}
7573

7674
verbose && @printf("=== idrs ===\n%4s\t%7s\n","iter","resnorm")
77-
R = C - op(X, args...)::T
75+
R = C - A*X
7876
normR = vecnorm(R)
7977
iter = 1
8078

@@ -123,7 +121,7 @@ function idrs_method!(log::ConvergenceHistory, X, op, args, C::T,
123121
V .= R .- V
124122

125123
U[k] .= Q .+ om .* V
126-
G[k] = op(U[k], args...)
124+
A_mul_B!(G[k], A, U[k])
127125

128126
# Bi-orthogonalise the new basis vectors
129127

@@ -164,15 +162,15 @@ function idrs_method!(log::ConvergenceHistory, X, op, args, C::T,
164162
return X
165163
end
166164
if k < s
167-
f[k+1:s] = f[k+1:s] - beta*M[k+1:s,k]
165+
f[k+1:s] .-= beta*M[k+1:s,k]
168166
end
169167
iter += 1
170168
end
171169

172170
# Now we have sufficient vectors in G_j to compute residual in G_j+1
173171
# Note: r is already perpendicular to P so v = r
174172
copy!(V, R)
175-
Q = op(V, args...)::T
173+
A_mul_B!(Q, A, V)
176174
om = omega(Q, R)
177175
R .-= om .* Q
178176
X .+= om .* V

0 commit comments

Comments
 (0)