This subroutine solves a general sparse linear system of equations using an iterative algorithm, conjugate gradient squared or generalized minimum residual, with or without preconditioning by an incomplete LU factorization. The subroutine is suitable for positive real matrices--that is, when the symmetric part of the matrix, (A+AT)/2, is positive definite. The sparse matrix is stored in compressed-matrix storage mode. Matrix A and vectors x and b are used:
where A, x, and b contain long-precision real numbers.
Notes:
| Fortran | CALL DSMGCG (m, nz, ac, ka, lda, b, x, iparm, rparm, aux1, naux1, aux2, naux2) |
| C and C++ | dsmgcg (m, nz, ac, ka, lda, b, x, iparm, rparm, aux1, naux1, aux2, naux2); |
| PL/I | CALL DSMGCG (m, nz, ac, ka, lda, b, x, iparm, rparm, aux1, naux1, aux2, naux2); |
If IPARM(1) > 0, IPARM(1) is the maximum number of iterations allowed.
If IPARM(1) = 0, the following default values are used:
If IPARM(2) = 0, the conjugate gradient squared method is used.
If IPARM(2) = k, the generalized minimum residual method, restarted after k steps, is used. Note that the size of the work area aux1 becomes larger as k increases. A value for k in the range of 5 to 10 is suitable for most problems.
If IPARM(3) = 0, the system is not preconditioned.
If IPARM(3) = 10, the system is preconditioned by an incomplete LU factorization.
If IPARM(3) = -10, the system is preconditioned by an incomplete LU factorization, where the factorization matrix was computed in an earlier call to this subroutine and is stored in aux2.
Specified as: an array of (at least) length 4, containing fullword integers, where:
RPARM(1) > 0, is the relative accuracy epsilon used in the stopping criterion. The iterative procedure is stopped when:
RPARM(2) is reserved.
RPARM(3), see On Return.
Specified as: a one-dimensional array of (at least) length 3, containing long-precision real numbers.
If naux1 = 0 and error 2015 is unrecoverable, aux1 is ignored.
Otherwise, it is a storage work area used by this subroutine, which is available for use by the calling program between calls to this subroutine. Its size is specified by naux1.
Specified as: an area of storage, containing long-precision real numbers.
If naux1 = 0 and error 2015 is unrecoverable, DSMGCG dynamically allocates the work area used by this subroutine. The work area is deallocated before control is returned to the calling program.
Otherwise, it must have at least the following value, where:
If IPARM(2) = 0, use naux1 >= 7m.
If IPARM(2) > 0, use naux1 >= (k+2)m+k(k+4)+1, where k = IPARM(2).
Specified as: an area of storage, containing long-precision real numbers.
IPARM(1) is unchanged.
IPARM(2) is unchanged.
IPARM(3) is unchanged.
IPARM(4) contains the number of iterations performed by this subroutine.
Returned as: a one-dimensional array of length 4, containing fullword integers.
RPARM(1) is unchanged.
RPARM(2) is reserved.
RPARM(3) contains the estimate of the error of the solution. If the process converged, RPARM(3) <= RPARM(1)
Returned as: a one-dimensional array of length 3, containing long-precision real numbers.
If IPARM(3) = 10, aux2 contains the incomplete LU factorization of matrix A.
If IPARM(3) = -10, aux2 is unchanged.
See Notes for additional information on aux2. Returned as: an area of storage, containing long-precision real numbers.
As a result, if you specify a larger epsilon, the algorithm takes fewer iterations to converge to a solution. If you specify a smaller epsilon, the algorithm requires more iterations and computer time, but converges to a more precise solution. If the value you specify is unreasonably small, the algorithm may fail to converge within the number of iterations it is allowed to perform.
The linear system:
is solved using either the conjugate gradient squared method or the generalized minimum residual method, with or without preconditioning by an incomplete LU factorization, where:
See references [86] and [88]. [36].
If your program uses a sparse matrix stored by rows and you want to use this subroutine, first convert your sparse matrix to compressed-matrix storage mode by using the subroutine DSRSM described on page DSRSM--Convert a Sparse Matrix from Storage-by-Rows to Compressed-Matrix Storage Mode.
Error 2015 is unrecoverable, naux1 = 0, and unable to allocate work area.
The following errors, with their corresponding return codes, can occur in this subroutine. For details on error handling, see What Can You Do about ESSL Computational Errors?.
This example finds the solution of the linear system Ax = b for the sparse matrix A, which is stored in compressed-matrix storage mode in arrays AC and KA. The system is solved using the conjugate gradient squared method. Matrix A is:
* *
| 2.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 |
| 0.0 2.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 |
| 0.0 1.0 2.0 0.0 0.0 0.0 0.0 0.0 0.0 |
| 1.0 0.0 0.0 2.0 -1.0 0.0 0.0 0.0 0.0 |
| 0.0 0.0 0.0 1.0 2.0 -1.0 0.0 0.0 0.0 |
| 0.0 0.0 0.0 0.0 1.0 2.0 -1.0 0.0 0.0 |
| 0.0 0.0 0.0 0.0 0.0 1.0 2.0 -1.0 0.0 |
| 0.0 0.0 0.0 0.0 0.0 0.0 1.0 2.0 -1.0 |
| 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 2.0 |
* *
M NZ AC KA LDA B X IPARM RPARM AUX1 NAUX1 AUX2 NAUX2
| | | | | | | | | | | | |
CALL DSMGCG( 9 , 3 , AC , KA , 9 , B , X , IPARM , RPARM , AUX1 , 63 , AUX2 , 0 )
IPARM(1) = 20 IPARM(2) = 0 IPARM(3) = 0 RPARM(1) = 1.D-7
* *
| 2.0 0.0 0.0 |
| 2.0 -1.0 0.0 |
| 1.0 2.0 0.0 |
| 1.0 2.0 -1.0 |
AC = | 1.0 2.0 -1.0 |
| 1.0 2.0 -1.0 |
| 1.0 2.0 -1.0 |
| 1.0 2.0 -1.0 |
| 1.0 2.0 0.0 |
* *
* *
| 1 . . |
| 2 3 . |
| 2 3 . |
| 1 4 5 |
KA = | 4 5 6 |
| 5 6 7 |
| 6 7 8 |
| 7 8 9 |
| 8 9 . |
* *
B = (2.0, 1.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0) X = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
X = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) IPARM(4) = 9 RPARM(3) = 0.150D-19
This example finds the solution of the linear system Ax = b for the same sparse matrix A as in Example 1, which is stored in compressed-matrix storage mode in arrays AC and KA. The system is solved using the generalized minimum residual method, restarted after 5 steps and preconditioned with an incomplete LU factorization. Most of the input is the same as in Example 1.
M NZ AC KA LDA B X IPARM RPARM AUX1 NAUX1 AUX2 NAUX2
| | | | | | | | | | | | |
CALL DSMGCG( 9 , 3 , AC , KA , 9 , B , X , IPARM , RPARM , AUX1 , 109 , AUX2 , 46 )
X = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0) IPARM(4) = 2 RPARM(3) = 0.290D-15