# NAG Library Routine Document

## 1Purpose

f11jef solves a real sparse symmetric system of linear equations, represented in symmetric coordinate storage format, using a conjugate gradient or Lanczos method, without preconditioning, with Jacobi or with SSOR preconditioning.

## 2Specification

Fortran Interface
 Subroutine f11jef ( n, nnz, a, irow, icol, b, tol, x, itn, work,
 Integer, Intent (In) :: n, nnz, irow(nnz), icol(nnz), maxitn, lwork Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: itn, iwork(n+1) Real (Kind=nag_wp), Intent (In) :: a(nnz), omega, b(n), tol Real (Kind=nag_wp), Intent (Inout) :: x(n) Real (Kind=nag_wp), Intent (Out) :: rnorm, work(lwork) Character (*), Intent (In) :: method Character (1), Intent (In) :: precon
#include nagmk26.h
 void f11jef_ (const char *method, const char *precon, const Integer *n, const Integer *nnz, const double a[], const Integer irow[], const Integer icol[], const double *omega, const double b[], const double *tol, const Integer *maxitn, double x[], double *rnorm, Integer *itn, double work[], const Integer *lwork, Integer iwork[], Integer *ifail, const Charlen length_method, const Charlen length_precon)

## 3Description

f11jef solves a real sparse symmetric linear system of equations
 $Ax=b,$
using a preconditioned conjugate gradient method (see Barrett et al. (1994)), or a preconditioned Lanczos method based on the algorithm SYMMLQ (see Paige and Saunders (1975)). The conjugate gradient method is more efficient if $A$ is positive definite, but may fail to converge for indefinite matrices. In this case the Lanczos method should be used instead. For further details see Barrett et al. (1994).
The routine allows the following choices for the preconditioner:
• no preconditioning;
• Jacobi preconditioning (see Young (1971));
• symmetric successive-over-relaxation (SSOR) preconditioning (see Young (1971)).
For incomplete Cholesky (IC) preconditioning see f11jcf.
The matrix $A$ is represented in symmetric coordinate storage (SCS) format (see Section 2.1.2 in the F11 Chapter Introduction) in the arrays a, irow and icol. The array a holds the nonzero entries in the lower triangular part of the matrix, while irow and icol hold the corresponding row and column indices.

## 4References

Barrett R, Berry M, Chan T F, Demmel J, Donato J, Dongarra J, Eijkhout V, Pozo R, Romine C and Van der Vorst H (1994) Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods SIAM, Philadelphia
Paige C C and Saunders M A (1975) Solution of sparse indefinite systems of linear equations SIAM J. Numer. Anal. 12 617–629
Young D (1971) Iterative Solution of Large Linear Systems Academic Press, New York

## 5Arguments

1:     $\mathbf{method}$ – Character(*)Input
On entry: specifies the iterative method to be used.
${\mathbf{method}}=\text{'CG'}$
${\mathbf{method}}=\text{'SYMMLQ'}$
Lanczos method (SYMMLQ).
Constraint: ${\mathbf{method}}=\text{'CG'}$ or $\text{'SYMMLQ'}$.
2:     $\mathbf{precon}$ – Character(1)Input
On entry: specifies the type of preconditioning to be used.
${\mathbf{precon}}=\text{'N'}$
No preconditioning.
${\mathbf{precon}}=\text{'J'}$
Jacobi.
${\mathbf{precon}}=\text{'S'}$
Symmetric successive-over-relaxation (SSOR).
Constraint: ${\mathbf{precon}}=\text{'N'}$, $\text{'J'}$ or $\text{'S'}$.
3:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 1$.
4:     $\mathbf{nnz}$ – IntegerInput
On entry: the number of nonzero elements in the lower triangular part of the matrix $A$.
Constraint: $1\le {\mathbf{nnz}}\le {\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$.
5:     $\mathbf{a}\left({\mathbf{nnz}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the nonzero elements of the lower triangular part of the matrix $A$, ordered by increasing row index, and by increasing column index within each row. Multiple entries for the same row and column indices are not permitted. The routine f11zbf may be used to order the elements in this way.
6:     $\mathbf{irow}\left({\mathbf{nnz}}\right)$ – Integer arrayInput
7:     $\mathbf{icol}\left({\mathbf{nnz}}\right)$ – Integer arrayInput
On entry: the row and column indices of the nonzero elements supplied in array a.
Constraints:
irow and icol must satisfy these constraints (which may be imposed by a call to f11zbf):
• $1\le {\mathbf{irow}}\left(\mathit{i}\right)\le {\mathbf{n}}$ and $1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{irow}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$;
• ${\mathbf{irow}}\left(\mathit{i}-1\right)<{\mathbf{irow}}\left(\mathit{i}\right)$ or ${\mathbf{irow}}\left(\mathit{i}-1\right)={\mathbf{irow}}\left(\mathit{i}\right)$ and ${\mathbf{icol}}\left(\mathit{i}-1\right)<{\mathbf{icol}}\left(\mathit{i}\right)$, for $\mathit{i}=2,3,\dots ,{\mathbf{nnz}}$.
8:     $\mathbf{omega}$ – Real (Kind=nag_wp)Input
On entry: if ${\mathbf{precon}}=\text{'S'}$, omega is the relaxation parameter $\omega$ to be used in the SSOR method. Otherwise omega need not be initialized.
Constraint: $0.0<{\mathbf{omega}}<2.0$.
9:     $\mathbf{b}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the right-hand side vector $b$.
10:   $\mathbf{tol}$ – Real (Kind=nag_wp)Input
On entry: the required tolerance. Let ${x}_{k}$ denote the approximate solution at iteration $k$, and ${r}_{k}$ the corresponding residual. The algorithm is considered to have converged at iteration $k$ if
 $rk∞≤τ×b∞+A∞xk∞.$
If ${\mathbf{tol}}\le 0.0$, $\tau =\mathrm{max}\phantom{\rule{0.25em}{0ex}}\sqrt{\epsilon },10\epsilon ,\sqrt{n}\epsilon$ is used, where $\epsilon$ is the machine precision. Otherwise $\tau =\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{tol}},10\epsilon ,\sqrt{n}\epsilon \right)$ is used.
Constraint: ${\mathbf{tol}}<1.0$.
11:   $\mathbf{maxitn}$ – IntegerInput
On entry: the maximum number of iterations allowed.
Constraint: ${\mathbf{maxitn}}\ge 1$.
12:   $\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: an initial approximation to the solution vector $x$.
On exit: an improved approximation to the solution vector $x$.
13:   $\mathbf{rnorm}$ – Real (Kind=nag_wp)Output
On exit: the final value of the residual norm ${‖{r}_{k}‖}_{\infty }$, where $k$ is the output value of itn.
14:   $\mathbf{itn}$ – IntegerOutput
On exit: the number of iterations carried out.
15:   $\mathbf{work}\left({\mathbf{lwork}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
16:   $\mathbf{lwork}$ – IntegerInput
On entry: the dimension of the array work as declared in the (sub)program from which f11jef is called.
Constraints:
• if ${\mathbf{method}}=\text{'CG'}$, ${\mathbf{lwork}}\ge 6×{\mathbf{n}}+\mathit{\nu }+120$;
• if ${\mathbf{method}}=\text{'SYMMLQ'}$, ${\mathbf{lwork}}\ge 7×{\mathbf{n}}+\mathit{\nu }+120$.
where $\mathit{\nu }={\mathbf{n}}$ for ${\mathbf{precon}}=\text{'J'}$ or $\text{'S'}$, and $0$ otherwise.
17:   $\mathbf{iwork}\left({\mathbf{n}}+1\right)$ – Integer arrayWorkspace
18:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{method}}\ne \text{'CG'}$ or $\text{'SYMMLQ'}$, or ${\mathbf{precon}}\ne \text{'N'}$, $\text{'J'}$ or $\text{'S'}$, or ${\mathbf{n}}<1$, or ${\mathbf{nnz}}<1$, or ${\mathbf{nnz}}>{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$, or omega lies outside the interval $\left(0.0,2.0\right)$, or ${\mathbf{tol}}\ge 1.0$, or ${\mathbf{maxitn}}<1$, or lwork too small.
${\mathbf{ifail}}=2$
On entry, the arrays irow and icol fail to satisfy the following constraints:
• $1\le {\mathbf{irow}}\left(i\right)\le {\mathbf{n}}$ and $1\le {\mathbf{icol}}\left(i\right)\le {\mathbf{irow}}\left(i\right)$, for $i=1,2,\dots ,{\mathbf{nnz}}$;
• ${\mathbf{irow}}\left(i-1\right)<{\mathbf{irow}}\left(i\right)$, or ${\mathbf{irow}}\left(i-1\right)={\mathbf{irow}}\left(i\right)$ and ${\mathbf{icol}}\left(i-1\right)<{\mathbf{icol}}\left(i\right)$, for $i=2,3,\dots ,{\mathbf{nnz}}$.
Therefore a nonzero element has been supplied which does not lie in the lower triangular part of $A$, is out of order, or has duplicate row and column indices. Call f11zbf to reorder and sum or remove duplicates.
${\mathbf{ifail}}=3$
On entry, the matrix $A$ has a zero diagonal element. Jacobi and SSOR preconditioners are not appropriate for this problem.
${\mathbf{ifail}}=4$
The required accuracy could not be obtained. However, a reasonable accuracy has been obtained and further iterations could not improve the result.
${\mathbf{ifail}}=5$
Required accuracy not obtained in maxitn iterations.
${\mathbf{ifail}}=6$
The preconditioner appears not to be positive definite.
${\mathbf{ifail}}=7$
The matrix of the coefficients appears not to be positive definite (conjugate gradient method only).
${\mathbf{ifail}}=8$ (f11gdf, f11gef or f11gff)
A serious error has occurred in an internal call to one of the specified routines. Check all subroutine calls and array sizes. Seek expert help.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

On successful termination, the final residual ${r}_{k}=b-A{x}_{k}$, where $k={\mathbf{itn}}$, satisfies the termination criterion
 $rk∞≤τ×b∞+A∞xk∞.$
The value of the final residual norm is returned in rnorm.

## 8Parallelism and Performance

f11jef is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f11jef makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The time taken by f11jef for each iteration is roughly proportional to nnz. One iteration with the Lanczos method (SYMMLQ) requires a slightly larger number of operations than one iteration with the conjugate gradient method.
The number of iterations required to achieve a prescribed accuracy cannot be easily determined a priori, as it can depend dramatically on the conditioning and spectrum of the preconditioned matrix of the coefficients $\stackrel{-}{A}={M}^{-1}A$.

## 10Example

This example solves a symmetric positive definite system of equations using the conjugate gradient method, with SSOR preconditioning.

### 10.1Program Text

Program Text (f11jefe.f90)

### 10.2Program Data

Program Data (f11jefe.d)

### 10.3Program Results

Program Results (f11jefe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017