GNU Octave Manual Version 3by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |

### 20.1.7 Reordering

In general any function or operator used on a sparse matrix will
result in a sparse matrix with the same or a larger number of non-zero
elements than the original matrix. This is particularly true for the
important case of sparse matrix factorizations. The usual way to
address this is to reorder the matrix, such that its factorization is
sparser than the factorization of the original matrix. That is the
factorization of `L * U = P * S * Q`

has sparser terms `L`

and `U`

than the equivalent factorization `L * U = S`

.

Several functions are available to reorder depending on the type of the
matrix to be factorized. If the matrix is symmetric positive-definite,
then `symamd`

or `csymamd`

should be used. Otherwise
`amd`

, `colamd`

or `ccolamd`

should be used. For completeness
the reordering functions `colperm`

and `randperm`

are
also available.

See Figure 20-2 for an example of the structure of a simple positive definite matrix.

The standard Cholesky factorization of this matrix can be
obtained by the same command that would be used for a full
matrix. This can be visualized with the command
`r = chol(A); spy(r);`

.
See Figure 20-3.
The original matrix had

non-zero terms, while this Cholesky factorization has

with only half of the symmetric matrix being stored. This is a significant level of fill in, and although not an issue for such a small test case, can represents a large overhead in working with other sparse matrices.

The appropriate sparsity preserving permutation of the original
matrix is given by `symamd`

and the factorization using this
reordering can be visualized using the command ```
q = symamd(A);
r = chol(A(q,q)); spy(r)
```

. This gives

non-zero terms which is a significant improvement.

The Cholesky factorization itself can be used to determine the
appropriate sparsity preserving reordering of the matrix during the
factorization, In that case this might be obtained with three return
arguments as r`[r, p, q] = chol(A); spy(r)`

.

In the case of an asymmetric matrix, the appropriate sparsity
preserving permutation is `colamd`

and the factorization using
this reordering can be visualized using the command ```
q =
colamd(A); [l, u, p] = lu(A(:,q)); spy(l+u)
```

.

Finally, Octave implicitly reorders the matrix when using the div (/) and ldiv (\) operators, and so no the user does not need to explicitly reorder the matrix to maximize performance.

__Loadable Function:__`p`=**ccolamd***(*`s`)__Loadable Function:__`p`=**ccolamd***(*`s`,`knobs`)__Loadable Function:__`p`=**ccolamd***(*`s`,`knobs`,`cmember`)__Loadable Function:__[`p`,`stats`] =**ccolamd***(...)*-
Constrained column approximate minimum degree permutation.

returns the column approximate minimum degree permutation vector for the sparse matrix`p`= ccolamd (`s`)`s`. For a non-symmetric matrix`s`,

tends to have sparser LU factors than`s`(:,`p`)`s`.`chol (`

also tends to be sparser than`s`(:,`p`)' *`s`(:,`p`))`chol (`

.`s`' *`s`)

optimizes the ordering for`p`= ccolamd (`s`, 1)`lu (`

. The ordering is followed by a column elimination tree post-ordering.`s`(:,`p`))`knobs`is an optional one- to five-element input vector, with a default value of`[0 10 10 1 0]`

if not present or empty. Entries not present are set to their defaults.`knobs`(1)-
if nonzero, the ordering is optimized for
`lu (S (:, p))`

. It will be a poor ordering for`chol (`

. This is the most important knob for ccolamd.`s`(:,`p`)' *`s`(:,`p`)) `knob`(2)-
if
`s`is m-by-n, rows with more than`max (16,`

entries are ignored.`knobs`(2) * sqrt (n)) `knob`(3)-
columns with more than
`max (16,`

entries are ignored and ordered last in the output permutation (subject to the cmember constraints).`knobs`(3) * sqrt (min (`m`,`n`))) `knob`(4)- if nonzero, aggressive absorption is performed.
`knob`(5)- if nonzero, statistics and knobs are printed.

`cmember`is an optional vector of length n. It defines the constraints on the column ordering. If

, then column`cmember`(j) =`c``j`is in constraint set`c`(`c`must be in the range 1 to`n`). In the output permutation`p`, all columns in set 1 appear first, followed by all columns in set 2, and so on.

if not present or empty.`cmember`= ones(1,n)`ccolamd (`

