cholesky_minnorm_solver Derived Type

type, public :: cholesky_minnorm_solver

Sparse direct minimum-norm solver class.

Example

  type(cholesky_minnorm_solver) :: solver
  call solver%analyze(m, n, irow, icol, istat) ! once for the sparsity pattern
  call solver%factor(a, damp, istat)           ! each time the values of A change
  call solver%solve(b, x, istat)               ! for each right-hand side

Inherited by

type~~cholesky_minnorm_solver~~InheritedByGraph type~cholesky_minnorm_solver cholesky_minnorm_solver type~nlesolver_type nlesolver_type type~nlesolver_type->type~cholesky_minnorm_solver cholesky

Components

Type Visibility Attributes Name Initial
logical, private :: analyzed = .false.

if analyze has been called

logical, private :: factored = .false.

if factor has been called

integer, private :: m = 0

number of rows in A

integer, private :: n = 0

number of columns in A

integer, private :: nnz = 0

number of nonzeros in A

real(kind=wp), private :: damp = zero

damping parameter used in the factorization

integer, private, dimension(:), allocatable :: rowptr

row pointers (size m+1)

integer, private, dimension(:), allocatable :: colidx

column indices (size nnz)

integer, private, dimension(:), allocatable :: map

index into the user's a array for each CSR element (size nnz)

real(kind=wp), private, dimension(:), allocatable :: val

values of A in CSR order (size nnz)

integer, private, dimension(:), allocatable :: adjptr

(size m+1)

integer, private, dimension(:), allocatable :: adj

(size adjptr(m+1)-1)

integer, private, dimension(:), allocatable :: perm

perm(new) = old

integer, private, dimension(:), allocatable :: iperm

iperm(old) = new

integer, private, dimension(:), allocatable :: first

first column in each row (size m)

integer(kind=ip), private, dimension(:), allocatable :: ptr

start of each row in env (size m+1)

real(kind=wp), private, dimension(:), allocatable :: env

envelope values


Type-Bound Procedures

procedure, public :: analyze

  • private subroutine analyze(me, m, n, irow, icol, istat)

    Symbolic analysis of the sparsity pattern of A. This only has to be called once for a given sparsity pattern.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(inout) :: me
    integer, intent(in) :: m

    number of rows in A

    integer, intent(in) :: n

    number of columns in A

    integer, intent(in), dimension(:) :: irow

    row indices of the nonzero elements of A

    integer, intent(in), dimension(:) :: icol

    column indices of the nonzero elements of A (same size as irow)

    integer, intent(out) :: istat

    status code (CHOLESKY_SUCCESS if no errors)

procedure, public :: factor

  • private subroutine factor(me, a, damp, istat)

    Numeric factorization: form in the envelope storage and compute its Cholesky factorization .

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(inout) :: me
    real(kind=wp), intent(in), dimension(:) :: a

    nonzero elements of A (in the same order as irow and icol in analyze)

    real(kind=wp), intent(in) :: damp

    damping parameter (0 for none)

    integer, intent(out) :: istat

    status code (CHOLESKY_SUCCESS if no errors)

procedure, public :: solve

  • private subroutine solve(me, b, x, istat, n_refine, rnorm)

    Solve for the minimum-norm solution: , .

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(inout) :: me
    real(kind=wp), intent(in), dimension(:) :: b

    right-hand side (size m)

    real(kind=wp), intent(out), dimension(:) :: x

    minimum-norm solution (size n)

    integer, intent(out) :: istat

    status code (CHOLESKY_SUCCESS if no errors)

    integer, intent(in), optional :: n_refine

    maximum number of iterative refinement steps (default is 2)

    real(kind=wp), intent(out), optional :: rnorm

    final residual norm

procedure, public :: destroy

  • private subroutine destroy(me)

    Destroy the solver (deallocate all the arrays).

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(out) :: me

procedure, public :: is_analyzed

  • private pure function is_analyzed(me)

    Returns true if analyze has been called successfully.

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(in) :: me

    Return Value logical

procedure, public :: envelope_size

  • private pure function envelope_size(me)

    Number of elements in the envelope of the Cholesky factor (i.e., the storage required for L, in reals). Returns 0 if not analyzed.

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(in) :: me

    Return Value integer(kind=int64)

procedure, public :: bandwidth

  • private pure function bandwidth(me)

    Maximum bandwidth of the reordered . Returns -1 if not analyzed.

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(in) :: me

    Return Value integer

procedure, public :: get_permutation

  • private subroutine get_permutation(me, perm)

    Returns the row ordering computed by analyze: perm(new) = old. Returns an unallocated array if not analyzed.

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(in) :: me
    integer, intent(out), dimension(:), allocatable :: perm

procedure, private :: lower_solve

  • private subroutine lower_solve(me, c, y)

    Solve using the Cholesky factor. c and y are in the original row ordering.

    Arguments

    Type IntentOptional Attributes Name
    class(cholesky_minnorm_solver), intent(in) :: me
    real(kind=wp), intent(in), dimension(me%m) :: c
    real(kind=wp), intent(out), dimension(me%m) :: y

Source Code

    type,public :: cholesky_minnorm_solver
        !! Sparse direct minimum-norm solver class.
        !!
        !!### Example
        !!```fortran
        !!  type(cholesky_minnorm_solver) :: solver
        !!  call solver%analyze(m, n, irow, icol, istat) ! once for the sparsity pattern
        !!  call solver%factor(a, damp, istat)           ! each time the values of A change
        !!  call solver%solve(b, x, istat)               ! for each right-hand side
        !!```
        private
        logical :: analyzed = .false. !! if `analyze` has been called
        logical :: factored = .false. !! if `factor` has been called
        integer :: m   = 0 !! number of rows in `A`
        integer :: n   = 0 !! number of columns in `A`
        integer :: nnz = 0 !! number of nonzeros in `A`
        real(wp) :: damp = zero !! damping parameter used in the factorization

        ! `A` stored by rows (CSR):
        integer,dimension(:),allocatable  :: rowptr !! row pointers (size `m+1`)
        integer,dimension(:),allocatable  :: colidx !! column indices (size `nnz`)
        integer,dimension(:),allocatable  :: map    !! index into the user's `a` array for each CSR element (size `nnz`)
        real(wp),dimension(:),allocatable :: val    !! values of `A` in CSR order (size `nnz`)

        ! graph of `A*A^T` (off-diagonal nonzeros), CSR:
        integer,dimension(:),allocatable :: adjptr !! (size `m+1`)
        integer,dimension(:),allocatable :: adj    !! (size `adjptr(m+1)-1`)

        ! row ordering:
        integer,dimension(:),allocatable :: perm  !! `perm(new) = old`
        integer,dimension(:),allocatable :: iperm !! `iperm(old) = new`

        ! envelope storage of the lower triangle of L (in the new ordering):
        ! row `r` holds columns `first(r):r`, stored contiguously starting at `ptr(r)`.
        integer,dimension(:),allocatable     :: first !! first column in each row (size `m`)
        integer(ip),dimension(:),allocatable :: ptr   !! start of each row in `env` (size `m+1`)
        real(wp),dimension(:),allocatable    :: env   !! envelope values

    contains

        private

        procedure,public :: analyze
        procedure,public :: factor
        procedure,public :: solve
        procedure,public :: destroy
        procedure,public :: is_analyzed
        procedure,public :: envelope_size
        procedure,public :: bandwidth
        procedure,public :: get_permutation

        procedure :: lower_solve

    end type cholesky_minnorm_solver