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