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_direct_real_gen_setup (f11md)

## Purpose

nag_sparse_direct_real_gen_setup (f11md) computes a column permutation suitable for LU $LU$ factorization (by nag_sparse_direct_real_gen_lu (f11me)) of a real sparse matrix in compressed column (Harwell–Boeing) format and applies it to the matrix. This function must be called prior to nag_sparse_direct_real_gen_lu (f11me).

## Syntax

[iprm, ifail] = f11md(spec, n, icolzp, irowix, iprm)
[iprm, ifail] = nag_sparse_direct_real_gen_setup(spec, n, icolzp, irowix, iprm)

## Description

Given a sparse matrix in compressed column (Harwell–Boeing) format A$A$ and a choice of column permutation schemes, the function computes those data structures that will be needed by the LU $LU$ factorization function nag_sparse_direct_real_gen_lu (f11me) and associated functions nag_sparse_direct_real_gen_diag (f11mm), nag_sparse_direct_real_gen_solve (f11mf) and nag_sparse_direct_real_gen_refine (f11mh). The column permutation choices are:
• original order (that is, no permutation);
• user-supplied permutation;
• a permutation, computed by the function, designed to minimize fill-in during the LU $LU$ factorization.
The algorithm for this computed permutation is based on the approximate minimum degree column ordering algorithm COLAMD. The computed permutation is not sensitive to the magnitude of the nonzero values of A$A$.

## References

Amestoy P R, Davis T A and Duff I S (1996) An approximate minimum degree ordering algorithm SIAM J. Matrix Anal. Appl. 17 886–905
Gilbert J R and Larimore S I (2004) A column approximate minimum degree ordering algorithm ACM Trans. Math. Software 30,3 353–376
Gilbert J R, Larimore S I and Ng E G (2004) Algorithm 836: COLAMD, an approximate minimum degree ordering algorithm ACM Trans. Math. Software 30, 3 377–380

## Parameters

### Compulsory Input Parameters

1:     spec – string (length ≥ 1)
Indicates the permutation to be applied.
spec = 'N'${\mathbf{spec}}=\text{'N'}$
The identity permutation is used (i.e., the columns are not permuted).
spec = 'U'${\mathbf{spec}}=\text{'U'}$
The permutation in the iprm array is used, as supplied by you.
spec = 'M'${\mathbf{spec}}=\text{'M'}$
The permutation computed by the COLAMD algorithm is used
Constraint: spec = 'N'${\mathbf{spec}}=\text{'N'}$, 'U'$\text{'U'}$ or 'M'$\text{'M'}$.
2:     n – int64int32nag_int scalar
n$n$, the order of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.
3:     icolzp( : $:$) – int64int32nag_int array
Note: the dimension of the array icolzp must be at least n + 1${\mathbf{n}}+1$.
icolzp(i)${\mathbf{icolzp}}\left(i\right)$ contains the index in A$A$ of the start of a new column. See Section [Compressed column storage (CCS) format] in the F11 Chapter Introduction.
4:     irowix( : $:$) – int64int32nag_int array
Note: the dimension of the array irowix must be at least icolzp(n + 1)1${\mathbf{icolzp}}\left({\mathbf{n}}+1\right)-1$, the number of nonzeros of the sparse matrix A$A$.
irowix(i)${\mathbf{irowix}}\left(i\right)$ contains the row index in A$A$ for element A(i)$A\left(i\right)$. See Section [Compressed column storage (CCS) format] in the F11 Chapter Introduction.
5:     iprm(7 × n$7×{\mathbf{n}}$) – int64int32nag_int array
The first n${\mathbf{n}}$ entries contain the column permutation supplied by you. This will be used if spec = 'U'${\mathbf{spec}}=\text{'U'}$, and ignored otherwise. If used, it must consist of a permutation of all the integers in the range [0,(n1)]$\left[0,\left({\mathbf{n}}-1\right)\right]$, the leftmost column of the matrix A$A$ denoted by 0$0$ and the rightmost by n1${\mathbf{n}}-1$. Labelling columns in this way, iprm(i) = j${\mathbf{iprm}}\left(i\right)=j$ means that column i1$i-1$ of A$A$ is in position j$j$ in APc$A{P}_{c}$, where Pr A Pc = LU ${P}_{r}A{P}_{c}=LU$ expresses the factorization to be performed.

None.

None.

### Output Parameters

1:     iprm(7 × n$7×{\mathbf{n}}$) – int64int32nag_int array
A new permutation is returned in the first n${\mathbf{n}}$ entries. The rest of the array contains data structures that will be used by other functions. The function computes the column elimination tree for A$A$ and a post-order permutation on the tree. It then compounds the iprm permutation given or computed by the COLAMD algorthm with the post-order permutation. This array is needed by the LU $LU$ factorization function nag_sparse_direct_real_gen_lu (f11me) and associated functions nag_sparse_direct_real_gen_solve (f11mf), nag_sparse_direct_real_gen_refine (f11mh) and nag_sparse_direct_real_gen_diag (f11mm) and should be passed to them unchanged.
2:     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$
 On entry, spec ≠ 'N'${\mathbf{spec}}\ne \text{'N'}$, 'U'$\text{'U'}$ or 'M'$\text{'M'}$, or n < 0${\mathbf{n}}<0$.
ifail = 2${\mathbf{ifail}}=2$
On entry, spec = 'U'${\mathbf{spec}}=\text{'U'}$, but iprm does not represent a valid permutation of the integers in [0,(n1)]$\left[0,\left({\mathbf{n}}-1\right)\right]$. An input value of iprm is either out of range or repeated.
ifail = 3${\mathbf{ifail}}=3$
Unspecified failure of the COLAMD algorithm. This should not happen and should be reported to NAG.
ifail = 4${\mathbf{ifail}}=4$
On entry, the array icolzp failed to satisfy the following constraints:
• icolzp(1) = 1${\mathbf{icolzp}}\left(1\right)=1$;
• icolzp(i1)icolzp(i)${\mathbf{icolzp}}\left(\mathit{i}-1\right)\le {\mathbf{icolzp}}\left(\mathit{i}\right)$, for i = 2,3,,n + 1$\mathit{i}=2,3,\dots ,{\mathbf{n}}+1$;
• icolzp(i)n × n + 1${\mathbf{icolzp}}\left(\mathit{i}\right)\le {\mathbf{n}}×{\mathbf{n}}+1$, for i = 1,2,,n + 1$\mathit{i}=1,2,\dots ,{\mathbf{n}}+1$.
ifail = 5${\mathbf{ifail}}=5$
On entry, the array irowix failed to satisfy the following constraints:
• 1irowix(i)n$1\le {\mathbf{irowix}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for i = 1,2,,icolzp(n + 1)1$\mathit{i}=1,2,\dots ,{\mathbf{icolzp}}\left({\mathbf{n}}+1\right)-1$;
• for each column i = 1n$i=1\dots {\mathbf{n}}$, the row indices irowix(j)${\mathbf{irowix}}\left(j\right)$, where j = icolzp(i)icolzp(i + 1)1$j={\mathbf{icolzp}}\left(i\right)\dots {\mathbf{icolzp}}\left(i+1\right)-1$, do not repeat.
ifail = 301${\mathbf{ifail}}=301$
Unable to allocate required internal workspace.

## Accuracy

Not applicable. This computation does not use floating point numbers.

We recommend calling this function with spec = 'M'${\mathbf{spec}}=\text{'M'}$ before calling nag_sparse_direct_real_gen_lu (f11me). The COLAMD algorithm computes a sparsity-preserving permutation Pc${P}_{c}$ solely from the pattern of A$A$ such that the LU $LU$ factorization Pr A Pc = LU ${P}_{r}A{P}_{c}=LU$ remains as sparse as possible, regardless of the subsequent choice of Pr${P}_{r}$. The algorithm takes advantage of the existence of super-columns (columns with the same sparsity pattern) to reduce running time.

## Example

```function nag_sparse_direct_real_gen_setup_example
n = int64(5);
icolzp = [int64(1); 3; 5; 7; 9; 12];
irowix = [int64(1); 3; 1; 5; 2; 3; 2; 4; 3; 4; 5];
iprm = zeros(1, 7*n, 'int64');
% Calculate COLAMD permutation
spec = 'M';
[iprm, ifail] = nag_sparse_direct_real_gen_setup(spec, n, icolzp, irowix, iprm);
fprintf('\nCOLAMD Permutation\n');
disp(int2str(iprm(1:n)));

% Calculate user permutation
spec = 'U';
iprm(1:n)= [4, 3, 2, 1, 0];
[iprm, ifail] = nag_sparse_direct_real_gen_setup(spec, n, icolzp, irowix, iprm);
fprintf('\nUser Permutation\n');
disp(int2str(iprm(1:n)));

% Calculate natural permutation
spec = 'N';
[iprm, ifail] = nag_sparse_direct_real_gen_setup(spec, n, icolzp, irowix, iprm);
fprintf('\nNatural Permutation\n');
disp(int2str(iprm(1:n)));
```
```

COLAMD Permutation
1  0  4  3  2

User Permutation
4  3  2  1  0

Natural Permutation
0  1  2  3  4

```
```function f11md_example
n = int64(5);
icolzp = [int64(1); 3; 5; 7; 9; 12];
irowix = [int64(1); 3; 1; 5; 2; 3; 2; 4; 3; 4; 5];
iprm = zeros(1, 7*n, 'int64');
% Calculate COLAMD permutation
spec = 'M';
[iprm, ifail] = f11md(spec, n, icolzp, irowix, iprm);
fprintf('\nCOLAMD Permutation\n');
disp(int2str(iprm(1:n)));

% Calculate user permutation
spec = 'U';
iprm(1:n)= [4, 3, 2, 1, 0];
[iprm, ifail] = f11md(spec, n, icolzp, irowix, iprm);
fprintf('\nUser Permutation\n');
disp(int2str(iprm(1:n)));

% Calculate natural permutation
spec = 'N';
[iprm, ifail] = f11md(spec, n, icolzp, irowix, iprm);
fprintf('\nNatural Permutation\n');
disp(int2str(iprm(1:n)));
```
```

COLAMD Permutation
1  0  4  3  2

User Permutation
4  3  2  1  0

Natural Permutation
0  1  2  3  4

```