Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_sparse_complex_gen_solve_bdilu (f11du)

## Purpose

nag_sparse_complex_gen_solve_bdilu (f11du) solves a complex sparse non-Hermitian system of linear equations, represented in coordinate storage format, using a restarted generalized minimal residual (RGMRES), conjugate gradient squared (CGS), stabilized bi-conjugate gradient (Bi-CGSTAB), or transpose-free quasi-minimal residual (TFQMR) method, with block Jacobi or additive Schwarz preconditioning.

## Syntax

[x, rnorm, itn, ifail] = f11du(method, nnz, a, irow, icol, nb, istb, indb, ipivp, ipivq, istr, idiag, b, m, tol, maxitn, x, 'n', n, 'la', la, 'lindb', lindb)
[x, rnorm, itn, ifail] = nag_sparse_complex_gen_solve_bdilu(method, nnz, a, irow, icol, nb, istb, indb, ipivp, ipivq, istr, idiag, b, m, tol, maxitn, x, 'n', n, 'la', la, 'lindb', lindb)

## Description

nag_sparse_complex_gen_solve_bdilu (f11du) solves a complex sparse non-Hermitian linear system of equations
 Ax = b, $Ax=b,$
using a preconditioned RGMRES (see Saad and Schultz (1986)), CGS (see Sonneveld (1989)), Bi-CGSTAB($\ell$) (see Van der Vorst (1989) and Sleijpen and Fokkema (1993)), or TFQMR (see Freund and Nachtigal (1991) and Freund (1993)) method.
nag_sparse_complex_gen_solve_bdilu (f11du) uses the incomplete (possibly overlapping) block LU$LU$ factorization determined by nag_sparse_complex_gen_precon_bdilu (f11dt) as the preconditioning matrix. A call to nag_sparse_complex_gen_solve_bdilu (f11du) must always be preceded by a call to nag_sparse_complex_gen_precon_bdilu (f11dt). Alternative preconditioners for the same storage scheme are available by calling nag_sparse_complex_gen_solve_ilu (f11dq) or nag_sparse_complex_gen_solve_jacssor (f11ds).
The matrix A$A$, and the preconditioning matrix M$M$, are represented in coordinate storage (CS) format (see Section [Coordinate storage (CS) format] in the F11 Chapter Introduction) in the arrays a, irow and icol, as returned from nag_sparse_complex_gen_precon_bdilu (f11dt). The array a holds the nonzero entries in these matrices, while irow and icol hold the corresponding row and column indices.
nag_sparse_complex_gen_solve_bdilu (f11du) is a Black Box function which calls nag_sparse_complex_gen_basic_setup (f11br), nag_sparse_complex_gen_basic_solver (f11bs) and nag_sparse_complex_gen_basic_diag (f11bt). If you wish to use an alternative storage scheme, preconditioner, or termination criterion, or require additional diagnostic information, you should call these underlying functions directly.

## References

Freund R W (1993) A transpose-free quasi-minimal residual algorithm for non-Hermitian linear systems SIAM J. Sci. Comput. 14 470–482
Freund R W and Nachtigal N (1991) QMR: a Quasi-Minimal Residual Method for Non-Hermitian Linear Systems Numer. Math. 60 315–339
Saad Y and Schultz M (1986) GMRES: a generalized minimal residual algorithm for solving nonsymmetric linear systems SIAM J. Sci. Statist. Comput. 7 856–869
Sleijpen G L G and Fokkema D R (1993) BiCGSTAB()$\left(\ell \right)$ for linear equations involving matrices with complex spectrum ETNA 1 11–32
Sonneveld P (1989) CGS, a fast Lanczos-type solver for nonsymmetric linear systems SIAM J. Sci. Statist. Comput. 10 36–52
Van der Vorst H (1989) Bi-CGSTAB, a fast and smoothly converging variant of Bi-CG for the solution of nonsymmetric linear systems SIAM J. Sci. Statist. Comput. 13 631–644

## Parameters

### Compulsory Input Parameters

