LFIRG

   more...

   more...
Uses iterative refinement to improve the solution of a real general system of linear equations.
Required Arguments
AN by N matrix containing the coefficient matrix of the linear system. (Input)
FACTN by N matrix containing the LU factorization of the coefficient matrix A as output from routine LFCRG/DLFCRG or LFTRG/DLFTRG. (Input).
IPVT — Vector of length N containing the pivoting information for the LU factorization of A as output from routine LFCRG/DLFCRG or LFTRG/DLFTRG. (Input)
B — Vector of length N containing the right-hand side of the linear system. (Input).
X — Vector of length N containing the solution to the linear system. (Output)
RES — Vector of length N containing the final correction at the improved solution. (Output)
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).
LDFACT — Leading dimension of FACT exactly as specified in the dimension statement of the calling program. (Input)
Default: LDFACT = size (FACT,1).
IPATH — Path indicator. (Input)
IPATH = 1 means the system A * X = B is solved.
IPATH = 2 means the system ATX = B is solved.
Default: IPATH = 1.
FORTRAN 90 Interface
Generic: CALL LFIRG (A, FACT, IPVT, B, X, RES [])
Specific: The specific interface names are S_LFIRG and D_LFIRG.
FORTRAN 77 Interface
Single: CALL LFIRG (N, A, LDA, FACT, LDFACT, IPVT, B, IPATH, X, RES)
Double: The double precision name is DLFIRG.
ScaLAPACK Interface
Generic: CALL LFIRG (A0, FACT0, IPVT0, B0, X0, RES0 [])
Specific: The specific interface names are S_LFIRG and D_LFIRG.
See the ScaLAPACK Usage Notes below for a description of the arguments for distributed computing.
Description
Routine LFIRG computes the solution of a system of linear algebraic equations having a real general coefficient matrix. Iterative refinement is performed on the solution vector to improve the accuracy. Usually almost all of the digits in the solution are accurate, even if the matrix is somewhat ill-conditioned. 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.
To compute the solution, the coefficient matrix must first undergo an LU factorization. This may be done by calling either LFCRG or LFTRG.
Iterative refinement fails only if the matrix is very ill-conditioned.
Routines LFIRG and LFSRG both solve a linear system given its LU factorization. LFIRG generally takes more time and produces a more accurate answer than LFSRG. Each iteration of the iterative refinement algorithm used by LFIRG calls LFSRG.
Comments
Informational error
Type
Code
Description
3
2
The input matrix is too ill-conditioned for iterative refinement to be effective.
ScaLAPACK Usage Notes
The arguments which differ from the standard version of this routine are:
A0MXLDA by MXCOL local matrix containing the local portions of the distributed matrix A. A contains the coefficient matrix of the linear system. (Input)
FACT0MXLDA by MXCOL local matrix containing the local portions of the distributed matrix FACT as output from routine LFCRG or LFTRG. FACT contains the LU factorization of the matrix A. (Input)
IPVT0 — Local vector of length MXLDA containing the local portions of the distributed vector IPVT. IPVT contains the pivoting information for the LU factorization as output from subroutine LFCRG or LFTRG. (Input)
B0 — Local vector of length MXLDA containing the local portions of the distributed vector B. B contains the right-hand side of the linear system. (Input)
X0 — Local vector of length MXLDA containing the local portions of the distributed vector X. X contains the solution to the linear system. (Output)
If B is not needed, B and X can share the same storage locations.
RES0 — Local vector of length MXLDA containing the local portions of the distributed vector RES. RES contains the final correction at the improved solution to the linear system. (Output)
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
A set of linear systems is solved successively. The right-hand-side vector is perturbed after solving the system each of the first two times by adding 0.5 to the second element.
 
USE LFIRG_INT
USE LFCRG_INT
USE UMACH_INT
USE WRRRN_INT
! Declare variables
PARAMETER (LDA=3, LDFACT=3, N=3)
INTEGER IPVT(N), NOUT
REAL A(LDA,LDA), B(N), FACT(LDFACT,LDFACT), RCOND, RES(N), X(N)
!
! Set values for A and B
!
! A = ( 1.0 3.0 3.0)
! ( 1.0 3.0 4.0)
! ( 1.0 4.0 3.0)
!
! B = ( -0.5 -1.0 1.5)
!
DATA A/1.0, 1.0, 1.0, 3.0, 3.0, 4.0, 3.0, 4.0, 3.0/
DATA B/-0.5, -1.0, 1.5/
!
CALL LFCRG (A, FACT, IPVT, RCOND)
! Print the reciprocal condition number
CALL UMACH (2, NOUT)
WRITE (NOUT,99999) RCOND, 1.0E0/RCOND
! Solve the three systems
DO 10 J=1, 3
CALL LFIRG (A, FACT, IPVT, B, X, RES)
! Print results
CALL WRRRN (’X’, X, 1, N, 1)
! Perturb B by adding 0.5 to B(2)
B(2) = B(2) + 0.5
 
10 CONTINUE
!
99999 FORMAT (’ RCOND = ’,F5.3,/,’ L1 Condition number = ’,F6.3)
END
Output
 
RCOND < 0.02
L1 Condition number < 100.0
X
1 2 3
-5.000 2.000 -0.500
X
1 2 3
-6.500 2.000 0.000
 
X
1 2 3
-8.000 2.000 0.500
ScaLAPACK Example
The same set of linear systems is solved successively as a distributed example. The right-hand side vector is perturbed after solving the system each of the first two times by adding 0.5 to the second element. 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 LFIRG_INT
USE UMACH_INT
USE LFCRG_INT
USE WRRRN_INT
USE SCALAPACK_SUPPORT
IMPLICIT NONE
INCLUDE ‘mpif.h’
! Declare variables
INTEGER J, LDA, N, DESCA(9), DESCL(9)
INTEGER INFO, MXCOL, MXLDA, NOUT
INTEGER, ALLOCATABLE :: IPVT0(:)
REAL, ALLOCATABLE :: A(:,:), B(:), X(:), X0(:), AINV(:,:)
REAL, ALLOCATABLE :: A0(:,:), FACT0(:,:), RES0(:), B0(:)
REAL RCOND
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), B(N), X(N))
! Set values for A and B
A(1,:) = (/ 1.0, 3.0, 3.0/)
A(2,:) = (/ 1.0, 3.0, 4.0/)
A(3,:) = (/ 1.0, 4.0, 3.0/)
!
B(:) = (/-0.5, -1.0, 1.5/)
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)
CALL DESCINIT(DESCL, N, 1, MP_MB, 1, 0, 0, MP_ICTXT, MXLDA, INFO)
! Allocate space for the local arrays
ALLOCATE(A0(MXLDA,MXCOL), X0(MXLDA),FACT0(MXLDA,MXCOL), &
B0(MXLDA), RES0(MXLDA), IPVT0(MXLDA))
! Map input arrays to the processor grid
CALL SCALAPACK_MAP(A, DESCA, A0)
! Call the factorization routine
CALL LFCRG (A0, FACT0, IPVT0, RCOND)
! Print the reciprocal condition number
! and the L1 condition number
IF(MP_RANK .EQ. 0) THEN
CALL UMACH (2, NOUT)
WRITE (NOUT,99998) RCOND, 1.0E0/RCOND
ENDIF
! Solve the three systems
! one at a time in X
DO 10 J=1, 3
CALL SCALAPACK_MAP(B, DESCL, B0)
CALL LFIRG (A0, FACT0, IPVT0, B0, X0, RES0)
CALL SCALAPACK_UNMAP(X0, DESCL, X)
! Print results
! Only Rank=0 has the solution, X.
IF(MP_RANK.EQ.0) CALL WRRRN (’X’, X, 1, N, 1)
IF(MP_RANK.EQ.0) B(2) = B(2) + 0.5
10 CONTINUE
IF (MP_RANK .EQ. 0) DEALLOCATE(A, AINV, B)
DEALLOCATE(A0, B0, IPVT0, FACT0, RES0, X0)
! Exit ScaLAPACK usage
CALL SCALAPACK_EXIT(MP_ICTXT)
! Shut down MPI
MP_NPROCS = MP_SETUP(‘FINAL’)
99998 FORMAT (’ RCOND = ’,F5.3,/,’ L1 Condition number = ’,F6.3)
END
Output
 
RCOND < 0.02
L1 Condition number < 100.0
 
X
1 2 3
-5.000 2.000 -0.500
X
1 2 3
-6.500 2.000 0.000
 
X
1 2 3
-8.000 2.000 0.500