I’m trying to solve several linear equations that each change with each step of time.
For example, I have a 100x300 grid that I need to solve for every time step.
I’m trying to use the in-place solvers from Krylov.jl. I make a matrix of multiple BicgstabSolver()
in order to allocate memory so that it can be used in multithreading but they all seem to change to the last value?
Here’s the example:
using Krylov
AA = [1.0+3.0im 2.0im; 2.0+0.0im 1.0+4.0im]
rhs = rand(ComplexF64, 2);
bicstab_solver = BicgstabSolver(length(rhs),length(rhs), typeof(rhs))
BICSTAB_Solver = fill(deepcopy(bicstab_solver), (100,300));
function testkrylovsolver(bsolv, AA)
for i in 1:size(bsolv)[2]
for j in 1:size(bsolv)[1]
rhs = rand(ComplexF64, 2);
Krylov.bicgstab!(bsolv[j,i],AA,rhs);
end
end
return nothing
end
testkrylovsolver(BICSTAB_Solver, AA)
To test:
BICSTAB_Solver[1,1].x
Output:
2-element Vector{ComplexF64}:
0.0638220002534428 + 0.022209886941768144im
0.1879664301184788 - 0.036897073475912104im
and
BICSTAB_Solver[100,6].x
Output:
2-element Vector{ComplexF64}:
0.0638220002534428 + 0.022209886941768144im
0.1879664301184788 - 0.036897073475912104im