1:     method – string
Specifies the iterative method to be used.
method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$
Restarted generalized minimum residual method.
method = 'CGS'${\mathbf{method}}=\text{'CGS'}$
method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$
Bi-conjugate gradient stabilized ($\ell$) method.
method = 'TFQMR'${\mathbf{method}}=\text{'TFQMR'}$
Transpose-free quasi-minimal residual method.
Constraint: method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, 'CGS'$\text{'CGS'}$, 'BICGSTAB'$\text{'BICGSTAB'}$ or 'TFQMR'$\text{'TFQMR'}$.
2:     nnz – int64int32nag_int scalar
The number of nonzero elements in the matrix A$A$. This must be the same value as was supplied in the preceding call to nag_sparse_complex_gen_precon_bdilu (f11dt).
Constraint: 1nnzn2$1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
3:     a(la) – complex array
la, the dimension of the array, must satisfy the constraint la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
The values returned in the array a by a previous call to nag_sparse_complex_gen_precon_bdilu (f11dt).
4:     irow(la) – int64int32nag_int array
5:     icol(la) – int64int32nag_int array
6:     nb – int64int32nag_int scalar
7:     istb(nb + 1${\mathbf{nb}}+1$) – int64int32nag_int array
8:     indb(lindb) – int64int32nag_int array
9:     ipivp(lindb) – int64int32nag_int array
10:   ipivq(lindb) – int64int32nag_int array
11:   istr(lindb + 1${\mathbf{lindb}}+1$) – int64int32nag_int array
12:   idiag(lindb) – int64int32nag_int array
la, the dimension of the array, must satisfy the constraint la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
The values returned in arrays irow, icol, ipivp, ipivq, istr and idiag by a previous call to nag_sparse_complex_gen_precon_bdilu (f11dt).
The arrays istb, indb and the scalars nb and lindb must be the same values that were supplied in the preceding call to nag_sparse_complex_gen_precon_bdilu (f11dt).
13:   b(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The right-hand side vector b$b$.
14:   m – int64int32nag_int scalar
If method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, m is the dimension of the restart subspace.
If method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$, m is the order $\ell$ of the polynomial Bi-CGSTAB method.
Otherwise, m is not referenced.
Constraints:
• if method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, 0 < mmin (n,50)$0<{\mathbf{m}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},50\right)$;
• if method = 'BICGSTAB'${\mathbf{method}}=\text{'BICGSTAB'}$, 0 < mmin (n,10)$0<{\mathbf{m}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},10\right)$.
15:   tol – double scalar
The required tolerance. Let xk${x}_{k}$ denote the approximate solution at iteration k$k$, and rk${r}_{k}$ the corresponding residual. The algorithm is considered to have converged at iteration k$k$ if
 ‖rk‖∞ ≤ τ × (‖b‖∞ + ‖A‖∞‖xk‖∞). $‖rk‖∞≤τ×(‖b‖∞+‖A‖∞‖xk‖∞).$
If tol0.0${\mathbf{tol}}\le 0.0$, τ = max (sqrt(ε),sqrt(n)ε)$\tau =\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(\sqrt{\epsilon },\sqrt{n}\epsilon \right)$ is used, where ε$\epsilon$ is the machine precision. Otherwise τ = max (tol,10ε,sqrt(n)ε)$\tau =\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{tol}},10\epsilon ,\sqrt{n}\epsilon \right)$ is used.
Constraint: tol < 1.0${\mathbf{tol}}<1.0$.
16:   maxitn – int64int32nag_int scalar
The maximum number of iterations allowed.
Constraint: maxitn1${\mathbf{maxitn}}\ge 1$.
17:   x(n) – complex array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
An initial approximation to the solution vector x$x$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays b, x. (An error is raised if these dimensions are not equal.)
n$n$, the order of the matrix A$A$. This must be the same value as was supplied in the preceding call to nag_sparse_complex_gen_precon_bdilu (f11dt).
Constraint: n1${\mathbf{n}}\ge 1$.
2:     la – int64int32nag_int scalar
Default: The dimension of the arrays a, irow, icol. (An error is raised if these dimensions are not equal.)
The dimension of the arrays a, irow and icol as declared in the (sub)program from which nag_sparse_complex_gen_solve_bdilu (f11du) is called. This must be the same value as was supplied in the preceding call to nag_sparse_complex_gen_precon_bdilu (f11dt).
Constraint: la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
3:     lindb – int64int32nag_int scalar
Default: For lindb, the dimension of the arrays idiag, indb, ipivp, ipivq. (An error is raised if these dimensions are not equal.)
The values returned in arrays irow, icol, ipivp, ipivq, istr and idiag by a previous call to nag_sparse_complex_gen_precon_bdilu (f11dt).
The arrays istb, indb and the scalars nb and lindb must be the same values that were supplied in the preceding call to nag_sparse_complex_gen_precon_bdilu (f11dt).

