GithubHelp home page GithubHelp logo

Comments (21)

dlfivefifty avatar dlfivefifty commented on June 27, 2024

This isn't implemented yet. Note that the LU factorisation of a BandedBlockBandedMatrix may have dense blocks, so when implemented it would consist of first converting to a BlockSkylineMatrix and using the block banded LU factorisation. This is possible to implement using LAPack's dense LU on the column blocks, but we haven't got around to it.

from blockbandedmatrices.jl.

djsegal avatar djsegal commented on June 27, 2024

Is there anything I could do to help?

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

If you want to try implementing it that would be great. The goal is to have lu!(::BlockSkylineMatrix) return a BlockSkylineMatrix. There are a few steps:

  1. Copy over lu!(::StridedMatrix) to LazyArrays.jl to work with general strided matrices. That is, something like
_lu!(_, A, pivot, check) = LinearAlgebra.lu!(A, pivot; check=check) # Fall back to standard `lu!`
function _lu!(::AbstractColumnMajor, A::AbstractMatrix{<:BlasFloat}, pivot, check)
    if pivot === Val(false)
        return generic_lufact!(A, pivot; check = check)
    end
    lpt = LAPACK.getrf!(A)
    check && checknonsingular(lpt[3])
    return LU{T,typeof(A)}(lpt[1], lpt[2], lpt[3])
end
lu!(A::AbstractMatrix, pivot::Union{Val{false}, Val{true}} = Val(true);
             check::Bool = true) = _lu!(MemoryLayout(A), A, pivot, check)
  1. If A is a BlockSkylineMatrix, then L = colblockbandwidth(A,1)[K]; V = view(A, Block.(K:K+L) is already a ColumnMajor, so LazyArrays.lu! should work. We therefore just need to go block-column-by-block-column, call lu!, (which modifies A in place), then use this to update the columns to the right of A.
  2. The last part is lu(A), which needs to pad A by adding extra blocks above the diagonal to capture the fill-in.

from blockbandedmatrices.jl.

djsegal avatar djsegal commented on June 27, 2024

Would the solver described in the following discourse post be useful for any of this?

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

I believe doing a hierarchical solver with block matrix inversion can be used to reduce the complexity from O(n^2) to O(n^(3/2)), where n is the total number of unknowns. The right way to do this would be to leverage https://github.com/JuliaMatrices/HierarchicalMatrices.jl.

That said, the first step is a proper standard LU decomposition, which while it is O(n^2) can easily leverage LAPack, and hence get multithreading for free, and for moderate n would surely be much faster than hierarchical solvers. Performance testing would then guide how many levels to use in a hierarchical solver.

from blockbandedmatrices.jl.

djsegal avatar djsegal commented on June 27, 2024

Putting the hierarchical matrices aside, how exactly is the LU decomposition not leveraging LAPack?

Is this like a 2 line fix or something much deeper?

// also, this segue should have probably gone on BandedMatrices... sorry about that 😬

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

Not two lines, I outlined what needs to be done above.

from blockbandedmatrices.jl.

djsegal avatar djsegal commented on June 27, 2024

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

Oh, BandedMatrices.jl already has a fast LU using LAPack, so I'm not sure I understand the point of block inversion except for BlockBandedMatrices.jl

from blockbandedmatrices.jl.

djsegal avatar djsegal commented on June 27, 2024

This was two separate issues.

At first, I wanted a black-box solution to quickly solving A\b using BandedBlockBanded matrices.

After realizing this wasn't possible, I setup my matrix so that it has 4 blocks:

submatrix type
A Banded
B Sparse
C Sparse
D Dense

Then using blockwise inversion, I setup a package that should in theory quickly do this. However I'm not getting the speedup I thought I'd get.

That's why I posted to discourse and thought it might be related to this issue. Apologies again for the confusion.

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

This is the sort of thing SparseMatrixCSC excels at, as it automatically deduces the optimal pivoting strategy. Is there a reason sparse matrices won't work for you here?

from blockbandedmatrices.jl.

djsegal avatar djsegal commented on June 27, 2024

It seemed like you could get a win in the limit of A becoming the whole matrix? Shouldn't a diagonal solver beat a sparse array solver (assuming narrow bands)?

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

For a well-conditioned banded matrix, UMFPack is almost as fast as LAPack, especially with OpenBLAS which has very slow banded solvers. My blog post https://approximatelyfunctioning.blogspot.com/2018/12/banded-matrices-and-ordinary.html gives some timing examples but these are with MKL. But even if you get a 4x speedup using a banded solver, that gain will probably be lost in a blockwise inversion.

from blockbandedmatrices.jl.

rveltz avatar rveltz commented on June 27, 2024

Can't it be done for BlockTridiagonalMatrix first? There should be an analytical formula

from blockbandedmatrices.jl.

rveltz avatar rveltz commented on June 27, 2024

For example, for BlockTridiagonalMatrix, the LU decomposition is known analytically. The issue is that the block of the decomposition could be dense whereas, in principle, we only need to store their action. I was thinking about using LazyArrays for this. Would you recommand something else?

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

Are you imagining an increasingly complicated operator tree? I don't think that's viable, and if it is LazyArrays.jl won't help since it templates the arguments, meaning having complicated operator trees requires excessive compiling.

For BlockTridiagonalMatrix you wouldn't want this anyways since the blocks are dense, so its possible to do the linear algebra directly.

from blockbandedmatrices.jl.

rveltz avatar rveltz commented on June 27, 2024

My blocks are 1000 x 1000 so I am not sure I want to fill them in with a LU decomposition. Also the matrice A is from a 5 points finite differences approximations, a bit like your Laplacian example but not homogenous. I was thinking about gauss seidel, but it is tranpose(A) which is diagonally dominant, so the convergence is slow.

from blockbandedmatrices.jl.

rveltz avatar rveltz commented on June 27, 2024

I forgot to say that you were right, this is what I intended to do until I read your answer...

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

Do you need to calculate the factorisation fast, or just invert systems fast? That is, are you using the same matrix with multiple right hand side?

The LU factors should be practically banded-block-banded (they’ll have exponential decay in the bands) so one option is to calculate the factorisation using dense LU and then compress the results.

But really this is a case where iterative methods are the go to solution.

from blockbandedmatrices.jl.

rveltz avatar rveltz commented on June 27, 2024

I need to invert systems fast. More precisely, I need to solve (I-A) \ rhs1 and (I-A/2) \ rhs2. Right now, I am doing this with SparseArrays: one third of the time is spent to build A and 2/3 of the time to solve the two equations.

I tried iterative methods but I dont have a good preconditioner. The convergence is way too slow.

from blockbandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 27, 2024

Right. What you are asking for may not currently be possible. I don't think hierarchical solvers will help much here either as the involve dense inverses, that is, for an n^2 x n^2 matrix we need to invert log(n) matrices of size n x n. After this inverse is calculated it can be compressed. So usually they are only used when the same inverse is reused multiple times.

I have some vague ideas on using the fact that the inverse of banded matrices is banded + semi-separable, hence can be represented using a small amount of memory and I believe form an algebra, but I don't have time to pursue this at the moment (I'm hoping for an interested student at some point).

from blockbandedmatrices.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.