# NAG FL Interfacef11dxf (complex_​gen_​precon_​jacobi)

## 1Purpose

f11dxf computes the approximate solution of a complex, Hermitian or non-Hermitian, sparse system of linear equations applying a number of Jacobi iterations. It is expected that f11dxf will be used as a preconditioner for the iterative solution of complex sparse systems of equations.

## 2Specification

Fortran Interface
 Subroutine f11dxf ( init, n, nnz, a, irow, icol, b, x, diag, work,
 Integer, Intent (In) :: niter, n, nnz, irow(nnz), icol(nnz) Integer, Intent (Inout) :: ifail Complex (Kind=nag_wp), Intent (In) :: a(nnz), b(n) Complex (Kind=nag_wp), Intent (Inout) :: diag(n) Complex (Kind=nag_wp), Intent (Out) :: x(n), work(n) Character (1), Intent (In) :: store, trans, init, check
#include <nag.h>
 void f11dxf_ (const char *store, const char *trans, const char *init, const Integer *niter, const Integer *n, const Integer *nnz, const Complex a[], const Integer irow[], const Integer icol[], const char *check, const Complex b[], Complex x[], Complex diag[], Complex work[], Integer *ifail, const Charlen length_store, const Charlen length_trans, const Charlen length_init, const Charlen length_check)
The routine may be called by the names f11dxf or nagf_sparse_complex_gen_precon_jacobi.

## 3Description

f11dxf computes the approximate solution of the complex sparse system of linear equations $Ax=b$ using niter iterations of the Jacobi algorithm (see also Golub and Van Loan (1996) and Young (1971)):
 $xk+1=xk+D-1b-Axk$ (1)
where $k=1,2,\dots ,{\mathbf{niter}}$ and ${x}_{0}=0$.
f11dxf can be used both for non-Hermitian and Hermitian systems of equations. For Hermitian matrices, either all nonzero elements of the matrix $A$ can be supplied using coordinate storage (CS), or only the nonzero elements of the lower triangle of $A$, using symmetric coordinate storage (SCS) (see the F11 Chapter Introduction).
It is expected that f11dxf will be used as a preconditioner for the iterative solution of complex sparse systems of equations, using either the suite comprising the routines f11grf, f11gsf and f11gtf, for Hermitian systems, or the suite comprising the routines f11brf, f11bsf and f11btf, for non-Hermitian systems of equations.
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Young D (1971) Iterative Solution of Large Linear Systems Academic Press, New York

## 5Arguments

1: $\mathbf{store}$Character(1) Input
On entry: specifies whether the matrix $A$ is stored using symmetric coordinate storage (SCS) (applicable only to a Hermitian matrix $A$) or coordinate storage (CS) (applicable to both Hermitian and non-Hermitian matrices).
${\mathbf{store}}=\text{'N'}$
The complete matrix $A$ is stored in CS format.
${\mathbf{store}}=\text{'S'}$
The lower triangle of the Hermitian matrix $A$ is stored in SCS format.
Constraint: ${\mathbf{store}}=\text{'N'}$ or $\text{'S'}$.
2: $\mathbf{trans}$Character(1) Input
On entry: if ${\mathbf{store}}=\text{'N'}$, specifies whether the approximate solution of $Ax=b$ or of ${A}^{\mathrm{H}}x=b$ is required.
${\mathbf{trans}}=\text{'N'}$
The approximate solution of $Ax=b$ is calculated.
${\mathbf{trans}}=\text{'T'}$
The approximate solution of ${A}^{\mathrm{H}}x=b$ is calculated.
Suggested value: if the matrix $A$ is Hermitian and stored in CS format, it is recommended that ${\mathbf{trans}}=\text{'N'}$ for reasons of efficiency.
Constraint: ${\mathbf{trans}}=\text{'N'}$ or $\text{'T'}$.
3: $\mathbf{init}$Character(1) Input
On entry: on first entry, init should be set to 'I', unless the diagonal elements of $A$ are already stored in the array diag. If diag already contains the diagonal of $A$, it must be set to 'N'.
${\mathbf{init}}=\text{'N'}$
diag must contain the diagonal of $A$.
${\mathbf{init}}=\text{'I'}$
diag will store the diagonal of $A$ on exit.
Suggested value: ${\mathbf{init}}=\text{'I'}$ on first entry; ${\mathbf{init}}=\text{'N'}$, subsequently, unless diag has been overwritten.
Constraint: ${\mathbf{init}}=\text{'N'}$ or $\text{'I'}$.
4: $\mathbf{niter}$Integer Input
On entry: the number of Jacobi iterations requested.
Constraint: ${\mathbf{niter}}\ge 1$.
5: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 1$.
6: $\mathbf{nnz}$Integer Input
On entry: if ${\mathbf{store}}=\text{'N'}$, the number of nonzero elements in the matrix $A$.
If ${\mathbf{store}}=\text{'S'}$, the number of nonzero elements in the lower triangle of the matrix $A$.
Constraints:
• if ${\mathbf{store}}=\text{'N'}$, $1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$;
• if ${\mathbf{store}}=\text{'S'}$, $1\le {\mathbf{nnz}}\le {\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$.
7: $\mathbf{a}\left({\mathbf{nnz}}\right)$Complex (Kind=nag_wp) array Input
On entry: if ${\mathbf{store}}=\text{'N'}$, the nonzero elements in the matrix $A$ (CS format).
If ${\mathbf{store}}=\text{'S'}$, the nonzero elements in the lower triangle of the matrix $A$ (SCS format).
In both cases, the elements of either $A$ or of its lower triangle must be ordered by increasing row index and by increasing column index within each row. Multiple entries for the same row and columns indices are not permitted. The routine f11znf or f11zpf may be used to reorder the elements in this way for CS and SCS storage, respectively.
8: $\mathbf{irow}\left({\mathbf{nnz}}\right)$Integer array Input
9: $\mathbf{icol}\left({\mathbf{nnz}}\right)$Integer array Input
On entry: if ${\mathbf{store}}=\text{'N'}$, the row and column indices of the nonzero elements supplied in a.
If ${\mathbf{store}}=\text{'S'}$, the row and column indices of the nonzero elements of the lower triangle of the matrix $A$ supplied in a.
Constraints:
• $1\le {\mathbf{irow}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$;
• if ${\mathbf{store}}=\text{'N'}$, $1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$;
• if ${\mathbf{store}}=\text{'S'}$, $1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{irow}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$;
• either ${\mathbf{irow}}\left(\mathit{i}-1\right)<{\mathbf{irow}}\left(\mathit{i}\right)$ or both ${\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}}$.
10: $\mathbf{check}$Character(1) Input
On entry: specifies whether or not the CS or SCS representation of the matrix $A$ should be checked.
${\mathbf{check}}=\text{'C'}$
Checks are carried out on the values of n, nnz, irow, icol; if ${\mathbf{init}}=\text{'N'}$, diag is also checked.
${\mathbf{check}}=\text{'N'}$
None of these checks are carried out.
Constraint: ${\mathbf{check}}=\text{'C'}$ or $\text{'N'}$.
11: $\mathbf{b}\left({\mathbf{n}}\right)$Complex (Kind=nag_wp) array Input
On entry: the right-hand side vector $b$.
12: $\mathbf{x}\left({\mathbf{n}}\right)$Complex (Kind=nag_wp) array Output
On exit: the approximate solution vector ${x}_{{\mathbf{niter}}}$.
13: $\mathbf{diag}\left({\mathbf{n}}\right)$Complex (Kind=nag_wp) array Input/Output
On entry: if ${\mathbf{init}}=\text{'N'}$, the diagonal elements of $A$.
On exit: if ${\mathbf{init}}=\text{'N'}$, unchanged on exit.
If ${\mathbf{init}}=\text{'I'}$, the diagonal elements of $A$.
14: $\mathbf{work}\left({\mathbf{n}}\right)$Complex (Kind=nag_wp) array Workspace
15: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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{check}}\ne \text{'N'}$ or $\text{'C'}$: ${\mathbf{check}}=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{init}}\ne \text{'N'}$ or $\text{'I'}$: ${\mathbf{init}}=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{niter}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{niter}}\ge 1$.
On entry, ${\mathbf{store}}\ne \text{'N'}$ or $\text{'S'}$: ${\mathbf{store}}=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{trans}}\ne \text{'N'}$ or $\text{'T'}$: ${\mathbf{trans}}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{nnz}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnz}}\ge 1$.
On entry, ${\mathbf{nnz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnz}}\le {\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$
On entry, ${\mathbf{nnz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$
${\mathbf{ifail}}=3$
On entry, ${\mathbf{a}}\left(i\right)$ is out of order: $i=〈\mathit{\text{value}}〉$.
On entry, $\mathit{I}=〈\mathit{\text{value}}〉$, ${\mathbf{icol}}\left(\mathit{I}\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{irow}}\left(\mathit{I}\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{icol}}\left(\mathit{I}\right)\ge 1$ and ${\mathbf{icol}}\left(\mathit{I}\right)\le {\mathbf{irow}}\left(\mathit{I}\right)$.
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{icol}}\left(i\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{icol}}\left(i\right)\ge 1$ and ${\mathbf{icol}}\left(i\right)\le {\mathbf{n}}$.
On entry, $\mathit{I}=〈\mathit{\text{value}}〉$, ${\mathbf{irow}}\left(\mathit{I}\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irow}}\left(\mathit{I}\right)\ge 1$ and ${\mathbf{irow}}\left(\mathit{I}\right)\le {\mathbf{n}}$.
On entry, the location (${\mathbf{irow}}\left(\mathit{I}\right),{\mathbf{icol}}\left(\mathit{I}\right)$) is a duplicate: $\mathit{I}=〈\mathit{\text{value}}〉$.
A nonzero element has been supplied which does not lie within the matrix $A$, is out of order, or has duplicate row and column indices. Consider calling either f11zaf or f11zbf to reorder and sum or remove duplicates when ${\mathbf{store}}=\text{'N'}$ or ${\mathbf{store}}=\text{'S'}$, respectively.
${\mathbf{ifail}}=4$
On entry, the element ${\mathbf{diag}}\left(\mathit{I}\right)$ is zero: $\mathit{I}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=5$
On entry, the diagonal element of the $\mathit{I}$th row is zero or missing: $\mathit{I}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

In general, the Jacobi method cannot be used on its own to solve systems of linear equations. The rate of convergence is bound by its spectral properties (see, for example, Golub and Van Loan (1996)) and as a solver, the Jacobi method can only be applied to a limited set of matrices. One condition that guarantees convergence is strict diagonal dominance.
However, the Jacobi method can be used successfully as a preconditioner to a wider class of systems of equations. The Jacobi method has good vector/parallel properties, hence it can be applied very efficiently. Unfortunately, it is not possible to provide criteria which define the applicability of the Jacobi method as a preconditioner, and its usefulness must be judged for each case.

## 8Parallelism and Performance

f11dxf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f11dxf 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.

### 9.1Timing

The time taken for a call to f11dxf is proportional to ${\mathbf{niter}}×{\mathbf{nnz}}$.

### 9.2Use of check

It is expected that a common use of f11dxf will be as preconditioner for the iterative solution of complex, Hermitian or non-Hermitian, linear systems. In this situation, f11dxf is likely to be called many times. In the interests of both reliability and efficiency, you are recommended to set ${\mathbf{check}}=\text{'C'}$ for the first of such calls, and to set ${\mathbf{check}}=\text{'N'}$ for all subsequent calls.

## 10Example

This example solves the complex sparse non-Hermitian system of equations $Ax=b$ iteratively using f11dxf as a preconditioner.

### 10.1Program Text

Program Text (f11dxfe.f90)

### 10.2Program Data

Program Data (f11dxfe.d)

### 10.3Program Results

Program Results (f11dxfe.r)