work lwork

### Output Parameters

1:     x(n) – complex array
An improved approximation to the solution vector x$x$.
2:     rnorm – double scalar
The final value of the residual norm rk${‖{r}_{k}‖}_{\infty }$, where k$k$ is the output value of itn.
3:     itn – int64int32nag_int scalar
The number of iterations carried out.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
Constraint: 1indb(b)n$1\le {\mathbf{indb}}\left(b\right)\le {\mathbf{n}}$ for all b$b$.
Constraint: 1mmin (n,_)$1\le {\mathbf{m}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},_\right)$.
Constraint: 1nbn$1\le {\mathbf{nb}}\le {\mathbf{n}}$.
Constraint: istb(1)1${\mathbf{istb}}\left(1\right)\ge 1$.
Constraint: istb(b + 1) > istb(b)${\mathbf{istb}}\left(b+1\right)>{\mathbf{istb}}\left(b\right)$ for all b$b$.
Constraint: la2 × nnz${\mathbf{la}}\ge 2×{\mathbf{nnz}}$.
Constraint: lindbistb(nb + 1)1${\mathbf{lindb}}\ge {\mathbf{istb}}\left({\mathbf{nb}}+1\right)-1$.
Constraint: maxitn1${\mathbf{maxitn}}\ge 1$.
Constraint: method = 'RGMRES'${\mathbf{method}}=\text{'RGMRES'}$, 'CGS'$\text{'CGS'}$ or 'BICGSTAB'$\text{'BICGSTAB'}$.
Constraint: nnzn2${\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
Constraint: nnz1${\mathbf{nnz}}\ge 1$.
Constraint: n1${\mathbf{n}}\ge 1$.
Constraint: tol < 1.0${\mathbf{tol}}<1.0$.
lwork is too small. lwork is too small.
ifail = 2${\mathbf{ifail}}=2$
Constraint: 1icol(i)n$1\le {\mathbf{icol}}\left(i\right)\le {\mathbf{n}}$ for all i$i$.
Check that a, irow, icol, ipivp, ipivq, istr and idiag have not been corrupted between calls to nag_sparse_complex_gen_precon_bdilu (f11dt) and nag_sparse_complex_gen_solve_bdilu (f11du).
Constraint: 1irow(i)n$1\le {\mathbf{irow}}\left(i\right)\le {\mathbf{n}}$ for all i$i$.
Check that a, irow, icol, ipivp, ipivq, istr and idiag have not been corrupted between calls to nag_sparse_complex_gen_precon_bdilu (f11dt) and nag_sparse_complex_gen_solve_bdilu (f11du).
On entry, element _$_$ of a was out of order.
Check that a, irow, icol, ipivp, ipivq, istr and idiag have not been corrupted between calls to nag_sparse_complex_gen_precon_bdilu (f11dt) and nag_sparse_complex_gen_solve_bdilu (f11du).
On entry, location _$_$ of (irow,icol)$\left({\mathbf{irow}},{\mathbf{icol}}\right)$ was a duplicate.
Check that a, irow, icol, ipivp, ipivq, istr and idiag have not been corrupted between calls to nag_sparse_complex_gen_precon_bdilu (f11dt) and nag_sparse_complex_gen_solve_bdilu (f11du).
ifail = 3${\mathbf{ifail}}=3$
The CS representation of the preconditioner is invalid.
Check that a, irow, icol, ipivp, ipivq, istr and idiag have not been corrupted between calls to nag_sparse_complex_gen_precon_bdilu (f11dt) and nag_sparse_complex_gen_solve_bdilu (f11du).
ifail = 4${\mathbf{ifail}}=4$
The required accuracy could not be obtained. However a reasonable accuracy may have been achieved.
ifail = 5${\mathbf{ifail}}=5$
The solution has not converged after _$_$ iterations.
ifail = 6${\mathbf{ifail}}=6$
Algorithmic breakdown. A solution is returned, although it is possible that it is completely inaccurate.

## Accuracy

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

The time taken by nag_sparse_complex_gen_solve_bdilu (f11du) for each iteration is roughly proportional to the value of nnzc returned from the preceding call to nag_sparse_complex_gen_precon_bdilu (f11dt).
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 coefficient matrix A = M1A$\stackrel{-}{A}={M}^{-1}A$.

## Example

```function nag_sparse_complex_gen_solve_bdilu_example
n   = int64(9);
nz  = int64(33);
a    = zeros(20*nz, 1);
irow = zeros(20*nz, 1, 'int64');
icol = zeros(20*nz, 1, 'int64');
a(1:nz) = [ 96.0 + -64.0i; -20.0 +  22.0i; -36.0 +  14.0i; ...
-12.0 +  10.0i;  96.0 + -64.0i; -20.0 +  22.0i; ...
-36.0 +  14.0i; -12.0 +  10.0i;  96.0 + -64.0i; ...
-36.0 +  14.0i; -28.0 +  18.0i;  96.0 + -64.0i; ...
-20.0 +  22.0i; -36.0 +  14.0i; -28.0 +  18.0i; ...
-12.0 +  10.0i;  96.0 + -64.0i; -20.0 +  22.0i; ...
-36.0 +  14.0i; -28.0 +  18.0i; -12.0 +  10.0i; ...
96.0 + -64.0i; -36.0 +  14.0i; -28.0 +  18.0i; ...
96.0 + -64.0i; -20.0 +  22.0i; -28.0 +  18.0i; ...
-12.0 +  10.0i;  96.0 + -64.0i; -20.0 +  22.0i; ...
-28.0 +  18.0i; -12.0 +  10.0i;  96.0 + -64.0i];
irow(1:nz) = [int64(1); 1; 1; 2; 2; 2; 2; 3; 3; 3; 4; 4; 4; 4; 5; 5; 5; ...
5; 5; 6; 6; 6; 6; 7; 7; 7; 8; 8; 8; 8; 9; 9; 9];
icol(1:nz) = [int64(1); 2; 4; 1; 2; 3; 5; 2; 3; 6; 1; 4; 5; 7; 2; 4; 5; ...
6; 8; 3; 5; 6; 9; 4; 7; 8; 5; 7; 8; 9; 6; 8; 9];
b = [100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i];
method = 'rgmres';
nb = int64(3);
nover = 1;
lfill = [int64(0); 0; 0];
dtol = [0; 0; 0];
pstrat = {'n'; 'n'; 'n'};
milu   = {'n'; 'n'; 'n'};
m = int64(2);
tol = 1e-6;
maxitn = int64(100);

% Set up initial approximate solution x
x = complex(zeros(n, 1));

% Define diagonal block indices.
% In this example use blocks of MB consecutive rows and initialise
% assuming no overlap.
mb = idivide(n+nb-1, nb);
istb = zeros(nb+1, 1, 'int64');
indb = zeros(3*n, 1, 'int64');
ipivp = zeros(3*n, 1, 'int64');
ipivq = zeros(3*n, 1, 'int64');
for k=1:nb
istb(k) = (k-1)*mb+1;
end
istb(nb+1) = n+1;
for i=1:n
indb(i) = i;
end

% Modify indb and istb to account for overlap.
[istb, indb, ifail] = nag_sparse_complex_gen_solve_bdilu_overlap(n, nz, ...
irow, icol, nb, istb, indb, 3*n, nover);
if (ifail == -999)
error('indb is too small, size of indb = %d', numel(indb));
end

% Calculate Factorisation
[a, irow, icol, ipivp, ipivq, istr, idiag, nnzc, npivm, ifail] = ...
nag_sparse_complex_gen_precon_bdilu(n, nz, a, irow, icol, istb, indb, ...
lfill, dtol, milu, ipivp, ipivq, 'pstrat', pstrat);

% Solve Ax = b using nag_sparse_real_gen_solve_bdilu
[x, rnorm, itn, ifail] = nag_sparse_complex_gen_solve_bdilu(method, nz, a, ...
irow, icol, nb, istb, indb, ...
ipivp, ipivq, istr, idiag, b, m, tol, maxitn, x);

fprintf('\nConverged in %d iterations\n', itn);
fprintf('Final redidual norm = %16.3d\n\n', rnorm);
fprintf('  Solution vector X\n  -----------------\n');
disp(x);

function [istb, indb, ifail] = nag_sparse_complex_gen_solve_bdilu_overlap(n, ...
nz, irow, icol, nb, istb, indb, lindb, nover)

ifail = 0;

% This function takes a set of row indices indb defining the diagonal blocks
% to be used in nag_sparse_complex_gen_precon_bdilu to define a block Jacobi
% or additive Schwarz preconditioner, and expands them to allow for nover
% levels of overlap.  The pointer array istb is also updated accordingly, so
% that the returned values of istb and indb can be passed to
% nag_sparse_complex_gen_precon_bdilu to define overlapping diagonal blocks.
iwork = zeros(3*n+1, 1, 'int64');

% Find the number of non-zero elements in each row of the matrix A, and
% the start address of each row. Store the start addresses in
% iwork(n+1,...,2*n+1).
for k=1:nz
iwork(irow(k)) = iwork(irow(k)) + 1;
end
iwork(n+1) = 1;
for i = 1:n
iwork(n+i+1) = iwork(n+i) + iwork(i);
end

% Loop over blocks
for k=1:nb
% Initialize marker array.
iwork(1:n) = 0;

% Mark the rows already in block k in the workspace array.
for l = istb(k):istb(k+1)-1
iwork(indb(l)) = 1;
end

% Loop over levels of overlap.
for iover=1:nover
% Initialize counter of new row indices to be added.
ind = 0;

% Loop over the rows currently in the diagonal block.
for l = istb(k):istb(k+1)-1
row = indb(l);

% Loop over non-zero elements in row
for i = iwork(n+row):iwork(n+row+1)-1

% If the column index of the non-zero element is not in the
% existing set for this block, store it to be added later, and
% mark it in the marker array.
if (iwork(icol(i))==0)
iwork(icol(i)) = 1;
ind = ind + 1;
iwork(2*n+1+ind) = icol(i);
end
end
end

% Shift the indices in indb and add the new entries for block k.
% Change istb accordingly.
ifail = -999;
return;
end

for i = istb(nb+1) - 1:-1:istb(k+1)
end
n21 = 2*n + 1;
ik = istb(k+1) - 1;
end
end
```
```

Converged in 8 iterations
Final redidual norm =        6.492e-04

Solution vector X
-----------------
2.2040 + 1.6972i
2.3511 + 1.9275i
1.5931 + 1.4368i
2.8641 + 1.9762i
3.0687 + 2.2645i
2.0467 + 1.6948i
2.2065 + 1.3244i
2.3724 + 1.5170i
1.6254 + 1.1783i

```
```function f11du_example
n   = int64(9);
nz  = int64(33);
a    = zeros(20*nz, 1);
irow = zeros(20*nz, 1, 'int64');
icol = zeros(20*nz, 1, 'int64');
a(1:nz) = [ 96.0 + -64.0i; -20.0 +  22.0i; -36.0 +  14.0i; ...
-12.0 +  10.0i;  96.0 + -64.0i; -20.0 +  22.0i; ...
-36.0 +  14.0i; -12.0 +  10.0i;  96.0 + -64.0i; ...
-36.0 +  14.0i; -28.0 +  18.0i;  96.0 + -64.0i; ...
-20.0 +  22.0i; -36.0 +  14.0i; -28.0 +  18.0i; ...
-12.0 +  10.0i;  96.0 + -64.0i; -20.0 +  22.0i; ...
-36.0 +  14.0i; -28.0 +  18.0i; -12.0 +  10.0i; ...
96.0 + -64.0i; -36.0 +  14.0i; -28.0 +  18.0i; ...
96.0 + -64.0i; -20.0 +  22.0i; -28.0 +  18.0i; ...
-12.0 +  10.0i;  96.0 + -64.0i; -20.0 +  22.0i; ...
-28.0 +  18.0i; -12.0 +  10.0i;  96.0 + -64.0i];
irow(1:nz) = [int64(1); 1; 1; 2; 2; 2; 2; 3; 3; 3; 4; 4; 4; 4; 5; 5; 5; ...
5; 5; 6; 6; 6; 6; 7; 7; 7; 8; 8; 8; 8; 9; 9; 9];
icol(1:nz) = [int64(1); 2; 4; 1; 2; 3; 5; 2; 3; 6; 1; 4; 5; 7; 2; 4; 5; ...
6; 8; 3; 5; 6; 9; 4; 7; 8; 5; 7; 8; 9; 6; 8; 9];
b = [100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i; 100+4i];
method = 'rgmres';
nb = int64(3);
nover = 1;
lfill = [int64(0); 0; 0];
dtol = [0; 0; 0];
pstrat = {'n'; 'n'; 'n'};
milu   = {'n'; 'n'; 'n'};
m = int64(2);
tol = 1e-6;
maxitn = int64(100);

% Set up initial approximate solution x
x = complex(zeros(n, 1));

% Define diagonal block indices.
% In this example use blocks of MB consecutive rows and initialise
% assuming no overlap.
mb = idivide(n+nb-1, nb);
istb = zeros(nb+1, 1, 'int64');
indb = zeros(3*n, 1, 'int64');
ipivp = zeros(3*n, 1, 'int64');
ipivq = zeros(3*n, 1, 'int64');
for k=1:nb
istb(k) = (k-1)*mb+1;
end
istb(nb+1) = n+1;
for i=1:n
indb(i) = i;
end

% Modify indb and istb to account for overlap.
[istb, indb, ifail] = f11du_overlap(n, nz, irow, icol, nb, ...
istb, indb, 3*n, nover);
if (ifail == -999)
error('indb is too small, size of indb = %d', numel(indb));
end

% Calculate Factorisation
[a, irow, icol, ipivp, ipivq, istr, idiag, nnzc, npivm, ifail] = ...
f11dt(n, nz, a, irow, icol, istb, indb, ...
lfill, dtol, milu, ipivp, ipivq, 'pstrat', pstrat);

% Solve Ax = b using f11dg
[x, rnorm, itn, ifail] = f11du(method, nz, a, irow, icol, nb, istb, indb, ...
ipivp, ipivq, istr, idiag, b, m, tol, maxitn, x);

fprintf('\nConverged in %d iterations\n', itn);
fprintf('Final redidual norm = %16.3d\n\n', rnorm);
fprintf('  Solution vector X\n  -----------------\n');
disp(x);

function [istb, indb, ifail] = f11du_overlap(n, nz, irow, icol, nb, ...
istb, indb, lindb, nover)

ifail = 0;

% This function takes a set of row indices indb defining the diagonal
% blocks to be used in f11dt to define a block Jacobi or additive Schwarz
% preconditioner, and expands them to allow for nover levels of overlap.
% The pointer array istb is also updated accordingly, so that the returned
% values of istb and indb can be passed to f11dt to define overlapping
% diagonal blocks.
iwork = zeros(3*n+1, 1, 'int64');

% Find the number of non-zero elements in each row of the matrix A, and
% the start address of each row. Store the start addresses in
% iwork(n+1,...,2*n+1).
for k=1:nz
iwork(irow(k)) = iwork(irow(k)) + 1;
end
iwork(n+1) = 1;
for i = 1:n
iwork(n+i+1) = iwork(n+i) + iwork(i);
end

% Loop over blocks
for k=1:nb
% Initialize marker array.
iwork(1:n) = 0;

% Mark the rows already in block k in the workspace array.
for l = istb(k):istb(k+1)-1
iwork(indb(l)) = 1;
end

% Loop over levels of overlap.
for iover=1:nover
% Initialize counter of new row indices to be added.
ind = 0;

% Loop over the rows currently in the diagonal block.
for l = istb(k):istb(k+1)-1
row = indb(l);

% Loop over non-zero elements in row
for i = iwork(n+row):iwork(n+row+1)-1

% If the column index of the non-zero element is not in the
% existing set for this block, store it to be added later, and
% mark it in the marker array.
if (iwork(icol(i))==0)
iwork(icol(i)) = 1;
ind = ind + 1;
iwork(2*n+1+ind) = icol(i);
end
end
end

% Shift the indices in indb and add the new entries for block k.
% Change istb accordingly.
ifail = -999;
return;
end

for i = istb(nb+1) - 1:-1:istb(k+1)
end
n21 = 2*n + 1;
ik = istb(k+1) - 1;
end
end
```
```

Converged in 8 iterations
Final redidual norm =        6.492e-04

Solution vector X
-----------------
2.2040 + 1.6972i
2.3511 + 1.9275i
1.5931 + 1.4368i
2.8641 + 1.9762i
3.0687 + 2.2645i
2.0467 + 1.6948i
2.2065 + 1.3244i
2.3724 + 1.5170i
1.6254 + 1.1783i

```