NAG Library Routine Document
F01BRF
1 Purpose
F01BRF factorizes a real sparse matrix. The routine either forms the $LU$ factorization of a permutation of the entire matrix, or, optionally, first permutes the matrix to block lower triangular form and then only factorizes the diagonal blocks.
2 Specification
SUBROUTINE F01BRF ( 
N, NZ, A, LICN, IRN, LIRN, ICN, PIVOT, IKEEP, IW, W, LBLOCK, GROW, ABORT, IDISP, IFAIL) 
INTEGER 
N, NZ, LICN, IRN(LIRN), LIRN, ICN(LICN), IKEEP(5*N), IW(8*N), IDISP(10), IFAIL 
REAL (KIND=nag_wp) 
A(LICN), PIVOT, W(N) 
LOGICAL 
LBLOCK, GROW, ABORT(4) 

3 Description
Given a real sparse matrix
$A$, F01BRF may be used to obtain the
$LU$ factorization of a permutation of
$A$,
where
$P$ and
$Q$ are permutation matrices,
$L$ is unit lower triangular and
$U$ is upper triangular. The routine uses a sparse variant of Gaussian elimination, and the pivotal strategy is designed to compromise between maintaining sparsity and controlling loss of accuracy through roundoff.
Optionally the routine first permutes the matrix into block lower triangular form and then only factorizes the diagonal blocks. For some matrices this gives a considerable saving in storage and execution time.
Extensive data checks are made; duplicated nonzeros can be accumulated.
The factorization is intended to be used by
F04AXF to solve sparse systems of linear equations
$Ax=b$ or
${A}^{\mathrm{T}}x=b$. If several matrices of the same sparsity pattern are to be factorized,
F01BSF should be used for the second and subsequent matrices.
The method is fully described in
Duff (1977).
A more recent algorithm for the same calculation is provided by
F11MEF.
4 References
Duff I S (1977) MA28 – a set of Fortran subroutines for sparse unsymmetric linear equations AERE Report R8730 HMSO
5 Parameters
 1: N – INTEGERInput
On entry: $n$, the order of the matrix $A$.
Constraint:
${\mathbf{N}}>0$.
 2: NZ – INTEGERInput
On entry: the number of nonzero elements in the matrix $A$.
Constraint:
${\mathbf{NZ}}>0$.
 3: A(LICN) – REAL (KIND=nag_wp) arrayInput/Output
On entry: ${\mathbf{A}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NZ}}$, must contain the nonzero elements of the sparse matrix $A$. They can be in any order since F01BRF will reorder them.
On exit: the nonzero elements in the
$LU$ factorization. The array must
not be changed by you between a call of F01BRF and a call of
F04AXF.
 4: LICN – INTEGERInput
On entry: the dimension of the arrays
A and
ICN as declared in the (sub)program from which F01BRF is called. Since the factorization is returned in
A and
ICN,
LICN should be large enough to accommodate this and should ordinarily be
$2$ to
$4$ times as large as
NZ.
Constraint:
${\mathbf{LICN}}\ge {\mathbf{NZ}}$.
 5: IRN(LIRN) – INTEGER arrayInput/Output
On entry: ${\mathbf{IRN}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NZ}}$, must contain the row index of the nonzero element stored in ${\mathbf{A}}\left(i\right)$.
On exit:
IRN is overwritten and is not needed for subsequent calls of
F01BSF or
F04AXF.
 6: LIRN – INTEGERInput
On entry: the dimension of the array
IRN as declared in the (sub)program from which F01BRF is called. It need not be as large as
LICN; normally it will not need to be very much greater than
NZ.
Constraint:
${\mathbf{LIRN}}\ge {\mathbf{NZ}}$.
 7: ICN(LICN) – INTEGER arrayCommunication Array
${\mathbf{ICN}}\left(\mathit{i}\right)$, for
$\mathit{i}=1,2,\dots ,{\mathbf{NZ}}$, must contain, on entry, the column index of the nonzero element stored in
${\mathbf{A}}\left(i\right)$.
ICN contains, on exit, the column indices of the nonzero elements in the factorization. The array must
not be changed by you between a call of F01BRF and subsequent calls of
F01BSF or
F04AXF.
 8: PIVOT – REAL (KIND=nag_wp)Input
