LightKrylov_BaseKrylov Module

This module provides a collection of Krylov-based factorizations forming the computational core of LightKrylov. It also provides a set of utility functions to operate on arrays of abstract_vector. The most important ones are:

  • arnoldi(A, X, H, info): Arnoldi factorization for general square matrices.
  • lanczos(A, X, H, info): Lanczos factorization for general symmetric/hermitian matrices.
  • bidiagonalization(A, U, V, B): Lanczos bidiagonalization for arbitrary matrices.
  • qr(X, R, perm, info): QR factorization (with and without column pivoting) of an array of abstract_vector.


Interfaces

Description

Given an array and a permutation vector , this function computes in-place the column-permuted matrix

where is the column-permutation matrix constructed from the permutation vector and its inverse.

Syntax

    call apply_inverse_permutation_matrix(X, perm)

Arguments

Q : Array of vectors derived from the base types defined in the AbstractVectors module. On entry, it is the original array. On exit, it contains the column-permuted version computed in-place. It is an intent(inout) argument.

perm : Rank-1 array of integer corresponding to the desired permutation vector. It is an intent(in) argument.

  • private subroutine apply_inverse_permutation_matrix_rsp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: Q(:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_array_rsp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=sp), intent(inout) :: Q(:,:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_rdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: Q(:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_array_rdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(inout) :: Q(:,:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_csp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: Q(:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_array_csp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    complex(kind=sp), intent(inout) :: Q(:,:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_cdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: Q(:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_inverse_permutation_matrix_array_cdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    complex(kind=dp), intent(inout) :: Q(:,:)

    Basis vectors to be (un-) permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

public interface apply_permutation_matrix

Description

Given an array and a permutation vector , this function computes in-place the column-permuted matrix

where is the column-permutation matrix constructed from the permutation vector .

Syntax

    call apply_permutation_matrix(X, perm)

Arguments

Q : Array of vectors derived from the base types defined in the AbstractVectors module. On entry, it is the original array. On exit, it contains the column-permuted version computed in-place. It is an intent(inout) argument.

perm : Rank-1 array of integer corresponding to the desired permutation vector. It is an intent(in) argument.

  • private subroutine apply_permutation_matrix_rsp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: Q(:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_array_rsp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=sp), intent(inout) :: Q(:,:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_rdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: Q(:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_array_rdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(inout) :: Q(:,:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_csp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: Q(:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_array_csp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    complex(kind=sp), intent(inout) :: Q(:,:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_cdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: Q(:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

  • private subroutine apply_permutation_matrix_array_cdp(Q, perm)

    Arguments

    Type IntentOptional Attributes Name
    complex(kind=dp), intent(inout) :: Q(:,:)

    Basis vectors to be permuted.

    integer, intent(in) :: perm(:)

    Permutation matrix (vector representation).

public interface arnoldi

Description

Given a square linear operator , find matrices and such that

where is an orthogonal basis and is upper Hessenberg.

Algorithmic Features

  • The operator only needs to be accessed through matrix-vector products.
  • Constructs an orthonormal Krylov basis via the Gram-Schmidt process.
  • Constructs an upper Hessenberg matrix whose eigenvalues approximates those of .
  • Checks for convergence and invariant subspaces.

References

  • Y. Saad. "Iterative methods for sparse linear systems", SIAM 2nd edition, 2003. see Chapter 6.3: Arnoldi's method.

Syntax

    call arnoldi(A, X, H, info [, kstart] [, kend] [, tol] [, transpose] [, blksize])

Arguments

A : Linear operator derived from one the base types provided by the AbstractLinops module. The operator needs to be square, i.e. the dimension of its domain and co-domain is the same. It is an intent(in) argument.

X : Array of types derived from one the base types provided by the AbstractVectors module. It needs to be consistent with the type of A. On exit, it contains the the computed Krylov vectors. The first entry X(1) is the starting vector for the Arnoldi factorization. Additionally, the maximum number of Arnoldi steps is equal to size(X) - 1. It is an intent(inout) argument.

H : real or complex rank-2 array. On exit, it contains the upper Hessenberg matrix computed from the Arnoldi factorization. It is an intent(inout) argument.

info : integer variable. It is the LightKrylov information flag. On exit, if info > 0, the Arnoldi factorization experienced a lucky breakdown. The array of Krylov vectors X spans an -invariant subpsace of dimension info.

kstart (optional): integer value determining the index of the first Arnoldi step to be computed. By default, kstart = 1.

kend (optional): integer value determining the index of the last Arnoldi step to be computed. By default, kend = size(X) - 1.

tol (optional): Numerical tolerance below which a subspace is considered to be -invariant. By default tol = atol_sp or tol = atol_rp depending on the kind of A.

transpose (optional): logical flag determining whether the Arnoldi factorization is applied to or . Default transpose = .false.

blksize (optional): integer value determining the dimension of a block for the block Arnoldi factorization. Default is blksize=1.

  • private subroutine arnoldi_rsp(A, X, H, info, kstart, kend, tol, transpose, blksize)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_rsp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_rsp), intent(inout) :: X(:)

    Orthogonal basis for the generated Krylov subspace.

    real(kind=sp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Arnoldi factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Arnoldi factorization (default size(X)-1)

    real(kind=sp), intent(in), optional :: tol

    Tolerance to determine whether an invariant subspace has been computed or not.

    logical, intent(in), optional :: transpose

    Whether is being transposed or not (default .false.)

    integer, intent(in), optional :: blksize

    Block size for block Arnoldi (default 1).

  • private subroutine arnoldi_rdp(A, X, H, info, kstart, kend, tol, transpose, blksize)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_rdp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_rdp), intent(inout) :: X(:)

    Orthogonal basis for the generated Krylov subspace.

    real(kind=dp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Arnoldi factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Arnoldi factorization (default size(X)-1)

    real(kind=dp), intent(in), optional :: tol

    Tolerance to determine whether an invariant subspace has been computed or not.

    logical, intent(in), optional :: transpose

    Whether is being transposed or not (default .false.)

    integer, intent(in), optional :: blksize

    Block size for block Arnoldi (default 1).

  • private subroutine arnoldi_csp(A, X, H, info, kstart, kend, tol, transpose, blksize)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_csp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_csp), intent(inout) :: X(:)

    Orthogonal basis for the generated Krylov subspace.

    complex(kind=sp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Arnoldi factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Arnoldi factorization (default size(X)-1)

    real(kind=sp), intent(in), optional :: tol

    Tolerance to determine whether an invariant subspace has been computed or not.

    logical, intent(in), optional :: transpose

    Whether is being transposed or not (default .false.)

    integer, intent(in), optional :: blksize

    Block size for block Arnoldi (default 1).

  • private subroutine arnoldi_cdp(A, X, H, info, kstart, kend, tol, transpose, blksize)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_cdp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_cdp), intent(inout) :: X(:)

    Orthogonal basis for the generated Krylov subspace.

    complex(kind=dp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Arnoldi factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Arnoldi factorization (default size(X)-1)

    real(kind=dp), intent(in), optional :: tol

    Tolerance to determine whether an invariant subspace has been computed or not.

    logical, intent(in), optional :: transpose

    Whether is being transposed or not (default .false.)

    integer, intent(in), optional :: blksize

    Block size for block Arnoldi (default 1).

public interface bidiagonalization

Description

Given a general linear operator , find matrices , and such that

where and are orthogonal bases for the column span and row span of , respectively, and is a bidiagonal matrix.

Algorithmic Features

  • The operator only needs to be accessed through matrix-vector products.
  • Constructs an orthonormal Krylov basis for the column span of .
  • Constructs an orthonormal Krylov basis for the row span of .
  • Constructs a bidiagonal matrix whose singular values approximates those of .
  • Checks for convergence and invariant subspaces.

References

  • R. M. Larsen. "Lanczos bidiagonalization with partial reorthogonalization." Technical Report, 1998. (PDF)

Syntax

    call bidiagonalization(A, U, V, B, info [, kstart] [, kend] [, tol])

Arguments

A : Linear operator derived from one the base types provided by the AbstractLinops module. It is an intent(in) argument.

U : Array of types derived from one the base types provided by the AbstractVectors module. It needs to be consistent with the type of A. On exit, it contains the the computed Krylov vectors for the column span of A. The first entry U(1) is the starting vector for the Lanczos factorization. Additionally, the maximum number of Lanczos steps is equal to size(X) - 1. It is an intent(inout) argument.

V : Array of types derived from one the base types provided by the AbstractVectors module. It needs to be consistent with the type of A. On exit, it contains the the computed Krylov vectors for the row span of A. It is an intent(inout) argument.

B : real or complex rank-2 array. On exit, it contains the bidiagonal matrix computed from the Lanczos factorization. It is an intent(inout) argument.

info : integer variable. It is the LightKrylov information flag. On exit, if info > 0, the Lanczos factorization experienced a lucky breakdown.

kstart (optional): integer value determining the index of the first Lanczos step to be computed. By default, kstart = 1.

kend (optional): integer value determining the index of the last Lanczos step to be computed. By default, kend = size(X) - 1.

tol (optional): Numerical tolerance below which a subspace is considered to be -invariant. By default tol = atol_sp or tol = atol_rp depending on the kind of A.

  • private subroutine lanczos_bidiagonalization_rsp(A, U, V, B, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_rsp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_rsp), intent(inout) :: U(:)

    Orthonormal basis for the column span of . On entry, U(1) needs to be set to the starting Krylov vector.

    class(abstract_vector_rsp), intent(inout) :: V(:)

    Orthonormal basis for the row span of .

    real(kind=sp), intent(inout) :: B(:,:)

    Bidiagonal matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Lanczos factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Lanczos factorization (default 1).

    real(kind=sp), intent(in), optional :: tol

    Tolerance to determine whether invariant subspaces have been computed or not.

  • private subroutine lanczos_bidiagonalization_rdp(A, U, V, B, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_rdp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_rdp), intent(inout) :: U(:)

    Orthonormal basis for the column span of . On entry, U(1) needs to be set to the starting Krylov vector.

    class(abstract_vector_rdp), intent(inout) :: V(:)

    Orthonormal basis for the row span of .

    real(kind=dp), intent(inout) :: B(:,:)

    Bidiagonal matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Lanczos factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Lanczos factorization (default 1).

    real(kind=dp), intent(in), optional :: tol

    Tolerance to determine whether invariant subspaces have been computed or not.

  • private subroutine lanczos_bidiagonalization_csp(A, U, V, B, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_csp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_csp), intent(inout) :: U(:)

    Orthonormal basis for the column span of . On entry, U(1) needs to be set to the starting Krylov vector.

    class(abstract_vector_csp), intent(inout) :: V(:)

    Orthonormal basis for the row span of .

    complex(kind=sp), intent(inout) :: B(:,:)

    Bidiagonal matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Lanczos factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Lanczos factorization (default 1).

    real(kind=sp), intent(in), optional :: tol

    Tolerance to determine whether invariant subspaces have been computed or not.

  • private subroutine lanczos_bidiagonalization_cdp(A, U, V, B, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_linop_cdp), intent(in) :: A

    Linear operator to be factorized.

    class(abstract_vector_cdp), intent(inout) :: U(:)

    Orthonormal basis for the column span of . On entry, U(1) needs to be set to the starting Krylov vector.

    class(abstract_vector_cdp), intent(inout) :: V(:)

    Orthonormal basis for the row span of .

    complex(kind=dp), intent(inout) :: B(:,:)

    Bidiagonal matrix.

    integer, intent(out) :: info

    Information flag.

    integer, intent(in), optional :: kstart

    Starting index for the Lanczos factorization (default 1).

    integer, intent(in), optional :: kend

    Final index for the Lanczos factorization (default 1).

    real(kind=dp), intent(in), optional :: tol

    Tolerance to determine whether invariant subspaces have been computed or not.

public interface double_gram_schmidt_step

Description

Given an array of abstract_vector and an abstract_vector (or array of abstract_vectors) , this subroutine returns a modified vector orthogonal to all columns of , i.e.

using a double Gram-Schmidt process. On exit, is orthogonal to albeit does not have unit-norm. Note moreover that is assumed to be an orthonormal set of vectors. The function can also return the projection coefficients .

Syntax

    call double_gram_schmidt_step(y, X, info [, if_chk_orthonormal] [, beta])

Arguments

y : abstract_vector (or array of abstract_vector) that needs to be orthogonalize in-place against .

X : Array of abstract_vector against which needs to be orthogonalized. Note the function assumes that is an orthonormal set of vectors, i.e. . If it this is not the case, the result are meaningless.

info : integer Information flag.

if_chk_orthonormal (optional) : logical flag (default .true.) to check whether is an orthonormal set of vectors or not. If the orthonormality returns .false., the function throws an error. Note that this check is however computationally expensive and can be disable for the sake of performances.

beta (optional) : real or complex array containing the coefficients .

  • private subroutine DGS_vector_against_basis_rsp(y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_rsp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=sp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine DGS_basis_against_basis_rsp(Y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_rsp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=sp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

  • private subroutine DGS_vector_against_basis_rdp(y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_rdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=dp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine DGS_basis_against_basis_rdp(Y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_rdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=dp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

  • private subroutine DGS_vector_against_basis_csp(y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_csp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=sp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine DGS_basis_against_basis_csp(Y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_csp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=sp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

  • private subroutine DGS_vector_against_basis_cdp(y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_cdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=dp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine DGS_basis_against_basis_cdp(Y, X, info, if_chk_orthonormal, beta)

    Computes one step of the double Gram-Schmidt orthogonalization process of the abstract_vector y against the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_cdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=dp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

public interface initialize_krylov_subspace

Description

Utility function to initialize a basis for a Krylov subspace.

Syntax

    call initialize_krylov_subspace(X [, X0])

Arguments

X : Array of vectors that needs to be initialized. It is an intent(inout) argument. Note that the first action in the subroutine is call zero_basis(X), effectively zeroing-out any data stored.

X0 (optional) : Collection of vectors which will form the first few Krylov vectors. Note that X0 need not be an orthonormal basis as this subroutine includes a call qr(X0).

  • private subroutine initialize_krylov_subspace_rsp(X, X0)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: X(:)
    class(abstract_vector_rsp), intent(in), optional :: X0(:)
  • private subroutine initialize_krylov_subspace_rdp(X, X0)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: X(:)
    class(abstract_vector_rdp), intent(in), optional :: X0(:)
  • private subroutine initialize_krylov_subspace_csp(X, X0)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: X(:)
    class(abstract_vector_csp), intent(in), optional :: X0(:)
  • private subroutine initialize_krylov_subspace_cdp(X, X0)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: X(:)
    class(abstract_vector_cdp), intent(in), optional :: X0(:)

public interface is_orthonormal

Description

Utility function returning a logical .true. if the set of vectors stored in form an orthonormal set of vectors and .false. otherwise.

Syntax

    out = is_orthonormal(X)

Arguments

X : Array of derived types extended from the base types provided in the AbstractVectors module.

  • private function is_orthonormal_rsp(X) result(ortho)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(in) :: X(:)

    Return Value logical

  • private function is_orthonormal_rdp(X) result(ortho)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(in) :: X(:)

    Return Value logical

  • private function is_orthonormal_csp(X) result(ortho)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(in) :: X(:)

    Return Value logical

  • private function is_orthonormal_cdp(X) result(ortho)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(in) :: X(:)

    Return Value logical

public interface krylov_schur

Description

Given a partial Krylov decomposition

this subroutine implements the Krylov-Schur restarting strategy proposed by Stewart [1].

References

  • G. W. Stewart. "A Krylov-Schur algorithm for large eigenproblems". SIAM Journal on Matrix Analysis and Applications, vol 23 (3), 2002.

Syntax

    call krylov_schur(n, X, H, select_eigs)

Arguments

n : Number of selected eigenvalues moved to the upper left-block of the Schur matrix. It is an intent(out) argument.

X : On entry, array of abstract_vector computed using the Arnoldi process. On exit, the first n columns form an orthonormal basis for the eigenspace associated with eigenvalues moved to the upper left-block of the Schur matrix. It is an intent(inout) argument.

H : On entry, real of complex upper Hessenberg matrix computed using the Arnoldi process. On exit, the leading block contains the block of the re-ordered Schur matrix containing the selected eigenvalues. It is an intent(inout) argument.

select_eigs : Procedure to select which eigenvalues to move in the upper-left block. It is an intent(inout) argument.

  • private subroutine krylov_schur_rsp(n, X, H, select_eigs)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(out) :: n

    Number eigenvalues that have been moved to the upper left block of the Schur factorization of H.

    class(abstract_vector_rsp), intent(inout) :: X(:)

    Krylov basis.

    real(kind=sp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    procedure(eigvals_select_sp) :: select_eigs

    Procedure to select the eigenvalues to move in the upper left-block.

  • private subroutine krylov_schur_rdp(n, X, H, select_eigs)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(out) :: n

    Number eigenvalues that have been moved to the upper left block of the Schur factorization of H.

    class(abstract_vector_rdp), intent(inout) :: X(:)

    Krylov basis.

    real(kind=dp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    procedure(eigvals_select_dp) :: select_eigs

    Procedure to select the eigenvalues to move in the upper left-block.

  • private subroutine krylov_schur_csp(n, X, H, select_eigs)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(out) :: n

    Number eigenvalues that have been moved to the upper left block of the Schur factorization of H.

    class(abstract_vector_csp), intent(inout) :: X(:)

    Krylov basis.

    complex(kind=sp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    procedure(eigvals_select_sp) :: select_eigs

    Procedure to select the eigenvalues to move in the upper left-block.

  • private subroutine krylov_schur_cdp(n, X, H, select_eigs)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(out) :: n

    Number eigenvalues that have been moved to the upper left block of the Schur factorization of H.

    class(abstract_vector_cdp), intent(inout) :: X(:)

    Krylov basis.

    complex(kind=dp), intent(inout) :: H(:,:)

    Upper Hessenberg matrix.

    procedure(eigvals_select_dp) :: select_eigs

    Procedure to select the eigenvalues to move in the upper left-block.

public interface lanczos

Description

Given a symmetric or Hermitian linear operator , find matrices and such that

where is an orthogonal basis and is symmetric tridiagonal.

Algorithmic Features

  • The operator only needs to be accessed through matrix-vector products.
  • Constructs an orthonormal Krylov basis via the Lanczos process with full reorthogonalization.
  • Constructs a symmetric tridiagonal matrix whose eigenvalues approximates those of .
  • Checks for convergence and invariant subspaces.

References

  • Y. Saad. "Iterative methods for sparse linear systems", SIAM 2nd edition, 2003. see Chapter 6.6: The symmetric Lanczos algorithm.

Syntax

    call lanczos(A, X, T, info [, kstart] [, kend] [, tol])

Arguments

A : Symmetric or Hermitian linear operator derived from one the base types provided by the AbstractLinops module. It is an intent(in) argument.

X : Array of types derived from one the base types provided by the AbstractVectors module. It needs to be consistent with the type of A. On exit, it contains the the computed Krylov vectors. The first entry X(1) is the starting vector for the Lanczos factorization. Additionally, the maximum number of Lanczos steps is equal to size(X) - 1. It is an intent(inout) argument.

T : real or complex rank-2 array. On exit, it contains the symmetric tridiagonal matrix computed from the Arnoldi factorization. It is an intent(inout) argument.

info : integer variable. It is the LightKrylov information flag. On exit, if info > 0, the Lanczos factorization experienced a lucky breakdown. The array of Krylov vectors X spans an -invariant subpsace of dimension info.

kstart (optional): integer value determining the index of the first Lanczos step to be computed. By default, kstart = 1.

kend (optional): integer value determining the index of the last Lanczos step to be computed. By default, kend = size(X) - 1.

tol (optional): Numerical tolerance below which a subspace is considered to be -invariant. By default tol = atol_sp or tol = atol_rp depending on the kind of A.

  • private subroutine lanczos_tridiagonalization_rsp(A, X, T, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_sym_linop_rsp), intent(in) :: A
    class(abstract_vector_rsp), intent(inout) :: X(:)
    real(kind=sp), intent(inout) :: T(:,:)
    integer, intent(out) :: info
    integer, intent(in), optional :: kstart
    integer, intent(in), optional :: kend
    real(kind=sp), intent(in), optional :: tol
  • private subroutine lanczos_tridiagonalization_rdp(A, X, T, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_sym_linop_rdp), intent(in) :: A
    class(abstract_vector_rdp), intent(inout) :: X(:)
    real(kind=dp), intent(inout) :: T(:,:)
    integer, intent(out) :: info
    integer, intent(in), optional :: kstart
    integer, intent(in), optional :: kend
    real(kind=dp), intent(in), optional :: tol
  • private subroutine lanczos_tridiagonalization_csp(A, X, T, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_hermitian_linop_csp), intent(in) :: A
    class(abstract_vector_csp), intent(inout) :: X(:)
    complex(kind=sp), intent(inout) :: T(:,:)
    integer, intent(out) :: info
    integer, intent(in), optional :: kstart
    integer, intent(in), optional :: kend
    real(kind=sp), intent(in), optional :: tol
  • private subroutine lanczos_tridiagonalization_cdp(A, X, T, info, kstart, kend, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_hermitian_linop_cdp), intent(in) :: A
    class(abstract_vector_cdp), intent(inout) :: X(:)
    complex(kind=dp), intent(inout) :: T(:,:)
    integer, intent(out) :: info
    integer, intent(in), optional :: kstart
    integer, intent(in), optional :: kend
    real(kind=dp), intent(in), optional :: tol

public interface orthogonalize_against_basis

  • private subroutine orthogonalize_vector_against_basis_rsp(y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_rsp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=sp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine orthogonalize_basis_against_basis_rsp(Y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector basis Y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_rsp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=sp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

  • private subroutine orthogonalize_vector_against_basis_rdp(y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_rdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=dp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine orthogonalize_basis_against_basis_rdp(Y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector basis Y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_rdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    real(kind=dp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

  • private subroutine orthogonalize_vector_against_basis_csp(y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_csp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=sp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine orthogonalize_basis_against_basis_csp(Y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector basis Y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_csp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=sp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

  • private subroutine orthogonalize_vector_against_basis_cdp(y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: y

    Input abstract_vector to orthogonalize

    class(abstract_vector_cdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=dp), intent(out), optional :: beta(:)

    Projection coefficients if requested

  • private subroutine orthogonalize_basis_against_basis_cdp(Y, X, info, if_chk_orthonormal, beta)

    Orthogonalizes the abstract_vector basis Y against a basis X of abstract_vector.

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: Y(:)

    Input abstract_vector basis to orthogonalize

    class(abstract_vector_cdp), intent(in) :: X(:)

    Input abstract_vector basis to orthogonalize against

    integer, intent(out) :: info

    Information flag.

    logical, intent(in), optional :: if_chk_orthonormal
    complex(kind=dp), intent(out), optional :: beta(:,:)

    Projection coefficients if requested

public interface orthonormalize_basis

Description

Given an array of vectors, it computes an orthonormal basis for its column-span using the double_gram_schmidt process. All computations are done in-place.

Syntax

    call orthonormalize_basis(X)

Arguments

X : Array of abstract_vector to orthonormalize. Note that this process is done in-place. It is an intent(inout) argument.

  • private subroutine orthonormalize_basis_rsp(X)

    Orthonormalizes the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: X(:)

    Input abstract_vector basis to orthogonalize against

  • private subroutine orthonormalize_basis_rdp(X)

    Orthonormalizes the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: X(:)

    Input abstract_vector basis to orthogonalize against

  • private subroutine orthonormalize_basis_csp(X)

    Orthonormalizes the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: X(:)

    Input abstract_vector basis to orthogonalize against

  • private subroutine orthonormalize_basis_cdp(X)

    Orthonormalizes the abstract_vector basis X

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: X(:)

    Input abstract_vector basis to orthogonalize against

public interface qr

Description

Given an array of types derived from abstract_vector, it computes the in-place QR factorization of , i.e.

where is an orthonormal arrays of vectors such that and is upper triangular. Note that it can also perform the QR factorization with column pivoting

where is a permutation matrix ensuring that the diagonal entries of have non-increasing absolute values. This amounts to using the pivoting QR as a rank-revealing factorization.

References

  • G. H. Golub & C. F. Van Loan. "Matrix Computations". 4th edition, The John Hopkins University Press, 2013. See Chapter 5.2.8: Modified Gram-Schmidt algorithm.

Syntax

    call qr(Q [, R] [, perm], info [, tol])

Arguments

Q: Array of types derived from one of the base types provided in the AbstractVectors module. On entry, it contains the original array. On exit, it is overwritten by the orthogonal basis for its span. It is an intent(inout) argument.

R: real or complex rank-2 array. On exit, its contains the upper triangular matrix resulting from the QR factorization. It is an intent(out) argument.

perm (optional): Rank-1 array of integer corresponding to the indices of permuted columns. If perm is absent, the naive QR factorization is being computed.

info: integer information flag.

tol (optional): Numerical tolerance to determine whether two vectors are colinear or not. Default tol = atol_sp or tol = atol_dp.

  • private subroutine qr_no_pivoting_rsp(Q, R, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    real(kind=sp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: info

    Information flag.

    real(kind=sp), intent(in), optional :: tol

    Tolerance to determine colinearity.

  • private subroutine qr_with_pivoting_rsp(Q, R, perm, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rsp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    real(kind=sp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: perm(size(Q))

    Permutation matrix.

    integer, intent(out) :: info

    Information flag.

    real(kind=sp), intent(in), optional :: tol

    Tolerance to detect colinearity.

  • private subroutine qr_no_pivoting_rdp(Q, R, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    real(kind=dp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: info

    Information flag.

    real(kind=dp), intent(in), optional :: tol

    Tolerance to determine colinearity.

  • private subroutine qr_with_pivoting_rdp(Q, R, perm, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_rdp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    real(kind=dp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: perm(size(Q))

    Permutation matrix.

    integer, intent(out) :: info

    Information flag.

    real(kind=dp), intent(in), optional :: tol

    Tolerance to detect colinearity.

  • private subroutine qr_no_pivoting_csp(Q, R, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    complex(kind=sp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: info

    Information flag.

    real(kind=sp), intent(in), optional :: tol

    Tolerance to determine colinearity.

  • private subroutine qr_with_pivoting_csp(Q, R, perm, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_csp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    complex(kind=sp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: perm(size(Q))

    Permutation matrix.

    integer, intent(out) :: info

    Information flag.

    real(kind=sp), intent(in), optional :: tol

    Tolerance to detect colinearity.

  • private subroutine qr_no_pivoting_cdp(Q, R, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    complex(kind=dp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: info

    Information flag.

    real(kind=dp), intent(in), optional :: tol

    Tolerance to determine colinearity.

  • private subroutine qr_with_pivoting_cdp(Q, R, perm, info, tol)

    Arguments

    Type IntentOptional Attributes Name
    class(abstract_vector_cdp), intent(inout) :: Q(:)

    Array of abstract_vector to be orthogonalized.

    complex(kind=dp), intent(out) :: R(:,:)

    Upper triangular matrix resulting from the QR factorization.

    integer, intent(out) :: perm(size(Q))

    Permutation matrix.

    integer, intent(out) :: info

    Information flag.

    real(kind=dp), intent(in), optional :: tol

    Tolerance to detect colinearity.


Abstract Interfaces

abstract interface

  • public function eigvals_select_dp(lambda) result(selected)

    Arguments

    Type IntentOptional Attributes Name
    complex(kind=dp), intent(in) :: lambda(:)

    Return Value logical, (size(lambda))

abstract interface

  • public function eigvals_select_sp(lambda) result(selected)

    Arguments

    Type IntentOptional Attributes Name
    complex(kind=sp), intent(in) :: lambda(:)

    Return Value logical, (size(lambda))