Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boundserror with multiple right hand sides #318

Open
lijas opened this issue Jun 30, 2022 · 3 comments
Open

Boundserror with multiple right hand sides #318

lijas opened this issue Jun 30, 2022 · 3 comments

Comments

@lijas
Copy link

lijas commented Jun 30, 2022

I get an error when not allocating x when I have multiple RHS.

A = Symmetric(rand(10,10))
b = rand(10,2)
cg(A,b) #Gives error because x is created as an vector
cg!(zeros(size(b)),A,b) #this works

I guess cg(A,b) should also work?

@lijas
Copy link
Author

lijas commented Jun 30, 2022

I talked a bit with @fredrikekre . Iterative solvers might not be suited for multiple RHS since it is unclear which residual to check?

@haampie
Copy link
Member

haampie commented Jun 30, 2022

A trivial version would be to just run the exact equivalent of

[cg(A, b[:, 1]), cg(A, b[:, 2]), ..., cg(A, b[:, n])]

with an optimization where matrix multiplications act on a block vector, so that you have a higher flop/memop ratio.

But you need to keep in mind vectors converge at different speeds, so the matrix multiplication should only happen on the block that's not converged (you can split it like [not converged | converged] and re-shuffle at the end).

@lijas
Copy link
Author

lijas commented Jul 1, 2022

Do you think there would be an advantage of doing

cg!(x,A,b)

where size(x) = size(b) = (1000, 3) (ie 3 right hand sides)

over just using one rhs at the time:

cg!(x1, A, b[:,1])
cg!(x2, A, b[:,2])
cg!(x2, A, b[:,3])

Lets assume the vectors will converge with roughly the same speed.
The first version works atm, but which residual will it use to check for convergence?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants