# Interface Consideration

## One-Based and Zero-Based Indexing

The Intel MKL Sparse BLAS Leve2 and Level 3 routines support one-based and zero-based indexing of data arrays.

Routines with typical interfaces support zero-based indexing for the following sparse data storage formats: CSR, CSC, BSR, and COO. Routines with simplified interfaces support zero based indexing for the following sparse data storage formats: CSR, BSR, and COO. See the complete list of Sparse BLAS Level 2 and Level 3 Routines .

The one-based indexing uses the convention of starting array indices at 1. The zero-based indexing uses the convention of starting array indices at 0. For example, indices of the 5-element array x can be presented in case of one-based indexing as follows:
`Element index: 1 2 3 4 5`
`Element value: 1.0 5.0 7.0 8.0 9.0`

and in case of zero-based indexing as follows:
`Element index: 0 1 2 3 4`
`Element value: 1.0 5.0 7.0 8.0 9.0`

The detailed descriptions of the one-based and zero-based variants of the sparse data storage formats are given in the “Sparse Matrix Storage Formats” in Appendix "Linear Solvers Basics".

Most parameters of the routines are identical for both one-based and zero-based indexing, but some of them have certain differences. The following table lists all these differences.

Parameter | One-based Indexing | Zero-based Indexing
val | Array containing non-zero elements of the matrix A, its length is `pntre(m) - pntrb(1)`. | Array containing non-zero elements of the matrix A, its length is `pntre(m—1) - pntrb(0)`.
pntrb | Array of length m. This array contains row indices, such that `pntrb(I) - pntrb(1)+1` is the first index of row I in the arrays val and indx | Array of length m. This array contains row indices, such that `pntrb(I) - pntrb(0)` is the first index of row I in the arrays val and indx.
pntre | Array of length m. This array contains row indices, such that `pntre(I) - pntrb(1)` is the last index of row I in the arrays val and indx. | Array of length m. This array contains row indices, such that `pntre(I) - pntrb(0)-1` is the last index of row I in the arrays val and indx.
ia | Array of length `m + 1`, containing indices of elements in the array a, such that `ia(I)` is the index in the array a of the first non-zero element from the row I. The value of the last element `ia(m + 1)` is equal to the number of non-zeros plus one. | Array of length `m+1`, containing indices of elements in the array a, such that `ia(I)` is the index in the array a of the first non-zero element from the row I. The value of the last element `ia(m)` is equal to the number of non-zeros.
ldb | Specifies the first dimension of b as declared in the calling (sub)program. | Specifies the second dimension of b as declared in the calling (sub)program.
ldc | Specifies the first dimension of c as declared in the calling (sub)program. | Specifies the second dimension of c as declared in the calling (sub)program.

## Difference Between Fortran and C Interfaces

Intel MKL provides both Fortran and C interfaces to all Sparse BLAS Leve2 and Level 3 routines. Parameter descriptions are common for both interfaces with the exception of data types that refer to the FORTRAN 77 standard types. Correspondence between data types specific to the Fortran and C interfaces are given below:
`Fortran C`
`REAL*4 float`
`REAL*8 double`
`INTEGER*4 int`
`INTEGER*8 long long int`
`CHARACTER char`

For routines with C interfaces all parameters (including scalars) must be passed by references.

Another difference is how two-dimensional arrays are represented. In Fortran the column-major order is used, and in C - row-major order. This changes the meaning of the parameters ldb and ldc (see the table above).

## Differences Between Intel MKL and NIST* Interfaces

The Intel MKL Sparse BLAS Level 3 routines have the following conventional interfaces:

`mkl_xyyymm(transa, m, n, k, alpha, matdescra, arg(A), b, ldb, beta, c, ldc)`, for matrix-matrix product;

`mkl_xyyysm(transa, m, n, alpha, matdescra, arg(A), b, ldb, c, ldc)`, for triangular solvers with multiple right-hand sides.

Here `x` denotes data type, and yyy - sparse matrix data structure (storage format).

The analogous NIST* Sparse BLAS (NSB) library routines have the following interfaces:

`xyyymm(transa, m, n, k, alpha, descra, arg(A), b, ldb, beta, c, ldc, work, lwork)`, for matrix-matrix product;

`xyyysm(transa, m, n, unitd, dv, alpha, descra, arg(A), b, ldb, beta, c, ldc, work, lwork)`, for triangular solvers with multiple right-hand sides.

Some similar arguments are used in both libraries. The argument transa indicates what operation is performed and is slightly different in the NSB library (see Table“Parameter transa”). The arguments m and k are the number of rows and column in the matrix A, respectively, n is the number of columns in the matrix C. The arguments alpha and beta are scalar alpha and beta respectively (beta is not used in the Intel MKL triangular solvers.) The arguments b and c are rectangular arrays with the first dimension ldb and ldc, respectively. `arg(A)` denotes the list of arguments that describe the sparse representation of A.

Parameter transa
| MKL interface | NSB interface | Operation
--- | --- | --- | ---
data type | CHARACTER*1 | INTEGER |
value | N or n | 0 | `op(A) = A`
| T or t | 1 | `op(A) = A'`
| C or c | 2 | `op(A) = A'`

The parameter matdescra describes the relevant characteristic of the matrix A. This manual describes matdescra as an array of six elements in line with the NIST* implementation. However, only the first four elements of the array are used in the current versions of the Intel MKL Sparse BLAS routines. Elements `matdescra (5)` and `matdescra(6)` are reserved for future use. Note that whether matdescra is described in the user's program as an array of length 6 or 4 is of no importance because the array is declared as a pointer in the Intel MKL routines. To learn more about declaration of the matdescra array see Sparse BLAS examples located in the following subdirectory of the Intel MKL installation directory: `examples/spblas/`. The table below list elements of the parameter matdescra, their values and meanings. The parameter matdescra corresponds to the argument descra from NSB library.

