LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
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 *> \htmlonly
9 *> Download ZHETRS2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrs2.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrs2.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrs2.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE ZHETRS2( 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 * COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
31 * ..
32 *
33 *
34 *> \par Purpose:
35 * =============
36 *>
37 *> \verbatim
38 *>
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.
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**H;
53 *> = 'L': Lower triangular, form is A = L*D*L**H.
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 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.
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 ZHETRF.
87 *> \endverbatim
88 *>
89 *> \param[in,out] B
90 *> \verbatim
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.
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 COMPLEX*16 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 June 2016
123 *
124 *> \ingroup complex16HEcomputational
125 *
126 * =====================================================================
127  SUBROUTINE zhetrs2( UPLO, N, NRHS, A, LDA, IPIV, B, LDB,
128  $ work, info )
129 *
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..--
133 * June 2016
134 *
135 * .. Scalar Arguments ..
136  CHARACTER UPLO
137  INTEGER INFO, LDA, LDB, N, NRHS
138 * ..
139 * .. Array Arguments ..
140  INTEGER IPIV( * )
141  COMPLEX*16 A( lda, * ), B( ldb, * ), WORK( * )
142 * ..
143 *
144 * =====================================================================
145 *
146 * .. Parameters ..
147  COMPLEX*16 ONE
148  parameter ( one = (1.0d+0,0.0d+0) )
149 * ..
150 * .. Local Scalars ..
151  LOGICAL UPPER
152  INTEGER I, IINFO, J, K, KP
153  DOUBLE PRECISION S
154  COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM
155 * ..
156 * .. External Functions ..
157  LOGICAL LSAME
158  EXTERNAL lsame
159 * ..
160 * .. External Subroutines ..
161  EXTERNAL zlacgv, zscal, zsyconv, zswap, ztrsm, xerbla
162 * ..
163 * .. Intrinsic Functions ..
164  INTRINSIC dble, dconjg, max
165 * ..
166 * .. Executable Statements ..
167 *
168  info = 0
169  upper = lsame( uplo, 'U' )
170  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
171  info = -1
172  ELSE IF( n.LT.0 ) THEN
173  info = -2
174  ELSE IF( nrhs.LT.0 ) THEN
175  info = -3
176  ELSE IF( lda.LT.max( 1, n ) ) THEN
177  info = -5
178  ELSE IF( ldb.LT.max( 1, n ) ) THEN
179  info = -8
180  END IF
181  IF( info.NE.0 ) THEN
182  CALL xerbla( 'ZHETRS2', -info )
183  RETURN
184  END IF
185 *
186 * Quick return if possible
187 *
188  IF( n.EQ.0 .OR. nrhs.EQ.0 )
189  $ RETURN
190 *
191 * Convert A
192 *
193  CALL zsyconv( uplo, 'C', n, a, lda, ipiv, work, iinfo )
194 *
195  IF( upper ) THEN
196 *
197 * Solve A*X = B, where A = U*D*U**H.
198 *
199 * P**T * B
200  k=n
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).
205  kp = ipiv( k )
206  IF( kp.NE.k )
207  $ CALL zswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
208  k=k-1
209  ELSE
210 * 2 x 2 diagonal block
211 * Interchange rows K-1 and -IPIV(K).
212  kp = -ipiv( k )
213  IF( kp.EQ.-ipiv( k-1 ) )
214  $ CALL zswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ), ldb )
215  k=k-2
216  END IF
217  END DO
218 *
219 * Compute (U \P**T * B) -> B [ (U \P**T * B) ]
220 *
221  CALL ztrsm('L','U','N','U',n,nrhs,one,a,lda,b,ldb)
222 *
223 * Compute D \ B -> B [ D \ (U \P**T * B) ]
224 *
225  i=n
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
232  akm1k = work(i)
233  akm1 = a( i-1, i-1 ) / akm1k
234  ak = a( i, i ) / dconjg( akm1k )
235  denom = akm1*ak - one
236  DO 15 j = 1, nrhs
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
241  15 CONTINUE
242  i = i - 1
243  ENDIF
244  ENDIF
245  i = i - 1
246  END DO
247 *
248 * Compute (U**H \ B) -> B [ U**H \ (D \ (U \P**T * B) ) ]
249 *
250  CALL ztrsm('L','U','C','U',n,nrhs,one,a,lda,b,ldb)
251 *
252 * P * B [ P * (U**H \ (D \ (U \P**T * B) )) ]
253 *
254  k=1
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).
259  kp = ipiv( k )
260  IF( kp.NE.k )
261  $ CALL zswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
262  k=k+1
263  ELSE
264 * 2 x 2 diagonal block
265 * Interchange rows K-1 and -IPIV(K).
266  kp = -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 )
269  k=k+2
270  ENDIF
271  END DO
272 *
273  ELSE
274 *
275 * Solve A*X = B, where A = L*D*L**H.
276 *
277 * P**T * B
278  k=1
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).
283  kp = ipiv( k )
284  IF( kp.NE.k )
285  $ CALL zswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
286  k=k+1
287  ELSE
288 * 2 x 2 diagonal block
289 * Interchange rows K and -IPIV(K+1).
290  kp = -ipiv( k+1 )
291  IF( kp.EQ.-ipiv( k ) )
292  $ CALL zswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ), ldb )
293  k=k+2
294  ENDIF
295  END DO
296 *
297 * Compute (L \P**T * B) -> B [ (L \P**T * B) ]
298 *
299  CALL ztrsm('L','L','N','U',n,nrhs,one,a,lda,b,ldb)
300 *
301 * Compute D \ B -> B [ D \ (L \P**T * B) ]
302 *
303  i=1
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 )
308  ELSE
309  akm1k = work(i)
310  akm1 = a( i, i ) / dconjg( akm1k )
311  ak = a( i+1, i+1 ) / akm1k
312  denom = akm1*ak - one
313  DO 25 j = 1, nrhs
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
318  25 CONTINUE
319  i = i + 1
320  ENDIF
321  i = i + 1
322  END DO
323 *
324 * Compute (L**H \ B) -> B [ L**H \ (D \ (L \P**T * B) ) ]
325 *
326  CALL ztrsm('L','L','C','U',n,nrhs,one,a,lda,b,ldb)
327 *
328 * P * B [ P * (L**H \ (D \ (L \P**T * B) )) ]
329 *
330  k=n
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).
335  kp = ipiv( k )
336  IF( kp.NE.k )
337  $ CALL zswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
338  k=k-1
339  ELSE
340 * 2 x 2 diagonal block
341 * Interchange rows K-1 and -IPIV(K).
342  kp = -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 )
345  k=k-2
346  ENDIF
347  END DO
348 *
349  END IF
350 *
351 * Revert A
352 *
353  CALL zsyconv( uplo, 'R', n, a, lda, ipiv, work, iinfo )
354 *
355  RETURN
356 *
357 * End of ZHETRS2
358 *
359  END
subroutine zsyconv(UPLO, WAY, N, A, LDA, IPIV, E, INFO)
ZSYCONV
Definition: zsyconv.f:116
subroutine zswap(N, ZX, INCX, ZY, INCY)
ZSWAP
Definition: zswap.f:52
subroutine zhetrs2(UPLO, N, NRHS, A, LDA, IPIV, B, LDB, WORK, INFO)
ZHETRS2
Definition: zhetrs2.f:129
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine zdscal(N, DA, ZX, INCX)
ZDSCAL
Definition: zdscal.f:54
subroutine ztrsm(SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA, B, LDB)
ZTRSM
Definition: ztrsm.f:182
subroutine zscal(N, ZA, ZX, INCX)
ZSCAL
Definition: zscal.f:54
subroutine zlacgv(N, X, INCX)
ZLACGV conjugates a complex vector.
Definition: zlacgv.f:76