# NAG FL Interfacef11dnf (complex_​gen_​precon_​ilu)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

f11dnf computes an incomplete $LU$ factorization of a complex sparse non-Hermitian matrix, represented in coordinate storage format. This factorization may be used as a preconditioner in combination with f11bsf or f11dqf.

## 2Specification

Fortran Interface
 Subroutine f11dnf ( n, nnz, a, la, irow, icol, dtol, milu, istr, nnzc,
 Integer, Intent (In) :: n, nnz, la, lfill, liwork Integer, Intent (Inout) :: irow(la), icol(la), ipivp(n), ipivq(n), ifail Integer, Intent (Out) :: istr(n+1), idiag(n), nnzc, npivm, iwork(liwork) Real (Kind=nag_wp), Intent (In) :: dtol Complex (Kind=nag_wp), Intent (Inout) :: a(la) Character (1), Intent (In) :: pstrat, milu
#include <nag.h>
 void f11dnf_ (const Integer *n, const Integer *nnz, Complex a[], const Integer *la, Integer irow[], Integer icol[], const Integer *lfill, const double *dtol, const char *pstrat, const char *milu, Integer ipivp[], Integer ipivq[], Integer istr[], Integer idiag[], Integer *nnzc, Integer *npivm, Integer iwork[], const Integer *liwork, Integer *ifail, const Charlen length_pstrat, const Charlen length_milu)
The routine may be called by the names f11dnf or nagf_sparse_complex_gen_precon_ilu.

## 3Description

f11dnf computes an incomplete $LU$ factorization (see Meijerink and Van der Vorst (1977) and Meijerink and Van der Vorst (1981)) of a complex sparse non-Hermitian $n×n$ matrix $A$. The factorization is intended primarily for use as a preconditioner with one of the iterative solvers f11bsf or f11dqf.
The decomposition is written in the form
 $A=M+R,$
where
 $M=PLDUQ$
and $L$ is lower triangular with unit diagonal elements, $D$ is diagonal, $U$ is upper triangular with unit diagonals, $P$ and $Q$ are permutation matrices, and $R$ is a remainder matrix.
The amount of fill-in occurring in the factorization can vary from zero to complete fill, and can be controlled by specifying either the maximum level of fill lfill, or the drop tolerance dtol.
The argument pstrat defines the pivoting strategy to be used. The options currently available are no pivoting, user-defined pivoting, partial pivoting by columns for stability, and complete pivoting by rows for sparsity and by columns for stability. The factorization may optionally be modified to preserve the row-sums of the original matrix.
The sparse matrix $A$ is represented in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). The array a stores all the nonzero elements of the matrix $A$, while arrays irow and icol store the corresponding row and column indices respectively. Multiple nonzero elements may not be specified for the same row and column index.
The preconditioning matrix $M$ is returned in terms of the CS representation of the matrix
 $C=L+D-1+U-2I.$
Further algorithmic details are given in Section 9.3.

## 4References

