001:SUBROUTINEDGESVX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, 002: $ EQUED, R, C, B, LDB, X, LDX, RCOND, FERR, BERR, 003: $ WORK, IWORK, INFO ) 004:*005:* -- LAPACK driver routine (version 3.2) --006:* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..007:* November 2006008:*009:* .. Scalar Arguments ..010: CHARACTER EQUED, FACT, TRANS 011: INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS 012: DOUBLE PRECISION RCOND 013:* ..014:* .. Array Arguments ..015: INTEGERIPIV( * ),IWORK( * ) 016: DOUBLE PRECISIONA( LDA, * ),AF( LDAF, * ),B( LDB, * ), 017: $BERR( * ),C( * ),FERR( * ),R( * ), 018: $WORK( * ),X( LDX, * ) 019:* ..020:*021:* Purpose022:* =======023:*024:* DGESVX uses the LU factorization to compute the solution to a real025:* system of linear equations026:* A * X = B,027:* where A is an N-by-N matrix and X and B are N-by-NRHS matrices.028:*029:* Error bounds on the solution and a condition estimate are also030:* provided.031:*032:* Description033:* ===========034:*035:* The following steps are performed:036:*037:* 1. If FACT = 'E', real scaling factors are computed to equilibrate038:* the system:039:* TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B040:* TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B041:* TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B042:* Whether or not the system will be equilibrated depends on the043:* scaling of the matrix A, but if equilibration is used, A is044:* overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N')045:* or diag(C)*B (if TRANS = 'T' or 'C').046:*047:* 2. If FACT = 'N' or 'E', the LU decomposition is used to factor the048:* matrix A (after equilibration if FACT = 'E') as049:* A = P * L * U,050:* where P is a permutation matrix, L is a unit lower triangular051:* matrix, and U is upper triangular.052:*053:* 3. If some U(i,i)=0, so that U is exactly singular, then the routine054:* returns with INFO = i. Otherwise, the factored form of A is used055:* to estimate the condition number of the matrix A. If the056:* reciprocal of the condition number is less than machine precision,057:* INFO = N+1 is returned as a warning, but the routine still goes on058:* to solve for X and compute error bounds as described below.059:*060:* 4. The system of equations is solved for X using the factored form061:* of A.062:*063:* 5. Iterative refinement is applied to improve the computed solution064:* matrix and calculate error bounds and backward error estimates065:* for it.066:*067:* 6. If equilibration was used, the matrix X is premultiplied by068:* diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so069:* that it solves the original system before equilibration.070:*071:* Arguments072:* =========073:*074:* FACT (input) CHARACTER*1075:* Specifies whether or not the factored form of the matrix A is076:* supplied on entry, and if not, whether the matrix A should be077:* equilibrated before it is factored.078:* = 'F': On entry, AF and IPIV contain the factored form of A.079:* If EQUED is not 'N', the matrix A has been080:* equilibrated with scaling factors given by R and C.081:* A, AF, and IPIV are not modified.082:* = 'N': The matrix A will be copied to AF and factored.083:* = 'E': The matrix A will be equilibrated if necessary, then084:* copied to AF and factored.085:*086:* TRANS (input) CHARACTER*1087:* Specifies the form of the system of equations:088:* = 'N': A * X = B (No transpose)089:* = 'T': A**T * X = B (Transpose)090:* = 'C': A**H * X = B (Transpose)091:*092:* N (input) INTEGER093:* The number of linear equations, i.e., the order of the094:* matrix A. N >= 0.095:*096:* NRHS (input) INTEGER097:* The number of right hand sides, i.e., the number of columns098:* of the matrices B and X. NRHS >= 0.099:*100:* A (input/output) DOUBLE PRECISION array, dimension (LDA,N)101:* On entry, the N-by-N matrix A. If FACT = 'F' and EQUED is102:* not 'N', then A must have been equilibrated by the scaling103:* factors in R and/or C. A is not modified if FACT = 'F' or104:* 'N', or if FACT = 'E' and EQUED = 'N' on exit.105:*106:* On exit, if EQUED .ne. 'N', A is scaled as follows:107:* EQUED = 'R': A := diag(R) * A108:* EQUED = 'C': A := A * diag(C)109:* EQUED = 'B': A := diag(R) * A * diag(C).110:*111:* LDA (input) INTEGER112:* The leading dimension of the array A. LDA >= max(1,N).113:*114:* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N)115:* If FACT = 'F', then AF is an input argument and on entry116:* contains the factors L and U from the factorization117:* A = P*L*U as computed by DGETRF. If EQUED .ne. 'N', then118:* AF is the factored form of the equilibrated matrix A.119:*120:* If FACT = 'N', then AF is an output argument and on exit121:* returns the factors L and U from the factorization A = P*L*U122:* of the original matrix A.123:*124:* If FACT = 'E', then AF is an output argument and on exit125:* returns the factors L and U from the factorization A = P*L*U126:* of the equilibrated matrix A (see the description of A for127:* the form of the equilibrated matrix).128:*129:* LDAF (input) INTEGER130:* The leading dimension of the array AF. LDAF >= max(1,N).131:*132:* IPIV (input or output) INTEGER array, dimension (N)133:* If FACT = 'F', then IPIV is an input argument and on entry134:* contains the pivot indices from the factorization A = P*L*U135:* as computed by DGETRF; row i of the matrix was interchanged136:* with row IPIV(i).137:*138:* If FACT = 'N', then IPIV is an output argument and on exit139:* contains the pivot indices from the factorization A = P*L*U140:* of the original matrix A.141:*142:* If FACT = 'E', then IPIV is an output argument and on exit143:* contains the pivot indices from the factorization A = P*L*U144:* of the equilibrated matrix A.145:*146:* EQUED (input or output) CHARACTER*1147:* Specifies the form of equilibration that was done.148:* = 'N': No equilibration (always true if FACT = 'N').149:* = 'R': Row equilibration, i.e., A has been premultiplied by150:* diag(R).151:* = 'C': Column equilibration, i.e., A has been postmultiplied152:* by diag(C).153:* = 'B': Both row and column equilibration, i.e., A has been154:* replaced by diag(R) * A * diag(C).155:* EQUED is an input argument if FACT = 'F'; otherwise, it is an156:* output argument.157:*158:* R (input or output) DOUBLE PRECISION array, dimension (N)159:* The row scale factors for A. If EQUED = 'R' or 'B', A is160:* multiplied on the left by diag(R); if EQUED = 'N' or 'C', R161:* is not accessed. R is an input argument if FACT = 'F';162:* otherwise, R is an output argument. If FACT = 'F' and163:* EQUED = 'R' or 'B', each element of R must be positive.164:*165:* C (input or output) DOUBLE PRECISION array, dimension (N)166:* The column scale factors for A. If EQUED = 'C' or 'B', A is167:* multiplied on the right by diag(C); if EQUED = 'N' or 'R', C168:* is not accessed. C is an input argument if FACT = 'F';169:* otherwise, C is an output argument. If FACT = 'F' and170:* EQUED = 'C' or 'B', each element of C must be positive.171:*172:* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)173:* On entry, the N-by-NRHS right hand side matrix B.174:* On exit,175:* if EQUED = 'N', B is not modified;176:* if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by177:* diag(R)*B;178:* if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is179:* overwritten by diag(C)*B.180:*181:* LDB (input) INTEGER182:* The leading dimension of the array B. LDB >= max(1,N).183:*184:* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS)185:* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X186:* to the original system of equations. Note that A and B are187:* modified on exit if EQUED .ne. 'N', and the solution to the188:* equilibrated system is inv(diag(C))*X if TRANS = 'N' and189:* EQUED = 'C' or 'B', or inv(diag(R))*X if TRANS = 'T' or 'C'190:* and EQUED = 'R' or 'B'.191:*192:* LDX (input) INTEGER193:* The leading dimension of the array X. LDX >= max(1,N).194:*195:* RCOND (output) DOUBLE PRECISION196:* The estimate of the reciprocal condition number of the matrix197:* A after equilibration (if done). If RCOND is less than the198:* machine precision (in particular, if RCOND = 0), the matrix199:* is singular to working precision. This condition is200:* indicated by a return code of INFO > 0.201:*202:* FERR (output) DOUBLE PRECISION array, dimension (NRHS)203:* The estimated forward error bound for each solution vector204:* X(j) (the j-th column of the solution matrix X).205:* If XTRUE is the true solution corresponding to X(j), FERR(j)206:* is an estimated upper bound for the magnitude of the largest207:* element in (X(j) - XTRUE) divided by the magnitude of the208:* largest element in X(j). The estimate is as reliable as209:* the estimate for RCOND, and is almost always a slight210:* overestimate of the true error.211:*212:* BERR (output) DOUBLE PRECISION array, dimension (NRHS)213:* The componentwise relative backward error of each solution214:* vector X(j) (i.e., the smallest relative change in215:* any element of A or B that makes X(j) an exact solution).216:*217:* WORK (workspace/output) DOUBLE PRECISION array, dimension (4*N)218:* On exit, WORK(1) contains the reciprocal pivot growth219:* factor norm(A)/norm(U). The "max absolute element" norm is220:* used. If WORK(1) is much less than 1, then the stability221:* of the LU factorization of the (equilibrated) matrix A222:* could be poor. This also means that the solution X, condition223:* estimator RCOND, and forward error bound FERR could be224:* unreliable. If factorization fails with 0<INFO<=N, then225:* WORK(1) contains the reciprocal pivot growth factor for the226:* leading INFO columns of A.227:*228:* IWORK (workspace) INTEGER array, dimension (N)229:*230:* INFO (output) INTEGER231:* = 0: successful exit232:* < 0: if INFO = -i, the i-th argument had an illegal value233:* > 0: if INFO = i, and i is234:* <= N: U(i,i) is exactly zero. The factorization has235:* been completed, but the factor U is exactly236:* singular, so the solution and error bounds237:* could not be computed. RCOND = 0 is returned.238:* = N+1: U is nonsingular, but RCOND is less than machine239:* precision, meaning that the matrix is singular240:* to working precision. Nevertheless, the241:* solution and error bounds are computed because242:* there are a number of situations where the243:* computed solution can be more accurate than the244:* value of RCOND would suggest.245:*246:* =====================================================================247:*248:* .. Parameters ..249: DOUBLE PRECISION ZERO, ONE 250:PARAMETER( ZERO = 0.0D+0, ONE = 1.0D+0 ) 251:* ..252:* .. Local Scalars ..253:LOGICALCOLEQU, EQUIL, NOFACT, NOTRAN, ROWEQU 254: CHARACTER NORM 255: INTEGER I, INFEQU, J 256: DOUBLE PRECISION AMAX, ANORM, BIGNUM, COLCND, RCMAX, RCMIN, 257: $ ROWCND, RPVGRW, SMLNUM 258:* ..259:* .. External Functions ..260:LOGICALLSAME 261: DOUBLE PRECISION DLAMCH, DLANGE, DLANTR 262:EXTERNALLSAME, DLAMCH, DLANGE, DLANTR 263:* ..264:* .. External Subroutines ..265:EXTERNALDGECON, DGEEQU, DGERFS, DGETRF, DGETRS, DLACPY, 266: $ DLAQGE, XERBLA 267:* ..268:* .. Intrinsic Functions ..269:INTRINSICMAX, MIN 270:* ..271:* .. Executable Statements ..272:*273: INFO = 0 274: NOFACT =LSAME( FACT, 'N' ) 275: EQUIL =LSAME( FACT, 'E' ) 276: NOTRAN =LSAME( TRANS, 'N' ) 277:IF( NOFACT .OR. EQUIL )THEN278: EQUED = 'N' 279: ROWEQU = .FALSE. 280: COLEQU = .FALSE. 281:ELSE282: ROWEQU =LSAME( EQUED, 'R' ) .OR.LSAME( EQUED, 'B' ) 283: COLEQU =LSAME( EQUED, 'C' ) .OR.LSAME( EQUED, 'B' ) 284: SMLNUM =DLAMCH( 'Safe minimum' ) 285: BIGNUM = ONE / SMLNUM 286:ENDIF287:*288:* Test the input parameters.289:*290:IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) ) 291: $THEN292: INFO = -1 293:ELSEIF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. 294: $LSAME( TRANS, 'C' ) )THEN295: INFO = -2 296:ELSEIF( N.LT.0 )THEN297: INFO = -3 298:ELSEIF( NRHS.LT.0 )THEN299: INFO = -4 300:ELSEIF( LDA.LT.MAX( 1, N ) )THEN301: INFO = -6 302:ELSEIF( LDAF.LT.MAX( 1, N ) )THEN303: INFO = -8 304:ELSEIF(LSAME( FACT, 'F' ) .AND. .NOT. 305: $ ( ROWEQU .OR. COLEQU .OR.LSAME( EQUED, 'N' ) ) )THEN306: INFO = -10 307:ELSE308:IF( ROWEQU )THEN309: RCMIN = BIGNUM 310: RCMAX = ZERO 311:DO10 J = 1, N 312: RCMIN =MIN( RCMIN,R( J ) ) 313: RCMAX =MAX( RCMAX,R( J ) ) 314: 10CONTINUE315:IF( RCMIN.LE.ZERO )THEN316: INFO = -11 317:ELSEIF( N.GT.0 )THEN318: ROWCND =MAX( RCMIN, SMLNUM ) /MIN( RCMAX, BIGNUM ) 319:ELSE320: ROWCND = ONE 321:ENDIF322:ENDIF323:IF( COLEQU .AND. INFO.EQ.0 )THEN324: RCMIN = BIGNUM 325: RCMAX = ZERO 326:DO20 J = 1, N 327: RCMIN =MIN( RCMIN,C( J ) ) 328: RCMAX =MAX( RCMAX,C( J ) ) 329: 20CONTINUE330:IF( RCMIN.LE.ZERO )THEN331: INFO = -12 332:ELSEIF( N.GT.0 )THEN333: COLCND =MAX( RCMIN, SMLNUM ) /MIN( RCMAX, BIGNUM ) 334:ELSE335: COLCND = ONE 336:ENDIF337:ENDIF338:IF( INFO.EQ.0 )THEN339:IF( LDB.LT.MAX( 1, N ) )THEN340: INFO = -14 341:ELSEIF( LDX.LT.MAX( 1, N ) )THEN342: INFO = -16 343:ENDIF344:ENDIF345:ENDIF346:*347:IF( INFO.NE.0 )THEN348:CALLXERBLA( 'DGESVX', -INFO ) 349:RETURN350:ENDIF351:*352:IF( EQUIL )THEN353:*354:* Compute row and column scalings to equilibrate the matrix A.355:*356:CALLDGEEQU( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, INFEQU ) 357:IF( INFEQU.EQ.0 )THEN358:*359:* Equilibrate the matrix.360:*361:CALLDLAQGE( N, N, A, LDA, R, C, ROWCND, COLCND, AMAX, 362: $ EQUED ) 363: ROWEQU =LSAME( EQUED, 'R' ) .OR.LSAME( EQUED, 'B' ) 364: COLEQU =LSAME( EQUED, 'C' ) .OR.LSAME( EQUED, 'B' ) 365:ENDIF366:ENDIF367:*368:* Scale the right hand side.369:*370:IF( NOTRAN )THEN371:IF( ROWEQU )THEN372:DO40 J = 1, NRHS 373:DO30 I = 1, N 374:B( I, J ) =R( I )*B( I, J ) 375: 30CONTINUE376: 40CONTINUE377:ENDIF378:ELSEIF( COLEQU )THEN379:DO60 J = 1, NRHS 380:DO50 I = 1, N 381:B( I, J ) =C( I )*B( I, J ) 382: 50CONTINUE383: 60CONTINUE384:ENDIF385:*386:IF( NOFACT .OR. EQUIL )THEN387:*388:* Compute the LU factorization of A.389:*390:CALLDLACPY( 'Full', N, N, A, LDA, AF, LDAF ) 391:CALLDGETRF( N, N, AF, LDAF, IPIV, INFO ) 392:*393:* Return if INFO is non-zero.394:*395:IF( INFO.GT.0 )THEN396:*397:* Compute the reciprocal pivot growth factor of the398:* leading rank-deficient INFO columns of A.399:*400: RPVGRW =DLANTR( 'M', 'U', 'N', INFO, INFO, AF, LDAF, 401: $ WORK ) 402:IF( RPVGRW.EQ.ZERO )THEN403: RPVGRW = ONE 404:ELSE405: RPVGRW =DLANGE( 'M', N, INFO, A, LDA, WORK ) / RPVGRW 406:ENDIF407:WORK( 1 ) = RPVGRW 408: RCOND = ZERO 409:RETURN410:ENDIF411:ENDIF412:*413:* Compute the norm of the matrix A and the414:* reciprocal pivot growth factor RPVGRW.415:*416:IF( NOTRAN )THEN417: NORM = '1' 418:ELSE419: NORM = 'I' 420:ENDIF421: ANORM =DLANGE( NORM, N, N, A, LDA, WORK ) 422: RPVGRW =DLANTR( 'M', 'U', 'N', N, N, AF, LDAF, WORK ) 423:IF( RPVGRW.EQ.ZERO )THEN424: RPVGRW = ONE 425:ELSE426: RPVGRW =DLANGE( 'M', N, N, A, LDA, WORK ) / RPVGRW 427:ENDIF428:*429:* Compute the reciprocal of the condition number of A.430:*431:CALLDGECON( NORM, N, AF, LDAF, ANORM, RCOND, WORK, IWORK, INFO ) 432:*433:* Compute the solution matrix X.434:*435:CALLDLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) 436:CALLDGETRS( TRANS, N, NRHS, AF, LDAF, IPIV, X, LDX, INFO ) 437:*438:* Use iterative refinement to improve the computed solution and439:* compute error bounds and backward error estimates for it.440:*441:CALLDGERFS( TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB, X, 442: $ LDX, FERR, BERR, WORK, IWORK, INFO ) 443:*444:* Transform the solution matrix X to a solution of the original445:* system.446:*447:IF( NOTRAN )THEN448:IF( COLEQU )THEN449:DO80 J = 1, NRHS 450:DO70 I = 1, N 451:X( I, J ) =C( I )*X( I, J ) 452: 70CONTINUE453: 80CONTINUE454:DO90 J = 1, NRHS 455:FERR( J ) =FERR( J ) / COLCND 456: 90CONTINUE457:ENDIF458:ELSEIF( ROWEQU )THEN459:DO110 J = 1, NRHS 460:DO100 I = 1, N 461:X( I, J ) =R( I )*X( I, J ) 462: 100CONTINUE463: 110CONTINUE464:DO120 J = 1, NRHS 465:FERR( J ) =FERR( J ) / ROWCND 466: 120CONTINUE467:ENDIF468:*469:WORK( 1 ) = RPVGRW 470:*471:* Set INFO = N+1 if the matrix is singular to working precision.472:*473:IF( RCOND.LT.DLAMCH( 'Epsilon' ) ) 474: $ INFO = N + 1 475:RETURN476:*477:* End of DGESVX478:*479:END480: