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