LFSCG

Solves a complex general system of linear equations given the LU factorization of the coefficient matrix.

Required Arguments

FACT — Complex N by N matrix containing the LU factorization of the coefficient matrix A as output from routine LFCCG/DLFCCG or LFTCG/DLFTCG. (Input)

IPVT — Vector of length N containing the pivoting information for the LU factorization of A as output from routine LFCCG/DLFCCG or LFTCG/DLFTCG. (Input)

B — Complex vector of length N containing the right-hand side of the linear system. (Input)

X — Complex 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.

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).

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).

Default: LDFACT = size (FACT,1).

IPATH — Path indicator. (Input)

IPATH = 1 means the system AX = B is solved.

IPATH = 2 means the system AHX = B is solved.

Default: IPATH = 1.

IPATH = 1 means the system AX = B is solved.

IPATH = 2 means the system AHX = B is solved.

Default: IPATH = 1.

FORTRAN 90 Interface

Generic: CALL LFSCG (FACT, IPVT, B, X [, …])

Specific: The specific interface names are S_LFSCG and D_LFSCG.

FORTRAN 77 Interface

Single: CALL LFSCG (N, FACT, LDFACT, IPVT, B, IPATH, X)

Double: The double precision name is DLFSCG.

ScaLAPACK Interface

Generic: CALL LFSCG (FACT0, IPVT0, B0, X0 [, …])

Specific: The specific interface names are S_LFSCG and D_LFSCG.

See the ScaLAPACK Usage Notes below for a description of the arguments for distributed computing.

Description

Routine LFSCG computes the solution of a system of linear algebraic equations having a complex general coefficient matrix. To compute the solution, the coefficient matrix must first undergo an LU factorization. This may be done by calling either LFCCG or LFTCG. 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.

Routines LFSCG and LFICG both solve a linear system given its LU factorization. LFICG generally takes more time and produces a more accurate answer than LFSCG. Each iteration of the iterative refinement algorithm used by LFICG calls LFSCG.

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:

FACT0 — MXLDA by MXCOL complex local matrix containing the local portions of the distributed matrix FACT as output from routine LFCCG/DLFCCG or LFTCG/DLFTCG. 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 LFCCG/DLFCCG or LFTCG/DLFTCG. (Input)

B0 — Complex 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 — Complex 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.

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 complex general 3 × 3 matrix. The input matrix is assumed to be well-conditioned, hence LFTCG is used rather than LFCCG.

USE IMSL_LIBRARIES

! Declare variables

PARAMETER (LDA=3, LDFACT=3, N=3)

INTEGER IPVT(N)

REAL THIRD

COMPLEX A(LDA,LDA), AINV(LDA,LDA), RJ(N), FACT(LDFACT,LDFACT)

! Declare functions

COMPLEX CMPLX

! 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

! Factor A

CALL LFTCG (A, FACT, IPVT)

! Set up the columns of the identity

! matrix one at a time in RJ

CALL CSET (N, (0.0,0.0), RJ, 1)

DO 20 J=1, N

RJ(J) = CMPLX(1.0,0.0)

! RJ is the J-th column of the identity

! matrix so the following LFSCG

! reference places the J-th column of

! the inverse of A in the J-th column

! of AINV

CALL LFSCG (FACT, IPVT, RJ, AINV(:,J))

RJ(J) = CMPLX(0.0,0.0)

20 CONTINUE

! 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. The input matrix is assumed to be well-conditioned, hence LFTCG is used rather than LFCCG. LFSCG 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 LFTCG_INT

USE LFSCG_INT

USE WRCRN_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(:)

COMPLEX, ALLOCATABLE :: A(:,:), AINV(:,:), X0(:)

COMPLEX, ALLOCATABLE :: A0(:,:), FACT0(:,:), RJ(:), RJ0(:)

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)

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 array to the processor grid

CALL SCALAPACK_MAP(A, DESCA, A0)

! Factor A

CALL LFTCG (A0, FACT0, IPVT0)

! Set up the columns of the identity

! matrix one at a time in RJ

RJ = (0.0, 0.0)

DO 10 J=1, N

RJ(J) = (1.0, 0.0)

CALL SCALAPACK_MAP(RJ, DESCL, RJ0)

! RJ is the J-th column of the identity

! matrix so the following LFICG

! reference computes the J-th column of

! the inverse of A

CALL LFSCG (FACT0, IPVT0, RJ0, X0)

RJ(J) = (0.0, 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 WRCRN (’AINV’, AINV)

IF (MP_RANK .EQ. 0) DEALLOCATE(A, AINV)

DEALLOCATE(A0, FACT0, IPVT0, 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 ( 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)