# NAG CL Interfacef11dkc (real_​gen_​precon_​jacobi)

Settings help

CL Name Style:

## 1Purpose

f11dkc computes the approximate solution of a real, symmetric or nonsymmetric, sparse system of linear equations applying a number of Jacobi iterations. It is expected that f11dkc will be used as a preconditioner for the iterative solution of real sparse systems of equations.

## 2Specification

 #include
 void f11dkc (Nag_SparseNsym_Store store, Nag_TransType trans, Nag_InitializeA init, Integer niter, Integer n, Integer nnz, const double a[], const Integer irow[], const Integer icol[], Nag_SparseNsym_CheckData check, const double b[], double x[], double diag[], NagError *fail)
The function may be called by the names: f11dkc, nag_sparse_real_gen_precon_jacobi or nag_sparse_nsym_jacobi.

## 3Description

f11dkc computes the approximate solution of the real 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-1(b-Axk)$ (1)
where $k=1,2,\dots ,{\mathbf{niter}}$ and ${x}_{0}=0$.
f11dkc can be used both for nonsymmetric and symmetric systems of equations. For symmetric 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 f11dkc will be used as a preconditioner for the iterative solution of real sparse systems of equations. This may be with either the symmetric or nonsymmetric suites of functions.
For symmetric systems the suite consists of:
For nonsymmetric systems the suite consists of:

