PSGESVX(l)
π PSGESVX(l) β LAPACK routine (version 1.5) π
okay bestie, sit down, hydrate, because we're about to solve a real system of linear equations and we're gonna look iconic doing it. this is PSGESVX, a LAPACK routine, and she is a whole main character. π«Ά
πΈ NAME πΈ
PSGESVX β bestie, she uses the LU factorization to compute the solution to a real system of linear equations
A(IA:IA+N-1,JA:JA+N-1) * X = B(IB:IB+N-1,JB:JB+NRHS-1),
like. that's her whole thing. that's the vibe. β¨
π SYNOPSIS π
SUBROUTINE PSGESVX( FACT, TRANS, N, NRHS, A, IA, JA, DESCA, AF, IAF,
JAF, DESCAF, IPIV, EQUED, R, C, B, IB, JB, DESCB, X,
IX, JX, DESCX, RCOND, FERR, BERR, WORK, LWORK,
IWORK, LIWORK, INFO )
CHARACTER EQUED, FACT, TRANS
INTEGER IA, IAF, IB, INFO, IX, JA, JAF, JB, JX, LIWORK,
LWORK, N, NRHS
REAL RCOND
INTEGER DESCA( * ), DESCAF( * ), DESCB( * ), DESCX( * ),
IPIV( * ), IWORK( * )
REAL A( * ), AF( * ), B( * ), BERR( * ), C( * ), FERR( *
), R( * ), WORK( * ), X( * )
look at all those arguments. she's booked and busy. π
β¨ PURPOSE β¨
PSGESVX uses the LU factorization to compute the solution to a real system of linear equations
where A(IA:IA+N-1,JA:JA+N-1) is an N-by-N matrix and X and B(IB:IB+N-1,JB:JB+NRHS-1) are N-by-NRHS matrices.
Error bounds on the solution and a condition estimate are also provided. she does it ALL. π
π Notes π
okay so before we go anywhere, you need to know how distributed arrays work, because this is ScaLAPACK and everything is β¨spread outβ¨.
Each global data object is described by an associated description vector. This vector stores the information required to establish the mapping between an object element and its corresponding process and memory location.
Let A be a generic term for any 2D block cyclicly distributed array. Such a global array has an associated description vector DESCA. In the following comments, the character _ should be read as "of the global array". iykyk π¦
DTYPE_A(global) β stored inDESCA( DTYPE_ )β the descriptor type. In this case,DTYPE_A = 1.CTXT_A(global) β stored inDESCA( CTXT_ )β the BLACS context handle, indicating the BLACS process grid A is distributed over. The context itself is global, but the handle (the integer value) may vary.M_A(global) β stored inDESCA( M_ )β the number of rows in the global array A.N_A(global) β stored inDESCA( N_ )β the number of columns in the global array A.MB_A(global) β stored inDESCA( MB_ )β the blocking factor used to distribute the rows of the array.NB_A(global) β stored inDESCA( NB_ )β the blocking factor used to distribute the columns of the array.RSRC_A(global) β stored inDESCA( RSRC_ )β the process row over which the first row of the array A is distributed.CSRC_A(global) β stored inDESCA( CSRC_ )β the process column over which the first column of the array A is distributed.LLD_A(local) β stored inDESCA( LLD_ )β the leading dimension of the local array.LLD_A >= MAX(1,LOCr(M_A)).
Let K be the number of rows or columns of a distributed matrix, and assume that its process grid has dimension p x q.
LOCr( K ) denotes the number of elements of K that a process would receive if K were distributed over the p processes of its process column.
Similarly, LOCc( K ) denotes the number of elements of K that a process would receive if K were distributed over the q processes of its process row.
The values of LOCr() and LOCc() may be determined via a call to the ScaLAPACK tool function, NUMROC:
LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
An upper bound for these quantities may be computed by:
LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
math girlies rise π§
π DESCRIPTION π
In the following description, A denotes A(IA:IA+N-1,JA:JA+N-1), B denotes B(IB:IB+N-1,JB:JB+NRHS-1) and X denotes X(IX:IX+N-1,JX:JX+NRHS-1).
The following steps are performed:
- If
FACT = 'E', real scaling factors are computed to equilibrate the system:
TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B
TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B
TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B
Whether or not the system will be equilibrated depends on the scaling of the matrix A, but if equilibration is used, A is overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') or diag(C)*B (if TRANS = 'T' or 'C').
- If
FACT = 'N'or'E', the LU decomposition is used to factor the matrix A (after equilibration ifFACT = 'E') as
A = P * L * U,
where P is a permutation matrix, L is a unit lower triangular matrix, and U is upper triangular.
- The factored form of A is used to estimate the condition number of the matrix A. If the reciprocal of the condition number is less than machine precision, steps 4-6 are skipped. π (yeah, she just. skips. them.)
- The system of equations is solved for X using the factored form of A.
- Iterative refinement is applied to improve the computed solution matrix and calculate error bounds and backward error estimates for it. glow-up arc β¨
- If
FACT = 'E'and equilibration was used, the matrix X is premultiplied bydiag(C)(ifTRANS = 'N') ordiag(R)(ifTRANS = 'T'or'C') so that it solves the original system before equilibration.
π ARGUMENTS π
FACTβ (global input)CHARACTER. Specifies whether or not the factored form of the matrixA(IA:IA+N-1,JA:JA+N-1)is supplied on entry, and if not, whether the matrixA(IA:IA+N-1,JA:JA+N-1)should be equilibrated before it is factored.= 'F': On entry,AF(IAF:IAF+N-1,JAF:JAF+N-1)andIPIVcontain the factored form ofA(IA:IA+N-1,JA:JA+N-1). IfEQUEDis not'N', the matrixA(IA:IA+N-1,JA:JA+N-1)has been equilibrated with scaling factors given byRandC.A(IA:IA+N-1,JA:JA+N-1),AF(IAF:IAF+N-1,JAF:JAF+N-1), andIPIVare not modified.= 'N': The matrixA(IA:IA+N-1,JA:JA+N-1)will be copied toAF(IAF:IAF+N-1,JAF:JAF+N-1)and factored.= 'E': The matrixA(IA:IA+N-1,JA:JA+N-1)will be equilibrated if necessary, then copied toAF(IAF:IAF+N-1,JAF:JAF+N-1)and factored.
TRANSβ (global input)CHARACTER. Specifies the form of the system of equations:= 'N':A(IA:IA+N-1,JA:JA+N-1) * X(IX:IX+N-1,JX:JX+NRHS-1) = B(IB:IB+N-1,JB:JB+NRHS-1)(No transpose)= 'T':A(IA:IA+N-1,JA:JA+N-1)**T * X(IX:IX+N-1,JX:JX+NRHS-1) = B(IB:IB+N-1,JB:JB+NRHS-1)(Transpose)= 'C':A(IA:IA+N-1,JA:JA+N-1)**H * X(IX:IX+N-1,JX:JX+NRHS-1) = B(IB:IB+N-1,JB:JB+NRHS-1)(Transpose)
Nβ (global input)INTEGER. The number of rows and columns to be operated on, i.e. the order of the distributed submatrixA(IA:IA+N-1,JA:JA+N-1).N >= 0.NRHSβ (global input)INTEGER. The number of right-hand sides, i.e., the number of columns of the distributed submatricesB(IB:IB+N-1,JB:JB+NRHS-1)andX(IX:IX+N-1,JX:JX+NRHS-1).NRHS >= 0.Aβ (local input/local output)REALpointer into the local memory to an array of local dimension(LLD_A,LOCc(JA+N-1)). On entry, the N-by-N matrixA(IA:IA+N-1,JA:JA+N-1). IfFACT = 'F'andEQUEDis not'N', thenA(IA:IA+N-1,JA:JA+N-1)must have been equilibrated by the scaling factors inRand/orC.A(IA:IA+N-1,JA:JA+N-1)is not modified ifFACT = 'F'or'N', or ifFACT = 'E'andEQUED = 'N'on exit.
On exit, if EQUED .ne. 'N', A(IA:IA+N-1,JA:JA+N-1) is scaled as follows:
EQUED = 'R':A(IA:IA+N-1,JA:JA+N-1) := diag(R) * A(IA:IA+N-1,JA:JA+N-1)EQUED = 'C':A(IA:IA+N-1,JA:JA+N-1) := A(IA:IA+N-1,JA:JA+N-1) * diag(C)EQUED = 'B':A(IA:IA+N-1,JA:JA+N-1) := diag(R) * A(IA:IA+N-1,JA:JA+N-1) * diag(C)
IAβ (global input)INTEGER. The row index in the global array A indicating the first row ofsub( A ).JAβ (global input)INTEGER. The column index in the global array A indicating the first column ofsub( A ).DESCAβ (global and local input)INTEGERarray of dimensionDLEN_. The array descriptor for the distributed matrix A.AFβ (local input or local output)REALpointer into the local memory to an array of local dimension(LLD_AF,LOCc(JA+N-1)). IfFACT = 'F', thenAF(IAF:IAF+N-1,JAF:JAF+N-1)is an input argument and on entry contains the factors L and U from the factorizationA(IA:IA+N-1,JA:JA+N-1) = P*L*Uas computed byPSGETRF. IfEQUED .ne. 'N', thenAFis the factored form of the equilibrated matrixA(IA:IA+N-1,JA:JA+N-1).
If FACT = 'N', then AF(IAF:IAF+N-1,JAF:JAF+N-1) is an output argument and on exit returns the factors L and U from the factorization A(IA:IA+N-1,JA:JA+N-1) = P*L*U of the original matrix A(IA:IA+N-1,JA:JA+N-1).
If FACT = 'E', then AF(IAF:IAF+N-1,JAF:JAF+N-1) is an output argument and on exit returns the factors L and U from the factorization A(IA:IA+N-1,JA:JA+N-1) = P*L*U of the equilibrated matrix A(IA:IA+N-1,JA:JA+N-1) (see the description of A(IA:IA+N-1,JA:JA+N-1) for the form of the equilibrated matrix).
IAFβ (global input)INTEGER. The row index in the global array AF indicating the first row ofsub( AF ).JAFβ (global input)INTEGER. The column index in the global array AF indicating the first column ofsub( AF ).DESCAFβ (global and local input)INTEGERarray of dimensionDLEN_. The array descriptor for the distributed matrix AF.IPIVβ (local input or local output)INTEGERarray, dimensionLOCr(M_A)+MB_A. IfFACT = 'F', thenIPIVis an input argument and on entry contains the pivot indices from the factorizationA(IA:IA+N-1,JA:JA+N-1) = P*L*Uas computed byPSGETRF;IPIV(i)-> The global row local row i was swapped with. This array must be aligned withA( IA:IA+N-1, * ).
If FACT = 'N', then IPIV is an output argument and on exit contains the pivot indices from the factorization A(IA:IA+N-1,JA:JA+N-1) = P*L*U of the original matrix A(IA:IA+N-1,JA:JA+N-1).
Okay so IPIV is like: if FACT = 'E', then IPIV is an output argument and on exit contains the pivot indices from the factorization A(IA:IA+N-1,JA:JA+N-1) = P*L*U of the equilibrated matrix A(IA:IA+N-1,JA:JA+N-1). Periodt. π
EQUED(global input or global output) CHARACTER β Specifies the form of equilibration that was done.= 'N': No equilibration (always true ifFACT = 'N').= 'R': Row equilibration, i.e.,A(IA:IA+N-1,JA:JA+N-1)has been premultiplied bydiag(R).= 'C': Column equilibration, i.e.,A(IA:IA+N-1,JA:JA+N-1)has been postmultiplied bydiag(C).= 'B': Both row and column equilibration, i.e.,A(IA:IA+N-1,JA:JA+N-1)has been replaced bydiag(R) * A(IA:IA+N-1,JA:JA+N-1) * diag(C).EQUEDis an input variable ifFACT = 'F'; otherwise, it is an output variable. So if you setFACT = 'F', you're telling it what's up; otherwise it tells you. π
R(local input or local output) REAL array, dimensionLOCr(M_A)β The row scale factors forA(IA:IA+N-1,JA:JA+N-1). IfEQUED = 'R'or'B',A(IA:IA+N-1,JA:JA+N-1)is multiplied on the left bydiag(R); ifEQUED='N'or'C',Ris not accessed.Ris an input variable ifFACT = 'F'; otherwise,Ris an output variable. IfFACT = 'F'andEQUED = 'R'or'B', each element ofRmust be positive.Ris replicated in every process column, and is aligned with the distributed matrixA. πC(local input or local output) REAL array, dimensionLOCc(N_A)β The column scale factors forA(IA:IA+N-1,JA:JA+N-1). IfEQUED = 'C'or'B',A(IA:IA+N-1,JA:JA+N-1)is multiplied on the right bydiag(C); ifEQUED = 'N'or'R',Cis not accessed.Cis an input variable ifFACT = 'F'; otherwise,Cis an output variable. IfFACT = 'F'andEQUED = 'C'orCis replicated in every process row, and is aligned with the distributed matrixA. πB(local input/local output) REAL pointer β into the local memory to an array of local dimension(LLD_B,LOCc(JB+NRHS-1) ). On entry, theN-by-NRHSright-hand side matrixB(IB:IB+N-1,JB:JB+NRHS-1). On exit, ifEQUED = 'N',B(IB:IB+N-1,JB:JB+NRHS-1)is not modified; ifTRANS = 'N'andEQUED = 'R'or'B',Bis overwritten bydiag(R)*B(IB:IB+N-1,JB:JB+NRHS-1); ifTRANS = 'T'or'C'andEQUED = 'C'or'B',B(IB:IB+N-1,JB:JB+NRHS-1)is overwritten bydiag(C)*B(IB:IB+N-1,JB:JB+NRHS-1). The way thatBgets overwritten depending onTRANSandEQUEDis giving main character energy. πIB(global input) INTEGER β The row index in the global arrayBindicating the first row ofsub( B ).JB(global input) INTEGER β The column index in the global arrayBindicating the first column ofsub( B ).DESCB(global and local input) INTEGER array of dimensionDLEN_β The array descriptor for the distributed matrixB.X(local input/local output) REAL pointer β into the local memory to an array of local dimension(LLD_X, LOCc(JX+NRHS-1)). IfINFO = 0, theN-by-NRHSsolution matrixX(IX:IX+N-1,JX:JX+NRHS-1)to the original system of equations. Note thatA(IA:IA+N-1,JA:JA+N-1)andB(IB:IB+N-1,JB:JB+NRHS-1)are modified on exit ifEQUED .ne. 'N', and the solution to the equilibrated system isinv(diag(C))*X(IX:IX+N-1,JX:JX+NRHS-1)ifTRANS = 'N'andEQUED = 'C'or'B', orinv(diag(R))*X(IX:IX+N-1,JX:JX+NRHS-1)ifTRANS = 'T'or'C'andEQUED = 'R'or'B'. π¦IX(global input) INTEGER β The row index in the global arrayXindicating the first row ofsub( X ).JX(global input) INTEGER β The column index in the global arrayXindicating the first column ofsub( X ).DESCX(global and local input) INTEGER array of dimensionDLEN_β The array descriptor for the distributed matrixX.RCOND(global output) REAL β The estimate of the reciprocal condition number of the matrixA(IA:IA+N-1,JA:JA+N-1)after equilibration (if done). IfRCONDis less than the machine precision (in particular, ifRCOND = 0), the matrix is singular to working precision. This condition is indicated by a return code ofINFO > 0. πFERR(local output) REAL array, dimensionLOCc(N_B)β The estimated forward error bounds for each solution vectorX(j)(thej-th column of the solution matrixX(IX:IX+N-1,JX:JX+NRHS-1). IfXTRUEis the true solution,FERR(j)bounds the magnitude of the largest entry in(X(j) - XTRUE)divided by the magnitude of the largest entry inX(j). The estimate is as reliable as the estimate forRCOND, and is almost always a slight overestimate of the true error.FERRis replicated in every process row, and is aligned with the matricesBandX`. πBERR(local output) REAL array, dimensionLOCc(N_B)β The componentwise relative backward error of each solution vectorX(j)(i.e., the smallest relative change in any entry ofA(IA:IA+N-1,JA:JA+N-1)orB(IB:IB+N-1,JB:JB+NRHS-1)that makesX(j)an exact solution).BERRis replicated in every process row, and is aligned with the matricesBandX. πWORK(local workspace/local output) REAL array, dimension(LWORK)β On exit,WORK(1)returns the minimal and optimalLWORK. β¨LWORK(local or global input) INTEGER β The dimension of the arrayWORK.LWORKis local input and must be at leastLWORK = MAX( PSGECON( LWORK ), PSGERFS( LWORK ) ) + LOCr( N_A ).- If
LWORK = -1, thenLWORKis global input and a workspace query is assumed; the routine only calculates the minimum and optimal size for all work arrays. Each of these values is returned in the first entry of the corresponding work array, and no error message is issued byPXERBLA. π
- If
IWORK(local workspace/local output) INTEGER array, dimension(LIWORK)β On exit,IWORK(1)returns the minimal and optimalLIWORK. β¨LIWORK(local or global input) INTEGER β The dimension of the arrayIWORK.LIWORKis local input and must be at leastLIWORK = LOCr(N_A).- If
LIWORK = -1, thenLIWORKis global input and a workspace query is assumed; the routine only calculates the minimum and optimal size for all work arrays. Each of these values is returned in the first entry of the corresponding work array, and no error message is issued byPXERBLA. π
- If
INFO(global output) INTEGER β= 0: successful exit< 0: ifINFO = -i, thei-th argument had an illegal value> 0: ifINFO = i, andiis<= N:U(IA+I-1,IA+I-1)is exactly zero. The factorization has been completed, but the factorUis exactly singular, so the solution and error bounds could not be computed.= N+1:RCONDis less than machine precision. The factorization has been completed, but the matrix is singular to working precision, and the solution and error bounds have not been computed. π
And that's the whole vibe for PSGESVX(l), bestie! This masterpiece is from LAPACK version 1.5, dated 12 May 1997. You absolutely ate this read, periodt. π
β¨
π¦ where this page comes from
- ubuntu jammy: scalapack-doc 1.5-11
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms