LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
ssytrs2.f
Go to the documentation of this file.
1 *> \brief \b SSYTRS2
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download SSYTRS2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytrs2.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytrs2.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytrs2.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE SSYTRS2( UPLO, N, NRHS, A, LDA, IPIV, B, LDB,
22 * WORK, INFO )
23 *
24 * .. Scalar Arguments ..
25 * CHARACTER UPLO
26 * INTEGER INFO, LDA, LDB, N, NRHS
27 * ..
28 * .. Array Arguments ..
29 * INTEGER IPIV( * )
30 * REAL A( LDA, * ), B( LDB, * ), WORK( * )
31 * ..
32 *
33 *
34 *> \par Purpose:
35 * =============
36 *>
37 *> \verbatim
38 *>
39 *> SSYTRS2 solves a system of linear equations A*X = B with a real
40 *> symmetric matrix A using the factorization A = U*D*U**T or
41 *> A = L*D*L**T computed by SSYTRF and converted by SSYCONV.
42 *> \endverbatim
43 *
44 * Arguments:
45 * ==========
46 *
47 *> \param[in] UPLO
48 *> \verbatim
49 *> UPLO is CHARACTER*1
50 *> Specifies whether the details of the factorization are stored
51 *> as an upper or lower triangular matrix.
52 *> = 'U': Upper triangular, form is A = U*D*U**T;
53 *> = 'L': Lower triangular, form is A = L*D*L**T.
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 matrix B. NRHS >= 0.
67 *> \endverbatim
68 *>
69 *> \param[in] A
70 *> \verbatim
71 *> A is REAL array, dimension (LDA,N)
72 *> The block diagonal matrix D and the multipliers used to
73 *> obtain the factor U or L as computed by SSYTRF.
74 *> \endverbatim
75 *>
76 *> \param[in] LDA
77 *> \verbatim
78 *> LDA is INTEGER
79 *> The leading dimension of the array A. LDA >= max(1,N).
80 *> \endverbatim
81 *>
82 *> \param[in] IPIV
83 *> \verbatim
84 *> IPIV is INTEGER array, dimension (N)
85 *> Details of the interchanges and the block structure of D
86 *> as determined by SSYTRF.
87 *> \endverbatim
88 *>
89 *> \param[in,out] B
90 *> \verbatim
91 *> B is REAL array, dimension (LDB,NRHS)
92 *> On entry, the right hand side matrix B.
93 *> On exit, the solution matrix X.
94 *> \endverbatim
95 *>
96 *> \param[in] LDB
97 *> \verbatim
98 *> LDB is INTEGER
99 *> The leading dimension of the array B. LDB >= max(1,N).
100 *> \endverbatim
101 *>
102 *> \param[out] WORK
103 *> \verbatim
104 *> WORK is REAL array, dimension (N)
105 *> \endverbatim
106 *>
107 *> \param[out] INFO
108 *> \verbatim
109 *> INFO is INTEGER
110 *> = 0: successful exit
111 *> < 0: if INFO = -i, the i-th argument had an illegal value
112 *> \endverbatim
113 *
114 * Authors:
115 * ========
116 *
117 *> \author Univ. of Tennessee
118 *> \author Univ. of California Berkeley
119 *> \author Univ. of Colorado Denver
120 *> \author NAG Ltd.
121 *
122 *> \date November 2011
123 *
124 *> \ingroup realSYcomputational
125 *
126 * =====================================================================
127  SUBROUTINE ssytrs2( UPLO, N, NRHS, A, LDA, IPIV, B, LDB,
128  $ work, info )
129 *
130 * -- LAPACK computational routine (version 3.4.0) --
131 * -- LAPACK is a software package provided by Univ. of Tennessee, --
132 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
133 * November 2011
134 *
135 * .. Scalar Arguments ..
136  CHARACTER uplo
137  INTEGER info, lda, ldb, n, nrhs
138 * ..
139 * .. Array Arguments ..
140  INTEGER ipiv( * )
141  REAL a( lda, * ), b( ldb, * ), work( * )
142 * ..
143 *
144 * =====================================================================
145 *
146 * .. Parameters ..
147  REAL one
148  parameter( one = 1.0e+0 )
149 * ..
150 * .. Local Scalars ..
151  LOGICAL upper
152  INTEGER i, iinfo, j, k, kp
153  REAL ak, akm1, akm1k, bk, bkm1, denom
154 * ..
155 * .. External Functions ..
156  LOGICAL lsame
157  EXTERNAL lsame
158 * ..
159 * .. External Subroutines ..
160  EXTERNAL sscal, ssyconv, sswap, strsm, xerbla
161 * ..
162 * .. Intrinsic Functions ..
163  INTRINSIC max
164 * ..
165 * .. Executable Statements ..
166 *
167  info = 0
168  upper = lsame( uplo, 'U' )
169  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
170  info = -1
171  ELSE IF( n.LT.0 ) THEN
172  info = -2
173  ELSE IF( nrhs.LT.0 ) THEN
174  info = -3
175  ELSE IF( lda.LT.max( 1, n ) ) THEN
176  info = -5
177  ELSE IF( ldb.LT.max( 1, n ) ) THEN
178  info = -8
179  END IF
180  IF( info.NE.0 ) THEN
181  CALL xerbla( 'SSYTRS2', -info )
182  return
183  END IF
184 *
185 * Quick return if possible
186 *
187  IF( n.EQ.0 .OR. nrhs.EQ.0 )
188  $ return
189 *
190 * Convert A
191 *
192  CALL ssyconv( uplo, 'C', n, a, lda, ipiv, work, iinfo )
193 *
194  IF( upper ) THEN
195 *
196 * Solve A*X = B, where A = U*D*U**T.
197 *
198 * P**T * B
199  k=n
200  DO WHILE ( k .GE. 1 )
201  IF( ipiv( k ).GT.0 ) THEN
202 * 1 x 1 diagonal block
203 * Interchange rows K and IPIV(K).
204  kp = ipiv( k )
205  IF( kp.NE.k )
206  $ CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
207  k=k-1
208  ELSE
209 * 2 x 2 diagonal block
210 * Interchange rows K-1 and -IPIV(K).
211  kp = -ipiv( k )
212  IF( kp.EQ.-ipiv( k-1 ) )
213  $ CALL sswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ), ldb )
214  k=k-2
215  END IF
216  END DO
217 *
218 * Compute (U \P**T * B) -> B [ (U \P**T * B) ]
219 *
220  CALL strsm('L','U','N','U',n,nrhs,one,a,lda,b,ldb)
221 *
222 * Compute D \ B -> B [ D \ (U \P**T * B) ]
223 *
224  i=n
225  DO WHILE ( i .GE. 1 )
226  IF( ipiv(i) .GT. 0 ) THEN
227  CALL sscal( nrhs, one / a( i, i ), b( i, 1 ), ldb )
228  elseif( i .GT. 1) THEN
229  IF ( ipiv(i-1) .EQ. ipiv(i) ) THEN
230  akm1k = work(i)
231  akm1 = a( i-1, i-1 ) / akm1k
232  ak = a( i, i ) / akm1k
233  denom = akm1*ak - one
234  DO 15 j = 1, nrhs
235  bkm1 = b( i-1, j ) / akm1k
236  bk = b( i, j ) / akm1k
237  b( i-1, j ) = ( ak*bkm1-bk ) / denom
238  b( i, j ) = ( akm1*bk-bkm1 ) / denom
239  15 continue
240  i = i - 1
241  ENDIF
242  ENDIF
243  i = i - 1
244  END DO
245 *
246 * Compute (U**T \ B) -> B [ U**T \ (D \ (U \P**T * B) ) ]
247 *
248  CALL strsm('L','U','T','U',n,nrhs,one,a,lda,b,ldb)
249 *
250 * P * B [ P * (U**T \ (D \ (U \P**T * B) )) ]
251 *
252  k=1
253  DO WHILE ( k .LE. n )
254  IF( ipiv( k ).GT.0 ) THEN
255 * 1 x 1 diagonal block
256 * Interchange rows K and IPIV(K).
257  kp = ipiv( k )
258  IF( kp.NE.k )
259  $ CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
260  k=k+1
261  ELSE
262 * 2 x 2 diagonal block
263 * Interchange rows K-1 and -IPIV(K).
264  kp = -ipiv( k )
265  IF( k .LT. n .AND. kp.EQ.-ipiv( k+1 ) )
266  $ CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
267  k=k+2
268  ENDIF
269  END DO
270 *
271  ELSE
272 *
273 * Solve A*X = B, where A = L*D*L**T.
274 *
275 * P**T * B
276  k=1
277  DO WHILE ( k .LE. n )
278  IF( ipiv( k ).GT.0 ) THEN
279 * 1 x 1 diagonal block
280 * Interchange rows K and IPIV(K).
281  kp = ipiv( k )
282  IF( kp.NE.k )
283  $ CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
284  k=k+1
285  ELSE
286 * 2 x 2 diagonal block
287 * Interchange rows K and -IPIV(K+1).
288  kp = -ipiv( k+1 )
289  IF( kp.EQ.-ipiv( k ) )
290  $ CALL sswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ), ldb )
291  k=k+2
292  ENDIF
293  END DO
294 *
295 * Compute (L \P**T * B) -> B [ (L \P**T * B) ]
296 *
297  CALL strsm('L','L','N','U',n,nrhs,one,a,lda,b,ldb)
298 *
299 * Compute D \ B -> B [ D \ (L \P**T * B) ]
300 *
301  i=1
302  DO WHILE ( i .LE. n )
303  IF( ipiv(i) .GT. 0 ) THEN
304  CALL sscal( nrhs, one / a( i, i ), b( i, 1 ), ldb )
305  ELSE
306  akm1k = work(i)
307  akm1 = a( i, i ) / akm1k
308  ak = a( i+1, i+1 ) / akm1k
309  denom = akm1*ak - one
310  DO 25 j = 1, nrhs
311  bkm1 = b( i, j ) / akm1k
312  bk = b( i+1, j ) / akm1k
313  b( i, j ) = ( ak*bkm1-bk ) / denom
314  b( i+1, j ) = ( akm1*bk-bkm1 ) / denom
315  25 continue
316  i = i + 1
317  ENDIF
318  i = i + 1
319  END DO
320 *
321 * Compute (L**T \ B) -> B [ L**T \ (D \ (L \P**T * B) ) ]
322 *
323  CALL strsm('L','L','T','U',n,nrhs,one,a,lda,b,ldb)
324 *
325 * P * B [ P * (L**T \ (D \ (L \P**T * B) )) ]
326 *
327  k=n
328  DO WHILE ( k .GE. 1 )
329  IF( ipiv( k ).GT.0 ) THEN
330 * 1 x 1 diagonal block
331 * Interchange rows K and IPIV(K).
332  kp = ipiv( k )
333  IF( kp.NE.k )
334  $ CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
335  k=k-1
336  ELSE
337 * 2 x 2 diagonal block
338 * Interchange rows K-1 and -IPIV(K).
339  kp = -ipiv( k )
340  IF( k.GT.1 .AND. kp.EQ.-ipiv( k-1 ) )
341  $ CALL sswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
342  k=k-2
343  ENDIF
344  END DO
345 *
346  END IF
347 *
348 * Revert A
349 *
350  CALL ssyconv( uplo, 'R', n, a, lda, ipiv, work, iinfo )
351 *
352  return
353 *
354 * End of SSYTRS2
355 *
356  END