## 4References

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}$Nag_SparseNsym_Store Input
On entry: specifies whether the matrix $A$ is stored using symmetric coordinate storage (SCS) (applicable only to a symmetric matrix $A$) or coordinate storage (CS) (applicable to both symmetric and non-symmetric matrices).
${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$
The complete matrix $A$ is stored in CS format.
${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreSCS}$
The lower triangle of the symmetric matrix $A$ is stored in SCS format.
Constraint: ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$ or $\mathrm{Nag_SparseNsym_StoreSCS}$.
2: $\mathbf{trans}$Nag_TransType Input
On entry: if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$, specifies whether the approximate solution of $Ax=b$ or of ${A}^{\mathrm{T}}x=b$ is required.
${\mathbf{trans}}=\mathrm{Nag_NoTrans}$
The approximate solution of $Ax=b$ is calculated.
${\mathbf{trans}}=\mathrm{Nag_Trans}$
The approximate solution of ${A}^{\mathrm{T}}x=b$ is calculated.
Suggested value: if the matrix $A$ is symmetric and stored in CS format, it is recommended that ${\mathbf{trans}}=\mathrm{Nag_NoTrans}$ for reasons of efficiency.
Constraint: ${\mathbf{trans}}=\mathrm{Nag_NoTrans}$ or $\mathrm{Nag_Trans}$.
3: $\mathbf{init}$Nag_InitializeA Input
On entry: on first entry, init should be set to $\mathrm{Nag_InitializeI}$, 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 $\mathrm{Nag_InputA}$.
${\mathbf{init}}=\mathrm{Nag_InputA}$
diag must contain the diagonal of $A$.
${\mathbf{init}}=\mathrm{Nag_InitializeI}$
diag will store the diagonal of $A$ on exit.
Suggested value: ${\mathbf{init}}=\mathrm{Nag_InitializeI}$ on first entry; ${\mathbf{init}}=\mathrm{Nag_InputA}$, subsequently, unless diag has been overwritten.
Constraint: ${\mathbf{init}}=\mathrm{Nag_InputA}$ or $\mathrm{Nag_InitializeI}$.
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}}=\mathrm{Nag_SparseNsym_StoreCS}$, the number of nonzero elements in the matrix $A$.
If ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreSCS}$, the number of nonzero elements in the lower triangle of the matrix $A$.
Constraints:
• if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$, $1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$;
• if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreSCS}$, $1\le {\mathbf{nnz}}\le {\mathbf{n}}×\left({\mathbf{n}}+1\right)/2$.
7: $\mathbf{a}\left[{\mathbf{nnz}}\right]$const double Input
On entry: if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$, the nonzero elements in the matrix $A$ (CS format).
If ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreSCS}$, 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 function f11zac or f11zbc may be used to reorder the elements in this way for CS and SCS storage, respectively.
8: $\mathbf{irow}\left[{\mathbf{nnz}}\right]$const Integer Input
9: $\mathbf{icol}\left[{\mathbf{nnz}}\right]$const Integer Input
On entry: if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$, the row and column indices of the nonzero elements supplied in a.
If ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreSCS}$, 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}=0,1,\dots ,{\mathbf{nnz}}-1$;
• if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreCS}$, $1\le {\mathbf{icol}}\left[\mathit{i}\right]\le {\mathbf{n}}$, for $\mathit{i}=0,1,\dots ,{\mathbf{nnz}}-1$;
• if ${\mathbf{store}}=\mathrm{Nag_SparseNsym_StoreSCS}$, $1\le {\mathbf{icol}}\left[\mathit{i}\right]\le {\mathbf{irow}}\left[\mathit{i}\right]$, for $\mathit{i}=0,1,\dots ,{\mathbf{nnz}}-1$;
• 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}=1,2,\dots ,{\mathbf{nnz}}-1$.
10: $\mathbf{check}$Nag_SparseNsym_CheckData Input
On entry: specifies whether or not the CS or SCS representation of the matrix $A$ should be checked.
${\mathbf{check}}=\mathrm{Nag_SparseNsym_Check}$
Checks are carried out on the values of n, nnz, irow, icol; if ${\mathbf{init}}=\mathrm{Nag_InputA}$, diag is also checked.
${\mathbf{check}}=\mathrm{Nag_SparseNsym_NoCheck}$
None of these checks are carried out.
Constraint: ${\mathbf{check}}=\mathrm{Nag_SparseNsym_Check}$ or $\mathrm{Nag_SparseNsym_NoCheck}$.
11: $\mathbf{b}\left[{\mathbf{n}}\right]$const double Input
On entry: the right-hand side vector $b$.
12: $\mathbf{x}\left[{\mathbf{n}}\right]$double Output
On exit: the approximate solution vector ${x}_{{\mathbf{niter}}}$.
13: $\mathbf{diag}\left[{\mathbf{n}}\right]$double Input/Output
On entry: if ${\mathbf{init}}=\mathrm{Nag_InputA}$, the diagonal elements of $A$.
On exit: if ${\mathbf{init}}=\mathrm{Nag_InputA}$, unchanged on exit.
If ${\mathbf{init}}=\mathrm{Nag_InitializeI}$, the diagonal elements of $A$.
14: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{niter}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{niter}}\ge 1$.
On entry, ${\mathbf{nnz}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnz}}\ge 1$.
NE_INT_2
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}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_CS
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{icol}}\left[\mathit{I}-1\right]=⟨\mathit{\text{value}}⟩$ and ${\mathbf{irow}}\left[\mathit{I}-1\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{icol}}\left[\mathit{I}-1\right]\ge 1$ and ${\mathbf{icol}}\left[\mathit{I}-1\right]\le {\mathbf{irow}}\left[\mathit{I}-1\right]$.
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{icol}}\left[\mathit{I}-1\right]=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{icol}}\left[\mathit{I}-1\right]\ge 1$ and ${\mathbf{icol}}\left[\mathit{I}-1\right]\le {\mathbf{n}}$.
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{irow}}\left[\mathit{I}-1\right]=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{irow}}\left[\mathit{I}-1\right]\ge 1$ and ${\mathbf{irow}}\left[\mathit{I}-1\right]\le {\mathbf{n}}$.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_STRICTLY_INCREASING
On entry, ${\mathbf{a}}\left[i-1\right]$ is out of order: $i=⟨\mathit{\text{value}}⟩$.
On entry, the location (${\mathbf{irow}}\left[\mathit{I}-1\right],{\mathbf{icol}}\left[\mathit{I}-1\right]$) is a duplicate: $\mathit{I}=⟨\mathit{\text{value}}⟩$.
NE_ZERO_DIAG_ELEM
On entry, the diagonal element of the $\mathit{I}$th row is zero or missing: $\mathit{I}=⟨\mathit{\text{value}}⟩$.
On entry, the element ${\mathbf{diag}}\left[\mathit{I}-1\right]$ is zero: $\mathit{I}=⟨\mathit{\text{value}}⟩$.

## 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

f11dkc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f11dkc 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 function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

### 9.1Timing

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

### 9.2Use of check

It is expected that a common use of f11dkc will be as preconditioner for the iterative solution of real, symmetric or nonsymmetric, linear systems. In this situation, f11dkc is likely to be called many times. In the interests of both reliability and efficiency, you are recommended to set ${\mathbf{check}}=\mathrm{Nag_SparseNsym_Check}$ for the first of such calls, and to set ${\mathbf{check}}=\mathrm{Nag_SparseNsym_NoCheck}$ for all subsequent calls.

## 10Example

This example solves the real sparse nonsymmetric system of equations $Ax=b$ iteratively using f11dkc as a preconditioner.

### 10.1Program Text

Program Text (f11dkce.c)

### 10.2Program Data

Program Data (f11dkce.d)

### 10.3Program Results

Program Results (f11dkce.r)