On entry: should have a value in the range
$0.0\le {\mathbf{PIVOT}}\le 0.9999$ and is used to control the choice of pivots. If
${\mathbf{PIVOT}}<0.0$, the value
$0.0$ is assumed, and if
${\mathbf{PIVOT}}>0.9999$, the value
$0.9999$ is assumed. When searching a row for a pivot, any element is excluded which is less than
PIVOT times the largest of those elements in the row available as pivots. Thus decreasing
PIVOT biases the algorithm to maintaining sparsity at the expense of stability.
Suggested value:
${\mathbf{PIVOT}}=0.1$ has been found to work well on test examples.
 9: IKEEP($5\times {\mathbf{N}}$) – INTEGER arrayCommunication Array
On exit: indexing information about the factorization.
You must
not change
IKEEP between a call of F01BRF and subsequent calls to
F01BSF or
F04AXF.
 10: IW($8\times {\mathbf{N}}$) – INTEGER arrayWorkspace
 11: W(N) – REAL (KIND=nag_wp) arrayOutput
On exit: if
${\mathbf{GROW}}=\mathrm{.TRUE.}$,
${\mathbf{W}}\left(1\right)$ contains an estimate (an upper bound) of the increase in size of elements encountered during the factorization (see
GROW); the rest of the array is used as workspace.
If ${\mathbf{GROW}}=\mathrm{.FALSE.}$, the array is not used.
 12: LBLOCK – LOGICALInput
On entry: if ${\mathbf{LBLOCK}}=\mathrm{.TRUE.}$, the matrix is preordered into block lower triangular form before the $LU$ factorization is performed; otherwise the entire matrix is factorized.
Suggested value:
${\mathbf{LBLOCK}}=\mathrm{.TRUE.}$ unless the matrix is known to be irreducible, or is singular and an upper bound on the rank is required.
 13: GROW – LOGICALInput
On entry: if
${\mathbf{GROW}}=\mathrm{.TRUE.}$, then on exit
${\mathbf{W}}\left(1\right)$ contains an estimate (an upper bound) of the increase in size of elements encountered during the factorization. If the matrix is wellscaled (see
Section 8.2), then a high value for
${\mathbf{W}}\left(1\right)$ indicates that the
$LU$ factorization may be inaccurate and you should be wary of the results and perhaps increase the parameter
PIVOT for subsequent runs (see
Section 7).
Suggested value:
${\mathbf{GROW}}=\mathrm{.TRUE.}$.
 14: ABORT($4$) – LOGICAL arrayInput
On entry: if
${\mathbf{ABORT}}\left(1\right)=\mathrm{.TRUE.}$, F01BRF will exit immediately on detecting a structural singularity (one that depends on the pattern of nonzeros) and return
${\mathbf{IFAIL}}={\mathbf{1}}$; otherwise it will complete the factorization (see
Section 8.3).
If
${\mathbf{ABORT}}\left(2\right)=\mathrm{.TRUE.}$, F01BRF will exit immediately on detecting a numerical singularity (one that depends on the numerical values) and return
${\mathbf{IFAIL}}={\mathbf{2}}$; otherwise it will complete the factorization (see
Section 8.3).
If
${\mathbf{ABORT}}\left(3\right)=\mathrm{.TRUE.}$, F01BRF will exit immediately (with
${\mathbf{IFAIL}}={\mathbf{5}}$) when the arrays
A and
ICN are filled up by the previously factorized, active and unfactorized parts of the matrix; otherwise it continues so that better guidance on necessary array sizes can be given in
${\mathbf{IDISP}}\left(6\right)$ and
${\mathbf{IDISP}}\left(7\right)$, and will exit with
IFAIL in the range
$4$ to
$6$. Note that there is always an immediate error exit if the array
IRN is too small.
If ${\mathbf{ABORT}}\left(4\right)=\mathrm{.TRUE.}$, F01BRF exits immediately (with ${\mathbf{IFAIL}}={\mathbf{13}}$) if it finds duplicate elements in the input matrix.
If
${\mathbf{ABORT}}\left(4\right)=\mathrm{.FALSE.}$, F01BRF proceeds using a value equal to the sum of the duplicate elements. In either case details of each duplicate element are output on the current advisory message unit (see
X04ABF), unless suppressed by the value of
IFAIL on entry.
Suggested values:
 ${\mathbf{ABORT}}\left(1\right)=\mathrm{.TRUE.}$;
 ${\mathbf{ABORT}}\left(2\right)=\mathrm{.TRUE.}$;
 ${\mathbf{ABORT}}\left(3\right)=\mathrm{.FALSE.}$;
 ${\mathbf{ABORT}}\left(4\right)=\mathrm{.TRUE.}$.
 15: IDISP($10$) – INTEGER arrayCommunication Array