Meijerink J and Van der Vorst H (1977) An iterative solution method for linear systems of which the coefficient matrix is a symmetric M-matrix Math. Comput. 31 148–162
Meijerink J and Van der Vorst H (1981) Guidelines for the usage of incomplete decompositions in solving sets of linear equations as they occur in practical problems J. Comput. Phys. 44 134–155

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{nnz}$Integer Input
On entry: the number of nonzero elements in the matrix $A$.
Constraint: $1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
3: $\mathbf{a}\left({\mathbf{la}}\right)$Complex (Kind=nag_wp) array Input/Output
On entry: the nonzero elements in 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 f11znf may be used to order the elements in this way.
On exit: the first nnz entries of a contain the nonzero elements of $A$ and the next nnzc entries contain the elements of the matrix $C$. Matrix elements are ordered by increasing row index, and by increasing column index within each row.
4: $\mathbf{la}$Integer Input
On entry: the dimension of the arrays a, irow and icol as declared in the (sub)program from which f11dnf is called. These arrays must be of sufficient size to store both $A$ (nnz elements) and $C$ (nnzc elements).
Constraint: ${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
5: $\mathbf{irow}\left({\mathbf{la}}\right)$Integer array Input/Output
6: $\mathbf{icol}\left({\mathbf{la}}\right)$Integer array Input/Output
On entry: the row and column indices of the nonzero elements supplied in a.
Constraints:
irow and icol must satisfy these constraints (which may be imposed by a call to f11znf):
• $1\le {\mathbf{irow}}\left(\mathit{i}\right)\le {\mathbf{n}}$ and $1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{n}}$, 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}}$.
On exit: the row and column indices of the nonzero elements returned in a.
7: $\mathbf{lfill}$Integer Input
On entry: if ${\mathbf{lfill}}\ge 0$ its value is the maximum level of fill allowed in the decomposition (see Section 9.2). A negative value of lfill indicates that dtol will be used to control the fill instead.
8: $\mathbf{dtol}$Real (Kind=nag_wp) Input
On entry: if ${\mathbf{lfill}}<0$, dtol is used as a drop tolerance to control the fill-in (see Section 9.2); otherwise dtol is not referenced.
Constraint: if ${\mathbf{lfill}}<0$, ${\mathbf{dtol}}\ge 0.0$.
9: $\mathbf{pstrat}$Character(1) Input
On entry: specifies the pivoting strategy to be adopted.
${\mathbf{pstrat}}=\text{'N'}$
No pivoting is carried out.
${\mathbf{pstrat}}=\text{'U'}$
Pivoting is carried out according to the user-defined input values of ipivp and ipivq.
${\mathbf{pstrat}}=\text{'P'}$
Partial pivoting by columns for stability is carried out.
${\mathbf{pstrat}}=\text{'C'}$
Complete pivoting by rows for sparsity, and by columns for stability, is carried out.
Suggested value: ${\mathbf{pstrat}}=\text{'C'}$.
Constraint: ${\mathbf{pstrat}}=\text{'N'}$, $\text{'U'}$, $\text{'P'}$ or $\text{'C'}$.
10: $\mathbf{milu}$Character(1) Input
On entry: indicates whether or not the factorization should be modified to preserve row-sums (see Section 9.4).
${\mathbf{milu}}=\text{'M'}$
The factorization is modified.
${\mathbf{milu}}=\text{'N'}$
The factorization is not modified.
Constraint: ${\mathbf{milu}}=\text{'M'}$ or $\text{'N'}$.
11: $\mathbf{ipivp}\left({\mathbf{n}}\right)$Integer array Input/Output
12: $\mathbf{ipivq}\left({\mathbf{n}}\right)$Integer array Input/Output
On entry: if ${\mathbf{pstrat}}=\text{'U'}$, ${\mathbf{ipivp}}\left(k\right)$ and ${\mathbf{ipivq}}\left(k\right)$ must specify the row and column indices of the element used as a pivot at elimination stage $k$. Otherwise ipivp and ipivq need not be initialized.
Constraint: if ${\mathbf{pstrat}}=\text{'U'}$, ipivp and ipivq must both hold valid permutations of the integers on [1,n].
On exit: the pivot indices. If ${\mathbf{ipivp}}\left(k\right)=i$ and ${\mathbf{ipivq}}\left(k\right)=j$ then the element in row $i$ and column $j$ was used as the pivot at elimination stage $k$.
13: $\mathbf{istr}\left({\mathbf{n}}+1\right)$Integer array Output
On exit: ${\mathbf{istr}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$, is the starting address in the arrays a, irow and icol of row $i$ of the matrix $C$. ${\mathbf{istr}}\left({\mathbf{n}}+1\right)$ is the address of the last nonzero element in $C$ plus one.
14: $\mathbf{idiag}\left({\mathbf{n}}\right)$Integer array Output
On exit: ${\mathbf{idiag}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$, holds the index of arrays a, irow and icol which holds the diagonal element in row $i$ of the matrix $C$.
15: $\mathbf{nnzc}$Integer Output
On exit: the number of nonzero elements in the matrix $C$.
16: $\mathbf{npivm}$Integer Output
On exit: if ${\mathbf{npivm}}>0$ it gives the number of pivots which were modified during the factorization to ensure that $M$ exists.
If ${\mathbf{npivm}}=-1$ no pivot modifications were required, but a local restart occurred (see Section 9.3). The quality of the preconditioner will generally depend on the returned value of npivm.
If npivm is large the preconditioner may not be satisfactory. In this case it may be advantageous to call f11dnf again with an increased value of lfill, a reduced value of dtol, or set ${\mathbf{pstrat}}=\text{'C'}$. See also Section 9.5.
17: $\mathbf{iwork}\left({\mathbf{liwork}}\right)$Integer array Workspace
18: $\mathbf{liwork}$Integer Input
On entry: the dimension of the array iwork as declared in the (sub)program from which f11dnf is called.
Constraint: ${\mathbf{liwork}}\ge 7×{\mathbf{n}}+2$.
19: $\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{dtol}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{dtol}}\ge 0.0$
On entry, ${\mathbf{la}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nnz}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{la}}\ge 2×{\mathbf{nnz}}$
On entry, liwork is too small: ${\mathbf{liwork}}=⟨\mathit{\text{value}}⟩$. Minimum required value of ${\mathbf{liwork}}=⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{milu}}\ne \text{'M'}$ or $\text{'N'}$: ${\mathbf{milu}}=⟨\mathit{\text{value}}⟩$.
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}}}^{2}$
On entry, ${\mathbf{pstrat}}\ne \text{'N'}$, $\text{'U'}$, $\text{'P'}$ or $\text{'C'}$: ${\mathbf{pstrat}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=2$
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{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$
On entry, $\mathit{I}=⟨\mathit{\text{value}}⟩$, ${\mathbf{irow}}\left(\mathit{I}\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{irow}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$
On entry, the location (${\mathbf{irow}}\left(\mathit{I}\right),{\mathbf{icol}}\left(\mathit{I}\right)$) is a duplicate: $\mathit{I}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=3$
On entry, a user-supplied value of ipivp is repeated.
On entry, a user-supplied value of ipivp lies outside the range $\left[1,{\mathbf{n}}\right]$.
On entry, a user-supplied value of ipivq is repeated.
On entry, a user-supplied value of ipivq lies outside the range $\left[1,{\mathbf{n}}\right]$.
${\mathbf{ifail}}=4$
The number of nonzero entries in the decomposition is too large. The decomposition has been terminated before completion. Either increase la, or reduce the fill by reducing lfill, or increasing dtol.
${\mathbf{ifail}}=5$
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.
${\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

The accuracy of the factorization will be determined by the size of the elements that are dropped and the size of any modifications made to the pivot elements. If these sizes are small then the computed factors will correspond to a matrix close to $A$. The factorization can generally be made more accurate by increasing lfill, or by reducing dtol with ${\mathbf{lfill}}<0$.
If f11dnf is used in combination with f11bsf or f11dqf, the more accurate the factorization the fewer iterations will be required. However, the cost of the decomposition will also generally increase.

## 8Parallelism and Performance

f11dnf is not threaded in any implementation.

### 9.1Timing

The time taken for a call to f11dnf is roughly proportional to ${{\mathbf{nnzc}}}^{2}/{\mathbf{n}}$.

### 9.2Control of Fill-in

If ${\mathbf{lfill}}\ge 0$ the amount of fill-in occurring in the incomplete factorization is controlled by limiting the maximum level of fill-in to lfill. The original nonzero elements of $A$ are defined to be of level $0$. The fill level of a new nonzero location occurring during the factorization is defined as:
 $k=max(ke,kc)+1,$
where ${k}_{\mathrm{e}}$ is the level of fill of the element being eliminated, and ${k}_{\mathrm{c}}$ is the level of fill of the element causing the fill-in.
If ${\mathbf{lfill}}<0$ the fill-in is controlled by means of the drop tolerance dtol. A potential fill-in element ${a}_{ij}$ occurring in row $i$ and column $j$ will not be included if:
 $|aij|
where $\alpha$ is the maximum modulus element in the matrix $A$.
For either method of control, any elements which are not included are discarded unless ${\mathbf{milu}}=\text{'M'}$, in which case their contributions are subtracted from the pivot element in the relevant elimination row, to preserve the row-sums of the original matrix.
Should the factorization process break down a local restart process is implemented as described in Section 9.3. This will affect the amount of fill present in the final factorization.

### 9.3Algorithmic Details

The factorization is constructed row by row. At each elimination stage a row index is chosen. In the case of complete pivoting this index is chosen in order to reduce fill-in. Otherwise the rows are treated in the order given, or some user-defined order.
The chosen row is copied from the original matrix $A$ and modified according to those previous elimination stages which affect it. During this process any fill-in elements are either dropped or kept according to the values of lfill or dtol. In the case of a modified factorization (${\mathbf{milu}}=\text{'M'}$) the sum of the dropped terms for the given row is stored.
Finally the pivot element for the row is chosen and the multipliers are computed for this elimination stage. For partial or complete pivoting the pivot element is chosen in the interests of stability as the element of largest absolute value in the row. Otherwise the pivot element is chosen in the order given, or some user-defined order.
If the factorization breaks down because the chosen pivot element is zero, or there is no nonzero pivot available, a local restart recovery process is implemented. The modification of the given pivot row according to previous elimination stages is repeated, but this time keeping all fill-in. Note that in this case the final factorization will include more fill than originally specified by the user-supplied value of lfill or dtol. The local restart usually results in a suitable nonzero pivot arising. The original criteria for dropping fill-in elements is then resumed for the next elimination stage (hence the local nature of the restart process). Should this restart process also fail to produce a nonzero pivot element an arbitrary unit pivot is introduced in an arbitrarily chosen column. f11dnf returns an integer argument npivm which gives the number of these arbitrary unit pivots introduced. If no pivots were modified but local restarts occurred ${\mathbf{npivm}}=-1$ is returned.

### 9.4Choice of Arguments

There is unfortunately no choice of the various algorithmic arguments which is optimal for all types of matrix, and some experimentation will generally be required for each new type of matrix encountered. The recommended approach is to start with ${\mathbf{lfill}}=0$ and ${\mathbf{pstrat}}=\text{'C'}$. If the value returned for npivm is significantly larger than zero, i.e., a large number of pivot modifications were required to ensure that $M$ existed, the preconditioner is not likely to be satisfactory. In this case increase lfill until npivm falls to a value close to zero.
For certain classes of matrices (typically those arising from the discretization of elliptic or parabolic partial differential equations) the convergence rate of the preconditioned iterative solver can sometimes be significantly improved by using an incomplete factorization which preserves the row-sums of the original matrix. In these cases try setting ${\mathbf{milu}}=\text{'M'}$.

### 9.5Direct Solution of Sparse Linear Systems

Although it is not the primary purpose of the routines f11dnf and f11dpf, they may be used together to obtain a direct solution to a nonsingular sparse complex non-Hermitian linear system. To achieve this the call to f11dpf should be preceded by a complete $LU$ factorization
 $A = PLDUQ=M .$
A complete factorization is obtained from a call to f11dnf with ${\mathbf{lfill}}<0$ and ${\mathbf{dtol}}=0.0$, provided ${\mathbf{npivm}}\le 0$ on exit. A positive value of npivm indicates that $A$ is singular, or ill-conditioned. A factorization with positive npivm may serve as a preconditioner, but will not result in a direct solution. It is, therefore, essential to check the output value of npivm if a direct solution is required.
The use of f11dnf and f11dpf as a direct method is illustrated in f11dpf.

## 10Example

This example reads in a complex sparse non-Hermitian matrix $A$ and calls f11dnf to compute an incomplete $LU$ factorization. It then outputs the nonzero elements of both $A$ and $C=L+{D}^{-1}+U-2I$.
The call to f11dnf has ${\mathbf{lfill}}=0$, and ${\mathbf{pstrat}}=\text{'C'}$, giving an unmodified zero-fill $LU$ factorization, with row pivoting for sparsity and column pivoting for stability.

### 10.1Program Text

Program Text (f11dnfe.f90)

### 10.2Program Data

Program Data (f11dnfe.d)

### 10.3Program Results

Program Results (f11dnfe.r)