Module for LSQR.
User function to access the sparse matrix A
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | mode |
|
||
integer, | intent(in) | :: | m |
number of rows in |
||
integer, | intent(in) | :: | n |
number of columns in |
||
real(kind=wp), | intent(inout), | dimension(:) | :: | x | ||
real(kind=wp), | intent(inout), | dimension(:) | :: | y |
main class to access the lsqr solver.
procedure(aprod_func), public, deferred :: aprod | ../../ User function to access the sparse matrix |
procedure, public :: lsqr => LSQR | ../../ main solver routine |
procedure, public :: acheck | |
procedure, public :: xcheck |
a simplier version of lsqr_solver where
the aprod
function is provided internally.
To use, first call the initialize
method
to set the matrix and other inputs.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | private | :: | m | = | 0 |
number of rows in |
|
integer, | private | :: | n | = | 0 |
number of columns in |
|
integer, | private | :: | num_nonzero_elements | = | 0 |
number of nonzero elements in |
|
integer, | private, | dimension(:), allocatable | :: | irow |
sparsity row indices |
||
integer, | private, | dimension(:), allocatable | :: | icol |
sparsity column indices |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | a |
sparse |
||
real(kind=wp), | private | :: | atol | = | zero |
relative error in definition of |
|
real(kind=wp), | private | :: | btol | = | zero |
relative error in definition of |
|
real(kind=wp), | private | :: | conlim | = | zero |
An upper limit on |
|
integer, | private | :: | itnlim | = | 100 |
max iterations |
|
integer, | private | :: | nout | = | 0 |
output unit for printing |
|
real(kind=wp), | private, | dimension(:), allocatable | :: | Ax |
|
||
real(kind=wp), | private, | dimension(:), allocatable | :: | Aty |
|
||
real(kind=wp), | private, | dimension(:), allocatable | :: | v |
workspace array (dimension n) |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | w |
workspace array (dimension n) |
procedure, public :: lsqr => LSQR | ../../ main solver routine |
procedure, public :: acheck | |
procedure, public :: xcheck | |
procedure, public :: initialize => initialize_ez | ../../ Constructor. Must be call first. |
procedure, public :: solve => solve_ez | |
procedure, public :: aprod => aprod_ez | ../../ internal routine |
Returns with precautions to avoid overflow.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | a | |||
real(kind=wp), | intent(in) | :: | b |
Constructor for lsqr_solver_ez.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver_ez), | intent(out) | :: | me | |||
integer, | intent(in) | :: | m |
number of rows in |
||
integer, | intent(in) | :: | n |
number of columns in |
||
real(kind=wp), | intent(in), | dimension(:) | :: | a |
nonzero elements of |
|
integer, | intent(in), | dimension(:) | :: | irow |
row indices of nonzero elements of |
|
integer, | intent(in), | dimension(:) | :: | icol |
column indices of nonzero elements of |
|
real(kind=wp), | intent(in), | optional | :: | atol |
relative error in definition of |
|
real(kind=wp), | intent(in), | optional | :: | btol |
relative error in definition of |
|
real(kind=wp), | intent(in), | optional | :: | conlim |
An upper limit on |
|
integer, | intent(in), | optional | :: | itnlim |
max iterations |
|
integer, | intent(in), | optional | :: | nout |
output unit for printing |
The internal aprod
function for the lsqr_solver_ez class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver_ez), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | mode |
|
||
integer, | intent(in) | :: | m |
number of rows in |
||
integer, | intent(in) | :: | n |
number of columns in |
||
real(kind=wp), | intent(inout), | dimension(:) | :: | x |
[n] |
|
real(kind=wp), | intent(inout), | dimension(:) | :: | y |
[m] |
Wrapper for LSQR for the easy version of the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver_ez), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(me%m) | :: | b | ||
real(kind=wp), | intent(in) | :: | damp | |||
real(kind=wp), | intent(out), | dimension(me%n) | :: | x |
the computed solution |
|
integer, | intent(out) | :: | istop |
exit code (see LSQR). |
||
real(kind=wp), | intent(out), | optional, | dimension(me%n) | :: | se | |
integer, | intent(out), | optional | :: | itn | ||
real(kind=wp), | intent(out), | optional | :: | anorm | ||
real(kind=wp), | intent(out), | optional | :: | acond | ||
real(kind=wp), | intent(out), | optional | :: | rnorm | ||
real(kind=wp), | intent(out), | optional | :: | arnorm | ||
real(kind=wp), | intent(out), | optional | :: | xnorm |
LSQR finds a solution to the following problems:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | m |
the number of rows in |
||
integer, | intent(in) | :: | n |
the number of columns in |
||
real(kind=wp), | intent(in) | :: | damp |
The damping parameter for problem 3 above.
(damp should be 0.0 for problems 1 and 2.)
If the system |
||
logical, | intent(in) | :: | wantse |
A logical variable to say if the array |
||
real(kind=wp), | intent(inout) | :: | u(m) |
The rhs vector |
||
real(kind=wp), | intent(inout) | :: | v(n) |
workspace |
||
real(kind=wp), | intent(inout) | :: | w(n) |
workspace |
||
real(kind=wp), | intent(out) | :: | x(n) |
Returns the computed solution |
||
real(kind=wp), | intent(out), | dimension(*) | :: | se |
If |
|
real(kind=wp), | intent(in) | :: | atol |
An estimate of the relative error in the data
defining the matrix |
||
real(kind=wp), | intent(in) | :: | btol |
An estimate of the relative error in the data
defining the rhs vector |
||
real(kind=wp), | intent(in) | :: | conlim |
An upper limit on |
||
integer, | intent(in) | :: | itnlim |
An upper limit on the number of iterations.
Suggested value:
* |
||
integer, | intent(in) | :: | nout |
File number for printed output. If nonzero,
a summary will be printed on file |
||
integer, | intent(out) | :: | istop |
An integer giving the reason for termination: |
||
integer, | intent(out) | :: | itn |
The number of iterations performed. |
||
real(kind=wp), | intent(out) | :: | anorm |
An estimate of the Frobenius norm of |
||
real(kind=wp), | intent(out) | :: | acond |
An estimate of |
||
real(kind=wp), | intent(out) | :: | rnorm |
An estimate of the final value of |
||
real(kind=wp), | intent(out) | :: | arnorm |
An estimate of the final value of
|
||
real(kind=wp), | intent(out) | :: | xnorm |
An estimate of the norm of the final
solution vector |
Checks the two modes of aprod for LSQR.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | m |
No. of rows of A. |
||
integer, | intent(in) | :: | n |
No. of columns of A. |
||
integer, | intent(in) | :: | nout |
A file number for printed output. |
||
real(kind=wp), | intent(in) | :: | eps |
The machine precision. |
||
real(kind=wp) | :: | v(n) | ||||
real(kind=wp) | :: | w(m) | ||||
real(kind=wp) | :: | x(n) | ||||
real(kind=wp) | :: | y(m) | ||||
integer, | intent(out) | :: | inform |
Error indicator. inform = 0 if aprod seems to be consistent. inform = 1 otherwise. |
Tests if x
solves a certain least-squares problem.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(lsqr_solver), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | m |
The number of rows in A. |
||
integer, | intent(in) | :: | n |
The number of columns in A. |
||
integer, | intent(in) | :: | nout |
A file number for printed output. If nout = 0, nothing is printed. |
||
real(kind=wp), | intent(in) | :: | anorm |
An estimate of norm(A) or norm( A, delta*I ) if delta > 0. Normally this will be available from LSQR or CRAIG. |
||
real(kind=wp), | intent(in) | :: | damp |
Possibly defines a damped problem. |
||
real(kind=wp), | intent(in) | :: | eps |
Machine precision. |
||
real(kind=wp), | intent(in) | :: | b(m) |
The right-hand side of Ax = b etc. |
||
real(kind=wp), | intent(out) | :: | u(m) |
On exit, u = r (where r = b - Ax). |
||
real(kind=wp), | intent(out) | :: | v(n) |
On exit, v = A'r. |
||
real(kind=wp), | intent(out) | :: | w(n) |
On exit, w = A'r - damp^2 x. |
||
real(kind=wp), | intent(in) | :: | x(n) |
The given estimate of a solution. |
||
integer, | intent(out) | :: | inform |
inform = 0 if b = 0 and x = 0. inform = 1, 2 or 3 if x seems to solve systems 1 2 or 3 above. |
||
real(kind=wp), | intent(out) | :: | test1 |
These are dimensionless quantities that should be "small" if x does seem to solve one of the systems. "small" means less than tol = eps**power, where power is defined as a parameter below. |
||
real(kind=wp), | intent(out) | :: | test2 |
These are dimensionless quantities that should be "small" if x does seem to solve one of the systems. "small" means less than tol = eps**power, where power is defined as a parameter below. |
||
real(kind=wp), | intent(out) | :: | test3 |
These are dimensionless quantities that should be "small" if x does seem to solve one of the systems. "small" means less than tol = eps**power, where power is defined as a parameter below. |