On exit: contains information about the factorization.
${\mathbf{IDISP}}\left(1\right)$ and
${\mathbf{IDISP}}\left(2\right)$ indicate the position in arrays
A and
ICN of the first and last elements in the
$LU$ factorization of the diagonal blocks. (
${\mathbf{IDISP}}\left(2\right)$ gives the number of nonzeros in the factorization.)
${\mathbf{IDISP}}\left(1\right)$ and
${\mathbf{IDISP}}\left(2\right)$ must not be changed by you between a call of F01BRF and subsequent calls to
F01BSF or
F04AXF.
${\mathbf{IDISP}}\left(3\right)$ and
${\mathbf{IDISP}}\left(4\right)$ monitor the adequacy of ‘elbow room’ in the arrays
IRN and
A (and
ICN) respectively, by giving the number of times that the data in these arrays has been compressed during the factorization to release more storage. If either
${\mathbf{IDISP}}\left(3\right)$ or
${\mathbf{IDISP}}\left(4\right)$ is quite large (say greater than
$10$), it will probably pay you to increase the size of the corresponding array(s) for subsequent runs. If either is very low or zero, then you can perhaps save storage by reducing the size of the corresponding array(s).
${\mathbf{IDISP}}\left(5\right)$, when ${\mathbf{LBLOCK}}=\mathrm{.FALSE.}$, gives an upper bound on the rank of the matrix; when ${\mathbf{LBLOCK}}=\mathrm{.TRUE.}$, gives an upper bound on the sum of the ranks of the lower triangular blocks.
${\mathbf{IDISP}}\left(6\right)$ and
${\mathbf{IDISP}}\left(7\right)$ give the minimum size of arrays
IRN and
A (and
ICN) respectively which would enable a successful run on an identical matrix (but some ‘elbowroom’ should be allowed – see
Section 8).
${\mathbf{IDISP}}\left(8\right)$ to
$\left(10\right)$ are only used if
${\mathbf{LBLOCK}}=\mathrm{.TRUE.}$.
 ${\mathbf{IDISP}}\left(8\right)$ gives the structural rank of the matrix.
 ${\mathbf{IDISP}}\left(9\right)$ gives the number of diagonal blocks.
 ${\mathbf{IDISP}}\left(10\right)$ gives the size of the largest diagonal block.
You must
not change
IDISP between a call of F01BRF and subsequent calls to
F01BSF or
F04AXF.
 16: IFAIL – INTEGERInput/Output

For this routine, the normal use of
IFAIL is extended to control the printing of error and warning messages as well as specifying hard or soft failure (see
Section 3.3 in the Essential Introduction).
On entry:
IFAIL must be set to a value with the decimal expansion
$\mathit{cba}$, where each of the decimal digits
$c$,
$b$ and
$a$ must have a value of
$0$ or
$1$.
$a=0$ 
specifies hard failure, otherwise soft failure; 
$b=0$ 
suppresses error messages, otherwise error messages will be printed (see Section 6); 
$c=0$ 
suppresses warning messages, otherwise warning messages will be printed (see Section 6). 
The recommended value for inexperienced users is $110$ (i.e., hard failure with all messages printed).
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{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}}=2$
Successful factorization of a numerically singular matrix (which may also be structurally singular) (see
Section 8.3).
 ${\mathbf{IFAIL}}=1$
Successful factorization of a structurally singular matrix (see
Section 8.3).
 ${\mathbf{IFAIL}}=1$
The matrix is structurally singular and the factorization has been abandoned (${\mathbf{ABORT}}\left(1\right)$ was .TRUE. on entry).
 ${\mathbf{IFAIL}}=2$
The matrix is numerically singular and the factorization has been abandoned (${\mathbf{ABORT}}\left(2\right)$ was .TRUE. on entry).
 ${\mathbf{IFAIL}}=3$
LIRN is too small: there is not enough space in the array
IRN to continue the factorization. You are recommended to try again with
LIRN (and the length of
IRN) equal to at least
${\mathbf{IDISP}}\left(6\right)+{\mathbf{N}}/2$.
 ${\mathbf{IFAIL}}=4$
LICN is much too small: there is much too little space in the arrays
A and
ICN to continue the factorization.
 ${\mathbf{IFAIL}}=5$
LICN is too small: there is not enough space in the arrays
A and
ICN to store the factorization. If
${\mathbf{ABORT}}\left(3\right)$ was .FALSE. on entry, the factorization has been completed but some of the
$LU$ factors have been discarded to create space;
${\mathbf{IDISP}}\left(7\right)$ then gives the minimum value of
LICN (i.e., the minimum length of
A and
ICN) required for a successful factorization of the same matrix.
 ${\mathbf{IFAIL}}=6$
LICN and
LIRN are both too small: effectively this is a combination of
${\mathbf{IFAIL}}={\mathbf{3}}$ and
${\mathbf{5}}$ (with
${\mathbf{ABORT}}\left(3\right)=\mathrm{.FALSE.}$).
 ${\mathbf{IFAIL}}=7$
LICN is too small: there is not enough space in the arrays
A and
ICN for the permutation to block triangular form.
 ${\mathbf{IFAIL}}=8$
On entry,  ${\mathbf{N}}\le 0$. 
 ${\mathbf{IFAIL}}=9$
On entry,  ${\mathbf{NZ}}\le 0$. 
 ${\mathbf{IFAIL}}=10$
On entry,  ${\mathbf{LICN}}<{\mathbf{NZ}}$. 
 ${\mathbf{IFAIL}}=11$
On entry,  ${\mathbf{LIRN}}<{\mathbf{NZ}}$. 
 ${\mathbf{IFAIL}}=12$
On entry, an element of the input matrix has a row or column index (i.e., an element of
IRN or
ICN) outside the range
$1$ to
N.
 ${\mathbf{IFAIL}}=13$
