# NAG Library Routine Document

## 1Purpose

f01lhf factorizes a real almost block diagonal matrix.

## 2Specification

Fortran Interface
 Subroutine f01lhf ( n, a, lena, tol,
 Integer, Intent (In) :: n, nbloks, blkstr(3,nbloks), lena Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: pivot(n), kpivot Real (Kind=nag_wp), Intent (Inout) :: a(lena), tol
#include <nagmk26.h>
 void f01lhf_ (const Integer *n, const Integer *nbloks, const Integer blkstr[], double a[], const Integer *lena, Integer pivot[], double *tol, Integer *kpivot, Integer *ifail)

## 3Description

f01lhf factorizes a real almost block diagonal matrix, $A$, by row elimination with alternate row and column pivoting such that no ‘fill-in’ is produced. The code, which is derived from ARCECO described in Diaz et al. (1983), uses Level 1 and Level 2 BLAS. No three successive diagonal blocks may have columns in common and therefore the almost block diagonal matrix must have the form shown in the following diagram:
Figure 1
This routine may be followed by f04lhf, which is designed to solve sets of linear equations $AX=B$ or ${A}^{\mathrm{T}}X=B$.

## 4References

Diaz J C, Fairweather G and Keast P (1983) Fortran packages for solving certain almost block diagonal linear systems by modified alternate row and column elimination ACM Trans. Math. Software 9 358–375

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}>0$.
2:     $\mathbf{nbloks}$ – IntegerInput
On entry: $n$, the total number of blocks of the matrix $A$.
Constraint: $0<{\mathbf{nbloks}}\le {\mathbf{n}}$.
3:     $\mathbf{blkstr}\left(3,{\mathbf{nbloks}}\right)$ – Integer arrayInput
On entry: information which describes the block structure of $A$ as follows:
• ${\mathbf{blkstr}}\left(1,k\right)$ must contain the number of rows in the $k$th block, $k=1,2,\dots ,{\mathbf{nbloks}}$;
• ${\mathbf{blkstr}}\left(2,k\right)$ must contain the number of columns in the $k$th block, $k=1,2,\dots ,{\mathbf{nbloks}}$;
• ${\mathbf{blkstr}}\left(3,k\right)$ must contain the number of columns of overlap between the $k$th and $\left(k+1\right)$th blocks, $k=1,2,\dots ,{\mathbf{nbloks}}-1$. ${\mathbf{blkstr}}\left(3,{\mathbf{nbloks}}\right)$ need not be set.
The following conditions delimit the structure of $A$:
• ${\mathbf{blkstr}}\left(1,k\right),{\mathbf{blkstr}}\left(2,k\right)>0\text{, }k=1,2,\dots ,{\mathbf{nbloks}}$,
• ${\mathbf{blkstr}}\left(3,k\right)\ge 0\text{, }k=1,2,\dots ,{\mathbf{nbloks}}-1$,
(there must be at least one column and one row in each block and a non-negative number of columns of overlap);
• ${\mathbf{blkstr}}\left(3,k-1\right)+{\mathbf{blkstr}}\left(3,k\right)\le {\mathbf{blkstr}}\left(2,k\right)\text{, }k=2,3,\dots ,{\mathbf{nbloks}}-1$,
(the total number of columns in overlaps in each block must not exceed the number of columns in that block);
• ${\mathbf{blkstr}}\left(2,1\right)\ge {\mathbf{blkstr}}\left(1,1\right)$,
• ${\mathbf{blkstr}}\left(2,1\right)+\sum _{k=2}^{j}\left[{\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k-1\right)\right]\ge \sum _{k=1}^{j}{\mathbf{blkstr}}\left(1,k\right)$, $j=2,3,\dots ,{\mathbf{nbloks}}-1$,
• $\sum _{k=1}^{j}\left[{\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k\right)\right]\le \sum _{k=1}^{j}{\mathbf{blkstr}}\left(1,k\right)\text{, }j=1,2,\dots ,{\mathbf{nbloks}}-1$,
(the index of the first column of the overlap between the $j$th and $\left(j+1\right)$th blocks must be $\le$ the index of the last row of the $j$th block, and the index of the last column of overlap must be $\ge$ the index of the last row of the $j$th block);
• $\sum _{k=1}^{{\mathbf{nbloks}}}{\mathbf{blkstr}}\left(1,k\right)=n$,
• ${\mathbf{blkstr}}\left(2,1\right)+\sum _{k=2}^{{\mathbf{nbloks}}}\left[{\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k-1\right)\right]=nk$,
(both the number of rows and the number of columns of $A$ must equal $n$).
4:     $\mathbf{a}\left({\mathbf{lena}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: the elements of the almost block diagonal matrix stored block by block, with each block stored column by column. The sizes of the blocks and the overlaps are defined by the argument blkstr.
If ${a}_{rs}$ is the first element in the $k$th block, then an arbitrary element ${a}_{ij}$ in the $k$th block must be stored in the array element:
 $a pk+ j-r mk+ i-s+1$
where
 $pk=∑l= 1 k- 1blkstr1l×blkstr2l$
is the base address of the $k$th block, and
 $mk=blkstr1k$
is the number of rows of the $k$th block.
See Section 9 for comments on scaling.
On exit: the factorized form of the matrix.
5:     $\mathbf{lena}$ – IntegerInput
On entry: the dimension of the array a as declared in the (sub)program from which f01lhf is called.
Constraint: ${\mathbf{lena}}\ge \sum _{k=1}^{{\mathbf{nbloks}}}\left[{\mathbf{blkstr}}\left(1,k\right)×{\mathbf{blkstr}}\left(2,k\right)\right]$.
6:     $\mathbf{pivot}\left({\mathbf{n}}\right)$ – Integer arrayOutput
On exit: details of the interchanges.
7:     $\mathbf{tol}$ – Real (Kind=nag_wp)Input/Output
On entry: a relative tolerance to be used to indicate whether or not the matrix is singular. For a discussion on how tol is used see Section 9. If tol is non-positive, tol is reset to $10\epsilon$, where $\epsilon$ is the machine precision.
On exit: unchanged unless ${\mathbf{tol}}\le 0.0$ on entry, in which case it is set to $10\epsilon$.
8:     $\mathbf{kpivot}$ – IntegerOutput
On exit: if ${\mathbf{ifail}}={\mathbf{2}}$, kpivot contains the value $k$, where $k$ is the first position on the diagonal of the matrix $A$ where too small a pivot was detected. Otherwise kpivot is set to $0$.
9:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . 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  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  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, $K=〈\mathit{\text{value}}〉$, ${\mathbf{blkstr}}\left(2,K\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{blkstr}}\left(1,K\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{blkstr}}\left(2,K\right)\ge {\mathbf{blkstr}}\left(1,K\right)$.
On entry, $K=〈\mathit{\text{value}}〉$, ${\mathbf{blkstr}}\left(2,K\right)=〈\mathit{\text{value}}〉$ ${\mathbf{blkstr}}\left(3,K\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{blkstr}}\left(1,K\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{blkstr}}\left(2,K\right)-{\mathbf{blkstr}}\left(3,K\right)\le {\mathbf{blkstr}}\left(1,K\right)$.
On entry, $K=〈\mathit{\text{value}}〉$ and ${\mathbf{blkstr}}\left(1,K\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{blkstr}}\left(1,K\right)\ge 1$.
On entry, $K=〈\mathit{\text{value}}〉$ and ${\mathbf{blkstr}}\left(2,K\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{blkstr}}\left(2,K\right)\ge 1$.
On entry, $K=〈\mathit{\text{value}}〉$ and ${\mathbf{blkstr}}\left(3,K\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{blkstr}}\left(3,K\right)\ge 0$.
On entry, $K=〈\mathit{\text{value}}〉$ ${\mathbf{blkstr}}\left(3,K\right)=〈\mathit{\text{value}}〉$ ${\mathbf{blkstr}}\left(3,K-1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{blkstr}}\left(2,K\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{blkstr}}\left(3,K\right)+{\mathbf{blkstr}}\left(3,K-1\right)\ge {\mathbf{blkstr}}\left(2,K\right)$.
On entry, lena is too small. ${\mathbf{lena}}=〈\mathit{\text{value}}〉$. Minimum possible dimension: $〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nbloks}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge {\mathbf{nbloks}}$.
On entry, ${\mathbf{nbloks}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nbloks}}\ge 1$.
On entry, the following equality does not hold: ${\mathbf{blkstr}}\left(2,1\right)+\mathrm{sum}\left({\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k-1\right):k=2,{\mathbf{nbloks}}\right)={\mathbf{n}}$.
On entry, the following equality does not hold: $\mathrm{sum}\left({\mathbf{blkstr}}\left(1,k\right):k=1,{\mathbf{nbloks}}\right)={\mathbf{n}}$.
On entry, the following inequality was not satisfied for: $J=〈\mathit{\text{value}}〉$. $\mathrm{sum}\left({\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k\right):k=1,J\right)\le \text{}$ $\mathrm{sum}\left({\mathbf{blkstr}}\left(1,k\right):k=1,J\right)\le \text{}$ ${\mathbf{blkstr}}\left(2,1\right)+\mathrm{sum}\left({\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k-1\right):k=2,J\right)$.
${\mathbf{ifail}}=2$
Factorization completed, but pivot in diagonal $I$ was small: $I=〈\mathit{\text{value}}〉$.
${\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

The accuracy of f01lhf depends on the conditioning of the matrix $A$.

## 8Parallelism and Performance

f01lhf 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.

Singularity or near singularity in $A$ is determined by the argument tol. If the absolute value of any pivot is less than ${\mathbf{tol}}×{a}_{\mathrm{max}}$, where ${a}_{\mathrm{max}}$ is the maximum absolute value of an element of $A$, then $A$ is said to be singular. The position on the diagonal of $A$ of the first of any such pivots is indicated by the argument kpivot. The factorization, and the test for near singularity, will be more accurate if before entry $A$ is scaled so that the $\infty$-norms of the rows and columns of $A$ are all of approximately the same order of magnitude. (The $\infty$-norm is the maximum absolute value of any element in the row or column.)

## 10Example

This example solves the set of linear equations $Ax=b$ where
 $A= -1.00 -0.98 -0.79 -0.15 -1.00 -0.25 -0.87 0.35 0.78 0.31 -0.85 0.89 -0.69 -0.98 -0.76 -0.82 0.12 -0.01 0.75 0.32 -1.00 -0.53 -0.83 -0.98 -0.58 0.04 0.87 0.38 -1.00 -0.21 -0.93 -0.84 0.37 -0.94 -0.96 -1.00 -0.99 -0.91 -0.28 -0.90 0.78 -0.93 -0.76 0.48 -0.87 -0.14 -1.00 -0.59 -0.99 0.21 -0.73 -0.48 -0.93 -0.91 0.10 -0.89 -0.68 -0.09 -0.58 -0.21 0.85 -0.39 0.79 -0.71 0.39 -0.99 -0.12 -0.75 0.17 -1.37 1.29 -1.59 1.10 -1.63 -1.01 -0.27 0.08 0.61 0.54 -0.41 0.16 -0.46 -0.67 0.56 -0.99 0.16 -0.16 0.98 -0.24 -0.41 0.40 -0.93 0.70 0.43 0.71 -0.97 -0.60 -0.30 0.18 -0.47 -0.98 -0.73 0.07 0.04 -0.25 -0.92 -0.52 -0.46 -0.58 -0.89 -0.94 -0.54 -1.00 -0.36$
and
 $b= -2.92 -1.17 -1.30 -1.17 -2.10 -4.51 -1.71 -4.59 -4.19 -0.93 -3.31 0.52 -0.12 -0.05 -0.98 -2.07 -2.73 -1.95$
The exact solution is
 $x=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1T.$

### 10.1Program Text

Program Text (f01lhfe.f90)

### 10.2Program Data

Program Data (f01lhfe.d)

### 10.3Program Results

Program Results (f01lhfe.r)