returns`s`, [], 1 :`n`)`1 :`

`n`

is about the same as`p`= ccolamd (`s`)

.`p`= colamd (`s`)`knobs`and its default values differ.`colamd`

always does aggressive absorption, and it finds an ordering suitable for both`lu (`

and`s`(:,`p`))`chol (`

; it cannot optimize its ordering for`S`(:,`p`)' *`s`(:,`p`))`lu (`

to the extent that`s`(:,`p`))`ccolamd (`

can.`s`, 1)`stats`is an optional 20-element output vector that provides data about the ordering and the validity of the input matrix`s`. Ordering statistics are in

.`stats`(1 : 3)

and`stats`(1)

are the number of dense or empty rows and columns ignored by ccolamd and`stats`(2)

is the number of garbage collections performed on the internal data structure used by ccolamd (roughly of size`stats`(3)`2.2 * nnz (`

integers).`s`) + 4 *`m`+ 7 *`n`

provide information if ccolamd was able to continue. The matrix is OK if`stats`(4 : 7)

is zero, or 1 if invalid.`stats`(4)

is the rightmost column index that is unsorted or contains duplicate entries, or zero if no such column exists.`stats`(5)

is the last seen duplicate or out-of-order row index in the column index given by`stats`(6)

, or zero if no such row index exists.`stats`(5)

is the number of duplicate or out-of-order row indices.`stats`(7)

is always zero in the current version of ccolamd (reserved for future use).`stats`(8 : 20)The authors of the code itself are S. Larimore, T. Davis (Uni of Florida) and S. Rajamanickam in collaboration with J. Bilbert and E. Ng. Supported by the National Science Foundation (DMS-9504974, DMS-9803599, CCR-0203270), and a grant from Sandia National Lab.

^{(15)}See also colamd, csymamd

__Loadable Function:__`p`=**colamd***(*`s`)__Loadable Function:__`p`=**colamd***(*`s`,`knobs`)__Loadable Function:__[`p`,`stats`] =**colamd***(*`s`)__Loadable Function:__[`p`,`stats`] =**colamd***(*`s`,`knobs`)-
Column approximate minimum degree permutation.

returns the column approximate minimum degree permutation vector for the sparse matrix`p`= colamd (`s`)`s`. For a non-symmetric matrix`s`,

tends to have sparser LU factors than`s`(:,`p`)`s`. The Cholesky factorization of

also tends to be sparser than that of`s`(:,`p`)' *`s`(:,`p`)

.`s`' *`s``knobs`is an optional one- to three-element input vector. If`s`is m-by-n, then rows with more than`max(16,`

entries are ignored. Columns with more than`knobs`(1)*sqrt(n))`max(16,knobs(2)*sqrt(min(m,n)))`

entries are removed prior to ordering, and ordered last in the output permutation`p`. Only completely dense rows or columns are removed if

and`knobs`(1)

are < 0, respectively. If`knobs`(2)

is nonzero,`knobs`(3)`stats`and`knobs`are printed. The default is

. Note that`knobs`= [10 10 0]`knobs`differs from earlier versions of colamd`stats`is an optional 20-element output vector that provides data about the ordering and the validity of the input matrix`s`. Ordering statistics are in

.`stats`(1:3)

and`stats`(1)

are the number of dense or empty rows and columns ignored by colamd and`stats`(2)

is the number of garbage collections performed on the internal data structure used by colamd (roughly of size`stats`(3)`2.2 * nnz(`

integers).`s`) + 4 *`m`+ 7 *`n`Octave built-in functions are intended to generate valid sparse matrices, with no duplicate entries, with ascending row indices of the nonzeros in each column, with a non-negative number of entries in each column (!) and so on. If a matrix is invalid, then colamd may or may not be able to continue. If there are duplicate entries (a row index appears two or more times in the same column) or if the row indices in a column are out of order, then colamd can correct these errors by ignoring the duplicate entries and sorting each column of its internal copy of the matrix

`s`(the input matrix`s`is not repaired, however). If a matrix is invalid in other ways then colamd cannot continue, an error message is printed, and no output arguments (`p`or`stats`) are returned. colamd is thus a simple way to check a sparse matrix to see if it's valid.

