LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
chetrs.f
Go to the documentation of this file.
1 *> \brief \b CHETRS
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download CHETRS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrs.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrs.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrs.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CHETRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
22 *
23 * .. Scalar Arguments ..
24 * CHARACTER UPLO
25 * INTEGER INFO, LDA, LDB, N, NRHS
26 * ..
27 * .. Array Arguments ..
28 * INTEGER IPIV( * )
29 * COMPLEX A( LDA, * ), B( LDB, * )
30 * ..
31 *
32 *
33 *> \par Purpose:
34 * =============
35 *>
36 *> \verbatim
37 *>
38 *> CHETRS 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 CHETRF.
41 *> \endverbatim
42 *
43 * Arguments:
44 * ==========
45 *
46 *> \param[in] UPLO
47 *> \verbatim
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.
53 *> \endverbatim
54 *>
55 *> \param[in] N
56 *> \verbatim
57 *> N is INTEGER
58 *> The order of the matrix A. N >= 0.
59 *> \endverbatim
60 *>
61 *> \param[in] NRHS
62 *> \verbatim
63 *> NRHS is INTEGER
64 *> The number of right hand sides, i.e., the number of columns
65 *> of the matrix B. NRHS >= 0.
66 *> \endverbatim
67 *>
68 *> \param[in] A
69 *> \verbatim
70 *> A is COMPLEX 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 CHETRF.
73 *> \endverbatim
74 *>
75 *> \param[in] LDA
76 *> \verbatim
77 *> LDA is INTEGER
78 *> The leading dimension of the array A. LDA >= max(1,N).
79 *> \endverbatim
80 *>
81 *> \param[in] IPIV
82 *> \verbatim
83 *> IPIV is INTEGER array, dimension (N)
84 *> Details of the interchanges and the block structure of D
85 *> as determined by CHETRF.
86 *> \endverbatim
87 *>
88 *> \param[in,out] B
89 *> \verbatim
90 *> B is COMPLEX array, dimension (LDB,NRHS)
91 *> On entry, the right hand side matrix B.
92 *> On exit, the solution matrix X.
93 *> \endverbatim
94 *>
95 *> \param[in] LDB
96 *> \verbatim
97 *> LDB is INTEGER
98 *> The leading dimension of the array B. LDB >= max(1,N).
99 *> \endverbatim
100 *>
101 *> \param[out] INFO
102 *> \verbatim
103 *> INFO is INTEGER
104 *> = 0: successful exit
105 *> < 0: if INFO = -i, the i-th argument had an illegal value
106 *> \endverbatim
107 *
108 * Authors:
109 * ========
110 *
111 *> \author Univ. of Tennessee
112 *> \author Univ. of California Berkeley
113 *> \author Univ. of Colorado Denver
114 *> \author NAG Ltd.
115 *
116 *> \date November 2011
117 *
118 *> \ingroup complexHEcomputational
119 *
120 * =====================================================================
121  SUBROUTINE chetrs( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
122 *
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..--
126 * November 2011
127 *
128 * .. Scalar Arguments ..
129  CHARACTER uplo
130  INTEGER info, lda, ldb, n, nrhs
131 * ..
132 * .. Array Arguments ..
133  INTEGER ipiv( * )
134  COMPLEX a( lda, * ), b( ldb, * )
135 * ..
136 *
137 * =====================================================================
138 *
139 * .. Parameters ..
140  COMPLEX one
141  parameter( one = ( 1.0e+0, 0.0e+0 ) )
142 * ..
143 * .. Local Scalars ..
144  LOGICAL upper
145  INTEGER j, k, kp
146  REAL s
147  COMPLEX ak, akm1, akm1k, bk, bkm1, denom
148 * ..
149 * .. External Functions ..
150  LOGICAL lsame
151  EXTERNAL lsame
152 * ..
153 * .. External Subroutines ..
154  EXTERNAL cgemv, cgeru, clacgv, csscal, cswap, xerbla
155 * ..
156 * .. Intrinsic Functions ..
157  INTRINSIC conjg, max, real
158 * ..
159 * .. Executable Statements ..
160 *
161  info = 0
162  upper = lsame( uplo, 'U' )
163  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
164  info = -1
165  ELSE IF( n.LT.0 ) THEN
166  info = -2
167  ELSE IF( nrhs.LT.0 ) THEN
168  info = -3
169  ELSE IF( lda.LT.max( 1, n ) ) THEN
170  info = -5
171  ELSE IF( ldb.LT.max( 1, n ) ) THEN
172  info = -8
173  END IF
174  IF( info.NE.0 ) THEN
175  CALL xerbla( 'CHETRS', -info )
176  return
177  END IF
178 *
179 * Quick return if possible
180 *
181  IF( n.EQ.0 .OR. nrhs.EQ.0 )
182  $ return
183 *
184  IF( upper ) THEN
185 *
186 * Solve A*X = B, where A = U*D*U**H.
187 *
188 * First solve U*D*X = B, overwriting B with X.
189 *
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.
192 *
193  k = n
194  10 continue
195 *
196 * If K < 1, exit from loop.
197 *
198  IF( k.LT.1 )
199  $ go to 30
200 *
201  IF( ipiv( k ).GT.0 ) THEN
202 *
203 * 1 x 1 diagonal block
204 *
205 * Interchange rows K and IPIV(K).
206 *
207  kp = ipiv( k )
208  IF( kp.NE.k )
209  $ CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
210 *
211 * Multiply by inv(U(K)), where U(K) is the transformation
212 * stored in column K of A.
213 *
214  CALL cgeru( k-1, nrhs, -one, a( 1, k ), 1, b( k, 1 ), ldb,
215  $ b( 1, 1 ), ldb )
216 *
217 * Multiply by the inverse of the diagonal block.
218 *
219  s = REAL( ONE ) / REAL( A( K, K ) )
220  CALL csscal( nrhs, s, b( k, 1 ), ldb )
221  k = k - 1
222  ELSE
223 *
224 * 2 x 2 diagonal block
225 *
226 * Interchange rows K-1 and -IPIV(K).
227 *
228  kp = -ipiv( k )
229  IF( kp.NE.k-1 )
230  $ CALL cswap( nrhs, b( k-1, 1 ), ldb, b( kp, 1 ), ldb )
231 *
232 * Multiply by inv(U(K)), where U(K) is the transformation
233 * stored in columns K-1 and K of A.
234 *
235  CALL cgeru( k-2, nrhs, -one, a( 1, k ), 1, b( k, 1 ), ldb,
236  $ b( 1, 1 ), ldb )
237  CALL cgeru( k-2, nrhs, -one, a( 1, k-1 ), 1, b( k-1, 1 ),
238  $ ldb, b( 1, 1 ), ldb )
239 *
240 * Multiply by the inverse of the diagonal block.
241 *
242  akm1k = a( k-1, k )
243  akm1 = a( k-1, k-1 ) / akm1k
244  ak = a( k, k ) / conjg( akm1k )
245  denom = akm1*ak - one
246  DO 20 j = 1, nrhs
247  bkm1 = b( k-1, j ) / akm1k
248  bk = b( k, j ) / conjg( akm1k )
249  b( k-1, j ) = ( ak*bkm1-bk ) / denom
250  b( k, j ) = ( akm1*bk-bkm1 ) / denom
251  20 continue
252  k = k - 2
253  END IF
254 *
255  go to 10
256  30 continue
257 *
258 * Next solve U**H *X = B, overwriting B with X.
259 *
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.
262 *
263  k = 1
264  40 continue
265 *
266 * If K > N, exit from loop.
267 *
268  IF( k.GT.n )
269  $ go to 50
270 *
271  IF( ipiv( k ).GT.0 ) THEN
272 *
273 * 1 x 1 diagonal block
274 *
275 * Multiply by inv(U**H(K)), where U(K) is the transformation
276 * stored in column K of A.
277 *
278  IF( k.GT.1 ) THEN
279  CALL clacgv( nrhs, b( k, 1 ), ldb )
280  CALL cgemv( 'Conjugate transpose', k-1, nrhs, -one, b,
281  $ ldb, a( 1, k ), 1, one, b( k, 1 ), ldb )
282  CALL clacgv( nrhs, b( k, 1 ), ldb )
283  END IF
284 *
285 * Interchange rows K and IPIV(K).
286 *
287  kp = ipiv( k )
288  IF( kp.NE.k )
289  $ CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
290  k = k + 1
291  ELSE
292 *
293 * 2 x 2 diagonal block
294 *
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.
297 *
298  IF( k.GT.1 ) THEN
299  CALL clacgv( nrhs, b( k, 1 ), ldb )
300  CALL cgemv( 'Conjugate transpose', k-1, nrhs, -one, b,
301  $ ldb, a( 1, k ), 1, one, b( k, 1 ), ldb )
302  CALL clacgv( nrhs, b( k, 1 ), ldb )
303 *
304  CALL clacgv( nrhs, b( k+1, 1 ), ldb )
305  CALL cgemv( 'Conjugate transpose', k-1, nrhs, -one, b,
306  $ ldb, a( 1, k+1 ), 1, one, b( k+1, 1 ), ldb )
307  CALL clacgv( nrhs, b( k+1, 1 ), ldb )
308  END IF
309 *
310 * Interchange rows K and -IPIV(K).
311 *
312  kp = -ipiv( k )
313  IF( kp.NE.k )
314  $ CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
315  k = k + 2
316  END IF
317 *
318  go to 40
319  50 continue
320 *
321  ELSE
322 *
323 * Solve A*X = B, where A = L*D*L**H.
324 *
325 * First solve L*D*X = B, overwriting B with X.
326 *
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.
329 *
330  k = 1
331  60 continue
332 *
333 * If K > N, exit from loop.
334 *
335  IF( k.GT.n )
336  $ go to 80
337 *
338  IF( ipiv( k ).GT.0 ) THEN
339 *
340 * 1 x 1 diagonal block
341 *
342 * Interchange rows K and IPIV(K).
343 *
344  kp = ipiv( k )
345  IF( kp.NE.k )
346  $ CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
347 *
348 * Multiply by inv(L(K)), where L(K) is the transformation
349 * stored in column K of A.
350 *
351  IF( k.LT.n )
352  $ CALL cgeru( n-k, nrhs, -one, a( k+1, k ), 1, b( k, 1 ),
353  $ ldb, b( k+1, 1 ), ldb )
354 *
355 * Multiply by the inverse of the diagonal block.
356 *
357  s = REAL( ONE ) / REAL( A( K, K ) )
358  CALL csscal( nrhs, s, b( k, 1 ), ldb )
359  k = k + 1
360  ELSE
361 *
362 * 2 x 2 diagonal block
363 *
364 * Interchange rows K+1 and -IPIV(K).
365 *
366  kp = -ipiv( k )
367  IF( kp.NE.k+1 )
368  $ CALL cswap( nrhs, b( k+1, 1 ), ldb, b( kp, 1 ), ldb )
369 *
370 * Multiply by inv(L(K)), where L(K) is the transformation
371 * stored in columns K and K+1 of A.
372 *
373  IF( k.LT.n-1 ) THEN
374  CALL cgeru( n-k-1, nrhs, -one, a( k+2, k ), 1, b( k, 1 ),
375  $ ldb, b( k+2, 1 ), ldb )
376  CALL cgeru( n-k-1, nrhs, -one, a( k+2, k+1 ), 1,
377  $ b( k+1, 1 ), ldb, b( k+2, 1 ), ldb )
378  END IF
379 *
380 * Multiply by the inverse of the diagonal block.
381 *
382  akm1k = a( k+1, k )
383  akm1 = a( k, k ) / conjg( akm1k )
384  ak = a( k+1, k+1 ) / akm1k
385  denom = akm1*ak - one
386  DO 70 j = 1, nrhs
387  bkm1 = b( k, j ) / conjg( 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
391  70 continue
392  k = k + 2
393  END IF
394 *
395  go to 60
396  80 continue
397 *
398 * Next solve L**H *X = B, overwriting B with X.
399 *
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.
402 *
403  k = n
404  90 continue
405 *
406 * If K < 1, exit from loop.
407 *
408  IF( k.LT.1 )
409  $ go to 100
410 *
411  IF( ipiv( k ).GT.0 ) THEN
412 *
413 * 1 x 1 diagonal block
414 *
415 * Multiply by inv(L**H(K)), where L(K) is the transformation
416 * stored in column K of A.
417 *
418  IF( k.LT.n ) THEN
419  CALL clacgv( nrhs, b( k, 1 ), ldb )
420  CALL cgemv( 'Conjugate transpose', n-k, nrhs, -one,
421  $ b( k+1, 1 ), ldb, a( k+1, k ), 1, one,
422  $ b( k, 1 ), ldb )
423  CALL clacgv( nrhs, b( k, 1 ), ldb )
424  END IF
425 *
426 * Interchange rows K and IPIV(K).
427 *
428  kp = ipiv( k )
429  IF( kp.NE.k )
430  $ CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
431  k = k - 1
432  ELSE
433 *
434 * 2 x 2 diagonal block
435 *
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.
438 *
439  IF( k.LT.n ) THEN
440  CALL clacgv( nrhs, b( k, 1 ), ldb )
441  CALL cgemv( 'Conjugate transpose', n-k, nrhs, -one,
442  $ b( k+1, 1 ), ldb, a( k+1, k ), 1, one,
443  $ b( k, 1 ), ldb )
444  CALL clacgv( nrhs, b( k, 1 ), ldb )
445 *
446  CALL clacgv( nrhs, b( k-1, 1 ), ldb )
447  CALL cgemv( 'Conjugate transpose', n-k, nrhs, -one,
448  $ b( k+1, 1 ), ldb, a( k+1, k-1 ), 1, one,
449  $ b( k-1, 1 ), ldb )
450  CALL clacgv( nrhs, b( k-1, 1 ), ldb )
451  END IF
452 *
453 * Interchange rows K and -IPIV(K).
454 *
455  kp = -ipiv( k )
456  IF( kp.NE.k )
457  $ CALL cswap( nrhs, b( k, 1 ), ldb, b( kp, 1 ), ldb )
458  k = k - 2
459  END IF
460 *
461  go to 90
462  100 continue
463  END IF
464 *
465  return
466 *
467 * End of CHETRS
468 *
469  END