LAPACK  3.5.0
LAPACK: Linear Algebra PACKage
 All Classes Files Functions Variables Typedefs Macros
dsposv.f
Go to the documentation of this file.
1 *> \brief <b> DSPOSV computes the solution to system of linear equations A * X = B for PO matrices</b>
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download DSPOSV + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsposv.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsposv.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsposv.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE DSPOSV( UPLO, N, NRHS, A, LDA, B, LDB, X, LDX, WORK,
22 * SWORK, ITER, INFO )
23 *
24 * .. Scalar Arguments ..
25 * CHARACTER UPLO
26 * INTEGER INFO, ITER, LDA, LDB, LDX, N, NRHS
27 * ..
28 * .. Array Arguments ..
29 * REAL SWORK( * )
30 * DOUBLE PRECISION A( LDA, * ), B( LDB, * ), WORK( N, * ),
31 * $ X( LDX, * )
32 * ..
33 *
34 *
35 *> \par Purpose:
36 * =============
37 *>
38 *> \verbatim
39 *>
40 *> DSPOSV computes the solution to a real system of linear equations
41 *> A * X = B,
42 *> where A is an N-by-N symmetric positive definite matrix and X and B
43 *> are N-by-NRHS matrices.
44 *>
45 *> DSPOSV first attempts to factorize the matrix in SINGLE PRECISION
46 *> and use this factorization within an iterative refinement procedure
47 *> to produce a solution with DOUBLE PRECISION normwise backward error
48 *> quality (see below). If the approach fails the method switches to a
49 *> DOUBLE PRECISION factorization and solve.
50 *>
51 *> The iterative refinement is not going to be a winning strategy if
52 *> the ratio SINGLE PRECISION performance over DOUBLE PRECISION
53 *> performance is too small. A reasonable strategy should take the
54 *> number of right-hand sides and the size of the matrix into account.
55 *> This might be done with a call to ILAENV in the future. Up to now, we
56 *> always try iterative refinement.
57 *>
58 *> The iterative refinement process is stopped if
59 *> ITER > ITERMAX
60 *> or for all the RHS we have:
61 *> RNRM < SQRT(N)*XNRM*ANRM*EPS*BWDMAX
62 *> where
63 *> o ITER is the number of the current iteration in the iterative
64 *> refinement process
65 *> o RNRM is the infinity-norm of the residual
66 *> o XNRM is the infinity-norm of the solution
67 *> o ANRM is the infinity-operator-norm of the matrix A
68 *> o EPS is the machine epsilon returned by DLAMCH('Epsilon')
69 *> The value ITERMAX and BWDMAX are fixed to 30 and 1.0D+00
70 *> respectively.
71 *> \endverbatim
72 *
73 * Arguments:
74 * ==========
75 *
76 *> \param[in] UPLO
77 *> \verbatim
78 *> UPLO is CHARACTER*1
79 *> = 'U': Upper triangle of A is stored;
80 *> = 'L': Lower triangle of A is stored.
81 *> \endverbatim
82 *>
83 *> \param[in] N
84 *> \verbatim
85 *> N is INTEGER
86 *> The number of linear equations, i.e., the order of the
87 *> matrix A. N >= 0.
88 *> \endverbatim
89 *>
90 *> \param[in] NRHS
91 *> \verbatim
92 *> NRHS is INTEGER
93 *> The number of right hand sides, i.e., the number of columns
94 *> of the matrix B. NRHS >= 0.
95 *> \endverbatim
96 *>
97 *> \param[in,out] A
98 *> \verbatim
99 *> A is DOUBLE PRECISION array,
100 *> dimension (LDA,N)
101 *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
102 *> N-by-N upper triangular part of A contains the upper
103 *> triangular part of the matrix A, and the strictly lower
104 *> triangular part of A is not referenced. If UPLO = 'L', the
105 *> leading N-by-N lower triangular part of A contains the lower
106 *> triangular part of the matrix A, and the strictly upper
107 *> triangular part of A is not referenced.
108 *> On exit, if iterative refinement has been successfully used
109 *> (INFO.EQ.0 and ITER.GE.0, see description below), then A is
110 *> unchanged, if double precision factorization has been used
111 *> (INFO.EQ.0 and ITER.LT.0, see description below), then the
112 *> array A contains the factor U or L from the Cholesky
113 *> factorization A = U**T*U or A = L*L**T.
114 *> \endverbatim
115 *>
116 *> \param[in] LDA
117 *> \verbatim
118 *> LDA is INTEGER
119 *> The leading dimension of the array A. LDA >= max(1,N).
120 *> \endverbatim
121 *>
122 *> \param[in] B
123 *> \verbatim
124 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
125 *> The N-by-NRHS right hand side matrix B.
126 *> \endverbatim
127 *>
128 *> \param[in] LDB
129 *> \verbatim
130 *> LDB is INTEGER
131 *> The leading dimension of the array B. LDB >= max(1,N).
132 *> \endverbatim
133 *>
134 *> \param[out] X
135 *> \verbatim
136 *> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
137 *> If INFO = 0, the N-by-NRHS solution matrix X.
138 *> \endverbatim
139 *>
140 *> \param[in] LDX
141 *> \verbatim
142 *> LDX is INTEGER
143 *> The leading dimension of the array X. LDX >= max(1,N).
144 *> \endverbatim
145 *>
146 *> \param[out] WORK
147 *> \verbatim
148 *> WORK is DOUBLE PRECISION array, dimension (N,NRHS)
149 *> This array is used to hold the residual vectors.
150 *> \endverbatim
151 *>
152 *> \param[out] SWORK
153 *> \verbatim
154 *> SWORK is REAL array, dimension (N*(N+NRHS))
155 *> This array is used to use the single precision matrix and the
156 *> right-hand sides or solutions in single precision.
157 *> \endverbatim
158 *>
159 *> \param[out] ITER
160 *> \verbatim
161 *> ITER is INTEGER
162 *> < 0: iterative refinement has failed, double precision
163 *> factorization has been performed
164 *> -1 : the routine fell back to full precision for
165 *> implementation- or machine-specific reasons
166 *> -2 : narrowing the precision induced an overflow,
167 *> the routine fell back to full precision
168 *> -3 : failure of SPOTRF
169 *> -31: stop the iterative refinement after the 30th
170 *> iterations
171 *> > 0: iterative refinement has been sucessfully used.
172 *> Returns the number of iterations
173 *> \endverbatim
174 *>
175 *> \param[out] INFO
176 *> \verbatim
177 *> INFO is INTEGER
178 *> = 0: successful exit
179 *> < 0: if INFO = -i, the i-th argument had an illegal value
180 *> > 0: if INFO = i, the leading minor of order i of (DOUBLE
181 *> PRECISION) A is not positive definite, so the
182 *> factorization could not be completed, and the solution
183 *> has not been computed.
184 *> \endverbatim
185 *
186 * Authors:
187 * ========
188 *
189 *> \author Univ. of Tennessee
190 *> \author Univ. of California Berkeley
191 *> \author Univ. of Colorado Denver
192 *> \author NAG Ltd.
193 *
194 *> \date November 2011
195 *
196 *> \ingroup doublePOsolve
197 *
198 * =====================================================================
199  SUBROUTINE dsposv( UPLO, N, NRHS, A, LDA, B, LDB, X, LDX, WORK,
200  $ swork, iter, info )
201 *
202 * -- LAPACK driver routine (version 3.4.0) --
203 * -- LAPACK is a software package provided by Univ. of Tennessee, --
204 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
205 * November 2011
206 *
207 * .. Scalar Arguments ..
208  CHARACTER uplo
209  INTEGER info, iter, lda, ldb, ldx, n, nrhs
210 * ..
211 * .. Array Arguments ..
212  REAL swork( * )
213  DOUBLE PRECISION a( lda, * ), b( ldb, * ), work( n, * ),
214  $ x( ldx, * )
215 * ..
216 *
217 * =====================================================================
218 *
219 * .. Parameters ..
220  LOGICAL doitref
221  parameter( doitref = .true. )
222 *
223  INTEGER itermax
224  parameter( itermax = 30 )
225 *
226  DOUBLE PRECISION bwdmax
227  parameter( bwdmax = 1.0e+00 )
228 *
229  DOUBLE PRECISION negone, one
230  parameter( negone = -1.0d+0, one = 1.0d+0 )
231 *
232 * .. Local Scalars ..
233  INTEGER i, iiter, ptsa, ptsx
234  DOUBLE PRECISION anrm, cte, eps, rnrm, xnrm
235 *
236 * .. External Subroutines ..
237  EXTERNAL daxpy, dsymm, dlacpy, dlat2s, dlag2s, slag2d,
238  $ spotrf, spotrs, xerbla
239 * ..
240 * .. External Functions ..
241  INTEGER idamax
242  DOUBLE PRECISION dlamch, dlansy
243  LOGICAL lsame
244  EXTERNAL idamax, dlamch, dlansy, lsame
245 * ..
246 * .. Intrinsic Functions ..
247  INTRINSIC abs, dble, max, sqrt
248 * ..
249 * .. Executable Statements ..
250 *
251  info = 0
252  iter = 0
253 *
254 * Test the input parameters.
255 *
256  IF( .NOT.lsame( uplo, 'U' ) .AND. .NOT.lsame( uplo, 'L' ) ) THEN
257  info = -1
258  ELSE IF( n.LT.0 ) THEN
259  info = -2
260  ELSE IF( nrhs.LT.0 ) THEN
261  info = -3
262  ELSE IF( lda.LT.max( 1, n ) ) THEN
263  info = -5
264  ELSE IF( ldb.LT.max( 1, n ) ) THEN
265  info = -7
266  ELSE IF( ldx.LT.max( 1, n ) ) THEN
267  info = -9
268  END IF
269  IF( info.NE.0 ) THEN
270  CALL xerbla( 'DSPOSV', -info )
271  RETURN
272  END IF
273 *
274 * Quick return if (N.EQ.0).
275 *
276  IF( n.EQ.0 )
277  $ RETURN
278 *
279 * Skip single precision iterative refinement if a priori slower
280 * than double precision factorization.
281 *
282  IF( .NOT.doitref ) THEN
283  iter = -1
284  go to 40
285  END IF
286 *
287 * Compute some constants.
288 *
289  anrm = dlansy( 'I', uplo, n, a, lda, work )
290  eps = dlamch( 'Epsilon' )
291  cte = anrm*eps*sqrt( dble( n ) )*bwdmax
292 *
293 * Set the indices PTSA, PTSX for referencing SA and SX in SWORK.
294 *
295  ptsa = 1
296  ptsx = ptsa + n*n
297 *
298 * Convert B from double precision to single precision and store the
299 * result in SX.
300 *
301  CALL dlag2s( n, nrhs, b, ldb, swork( ptsx ), n, info )
302 *
303  IF( info.NE.0 ) THEN
304  iter = -2
305  go to 40
306  END IF
307 *
308 * Convert A from double precision to single precision and store the
309 * result in SA.
310 *
311  CALL dlat2s( uplo, n, a, lda, swork( ptsa ), n, info )
312 *
313  IF( info.NE.0 ) THEN
314  iter = -2
315  go to 40
316  END IF
317 *
318 * Compute the Cholesky factorization of SA.
319 *
320  CALL spotrf( uplo, n, swork( ptsa ), n, info )
321 *
322  IF( info.NE.0 ) THEN
323  iter = -3
324  go to 40
325  END IF
326 *
327 * Solve the system SA*SX = SB.
328 *
329  CALL spotrs( uplo, n, nrhs, swork( ptsa ), n, swork( ptsx ), n,
330  $ info )
331 *
332 * Convert SX back to double precision
333 *
334  CALL slag2d( n, nrhs, swork( ptsx ), n, x, ldx, info )
335 *
336 * Compute R = B - AX (R is WORK).
337 *
338  CALL dlacpy( 'All', n, nrhs, b, ldb, work, n )
339 *
340  CALL dsymm( 'Left', uplo, n, nrhs, negone, a, lda, x, ldx, one,
341  $ work, n )
342 *
343 * Check whether the NRHS normwise backward errors satisfy the
344 * stopping criterion. If yes, set ITER=0 and return.
345 *
346  DO i = 1, nrhs
347  xnrm = abs( x( idamax( n, x( 1, i ), 1 ), i ) )
348  rnrm = abs( work( idamax( n, work( 1, i ), 1 ), i ) )
349  IF( rnrm.GT.xnrm*cte )
350  $ go to 10
351  END DO
352 *
353 * If we are here, the NRHS normwise backward errors satisfy the
354 * stopping criterion. We are good to exit.
355 *
356  iter = 0
357  RETURN
358 *
359  10 CONTINUE
360 *
361  DO 30 iiter = 1, itermax
362 *
363 * Convert R (in WORK) from double precision to single precision
364 * and store the result in SX.
365 *
366  CALL dlag2s( n, nrhs, work, n, swork( ptsx ), n, info )
367 *
368  IF( info.NE.0 ) THEN
369  iter = -2
370  go to 40
371  END IF
372 *
373 * Solve the system SA*SX = SR.
374 *
375  CALL spotrs( uplo, n, nrhs, swork( ptsa ), n, swork( ptsx ), n,
376  $ info )
377 *
378 * Convert SX back to double precision and update the current
379 * iterate.
380 *
381  CALL slag2d( n, nrhs, swork( ptsx ), n, work, n, info )
382 *
383  DO i = 1, nrhs
384  CALL daxpy( n, one, work( 1, i ), 1, x( 1, i ), 1 )
385  END DO
386 *
387 * Compute R = B - AX (R is WORK).
388 *
389  CALL dlacpy( 'All', n, nrhs, b, ldb, work, n )
390 *
391  CALL dsymm( 'L', uplo, n, nrhs, negone, a, lda, x, ldx, one,
392  $ work, n )
393 *
394 * Check whether the NRHS normwise backward errors satisfy the
395 * stopping criterion. If yes, set ITER=IITER>0 and return.
396 *
397  DO i = 1, nrhs
398  xnrm = abs( x( idamax( n, x( 1, i ), 1 ), i ) )
399  rnrm = abs( work( idamax( n, work( 1, i ), 1 ), i ) )
400  IF( rnrm.GT.xnrm*cte )
401  $ go to 20
402  END DO
403 *
404 * If we are here, the NRHS normwise backward errors satisfy the
405 * stopping criterion, we are good to exit.
406 *
407  iter = iiter
408 *
409  RETURN
410 *
411  20 CONTINUE
412 *
413  30 CONTINUE
414 *
415 * If we are at this place of the code, this is because we have
416 * performed ITER=ITERMAX iterations and never satisified the
417 * stopping criterion, set up the ITER flag accordingly and follow
418 * up on double precision routine.
419 *
420  iter = -itermax - 1
421 *
422  40 CONTINUE
423 *
424 * Single-precision iterative refinement failed to converge to a
425 * satisfactory solution, so we resort to double precision.
426 *
427  CALL dpotrf( uplo, n, a, lda, info )
428 *
429  IF( info.NE.0 )
430  $ RETURN
431 *
432  CALL dlacpy( 'All', n, nrhs, b, ldb, x, ldx )
433  CALL dpotrs( uplo, n, nrhs, a, lda, x, ldx, info )
434 *
435  RETURN
436 *
437 * End of DSPOSV.
438 *
439  END