Possible Values of the Parameter matdescra (descra)
| MKL interface | NSB interface | Matrix characteristics
--- | --- | --- | ---
| one-based indexing | zero-based indexing |  |
data type | CHARACTER | Char | INTEGER |
1st element | `matdescra(1)` | `matdescra(0)` | `descra(1)` | matrix structure
value | G | G | 0 | general
| S | S | 1 | symmetric `(A = A'`)
| H | H | 2 | Hermitian `(A=conjg(A')`)
| T | T | 3 | triangular
| A | A | 4 | skew(anti)-symmetric `(A=-A')`
| D | D | 5 | diagonal
2nd element | `matdescra(2)` | `matdescra(1)` | `descra(2)` | upper/lower triangular indicator
value | L | L | 1 | lower
| U | U | 2 | upper
3rd element | `matdescra(3)` | `matdescra(2)` | `descra(3)` | main diagonal type
value | N | N | 0 | non-unit
| U | U | 1 | unit
4th element | `matdescra(4)` | `matdescra(3)` |  | type of indexing
value | F |  |  | one-based indexing
|  | C |  | zero-based indexing

In some cases possible element values of the parameter matdescra depend on the values of other elements. The Table "Possible Combinations of Element Values of the Parameter matdescra" lists all possible combinations of element values for both multiplication routines and triangular solvers.

Possible Combinations of Element Values of the Parameter matdescra
Routines
matdescra(1) | matdescra(2) | matdescra(3) | matdescra( 4)
Multiplication Routines | G | ignored | ignored | F (default) or C
| S or H | L (default) | N (default) | F (default) or C
| S or H | L (default) | U | F (default) or C
| S or H | U | N (default) | F (default) or C
| S or H | U | U | F (default) or C
| A | L (default) | ignored | F (default) or C
| A | U | ignored | F (default) or C
Multiplication Routines and Triangular Solvers | T | L | U | F (default) or C
| T | L | N | F (default) or C
| T | U | U | F (default) or C
| T | U | N | F (default) or C
| D | ignored | N (default) | F (default) or C
| D | ignored | U | F (default) or C

For a matrix in the skyline format with main diagonal declared to be unit, diagonal elements must be stored in the sparse representation even if they are zero. In all other formats diagonal elements can be stored (if needed) in the sparse representation if they are not zero.

## Operations with Partial Matrices

One of the distinctive feature of the Intel MKL Sparse BLAS routines is a possibility to perform operations only on partial matrices composed of certain parts (triangles and main diagonal) of the input sparse matrix. It can be done by setting properly first three elements of the parameter matdescra.

An arbitrary sparse matrix A can be decomposed as
`A = L + D + U`

where L is the strict lower triangle of A, U is the strict upper triangle of A, D is the main diagonal.

Table “Output Matrices for Multiplication Routines” shows correspondence between the output matrices and values of the parameter matdescra for the sparse matrix A for multiplication routines.

Output Matrices for Multiplication Routines
matdescra(1) | matdescra(2) | matdescra(3) | Output Matrix
--- | --- | --- | ---
G | ignored | ignored | `alpha*op(A)*x + beta*y`
|  |  | alpha*op(A)*B + beta*C
S or H | L | N | `alpha*op(L+D+L')*x + beta*y`
|  |  | alpha*op(L+D+L')*B + beta*C
S or H | L | U | `alpha*op(L+I+L')*x + beta*y`
|  |  | `alpha*op(L+I+L')*B + beta*C`
S or H | U | N | `alpha*op(U'+D+U)*x + beta*y`
|  |  | alpha*op(U'+D+U)*B + beta*C
S or H | U | U | `alpha*op(U'+I+U)*x + beta*y`
|  |  | alpha*op(U'+I+U)*B + beta*C
T | L | U | `alpha*op(L+I)*x + beta*y`
|  |  | alpha*op(L+I)*B + beta*C
T | L | N | `alpha*op(L+D)*x + beta*y`
|  |  | alpha*op(L+D)*B + beta*C
T | U | U | `alpha*op(U+I)*x + beta*y`
|  |  | alpha*op(U+I)*B + beta*C
T | U | N | `alpha*op(U+D)*x + beta*y`
|  |  | alpha*op(U+D)*B + beta*C
A | L | ignored | `alpha*op(L-L')*x + beta*y`
|  |  | alpha*op(L-L')*B + beta*C
A | U | ignored | `alpha*op(U-U')*x + beta*y`
|  |  | alpha*op(U-U')*B + beta*C
D | ignored | N | `alpha*D*x + beta*y`
|  |  | alpha*D*B + beta*C
D | ignored | U | `alpha*x + beta*y`
|  |  | alpha*B + beta*C

Table “Output Matrices for Triangular Solvers” shows correspondence between the output matrices and values of the parameter matdescra for the sparse matrix A for triangular solvers.

Output Matrices for Triangular Solvers
matdescra(1) | matdescra(2) | matdescra(3) | Output Matrix
--- | --- | --- | ---
T | L | N | `alpha*inv(op(L+L))*x`
|  |  | alpha*inv(op(L+L))*B
T | L | U | `alpha*inv(op(L+L))*x`
|  |  | alpha*inv(op(L+L))*B
T | U | N | `alpha*inv(op(U+U))*x`
|  |  | alpha*inv(op(U+U))*B
T | U | U | `alpha*inv(op(U+U))*x`
|  |  | alpha*inv(op(U+U))*B
D | ignored | N | `alpha*inv(D)*x`
|  |  | alpha*inv(D)*B
D | ignored | U | `alpha*x`
|  |  | alpha*B

Parent topic: Sparse BLAS Level 2 and Level 3 Routines