You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

spprfs.f 13 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. *> \brief \b SPPRFS
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SPPRFS + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/spprfs.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/spprfs.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/spprfs.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
  22. * BERR, WORK, IWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER UPLO
  26. * INTEGER INFO, LDB, LDX, N, NRHS
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IWORK( * )
  30. * REAL AFP( * ), AP( * ), B( LDB, * ), BERR( * ),
  31. * $ FERR( * ), WORK( * ), X( LDX, * )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> SPPRFS improves the computed solution to a system of linear
  41. *> equations when the coefficient matrix is symmetric positive definite
  42. *> and packed, and provides error bounds and backward error estimates
  43. *> for the solution.
  44. *> \endverbatim
  45. *
  46. * Arguments:
  47. * ==========
  48. *
  49. *> \param[in] UPLO
  50. *> \verbatim
  51. *> UPLO is CHARACTER*1
  52. *> = 'U': Upper triangle of A is stored;
  53. *> = 'L': Lower triangle of A is stored.
  54. *> \endverbatim
  55. *>
  56. *> \param[in] N
  57. *> \verbatim
  58. *> N is INTEGER
  59. *> The order of the matrix A. N >= 0.
  60. *> \endverbatim
  61. *>
  62. *> \param[in] NRHS
  63. *> \verbatim
  64. *> NRHS is INTEGER
  65. *> The number of right hand sides, i.e., the number of columns
  66. *> of the matrices B and X. NRHS >= 0.
  67. *> \endverbatim
  68. *>
  69. *> \param[in] AP
  70. *> \verbatim
  71. *> AP is REAL array, dimension (N*(N+1)/2)
  72. *> The upper or lower triangle of the symmetric matrix A, packed
  73. *> columnwise in a linear array. The j-th column of A is stored
  74. *> in the array AP as follows:
  75. *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
  76. *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
  77. *> \endverbatim
  78. *>
  79. *> \param[in] AFP
  80. *> \verbatim
  81. *> AFP is REAL array, dimension (N*(N+1)/2)
  82. *> The triangular factor U or L from the Cholesky factorization
  83. *> A = U**T*U or A = L*L**T, as computed by SPPTRF/CPPTRF,
  84. *> packed columnwise in a linear array in the same format as A
  85. *> (see AP).
  86. *> \endverbatim
  87. *>
  88. *> \param[in] B
  89. *> \verbatim
  90. *> B is REAL array, dimension (LDB,NRHS)
  91. *> The right hand side matrix B.
  92. *> \endverbatim
  93. *>
  94. *> \param[in] LDB
  95. *> \verbatim
  96. *> LDB is INTEGER
  97. *> The leading dimension of the array B. LDB >= max(1,N).
  98. *> \endverbatim
  99. *>
  100. *> \param[in,out] X
  101. *> \verbatim
  102. *> X is REAL array, dimension (LDX,NRHS)
  103. *> On entry, the solution matrix X, as computed by SPPTRS.
  104. *> On exit, the improved solution matrix X.
  105. *> \endverbatim
  106. *>
  107. *> \param[in] LDX
  108. *> \verbatim
  109. *> LDX is INTEGER
  110. *> The leading dimension of the array X. LDX >= max(1,N).
  111. *> \endverbatim
  112. *>
  113. *> \param[out] FERR
  114. *> \verbatim
  115. *> FERR is REAL array, dimension (NRHS)
  116. *> The estimated forward error bound for each solution vector
  117. *> X(j) (the j-th column of the solution matrix X).
  118. *> If XTRUE is the true solution corresponding to X(j), FERR(j)
  119. *> is an estimated upper bound for the magnitude of the largest
  120. *> element in (X(j) - XTRUE) divided by the magnitude of the
  121. *> largest element in X(j). The estimate is as reliable as
  122. *> the estimate for RCOND, and is almost always a slight
  123. *> overestimate of the true error.
  124. *> \endverbatim
  125. *>
  126. *> \param[out] BERR
  127. *> \verbatim
  128. *> BERR is REAL array, dimension (NRHS)
  129. *> The componentwise relative backward error of each solution
  130. *> vector X(j) (i.e., the smallest relative change in
  131. *> any element of A or B that makes X(j) an exact solution).
  132. *> \endverbatim
  133. *>
  134. *> \param[out] WORK
  135. *> \verbatim
  136. *> WORK is REAL array, dimension (3*N)
  137. *> \endverbatim
  138. *>
  139. *> \param[out] IWORK
  140. *> \verbatim
  141. *> IWORK is INTEGER array, dimension (N)
  142. *> \endverbatim
  143. *>
  144. *> \param[out] INFO
  145. *> \verbatim
  146. *> INFO is INTEGER
  147. *> = 0: successful exit
  148. *> < 0: if INFO = -i, the i-th argument had an illegal value
  149. *> \endverbatim
  150. *
  151. *> \par Internal Parameters:
  152. * =========================
  153. *>
  154. *> \verbatim
  155. *> ITMAX is the maximum number of steps of iterative refinement.
  156. *> \endverbatim
  157. *
  158. * Authors:
  159. * ========
  160. *
  161. *> \author Univ. of Tennessee
  162. *> \author Univ. of California Berkeley
  163. *> \author Univ. of Colorado Denver
  164. *> \author NAG Ltd.
  165. *
  166. *> \ingroup realOTHERcomputational
  167. *
  168. * =====================================================================
  169. SUBROUTINE SPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
  170. $ BERR, WORK, IWORK, INFO )
  171. *
  172. * -- LAPACK computational routine --
  173. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  174. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  175. *
  176. * .. Scalar Arguments ..
  177. CHARACTER UPLO
  178. INTEGER INFO, LDB, LDX, N, NRHS
  179. * ..
  180. * .. Array Arguments ..
  181. INTEGER IWORK( * )
  182. REAL AFP( * ), AP( * ), B( LDB, * ), BERR( * ),
  183. $ FERR( * ), WORK( * ), X( LDX, * )
  184. * ..
  185. *
  186. * =====================================================================
  187. *
  188. * .. Parameters ..
  189. INTEGER ITMAX
  190. PARAMETER ( ITMAX = 5 )
  191. REAL ZERO
  192. PARAMETER ( ZERO = 0.0E+0 )
  193. REAL ONE
  194. PARAMETER ( ONE = 1.0E+0 )
  195. REAL TWO
  196. PARAMETER ( TWO = 2.0E+0 )
  197. REAL THREE
  198. PARAMETER ( THREE = 3.0E+0 )
  199. * ..
  200. * .. Local Scalars ..
  201. LOGICAL UPPER
  202. INTEGER COUNT, I, IK, J, K, KASE, KK, NZ
  203. REAL EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
  204. * ..
  205. * .. Local Arrays ..
  206. INTEGER ISAVE( 3 )
  207. * ..
  208. * .. External Subroutines ..
  209. EXTERNAL SAXPY, SCOPY, SLACN2, SPPTRS, SSPMV, XERBLA
  210. * ..
  211. * .. Intrinsic Functions ..
  212. INTRINSIC ABS, MAX
  213. * ..
  214. * .. External Functions ..
  215. LOGICAL LSAME
  216. REAL SLAMCH
  217. EXTERNAL LSAME, SLAMCH
  218. * ..
  219. * .. Executable Statements ..
  220. *
  221. * Test the input parameters.
  222. *
  223. INFO = 0
  224. UPPER = LSAME( UPLO, 'U' )
  225. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  226. INFO = -1
  227. ELSE IF( N.LT.0 ) THEN
  228. INFO = -2
  229. ELSE IF( NRHS.LT.0 ) THEN
  230. INFO = -3
  231. ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  232. INFO = -7
  233. ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
  234. INFO = -9
  235. END IF
  236. IF( INFO.NE.0 ) THEN
  237. CALL XERBLA( 'SPPRFS', -INFO )
  238. RETURN
  239. END IF
  240. *
  241. * Quick return if possible
  242. *
  243. IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
  244. DO 10 J = 1, NRHS
  245. FERR( J ) = ZERO
  246. BERR( J ) = ZERO
  247. 10 CONTINUE
  248. RETURN
  249. END IF
  250. *
  251. * NZ = maximum number of nonzero elements in each row of A, plus 1
  252. *
  253. NZ = N + 1
  254. EPS = SLAMCH( 'Epsilon' )
  255. SAFMIN = SLAMCH( 'Safe minimum' )
  256. SAFE1 = NZ*SAFMIN
  257. SAFE2 = SAFE1 / EPS
  258. *
  259. * Do for each right hand side
  260. *
  261. DO 140 J = 1, NRHS
  262. *
  263. COUNT = 1
  264. LSTRES = THREE
  265. 20 CONTINUE
  266. *
  267. * Loop until stopping criterion is satisfied.
  268. *
  269. * Compute residual R = B - A * X
  270. *
  271. CALL SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
  272. CALL SSPMV( UPLO, N, -ONE, AP, X( 1, J ), 1, ONE, WORK( N+1 ),
  273. $ 1 )
  274. *
  275. * Compute componentwise relative backward error from formula
  276. *
  277. * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
  278. *
  279. * where abs(Z) is the componentwise absolute value of the matrix
  280. * or vector Z. If the i-th component of the denominator is less
  281. * than SAFE2, then SAFE1 is added to the i-th components of the
  282. * numerator and denominator before dividing.
  283. *
  284. DO 30 I = 1, N
  285. WORK( I ) = ABS( B( I, J ) )
  286. 30 CONTINUE
  287. *
  288. * Compute abs(A)*abs(X) + abs(B).
  289. *
  290. KK = 1
  291. IF( UPPER ) THEN
  292. DO 50 K = 1, N
  293. S = ZERO
  294. XK = ABS( X( K, J ) )
  295. IK = KK
  296. DO 40 I = 1, K - 1
  297. WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK
  298. S = S + ABS( AP( IK ) )*ABS( X( I, J ) )
  299. IK = IK + 1
  300. 40 CONTINUE
  301. WORK( K ) = WORK( K ) + ABS( AP( KK+K-1 ) )*XK + S
  302. KK = KK + K
  303. 50 CONTINUE
  304. ELSE
  305. DO 70 K = 1, N
  306. S = ZERO
  307. XK = ABS( X( K, J ) )
  308. WORK( K ) = WORK( K ) + ABS( AP( KK ) )*XK
  309. IK = KK + 1
  310. DO 60 I = K + 1, N
  311. WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK
  312. S = S + ABS( AP( IK ) )*ABS( X( I, J ) )
  313. IK = IK + 1
  314. 60 CONTINUE
  315. WORK( K ) = WORK( K ) + S
  316. KK = KK + ( N-K+1 )
  317. 70 CONTINUE
  318. END IF
  319. S = ZERO
  320. DO 80 I = 1, N
  321. IF( WORK( I ).GT.SAFE2 ) THEN
  322. S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
  323. ELSE
  324. S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
  325. $ ( WORK( I )+SAFE1 ) )
  326. END IF
  327. 80 CONTINUE
  328. BERR( J ) = S
  329. *
  330. * Test stopping criterion. Continue iterating if
  331. * 1) The residual BERR(J) is larger than machine epsilon, and
  332. * 2) BERR(J) decreased by at least a factor of 2 during the
  333. * last iteration, and
  334. * 3) At most ITMAX iterations tried.
  335. *
  336. IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
  337. $ COUNT.LE.ITMAX ) THEN
  338. *
  339. * Update solution and try again.
  340. *
  341. CALL SPPTRS( UPLO, N, 1, AFP, WORK( N+1 ), N, INFO )
  342. CALL SAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
  343. LSTRES = BERR( J )
  344. COUNT = COUNT + 1
  345. GO TO 20
  346. END IF
  347. *
  348. * Bound error from formula
  349. *
  350. * norm(X - XTRUE) / norm(X) .le. FERR =
  351. * norm( abs(inv(A))*
  352. * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
  353. *
  354. * where
  355. * norm(Z) is the magnitude of the largest component of Z
  356. * inv(A) is the inverse of A
  357. * abs(Z) is the componentwise absolute value of the matrix or
  358. * vector Z
  359. * NZ is the maximum number of nonzeros in any row of A, plus 1
  360. * EPS is machine epsilon
  361. *
  362. * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
  363. * is incremented by SAFE1 if the i-th component of
  364. * abs(A)*abs(X) + abs(B) is less than SAFE2.
  365. *
  366. * Use SLACN2 to estimate the infinity-norm of the matrix
  367. * inv(A) * diag(W),
  368. * where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
  369. *
  370. DO 90 I = 1, N
  371. IF( WORK( I ).GT.SAFE2 ) THEN
  372. WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
  373. ELSE
  374. WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
  375. END IF
  376. 90 CONTINUE
  377. *
  378. KASE = 0
  379. 100 CONTINUE
  380. CALL SLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
  381. $ KASE, ISAVE )
  382. IF( KASE.NE.0 ) THEN
  383. IF( KASE.EQ.1 ) THEN
  384. *
  385. * Multiply by diag(W)*inv(A**T).
  386. *
  387. CALL SPPTRS( UPLO, N, 1, AFP, WORK( N+1 ), N, INFO )
  388. DO 110 I = 1, N
  389. WORK( N+I ) = WORK( I )*WORK( N+I )
  390. 110 CONTINUE
  391. ELSE IF( KASE.EQ.2 ) THEN
  392. *
  393. * Multiply by inv(A)*diag(W).
  394. *
  395. DO 120 I = 1, N
  396. WORK( N+I ) = WORK( I )*WORK( N+I )
  397. 120 CONTINUE
  398. CALL SPPTRS( UPLO, N, 1, AFP, WORK( N+1 ), N, INFO )
  399. END IF
  400. GO TO 100
  401. END IF
  402. *
  403. * Normalize error.
  404. *
  405. LSTRES = ZERO
  406. DO 130 I = 1, N
  407. LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
  408. 130 CONTINUE
  409. IF( LSTRES.NE.ZERO )
  410. $ FERR( J ) = FERR( J ) / LSTRES
  411. *
  412. 140 CONTINUE
  413. *
  414. RETURN
  415. *
  416. * End of SPPRFS
  417. *
  418. END