provide information if colamd was able to continue. The matrix is OK if`stats`(4:7)

is zero, or 1 if invalid.`stats`(4)

is the rightmost column index that is unsorted or contains duplicate entries, or zero if no such column exists.`stats`(5)

is the last seen duplicate or out-of-order row index in the column index given by`stats`(6)

, or zero if no such row index exists.`stats`(5)

is the number of duplicate or out-of-order row indices.`stats`(7)

is always zero in the current version of colamd (reserved for future use).`stats`(8:20)The ordering is followed by a column elimination tree post-ordering.

The authors of the code itself are Stefan I. Larimore and Timothy A. Davis (davis@cise.ufl.edu), University of Florida. The algorithm was developed in collaboration with John Gilbert, Xerox PARC, and Esmond Ng, Oak Ridge National Laboratory.

^{(16)}See also colperm, symamd

__Function File:__`p`=**colperm***(*`s`)- Returns the column permutations such that the columns of

are ordered in terms of increase number of non-zero elements. If`s`(:,`p`)`s`is symmetric, then`p`is chosen such that

orders the rows and columns with increasing number of non zeros elements.`s`(`p`,`p`)

__Loadable Function:__`p`=**csymamd***(*`s`)__Loadable Function:__`p`=**csymamd***(*`s`,`knobs`)__Loadable Function:__`p`=**csymamd***(*`s`,`knobs`,`cmember`)__Loadable Function:__[`p`,`stats`] =**csymamd***(...)*-
For a symmetric positive definite matrix

`s`, returns the permutation vector`p`such that

tends to have a sparser Cholesky factor than`s`(`p`,`p`)`s`. Sometimes`csymamd`

works well for symmetric indefinite matrices too. The matrix`s`is assumed to be symmetric; only the strictly lower triangular part is referenced.`s`must be square. The ordering is followed by an elimination tree post-ordering.`knobs`is an optional one- to three-element input vector, with a default value of`[10 1 0]`

if present or empty. Entries not present are set to their defaults.`knobs`(1)-
If
`s`is n-by-n, then rows and columns with more than`max(16,`

entries are ignored, and ordered last in the output permutation (subject to the cmember constraints).`knobs`(1)*sqrt(n)) `knobs`(2)- If nonzero, aggressive absorption is performed.
`knobs`(3)- If nonzero, statistics and knobs are printed.

`cmember`is an optional vector of length n. It defines the constraints on the ordering. If

, then row/column j is in constraint set`cmember`(j) =`s``c`(`c`must be in the range 1 to n). In the output permutation`p`, rows/columns in set 1 appear first, followed by all rows/columns in set 2, and so on.

if not present or empty.`cmember`= ones(1,n)`csymamd(`

returns`s`,[],1:n)`1:n`

.

is about the same as`p`= csymamd(`s`)

.`p`= symamd(`s`)`knobs`and its default values differ.

provide information if ccolamd was able to continue. The matrix is OK if`stats`(4:7)

is zero, or 1 if invalid.`stats`(4)

is the rightmost column index that is unsorted or contains duplicate entries, or zero if no such column exists.`stats`(5)

is the last seen duplicate or out-of-order row index in the column index given by`stats`(6)

, or zero if no such row index exists.`stats`(5)

is the number of duplicate or out-of-order row indices.`stats`(7)

is always zero in the current version of ccolamd (reserved for future use).`stats`(8:20)The authors of the code itself are S. Larimore, T. Davis (Uni of Florida) and S. Rajamanickam in collaboration with J. Bilbert and E. Ng. Supported by the National Science Foundation (DMS-9504974, DMS-9803599, CCR-0203270), and a grant from Sandia National Lab.

^{(17)}See also symamd, ccolamd

__Loadable Function:__`p`=**dmperm***(*`s`)__Loadable Function:__[`p`,`q`,`r`,`s`] =**dmperm***(*`s`)-
Perform a Dulmage-Mendelsohn permutation on the sparse matrix

`s`. With a single output argument*dmperm*performs the row permutations`p`such that

has no zero elements on the diagonal.`s`(`p`,:)Called with two or more output arguments, returns the row and column permutations, such that

is in block triangular form. The values of`s`(`p`,`q`)`r`and`s`define the boundaries of the blocks. If`s`is square then