Duplicate elements have been found in the input matrix and the factorization has been abandoned (${\mathbf{ABORT}}\left(4\right)=\mathrm{.TRUE.}$ on entry).
7 Accuracy
The factorization obtained is exact for a perturbed matrix whose $\left(i,j\right)$th element differs from ${a}_{ij}$ by less than $3\epsilon \rho {m}_{ij}$ where $\epsilon $ is the machine precision, $\rho $ is the growth value returned in ${\mathbf{W}}\left(1\right)$ if ${\mathbf{GROW}}=\mathrm{.TRUE.}$, and ${m}_{ij}$ the number of Gaussian elimination operations applied to element $\left(i,j\right)$. The value of ${m}_{ij}$ is not greater than $n$ and is usually much less. Small $\rho $ values therefore guarantee accurate results, but unfortunately large $\rho $ values may give a very pessimistic indication of accuracy.
The time required may be estimated very roughly from the number
$\tau $ of nonzeros in the factorized form (output as
${\mathbf{IDISP}}\left(2\right)$) and for F01BRF and its associates is
F01BRF: 
$5{\tau}^{2}/n$ units 
F01BSF: 
${\tau}^{2}/n$ units 
F04AXF: 
$2\tau $ units 
where our unit is the time for the inner loop of a full matrix code (e.g., solving a full set of equations takes about
$\frac{1}{3}{n}^{3}$ units). Note that the faster
F01BSF time makes it well worthwhile to use this for a sequence of problems with the same pattern.
It should be appreciated that
$\tau $ varies widely from problem to problem. For network problems it may be little greater than
NZ, the number of nonzeros in
$A$; for discretization of twodimensional and threedimensional partial differential equations it may be about
$3n{\mathrm{log}}_{2}n$ and
$\frac{1}{2}{n}^{5/3}$, respectively.
The time taken by F01BRF to find the block lower triangular form (${\mathbf{LBLOCK}}=\mathrm{.TRUE.}$) is typically $5\u201315\%$ of the time taken by the routine when it is not found (${\mathbf{LBLOCK}}=\mathrm{.FALSE.}$). If the matrix is irreducible (${\mathbf{IDISP}}\left(9\right)=1$ after a call with ${\mathbf{LBLOCK}}=\mathrm{.TRUE.}$) then this time is wasted. Otherwise, particularly if the largest block is small (${\mathbf{IDISP}}\left(10\right)\ll n$), the consequent savings are likely to be greater.
The time taken to estimate growth (${\mathbf{GROW}}=\mathrm{.TRUE.}$) is typically under $20\%$ of the overall time.
The overall time may be substantially increased if there is inadequate ‘elbowroom’ in the arrays
A,
IRN and
ICN. When the sizes of the arrays are minimal (
${\mathbf{IDISP}}\left(6\right)$ and
${\mathbf{IDISP}}\left(7\right)$) it can execute as much as three times slower. Values of
${\mathbf{IDISP}}\left(3\right)$ and
${\mathbf{IDISP}}\left(4\right)$ greater than about
$10$ indicate that it may be worthwhile to increase array sizes.
The use of a relative pivot tolerance
PIVOT essentially presupposes that the matrix is wellscaled, i.e., that the matrix elements are broadly comparable in size. Practical problems are often naturally wellscaled but particular care is needed for problems containing mixed types of variables (for example millimetres and neutron fluxes).
It is envisaged that F01BRF will almost always be called for square nonsingular matrices and that singularity indicates an error condition. However, even if the matrix is singular it is possible to complete the factorization. It is even possible for
F04AXF to solve a set of equations whose matrix is singular provided the set is consistent.
Two forms of singularity are possible. If the matrix would be singular for any values of the nonzeros (e.g., if it has a whole row of zeros), then we say it is structurally singular, and continue only if ${\mathbf{ABORT}}\left(1\right)=\mathrm{.FALSE.}$. If the matrix is nonsingular by virtue of the particular values of the nonzeros, then we say that it is numerically singular and continue only if ${\mathbf{ABORT}}\left(2\right)=\mathrm{.FALSE.}$, in which case an upper bound on the rank of the matrix is returned in ${\mathbf{IDISP}}\left(5\right)$ when ${\mathbf{LBLOCK}}=\mathrm{.FALSE.}$.
Rectangular matrices may be treated by setting
N to the larger of the number of rows and numbers of columns and setting
${\mathbf{ABORT}}\left(1\right)=\mathrm{.FALSE.}$.
Note: the soft
failure option should be used (last digit of ${\mathbf{IFAIL}}={\mathbf{1}}$) if you wish to factorize singular matrices with ${\mathbf{ABORT}}\left(1\right)$ or ${\mathbf{ABORT}}\left(2\right)$ set to .FALSE..
The matrix $A$ may consist of a sum of contributions from different subsystems (for example finite elements). In such cases you may rely on F01BRF to perform assembly, since duplicated elements are summed.
The following code may be used to compute the determinant of
$A$ (as the real variable
DET) after a call of F01BRF:
DET = 1.0
ID = IDISP(1)
DO 10 I = 1, N
IDG = ID + IKEEP(3*N+I)
DET = DET*A(IDG)
IF (IKEEP(N+I).NE.I)DET = DET
IF (IKEEP(2*N+I).NE.I)DET = DET
ID = ID + IKEEP(I)
10 CONTINUE
9 Example
This example factorizes the real sparse matrix:
This example program simply prints out some information about the factorization as returned by F01BRF in
${\mathbf{W}}\left(1\right)$ and
IDISP. Normally the call of F01BRF would be followed by a call of
F04AXF (see
Section 9 in F04AXF).
9.1 Program Text
Program Text (f01brfe.f90)
9.2 Program Data
Program Data (f01brfe.d)
9.3 Program Results
Program Results (f01brfe.r)