LINCG
Computes the inverse of a complex general matrix.
Required Arguments
A — Complex N by N matrix containing the matrix to be inverted. (Input)
AINV — Complex N by N matrix containing the inverse of A. (Output)
If A is not needed, A and AINV can share the same storage locations.
Optional Arguments
N — Number of equations. (Input)
Default: N = size (A,2).
LDA — Leading dimension of A exactly as specified in the dimension statement of the calling program. (Input)
Default: LDA = size (A,1).
LDAINV — Leading dimension of AINV exactly as specified in the dimension statement of the calling program. (Input)
Default: LDAINV = size (AINV,1).
FORTRAN 90 Interface
Generic: CALL LINCG (A, AINV [, …])
Specific: The specific interface names are S_LINCG and D_LINCG.
FORTRAN 77 Interface
Single: CALL LINCG (N, A, LDA, AINV, LDAINV)
Double: The double precision name is DLINCG.
ScaLAPACK Interface
Generic: CALL LINCG (A0, AINV0 [, …])
Specific: The specific interface names are S_LINCG and D_LINCG.
See the
ScaLAPACK Usage Notes below for a description of the arguments for distributed computing.
Description
Routine
LINCG computes the inverse of a complex general matrix. The underlying code is based on either LINPACK , LAPACK, or ScaLAPACK code depending upon which supporting libraries are used during linking. For a detailed explanation see
Using ScaLAPACK, LAPACK, LINPACK, and EISPACK in the Introduction section of this manual.
LINCG first uses the routine
LFCCG to compute an
LU factorization of the coefficient matrix and to estimate the condition number of the matrix.
LFCCG computes
U and the information needed to compute
L.
LINCT is then used to compute
U-1, i.e. use the inverse of
U. Finally
A-1 is computed using
A-1 =
U-1L-1.
LINCG fails if U, the upper triangular part of the factorization, has a zero diagonal element or if the iterative refinement algorithm fails to converge. This errors occurs only if A is singular or very close to a singular matrix.
If the estimated condition number is greater than 1/ɛ (where ɛ is machine precision), a warning error is issued. This indicates that very small changes in A can cause very large changes in A-1.
Comments
1. Workspace may be explicitly provided, if desired, by use of L2NCG/DL2NCG. The reference is:
CALL L2NCG (N, A, LDA, AINV, LDAINV, WK, IWK)
The additional arguments are as follows:
WK — Complex work vector of length N + N(N − 1)/2.
IWK — Integer work vector of length N.
2. Informational errors
Type | Code | Description |
---|
3 | 1 | The input matrix is too ill-conditioned. The inverse might not be accurate. |
4 | 2 | The input matrix is singular. |
ScaLAPACK Usage Notes
The arguments which differ from the standard version of this routine are:
A0 — MXLDA by MXCOL complex local matrix containing the local portions of the distributed matrix A. A contains the matrix to be inverted. (Input)
AINV0 — MXLDA by MXCOL complex local matrix containing the local portions of the distributed matrix AINV. AINV contains the inverse of the matrix A. (Output)
If A is not needed, A and AINV can share the same storage locations.
All other arguments are global and are the same as described for the standard version of the routine. In the argument descriptions above,
MXLDA and
MXCOL can be obtained through a call to
SCALAPACK_GETDIM (see
Utilities) after a call to
SCALAPACK_SETUP (see
Utilities) has been made. See the
ScaLAPACK Example below.
Examples
Example
The inverse is computed for a complex general 3 × 3 matrix.
USE LINCG_INT
USE WRCRN_INT
USE CSSCAL_INT
! Declare variables
PARAMETER (LDA=3, LDAINV=3, N=3)
REAL THIRD
COMPLEX A(LDA,LDA), AINV(LDAINV,LDAINV)
! Set values for A
!
! A = ( 1.0+1.0i 2.0+3.0i 3.0+3.0i)
! ( 2.0+1.0i 5.0+3.0i 7.0+4.0i)
! ( -2.0+1.0i -4.0+4.0i -5.0+3.0i)
!
DATA A/(1.0,1.0), (2.0,1.0), (-2.0,1.0), (2.0,3.0), (5.0,3.0),&
(-4.0,4.0), (3.0,3.0), (7.0,4.0), (-5.0,3.0)/
!
! Scale A by dividing by three
THIRD = 1.0/3.0
DO 10 I=1, N
CALL CSSCAL (N, THIRD, A(:,I), 1)
10 CONTINUE
! Calculate the inverse of A
CALL LINCG (A, AINV)
! Print results
CALL WRCRN (’AINV’, AINV)
END
Output
AINV
1 2 3
1 ( 6.400,-2.800) (-3.800, 2.600) (-2.600, 1.200)
2 (-1.600,-1.800) ( 0.200, 0.600) ( 0.400,-0.800)
3 (-0.600, 2.200) ( 1.200,-1.400) ( 0.400, 0.200)
ScaLAPACK Example
The inverse of the same 3
× 3 matrix is computed as a distributed example.
SCALAPACK_MAP and
SCALAPACK_UNMAP are IMSL utility routines (see
Chapter 11, “Utilities”) used to map and unmap arrays to and from the processor grid. They are used here for brevity.
DESCINIT is a ScaLAPACK tools routine which initializes the descriptors for the local arrays.
USE MPI_SETUP_INT
USE LINCG_INT
USE WRCRN_INT
USE SCALAPACK_SUPPORT
IMPLICIT NONE
INCLUDE ‘mpif.h’
! Declare variables
INTEGER J, LDA, N, DESCA(9)
INTEGER INFO, MXCOL, MXLDA, NPROW, NPCOL
COMPLEX, ALLOCATABLE :: A(:,:), AINV(:,:)
COMPLEX, ALLOCATABLE :: A0(:,:), AINV0(:,:)
REAL THIRD
PARAMETER (LDA=3, N=3)
! Set up for MPI
MP_NPROCS = MP_SETUP()
IF(MP_RANK .EQ. 0) THEN
ALLOCATE (A(LDA,N), AINV(LDA,N))
! Set values for A
A(1,:) = (/ ( 1.0, 1.0), ( 2.0, 3.0), ( 3.0, 3.0)/)
A(2,:) = (/ ( 2.0, 1.0), ( 5.0, 3.0), ( 7.0, 4.0)/)
A(3,:) = (/ (-2.0, 1.0), (-4.0, 4.0), (-5.0, 3.0)/)
! Scale A by dividing by three
THIRD = 1.0/3.0
A = A * THIRD
ENDIF
! Set up a 1D processor grid and define
! its context ID, MP_ICTXT
CALL SCALAPACK_SETUP(N, N, .TRUE., .TRUE.)
! Get the array descriptor entities MXLDA,
! and MXCOL
CALL SCALAPACK_GETDIM(N, N, MP_MB, MP_NB, MXLDA, MXCOL)
! Set up the array descriptors
CALL DESCINIT(DESCA, N, N, MP_MB, MP_NB, 0, 0, MP_ICTXT, MXLDA, INFO)
! Allocate space for the local arrays
ALLOCATE(A0(MXLDA,MXCOL), AINV0(MXLDA,MXCOL))
! Map input array to the processor grid
CALL SCALAPACK_MAP(A, DESCA, A0)
! Factor A
CALL LINCG (A0, AINV0)
! Unmap the results from the distributed
! arrays back to a non-distributed array.
! After the unmap, only Rank=0 has the full
! array.
CALL SCALAPACK_UNMAP(AINV0, DESCA, AINV)
! Print results.
! Only Rank=0 has the solution, X.
IF(MP_RANK.EQ.0) CALL WRCRN (’AINV’, AINV)
IF (MP_RANK .EQ. 0) DEALLOCATE(A, AINV)
DEALLOCATE(A0, AINV0)
! Exit ScaLAPACK usage
CALL SCALAPACK_EXIT(MP_ICTXT)
! Shut down MPI
MP_NPROCS = MP_SETUP(‘FINAL’)
END
Output
AINV
1 2 3
1 ( 6.400,-2.800) (-3.800, 2.600) (-2.600, 1.200)
2 (-1.600,-1.800) ( 0.200, 0.600) ( 0.400,-0.800)
3 (-0.600, 2.200) ( 1.200,-1.400) ( 0.400, 0.200)