C H A P T E R 4 |
Working With Matrices |
Most matrices can be stored in ways that save both storage space and computation time. Sun Performance Library uses the following storage schemes:
The Sun Performance Library processes matrices that are in one of four forms:
Storage schemes and matrix types are described in the following sections.
Some Sun Performance Library routines that work with arrays stored normally have corresponding routines that take advantage of these special storage forms. For example, DGBMV will form the product of a general matrix in banded storage and a vector, and DTPMV will form the product of a triangular matrix in packed storage and a vector.
A banded matrix is stored so the jth column of the matrix corresponds to the jth column of the Fortran array.
The following code copies a banded general matrix in a general array into banded storage mode.
Note that this method of storing banded matrices is compatible with the storage method used by LAPACK, BLAS, and LINPACK, but is inconsistent with the method used by EISPACK.
A packed vector is an alternate representation for a triangular, symmetric, or Hermitian matrix. An array is packed into a vector by storing the elements sequentially column by column into the vector. Space for the diagonal elements is always reserved, even if the values of the diagonal elements are known, such as in a unit diagonal matrix.
An upper triangular matrix or a symmetric matrix whose upper triangle is stored in general storage in the array A, can be transferred to packed storage in the array AP as shown below. This code comes from the comment block of the LAPACK routine DTPTRI.
JC = 1 DO J = 1, N DO I = 1, J AP(JC+I-1) = A(I,J) END DO JC = JC + J END DO |
Similarly, a lower triangular matrix or a symmetric matrix whose lower triangle is stored in general storage in the array A, can be transferred to packed storage in the array AP as shown below:
JC = 1 DO J = 1, N DO I = J, N AP(JC+I-1) = A(I,J) END DO JC = JC + N - J + 1 END DO |
The general matrix form is the most common matrix, and most operations performed by the Sun Performance Library can be done on general arrays. In many cases, there are routines that will work with the other forms of the arrays. For example, DGEMM will form the product of two general matrices and DTRMM will form the product of a triangular and a general matrix.
A general matrix is stored so that there is a one-to-one correspondence between the elements of the matrix and the elements of the array. Element Aij of a matrix A is stored in element A(I,J) of the corresponding array A. The general form is the most common form. A general matrix, because it is dense, has no special storage scheme. In a general banded matrix, however, the diagonal of the matrix is stored in the row below the upper diagonals.
For example, as shown below, the general banded matrix can be represented with banded storage. Elements shown with the symbol × are never accessed by routines that process banded arrays.
A triangular matrix is stored so that there is a one-to-one correspondence between the nonzero elements of the matrix and the elements of the array, but the elements of the array corresponding to the zero elements of the matrix are never accessed by routines that process triangular arrays.
A triangular matrix can be stored using packed storage.
A triangular banded matrix can be stored using banded storage as shown below. Elements shown with the symbol × are never accessed by routines that process banded arrays.
A symmetric matrix is similar to a triangular matrix in that the data in either the upper or lower triangle corresponds to the elements of the array. The contents of the other elements in the array are assumed and those array elements are never accessed by routines that process symmetric or Hermitian arrays.
A symmetric matrix can be stored using packed storage.
A symmetric banded matrix can be stored using banded storage as shown below. Elements shown with the symbol × are never accessed by routines that process banded arrays.
A tridiagonal matrix has elements only on the main diagonal, the first superdiagonal, and the first subdiagonal. It is stored using three 1-dimensional arrays.
The Sun Performance Library sparse solver package is a collection of routines that efficiently factor and solve sparse linear systems of equations. Use the sparse solver package to:
The sparse solver package contains interfaces for FORTRAN 77. Fortran 95 and C interfaces are not currently provided. To use the sparse solver routines from Fortran 95, use the FORTRAN 77 interfaces. To use the sparse solver routines with C, append an underscore to the routine name (dgssin_(), dgssor_(), and so on), pass arguments by reference, and use 1-based array indexing.
Sparse matrices are usually represented in formats that minimize storage requirements. By taking advantage of the sparsity and not storing zeros, considerable storage space can be saved. The storage format used by the general sparse solver is the compressed sparse column (CSC) format (also called the Harwell-Boeing format).
The CSC format represents a sparse matrix with two integer arrays and one floating point array. The integer arrays (colptr and rowind) specify the location of the nonzeros of the sparse matrix, and the floating point array (values) is used for the nonzero values.
The column pointer (colptr) array consists of n+1 elements where colptr(i) points to the beginning of the ith column, and colptr(i + 1) - 1 points to the end of the ith column. The row indices (rowind) array contains the row indices of the nonzero values. The values arrays contains the corresponding nonzero numerical values.
The following matrix data formats exist for a sparse matrix of neqns equations and nnz nonzeros:
The most efficient data representation often depends on the specific problem. The following sections show examples of sparse matrix data formats.
A symmetric sparse matrix is a matrix where a(i, j) = a(j, i) for all i and j. Because of this symmetry, only the lower triangular values need to be passed to the solver routines. The upper triangle can be determined from the lower triangle.
An example of a symmetric matrix is shown below. This example is derived from A. George and J. W-H. Liu. "Computer Solution of Large Sparse Positive Definite Systems."
A structurally symmetric sparse matrix has nonzero values with the property that if a(i, j) 0, then a(j, i)
0 for all i and j. When solving a structurally symmetric system, the entire matrix must be passed to the solver routines.
An example of a structurally symmetric matrix is shown below.
An unsymmetric sparse matrix does not have a(i, j) = a(j, i) for all i and j. The structure of the matrix does not have an apparent pattern. When solving an unsymmetric system, the entire matrix must be passed to the solver routines. An example of an unsymmetric matrix is shown below.
The Sun Performance Library sparse BLAS package is based on the following two packages:
Refer to the following sources for additional sparse BLAS information.
The Netlib Sparse BLAS and NIST Fortran Sparse BLAS Library routines each use their own naming conventions, as described in the following two sections.
Each Netlib Sparse BLAS routine has a name of the form Prefix-Root-Suffix where the:
TABLE 4-1 lists the naming conventions for the Netlib Sparse BLAS vector routines.
The prefix can be one of the following data types:
The I, CI, and UI suffixes denote sparse BLAS routines that are direct extensions to dense BLAS routines.
Each NIST Fortran Sparse BLAS routine has a six-character name of the form XYYYZZ where:
TABLE 4-2 shows the values for X, Y, and Z.
BSC: block compressed sparse column |
||
SM: solution of triangular system (supported for all formats except COO) |
The Sun Performance Library sparse solver package contains the routines listed in TABLE 4-3.
Use the regular interface to solve multiple matrices with the same structure, but different numerical values, as shown below:
The one-call interface is not as flexible as the regular interface, but it covers the most common case of factoring a single matrix and solving some number right-hand sides. Additional calls to dgsssl() are allowed to solve for additional right-hand sides, as shown in the following example.
To solve problems with the sparse solver package, use the sparse solver routines in the order shown in TABLE 4-4.
Regular Interface: For solving multiple matrices with the same structure |
|
CODE EXAMPLE 4-1 shows solving a symmetric system using the one-call interface, and CODE EXAMPLE 4-2 shows solving a symmetric system using the regular interface.
The following books and papers provide additional information for the sparse BLAS and sparse solver routines.
Copyright © 2002, Sun Microsystems, Inc. All rights reserved.