00001 SUBROUTINE SPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X,
00002 $ LDX, FERR, BERR, WORK, IWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 CHARACTER UPLO
00013 INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS
00014
00015
00016 INTEGER IWORK( * )
00017 REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
00018 $ BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 INTEGER ITMAX
00107 PARAMETER ( ITMAX = 5 )
00108 REAL ZERO
00109 PARAMETER ( ZERO = 0.0E+0 )
00110 REAL ONE
00111 PARAMETER ( ONE = 1.0E+0 )
00112 REAL TWO
00113 PARAMETER ( TWO = 2.0E+0 )
00114 REAL THREE
00115 PARAMETER ( THREE = 3.0E+0 )
00116
00117
00118 LOGICAL UPPER
00119 INTEGER COUNT, I, J, K, KASE, NZ
00120 REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
00121
00122
00123 INTEGER ISAVE( 3 )
00124
00125
00126 EXTERNAL SAXPY, SCOPY, SLACN2, SPOTRS, SSYMV, XERBLA
00127
00128
00129 INTRINSIC ABS, MAX
00130
00131
00132 LOGICAL LSAME
00133 REAL SLAMCH
00134 EXTERNAL LSAME, SLAMCH
00135
00136
00137
00138
00139
00140 INFO = 0
00141 UPPER = LSAME( UPLO, 'U' )
00142 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00143 INFO = -1
00144 ELSE IF( N.LT.0 ) THEN
00145 INFO = -2
00146 ELSE IF( NRHS.LT.0 ) THEN
00147 INFO = -3
00148 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00149 INFO = -5
00150 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
00151 INFO = -7
00152 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00153 INFO = -9
00154 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00155 INFO = -11
00156 END IF
00157 IF( INFO.NE.0 ) THEN
00158 CALL XERBLA( 'SPORFS', -INFO )
00159 RETURN
00160 END IF
00161
00162
00163
00164 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00165 DO 10 J = 1, NRHS
00166 FERR( J ) = ZERO
00167 BERR( J ) = ZERO
00168 10 CONTINUE
00169 RETURN
00170 END IF
00171
00172
00173
00174 NZ = N + 1
00175 EPS = SLAMCH( 'Epsilon' )
00176 SAFMIN = SLAMCH( 'Safe minimum' )
00177 SAFE1 = NZ*SAFMIN
00178 SAFE2 = SAFE1 / EPS
00179
00180
00181
00182 DO 140 J = 1, NRHS
00183
00184 COUNT = 1
00185 LSTRES = THREE
00186 20 CONTINUE
00187
00188
00189
00190
00191
00192 CALL SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
00193 CALL SSYMV( UPLO, N, -ONE, A, LDA, X( 1, J ), 1, ONE,
00194 $ WORK( N+1 ), 1 )
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 DO 30 I = 1, N
00206 WORK( I ) = ABS( B( I, J ) )
00207 30 CONTINUE
00208
00209
00210
00211 IF( UPPER ) THEN
00212 DO 50 K = 1, N
00213 S = ZERO
00214 XK = ABS( X( K, J ) )
00215 DO 40 I = 1, K - 1
00216 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
00217 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
00218 40 CONTINUE
00219 WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK + S
00220 50 CONTINUE
00221 ELSE
00222 DO 70 K = 1, N
00223 S = ZERO
00224 XK = ABS( X( K, J ) )
00225 WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK
00226 DO 60 I = K + 1, N
00227 WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
00228 S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
00229 60 CONTINUE
00230 WORK( K ) = WORK( K ) + S
00231 70 CONTINUE
00232 END IF
00233 S = ZERO
00234 DO 80 I = 1, N
00235 IF( WORK( I ).GT.SAFE2 ) THEN
00236 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
00237 ELSE
00238 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
00239 $ ( WORK( I )+SAFE1 ) )
00240 END IF
00241 80 CONTINUE
00242 BERR( J ) = S
00243
00244
00245
00246
00247
00248
00249
00250 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00251 $ COUNT.LE.ITMAX ) THEN
00252
00253
00254
00255 CALL SPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
00256 CALL SAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
00257 LSTRES = BERR( J )
00258 COUNT = COUNT + 1
00259 GO TO 20
00260 END IF
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 DO 90 I = 1, N
00285 IF( WORK( I ).GT.SAFE2 ) THEN
00286 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
00287 ELSE
00288 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
00289 END IF
00290 90 CONTINUE
00291
00292 KASE = 0
00293 100 CONTINUE
00294 CALL SLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
00295 $ KASE, ISAVE )
00296 IF( KASE.NE.0 ) THEN
00297 IF( KASE.EQ.1 ) THEN
00298
00299
00300
00301 CALL SPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
00302 DO 110 I = 1, N
00303 WORK( N+I ) = WORK( I )*WORK( N+I )
00304 110 CONTINUE
00305 ELSE IF( KASE.EQ.2 ) THEN
00306
00307
00308
00309 DO 120 I = 1, N
00310 WORK( N+I ) = WORK( I )*WORK( N+I )
00311 120 CONTINUE
00312 CALL SPOTRS( UPLO, N, 1, AF, LDAF, WORK( N+1 ), N, INFO )
00313 END IF
00314 GO TO 100
00315 END IF
00316
00317
00318
00319 LSTRES = ZERO
00320 DO 130 I = 1, N
00321 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
00322 130 CONTINUE
00323 IF( LSTRES.NE.ZERO )
00324 $ FERR( J ) = FERR( J ) / LSTRES
00325
00326 140 CONTINUE
00327
00328 RETURN
00329
00330
00331
00332 END