3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZHETRS2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrs2.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrs2.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrs2.f">
21 * SUBROUTINE ZHETRS2( UPLO, N, NRHS, A, LDA, IPIV, B, LDB,
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDA, LDB, N, NRHS
28 * .. Array Arguments ..
30 * COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
39 *> ZHETRS2 solves a system of linear equations A*X = B with a complex
40 *> Hermitian matrix A using the factorization A = U*D*U**H or
41 *> A = L*D*L**H computed by ZHETRF and converted by ZSYCONV.
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**H;
53 *> = 'L': Lower triangular, form is A = L*D*L**H.
59 *> The order of the matrix A. N >= 0.
65 *> The number of right hand sides, i.e., the number of columns
66 *> of the matrix B. NRHS >= 0.
71 *> A is COMPLEX*16 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 ZHETRF.
79 *> The leading dimension of the array A. LDA >= max(1,N).
84 *> IPIV is INTEGER array, dimension (N)
85 *> Details of the interchanges and the block structure of D
86 *> as determined by ZHETRF.
91 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
92 *> On entry, the right hand side matrix B.
93 *> On exit, the solution matrix X.
99 *> The leading dimension of the array B. LDB >= max(1,N).
104 *> WORK is COMPLEX*16 array, dimension (N)
110 *> = 0: successful exit
111 *> < 0: if INFO = -i, the i-th argument had an illegal value
117 *> \author Univ. of Tennessee
118 *> \author Univ. of California Berkeley
119 *> \author Univ. of Colorado Denver
124 *> \ingroup complex16HEcomputational
126 * =====================================================================
127 SUBROUTINE ZHETRS2( UPLO, N, NRHS, A, LDA, IPIV, B, LDB,
130 * -- LAPACK computational routine (version 3.6.1) --
131 * -- LAPACK is a software package provided by Univ. of Tennessee, --
132 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
135 * .. Scalar Arguments ..
137 INTEGER INFO, LDA, LDB, N, NRHS
139 * .. Array Arguments ..
141 COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
144 * =====================================================================
148 PARAMETER ( ONE = (1.0D+0,0.0D+0) )
150 * .. Local Scalars ..
152 INTEGER I, IINFO, J, K, KP
154 COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM
156 * .. External Functions ..
160 * .. External Subroutines ..
161 EXTERNAL ZLACGV, ZSCAL, ZSYCONV, ZSWAP, ZTRSM, XERBLA
163 * .. Intrinsic Functions ..
164 INTRINSIC DBLE, DCONJG, MAX
166 * .. Executable Statements ..
169 UPPER = LSAME( UPLO, 'U' )
170 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
172 ELSE IF( N.LT.0 ) THEN
174 ELSE IF( NRHS.LT.0 ) THEN
176 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
178 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
182 CALL XERBLA( 'ZHETRS2', -INFO )
186 * Quick return if possible
188 IF( N.EQ.0 .OR. NRHS.EQ.0 )
193 CALL ZSYCONV( UPLO, 'C', N, A, LDA, IPIV, WORK, IINFO )
197 * Solve A*X = B, where A = U*D*U**H.
201 DO WHILE ( K .GE. 1 )
202 IF( IPIV( K ).GT.0 ) THEN
203 * 1 x 1 diagonal block
204 * Interchange rows K and IPIV(K).
207 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
210 * 2 x 2 diagonal block
211 * Interchange rows K-1 and -IPIV(K).
213 IF( KP.EQ.-IPIV( K-1 ) )
214 $ CALL ZSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
219 * Compute (U \P**T * B) -> B [ (U \P**T * B) ]
221 CALL ZTRSM('L','U','N','U',N,NRHS,ONE,A,LDA,B,LDB)
223 * Compute D \ B -> B [ D \ (U \P**T * B) ]
226 DO WHILE ( I .GE. 1 )
227 IF( IPIV(I) .GT. 0 ) THEN
228 S = DBLE( ONE ) / DBLE( A( I, I ) )
229 CALL ZDSCAL( NRHS, S, B( I, 1 ), LDB )
230 ELSEIF ( I .GT. 1) THEN
231 IF ( IPIV(I-1) .EQ. IPIV(I) ) THEN
233 AKM1 = A( I-1, I-1 ) / AKM1K
234 AK = A( I, I ) / DCONJG( AKM1K )
235 DENOM = AKM1*AK - ONE
237 BKM1 = B( I-1, J ) / AKM1K
238 BK = B( I, J ) / DCONJG( AKM1K )
239 B( I-1, J ) = ( AK*BKM1-BK ) / DENOM
240 B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM
248 * Compute (U**H \ B) -> B [ U**H \ (D \ (U \P**T * B) ) ]
250 CALL ZTRSM('L','U','C','U',N,NRHS,ONE,A,LDA,B,LDB)
252 * P * B [ P * (U**H \ (D \ (U \P**T * B) )) ]
255 DO WHILE ( K .LE. N )
256 IF( IPIV( K ).GT.0 ) THEN
257 * 1 x 1 diagonal block
258 * Interchange rows K and IPIV(K).
261 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
264 * 2 x 2 diagonal block
265 * Interchange rows K-1 and -IPIV(K).
267 IF( K .LT. N .AND. KP.EQ.-IPIV( K+1 ) )
268 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
275 * Solve A*X = B, where A = L*D*L**H.
279 DO WHILE ( K .LE. N )
280 IF( IPIV( K ).GT.0 ) THEN
281 * 1 x 1 diagonal block
282 * Interchange rows K and IPIV(K).
285 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
288 * 2 x 2 diagonal block
289 * Interchange rows K and -IPIV(K+1).
291 IF( KP.EQ.-IPIV( K ) )
292 $ CALL ZSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
297 * Compute (L \P**T * B) -> B [ (L \P**T * B) ]
299 CALL ZTRSM('L','L','N','U',N,NRHS,ONE,A,LDA,B,LDB)
301 * Compute D \ B -> B [ D \ (L \P**T * B) ]
304 DO WHILE ( I .LE. N )
305 IF( IPIV(I) .GT. 0 ) THEN
306 S = DBLE( ONE ) / DBLE( A( I, I ) )
307 CALL ZDSCAL( NRHS, S, B( I, 1 ), LDB )
310 AKM1 = A( I, I ) / DCONJG( AKM1K )
311 AK = A( I+1, I+1 ) / AKM1K
312 DENOM = AKM1*AK - ONE
314 BKM1 = B( I, J ) / DCONJG( AKM1K )
315 BK = B( I+1, J ) / AKM1K
316 B( I, J ) = ( AK*BKM1-BK ) / DENOM
317 B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
324 * Compute (L**H \ B) -> B [ L**H \ (D \ (L \P**T * B) ) ]
326 CALL ZTRSM('L','L','C','U',N,NRHS,ONE,A,LDA,B,LDB)
328 * P * B [ P * (L**H \ (D \ (L \P**T * B) )) ]
331 DO WHILE ( K .GE. 1 )
332 IF( IPIV( K ).GT.0 ) THEN
333 * 1 x 1 diagonal block
334 * Interchange rows K and IPIV(K).
337 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
340 * 2 x 2 diagonal block
341 * Interchange rows K-1 and -IPIV(K).
343 IF( K.GT.1 .AND. KP.EQ.-IPIV( K-1 ) )
344 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
353 CALL ZSYCONV( UPLO, 'R', N, A, LDA, IPIV, WORK, IINFO )