.`r`==`s`The method used is described in: A. Pothen & C.-J. Fan. Computing the block triangular form of a sparse matrix. ACM Trans. Math. Software, 16(4):303-324, 1990.

See also colamd, ccolamd

__Loadable Function:__`p`=**symamd***(*`s`)__Loadable Function:__`p`=**symamd***(*`s`,`knobs`)__Loadable Function:__[`p`,`stats`] =**symamd***(*`s`)__Loadable Function:__[`p`,`stats`] =**symamd***(*`s`,`knobs`)-
For a symmetric positive definite matrix

`s`, returns the permutation vector p such that

tends to have a sparser Cholesky factor than`s`(`p`,`p`)`s`. Sometimes symamd works well for symmetric indefinite matrices too. The matrix`s`is assumed to be symmetric; only the strictly lower triangular part is referenced.`s`must be square.`knobs`is an optional one- to two-element input vector. If`s`is n-by-n, then rows and columns with more than`max(16,`

entries are removed prior to ordering, and ordered last in the output permutation`knobs`(1)*sqrt(n))`p`. No rows/columns are removed if

. If`knobs`(1) < 0

is nonzero,`knobs`(2)`stats`

and`knobs`are printed. The default is

. Note that`knobs`= [10 0]`knobs`differs from earlier versions of symamd.`stats`is an optional 20-element output vector that provides data about the ordering and the validity of the input matrix`s`. Ordering statistics are in

.`stats`(1:3)

is the number of dense or empty rows and columns ignored by symamd and`stats`(1) =`stats`(2)

is the number of garbage collections performed on the internal data structure used by symamd (roughly of size`stats`(3)`8.4 * nnz (tril (`

integers).`s`, -1)) + 9 *`n`Octave built-in functions are intended to generate valid sparse matrices, with no duplicate entries, with ascending row indices of the nonzeros in each column, with a non-negative number of entries in each column (!) and so on. If a matrix is invalid, then symamd may or may not be able to continue. If there are duplicate entries (a row index appears two or more times in the same column) or if the row indices in a column are out of order, then symamd can correct these errors by ignoring the duplicate entries and sorting each column of its internal copy of the matrix S (the input matrix S is not repaired, however). If a matrix is invalid in other ways then symamd cannot continue, an error message is printed, and no output arguments (

`p`or`stats`) are returned. symamd is thus a simple way to check a sparse matrix to see if it's valid.

provide information if symamd was able to continue. The matrix is OK if`stats`(4:7)

is zero, or 1 if invalid.`stats`(4)

is the rightmost column index that is unsorted or contains duplicate entries, or zero if no such column exists.`stats`(5)

is the last seen duplicate or out-of-order row index in the column index given by`stats`(6)

, or zero if no such row index exists.`stats`(5)

is the number of duplicate or out-of-order row indices.`stats`(7)

is always zero in the current version of symamd (reserved for future use).`stats`(8:20)The ordering is followed by a column elimination tree post-ordering.

The authors of the code itself are Stefan I. Larimore and Timothy A. Davis (davis@cise.ufl.edu), University of Florida. The algorithm was developed in collaboration with John Gilbert, Xerox PARC, and Esmond Ng, Oak Ridge National Laboratory.

^{(18)}See also colperm, colamd

__Loadable Function:__`p`=**symrcm***(*`S`)- Symmetric reverse Cuthill-McKee permutation of
`S`. Return a permutation vector`p`such that

tends to have its diagonal elements closer to the diagonal than`S`(`p`,`p`)`S`. This is a good preordering for LU or Cholesky factorization of matrices that come from `long, skinny' problems. It works for both symmetric and asymmetric`S`.The algorithm represents a heuristic approach to the NP-complete bandwidth minimization problem. The implementation is based in the descriptions found in

E. Cuthill, J. McKee: “Reducing the Bandwidth of Sparse Symmetric Matrices”. Proceedings of the 24th ACM National Conference, 157-172 1969, Brandon Press, New Jersey.

Alan George, Joseph W. H. Liu: “Computer Solution of Large Sparse Positive Definite Systems”, Prentice Hall Series in Computational Mathematics, ISBN 0-13-165274-5, 1981.

See also colperm, colamd, symamd

ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |