LFSRG

   more...

   more...
Solves a real general system of linear equations given the LU factorization of the coefficient matrix.
Required Arguments
FACTN by N matrix containing the LU factorization of the coefficient matrix A as output from routine LFCRG or LFTRG. (Input)
IPVT — Vector of length N containing the pivoting information for the LU factorization of A as output from subroutine LFCRG or LFTRG. (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)
If B is not needed, B and X can share the same storage locations.
Optional Arguments
N — Number of equations. (Input)
Default: N = size (FACT, 2).
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 AX = B is solved.
IPATH = 2 means the system ATX = B is solved.
Default: IPATH = 1.
FORTRAN 90 Interface
Generic: CALL LFSRG (FACT, IPVT, B, X [])
Specific: The specific interface names are S_LFSRG and D_LFSRG.
FORTRAN 77 Interface
Single: CALL LFSRG (N, FACT, LDFACT, IPVT, B, IPATH, X)
Double: The double precision name is DLFSRG.
ScaLAPACK Interface
Generic: CALL LFSRG (FACT0, IPVT0, B0, X0 [])
Specific: The specific interface names are S_LFSRG and D_LFSRG.
See the ScaLAPACK Usage Notes below for a description of the arguments for distributed computing.
Description
Routine LFSRG computes the solution of a system of linear algebraic equations having a real general coefficient matrix. To compute the solution, the coefficient matrix must first undergo an LU factorization. This may be done by calling either LFCRG or LFTRG. The solution to Ax = b is found by solving the triangular systems Ly = b and Ux = y. The forward elimination step consists of solving the system Ly = b by applying the same permutations and elimination operations to b that were applied to the columns of A in the factorization routine. The backward substitution step consists of solving the triangular system Ux = y for x.
LFSRG and LFIRG 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. 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.
ScaLAPACK Usage Notes
The arguments which differ from the standard version of this routine are:
FACT0MXLDA by MXCOL local matrix containing the local portions of the distributed matrix FACT as output from routine LFCRG. 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/DLFTRG. (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.
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 real general 3 × 3 matrix. The input matrix is assumed to be well-conditioned, hence, LFTRG is used rather than LFCRG.
 
USE LFSRG_INT
USE LFTRG_INT
USE WRRRN_INT
! Declare variables
PARAMETER (LDA=3, LDFACT=3, N=3)
INTEGER I, IPVT(N), J
REAL A(LDA,LDA), AINV(LDA,LDA), FACT(LDFACT,LDFACT), RJ(N)
!
! Set values for A
A(1,:) = (/ 1.0, 3.0, 3.0/)
A(2,:) = (/ 1.0, 3.0, 4.0/)
A(3,:) = (/ 1.0, 4.0, 3.0/)
!
CALL LFTRG (A, FACT, IPVT)
! Set up the columns of the identity
! matrix one at a time in RJ
RJ = 0.0E0
DO 10 J=1, N
RJ(J) = 1.0
! RJ is the J-th column of the identity
! matrix so the following LFSRG
! reference places the J-th column of
! the inverse of A in the J-th column
! of AINV
CALL LFSRG (FACT, IPVT, RJ, AINV(:,J))
RJ(J) = 0.0
10 CONTINUE
! Print results
CALL WRRRN (’AINV’, AINV)
END
Output
 
AINV
1 2 3
1 7.000 -3.000 -3.000
2 -1.000 0.000 1.000
3 -1.000 1.000 0.000
ScaLAPACK Example
The inverse of the same 3 × 3 matrix is computed as a distributed example. The input matrix is assumed to be well-conditioned, hence, LFTRG is used rather than LFCRG. LFSRG is called to determine the columns of the inverse. 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 LFTRG_INT
USE UMACH_INT
USE LFSRG_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
INTEGER, ALLOCATABLE :: IPVT0(:)
REAL, ALLOCATABLE :: A(:,:), AINV(:,:), X0(:), RJ(:)
REAL, ALLOCATABLE :: A0(:,:), FACT0(:,:), RJ0(:)
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, 3.0, 3.0/)
A(2,:) = (/ 1.0, 3.0, 4.0/)
A(3,:) = (/ 1.0, 4.0, 3.0/)
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), RJ(N), &
RJ0(MXLDA), IPVT0(MXLDA))
! Map input arrays to the processor grid
CALL SCALAPACK_MAP(A, DESCA, A0)
! Call the factorization routine
CALL LFTRG (A0, FACT0, IPVT0)
! Set up the columns of the identity
! matrix one at a time in RJ
RJ = 0.0E0
DO 10 J=1, N
RJ(J) = 1.0
CALL SCALAPACK_MAP(RJ, DESCL, RJ0)
! RJ is the J-th column of the identity
! matrix so the following LFIRG
! reference computes the J-th column of
! the inverse of A
CALL LFSRG (FACT0, IPVT0, RJ0, X0)
RJ(J) = 0.0
CALL SCALAPACK_UNMAP(X0, DESCL, AINV(:,J))
10 CONTINUE
! Print results
! Only Rank=0 has the solution, AINV.
IF(MP_RANK.EQ.0) CALL WRRRN (’AINV’, AINV)
IF (MP_RANK .EQ. 0) DEALLOCATE(A, AINV)
DEALLOCATE(A0, IPVT0, FACT0, RJ, RJ0, X0)
! Exit ScaLAPACK usage
CALL SCALAPACK_EXIT(MP_ICTXT)
! Shut down MPI
MP_NPROCS = MP_SETUP(‘FINAL’)
END
Output
AINV
1 2 3
1 7.000 -3.000 -3.000
2 -1.000 0.000 1.000
3 -1.000 1.000 0.000
Published date: 03/19/2020
Last modified date: 03/19/2020