You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/custom_workspaces.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,6 +188,17 @@ function Krylov.kscal!(n::Integer, s::T, x::HaloVector{T}) where T <: FloatOrCom
188
188
return x
189
189
end
190
190
191
+
function Krylov.kdiv!(n::Integer, x::HaloVector{T}, s::T) where T <: FloatOrComplex
192
+
mx, nx = size(x.data)
193
+
_x = x.data
194
+
for i = 1:mx-1
195
+
for j = 1:nx-1
196
+
_x[i,j] = _x[i,j] / s
197
+
end
198
+
end
199
+
return x
200
+
end
201
+
191
202
function Krylov.kaxpy!(n::Integer, s::T, x::HaloVector{T}, y::HaloVector{T}) where T <: FloatOrComplex
192
203
mx, nx = size(x.data)
193
204
_x = x.data
@@ -224,6 +235,30 @@ function Krylov.kcopy!(n::Integer, y::HaloVector{T}, x::HaloVector{T}) where T <
224
235
return y
225
236
end
226
237
238
+
function Krylov.kscalcopy!(n::Integer, y::HaloVector{T}, s::T, x::HaloVector{T}) where T <: FloatOrComplex
239
+
mx, nx = size(x.data)
240
+
_x = x.data
241
+
_y = y.data
242
+
for i = 1:mx-1
243
+
for j = 1:nx-1
244
+
_y[i,j] = s * _x[i,j]
245
+
end
246
+
end
247
+
return y
248
+
end
249
+
250
+
function Krylov.kdivcopy!(n::Integer, y::HaloVector{T}, x::HaloVector{T}, s::T) where T <: FloatOrComplex
251
+
mx, nx = size(x.data)
252
+
_x = x.data
253
+
_y = y.data
254
+
for i = 1:mx-1
255
+
for j = 1:nx-1
256
+
_y[i,j] = _x[i,j] / s
257
+
end
258
+
end
259
+
return y
260
+
end
261
+
227
262
function Krylov.kfill!(x::HaloVector{T}, val::T) where T <: FloatOrComplex
228
263
mx, nx = size(x.data)
229
264
_x = x.data
@@ -251,7 +286,13 @@ function Krylov.kref!(n::Integer, x::HaloVector{T}, y::HaloVector{T}, c::T, s::T
251
286
end
252
287
```
253
288
254
-
Note that `Krylov.kref!` is only required for `minres_qlp`.
289
+
By default, `kdiv!(n, y, x, s)` calls `kscal!(n, y, t, x)` with `t = 1/s`, so a separate implementation isn't required.
290
+
However, this approach may introduce numerical issues when `s` is very small.
291
+
We do this because computing $y \leftarrow t \times x$ can often leverage SIMD or fused multiply-add (FMA) instructions on certain architectures, capabilities that a direct element-wise division $y \leftarrow x/s$ typically lacks.
292
+
Thus, the implementation of `kdiv!` provides flexibility, allowing users to choose a trade-off between speed and numerical precision by overloading the function if needed.
293
+
The operations provided by `kdivcopy!` and `kscalcopy!` could be implemented directly by using `kcopy!`, `kscal!`, and `kdiv!` but require two separate memory passes, which can be suboptimal for performance.
294
+
To address this limitation, `kdivcopy!` and `kscalcopy!` fuse the copy and scaling/division operations into a single memory pass.
295
+
Note that `Krylov.kref!` is only required for the function `minres_qlp`.
255
296
256
297
### 2D Poisson equation solver with Krylov methods
0 commit comments