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

Use FastLapackInterface.jl tooling #61

Closed
ChrisRackauckas opened this issue Dec 16, 2021 · 5 comments
Closed

Use FastLapackInterface.jl tooling #61

ChrisRackauckas opened this issue Dec 16, 2021 · 5 comments

Comments

@ChrisRackauckas
Copy link
Member

In Base.LinearAlgebra, the Lapack routines are always called twice, once for computing the necessary workspace and once for executing the function. In FastLapackInterface.jl, I introduce a specialized type for each factorization (LU, Cholesky, QR and Schur) that contains all necessary intermediary matrices and a function that execute the algorithm with preallocated space.

https://git.dynare.org/DynareJulia/FastLapackInterface.jl

Seems like that would be useful to use here since it would match our pre-caching interface.

@MichelJuillard

@MichelJuillard
Copy link

Tell me if I can be of any help or if I can improve the current implementation in any way

@MichelJuillard
Copy link

LU factorization needs two workspaces:

  • lu: a n x n matrix containing L and U triangular matrices
  • ipvt: a pivot vector with n elements
    If you want to keep the original matrix, you need the lu workspace, otherwise you only need ipvt
    Does LinearSolve.solve() keep the A matrix intact or is the replaced by the factorization?
    Note also, that in the case of LU factorization, Lapack doesn't need a first pass to compute the size of the workspace as it is self evident here.

@rayegun
Copy link
Collaborator

rayegun commented Dec 18, 2021

By default it does a deepcopy unless you pass alias_A=true to init in common.jl. Then it does lu!, which (I believe) is destructive to that copy held in the LinearCache.

@ChrisRackauckas
Copy link
Member Author

Yeah for safety it defaults to copying, but the keyword argument alias_A = true turns that off. When that argument is true, we are free to modify the original A how we please.

@MichelJuillard
Copy link

I. In factorization.jl:41

  • A is the object in which we store the factorization
  • we need an additional vector to store the pivots
  • then we call xgetrf_ to compute the factorization (small improvement with respect to Base.lu!(), the pivot vector is allocated once for all problems with the same size)

II. If the factorization is stored in A by xgetrf_, we need to call xgetrs_ to actually solve the linear problem instead of Base.ldiv!() that expects a Base.LU object

@rayegun rayegun closed this as completed Jul 14, 2022
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

3 participants