3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZHETRS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrs.f">
21 * SUBROUTINE ZHETRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, LDB, N, NRHS
27 * .. Array Arguments ..
29 * COMPLEX*16 A( LDA, * ), B( LDB, * )
38 *> ZHETRS solves a system of linear equations A*X = B with a complex
39 *> Hermitian matrix A using the factorization A = U*D*U**H or
40 *> A = L*D*L**H computed by ZHETRF.
48 *> UPLO is CHARACTER*1
49 *> Specifies whether the details of the factorization are stored
50 *> as an upper or lower triangular matrix.
51 *> = 'U': Upper triangular, form is A = U*D*U**H;
52 *> = 'L': Lower triangular, form is A = L*D*L**H.
58 *> The order of the matrix A. N >= 0.
64 *> The number of right hand sides, i.e., the number of columns
65 *> of the matrix B. NRHS >= 0.
70 *> A is COMPLEX*16 array, dimension (LDA,N)
71 *> The block diagonal matrix D and the multipliers used to
72 *> obtain the factor U or L as computed by ZHETRF.
78 *> The leading dimension of the array A. LDA >= max(1,N).
83 *> IPIV is INTEGER array, dimension (N)
84 *> Details of the interchanges and the block structure of D
85 *> as determined by ZHETRF.
90 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
91 *> On entry, the right hand side matrix B.
92 *> On exit, the solution matrix X.
98 *> The leading dimension of the array B. LDB >= max(1,N).
104 *> = 0: successful exit
105 *> < 0: if INFO = -i, the i-th argument had an illegal value
111 *> \author Univ. of Tennessee
112 *> \author Univ. of California Berkeley
113 *> \author Univ. of Colorado Denver
116 *> \date November 2011
118 *> \ingroup complex16HEcomputational
120 * =====================================================================
121 SUBROUTINE ZHETRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
123 * -- LAPACK computational routine (version 3.4.0) --
124 * -- LAPACK is a software package provided by Univ. of Tennessee, --
125 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
128 * .. Scalar Arguments ..
130 INTEGER INFO, LDA, LDB, N, NRHS
132 * .. Array Arguments ..
134 COMPLEX*16 A( LDA, * ), B( LDB, * )
137 * =====================================================================
141 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
143 * .. Local Scalars ..
147 COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM
149 * .. External Functions ..
153 * .. External Subroutines ..
154 EXTERNAL XERBLA, ZDSCAL, ZGEMV, ZGERU, ZLACGV, ZSWAP
156 * .. Intrinsic Functions ..
157 INTRINSIC DBLE, DCONJG, MAX
159 * .. Executable Statements ..
162 UPPER = LSAME( UPLO, 'U' )
163 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
165 ELSE IF( N.LT.0 ) THEN
167 ELSE IF( NRHS.LT.0 ) THEN
169 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
171 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
175 CALL XERBLA( 'ZHETRS', -INFO )
179 * Quick return if possible
181 IF( N.EQ.0 .OR. NRHS.EQ.0 )
186 * Solve A*X = B, where A = U*D*U**H.
188 * First solve U*D*X = B, overwriting B with X.
190 * K is the main loop index, decreasing from N to 1 in steps of
191 * 1 or 2, depending on the size of the diagonal blocks.
196 * If K < 1, exit from loop.
201 IF( IPIV( K ).GT.0 ) THEN
203 * 1 x 1 diagonal block
205 * Interchange rows K and IPIV(K).
209 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
211 * Multiply by inv(U(K)), where U(K) is the transformation
212 * stored in column K of A.
214 CALL ZGERU( K-1, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
217 * Multiply by the inverse of the diagonal block.
219 S = DBLE( ONE ) / DBLE( A( K, K ) )
220 CALL ZDSCAL( NRHS, S, B( K, 1 ), LDB )
224 * 2 x 2 diagonal block
226 * Interchange rows K-1 and -IPIV(K).
230 $ CALL ZSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
232 * Multiply by inv(U(K)), where U(K) is the transformation
233 * stored in columns K-1 and K of A.
235 CALL ZGERU( K-2, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
237 CALL ZGERU( K-2, NRHS, -ONE, A( 1, K-1 ), 1, B( K-1, 1 ),
238 $ LDB, B( 1, 1 ), LDB )
240 * Multiply by the inverse of the diagonal block.
243 AKM1 = A( K-1, K-1 ) / AKM1K
244 AK = A( K, K ) / DCONJG( AKM1K )
245 DENOM = AKM1*AK - ONE
247 BKM1 = B( K-1, J ) / AKM1K
248 BK = B( K, J ) / DCONJG( AKM1K )
249 B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
250 B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
258 * Next solve U**H *X = B, overwriting B with X.
260 * K is the main loop index, increasing from 1 to N in steps of
261 * 1 or 2, depending on the size of the diagonal blocks.
266 * If K > N, exit from loop.
271 IF( IPIV( K ).GT.0 ) THEN
273 * 1 x 1 diagonal block
275 * Multiply by inv(U**H(K)), where U(K) is the transformation
276 * stored in column K of A.
279 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
280 CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
281 $ LDB, A( 1, K ), 1, ONE, B( K, 1 ), LDB )
282 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
285 * Interchange rows K and IPIV(K).
289 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
293 * 2 x 2 diagonal block
295 * Multiply by inv(U**H(K+1)), where U(K+1) is the transformation
296 * stored in columns K and K+1 of A.
299 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
300 CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
301 $ LDB, A( 1, K ), 1, ONE, B( K, 1 ), LDB )
302 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
304 CALL ZLACGV( NRHS, B( K+1, 1 ), LDB )
305 CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
306 $ LDB, A( 1, K+1 ), 1, ONE, B( K+1, 1 ), LDB )
307 CALL ZLACGV( NRHS, B( K+1, 1 ), LDB )
310 * Interchange rows K and -IPIV(K).
314 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
323 * Solve A*X = B, where A = L*D*L**H.
325 * First solve L*D*X = B, overwriting B with X.
327 * K is the main loop index, increasing from 1 to N in steps of
328 * 1 or 2, depending on the size of the diagonal blocks.
333 * If K > N, exit from loop.
338 IF( IPIV( K ).GT.0 ) THEN
340 * 1 x 1 diagonal block
342 * Interchange rows K and IPIV(K).
346 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
348 * Multiply by inv(L(K)), where L(K) is the transformation
349 * stored in column K of A.
352 $ CALL ZGERU( N-K, NRHS, -ONE, A( K+1, K ), 1, B( K, 1 ),
353 $ LDB, B( K+1, 1 ), LDB )
355 * Multiply by the inverse of the diagonal block.
357 S = DBLE( ONE ) / DBLE( A( K, K ) )
358 CALL ZDSCAL( NRHS, S, B( K, 1 ), LDB )
362 * 2 x 2 diagonal block
364 * Interchange rows K+1 and -IPIV(K).
368 $ CALL ZSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
370 * Multiply by inv(L(K)), where L(K) is the transformation
371 * stored in columns K and K+1 of A.
374 CALL ZGERU( N-K-1, NRHS, -ONE, A( K+2, K ), 1, B( K, 1 ),
375 $ LDB, B( K+2, 1 ), LDB )
376 CALL ZGERU( N-K-1, NRHS, -ONE, A( K+2, K+1 ), 1,
377 $ B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
380 * Multiply by the inverse of the diagonal block.
383 AKM1 = A( K, K ) / DCONJG( AKM1K )
384 AK = A( K+1, K+1 ) / AKM1K
385 DENOM = AKM1*AK - ONE
387 BKM1 = B( K, J ) / DCONJG( AKM1K )
388 BK = B( K+1, J ) / AKM1K
389 B( K, J ) = ( AK*BKM1-BK ) / DENOM
390 B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
398 * Next solve L**H *X = B, overwriting B with X.
400 * K is the main loop index, decreasing from N to 1 in steps of
401 * 1 or 2, depending on the size of the diagonal blocks.
406 * If K < 1, exit from loop.
411 IF( IPIV( K ).GT.0 ) THEN
413 * 1 x 1 diagonal block
415 * Multiply by inv(L**H(K)), where L(K) is the transformation
416 * stored in column K of A.
419 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
420 CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
421 $ B( K+1, 1 ), LDB, A( K+1, K ), 1, ONE,
423 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
426 * Interchange rows K and IPIV(K).
430 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
434 * 2 x 2 diagonal block
436 * Multiply by inv(L**H(K-1)), where L(K-1) is the transformation
437 * stored in columns K-1 and K of A.
440 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
441 CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
442 $ B( K+1, 1 ), LDB, A( K+1, K ), 1, ONE,
444 CALL ZLACGV( NRHS, B( K, 1 ), LDB )
446 CALL ZLACGV( NRHS, B( K-1, 1 ), LDB )
447 CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
448 $ B( K+1, 1 ), LDB, A( K+1, K-1 ), 1, ONE,
450 CALL ZLACGV( NRHS, B( K-1, 1 ), LDB )
453 * Interchange rows K and -IPIV(K).
457 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )