LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
chetri_3x.f
Go to the documentation of this file.
1*> \brief \b CHETRI_3X
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CHETRI_3X + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri_3x.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri_3x.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri_3x.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO )
20*
21* .. Scalar Arguments ..
22* CHARACTER UPLO
23* INTEGER INFO, LDA, N, NB
24* ..
25* .. Array Arguments ..
26* INTEGER IPIV( * )
27* COMPLEX A( LDA, * ), E( * ), WORK( N+NB+1, * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*> CHETRI_3X computes the inverse of a complex Hermitian indefinite
36*> matrix A using the factorization computed by CHETRF_RK or CHETRF_BK:
37*>
38*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T),
39*>
40*> where U (or L) is unit upper (or lower) triangular matrix,
41*> U**H (or L**H) is the conjugate of U (or L), P is a permutation
42*> matrix, P**T is the transpose of P, and D is Hermitian and block
43*> diagonal with 1-by-1 and 2-by-2 diagonal blocks.
44*>
45*> This is the blocked version of the algorithm, calling Level 3 BLAS.
46*> \endverbatim
47*
48* Arguments:
49* ==========
50*
51*> \param[in] UPLO
52*> \verbatim
53*> UPLO is CHARACTER*1
54*> Specifies whether the details of the factorization are
55*> stored as an upper or lower triangular matrix.
56*> = 'U': Upper triangle of A is stored;
57*> = 'L': Lower triangle of A is stored.
58*> \endverbatim
59*>
60*> \param[in] N
61*> \verbatim
62*> N is INTEGER
63*> The order of the matrix A. N >= 0.
64*> \endverbatim
65*>
66*> \param[in,out] A
67*> \verbatim
68*> A is COMPLEX array, dimension (LDA,N)
69*> On entry, diagonal of the block diagonal matrix D and
70*> factors U or L as computed by CHETRF_RK and CHETRF_BK:
71*> a) ONLY diagonal elements of the Hermitian block diagonal
72*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k);
73*> (superdiagonal (or subdiagonal) elements of D
74*> should be provided on entry in array E), and
75*> b) If UPLO = 'U': factor U in the superdiagonal part of A.
76*> If UPLO = 'L': factor L in the subdiagonal part of A.
77*>
78*> On exit, if INFO = 0, the Hermitian inverse of the original
79*> matrix.
80*> If UPLO = 'U': the upper triangular part of the inverse
81*> is formed and the part of A below the diagonal is not
82*> referenced;
83*> If UPLO = 'L': the lower triangular part of the inverse
84*> is formed and the part of A above the diagonal is not
85*> referenced.
86*> \endverbatim
87*>
88*> \param[in] LDA
89*> \verbatim
90*> LDA is INTEGER
91*> The leading dimension of the array A. LDA >= max(1,N).
92*> \endverbatim
93*>
94*> \param[in] E
95*> \verbatim
96*> E is COMPLEX array, dimension (N)
97*> On entry, contains the superdiagonal (or subdiagonal)
98*> elements of the Hermitian block diagonal matrix D
99*> with 1-by-1 or 2-by-2 diagonal blocks, where
100*> If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) not referenced;
101*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced.
102*>
103*> NOTE: For 1-by-1 diagonal block D(k), where
104*> 1 <= k <= N, the element E(k) is not referenced in both
105*> UPLO = 'U' or UPLO = 'L' cases.
106*> \endverbatim
107*>
108*> \param[in] IPIV
109*> \verbatim
110*> IPIV is INTEGER array, dimension (N)
111*> Details of the interchanges and the block structure of D
112*> as determined by CHETRF_RK or CHETRF_BK.
113*> \endverbatim
114*>
115*> \param[out] WORK
116*> \verbatim
117*> WORK is COMPLEX array, dimension (N+NB+1,NB+3).
118*> \endverbatim
119*>
120*> \param[in] NB
121*> \verbatim
122*> NB is INTEGER
123*> Block size.
124*> \endverbatim
125*>
126*> \param[out] INFO
127*> \verbatim
128*> INFO is INTEGER
129*> = 0: successful exit
130*> < 0: if INFO = -i, the i-th argument had an illegal value
131*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
132*> inverse could not be computed.
133*> \endverbatim
134*
135* Authors:
136* ========
137*
138*> \author Univ. of Tennessee
139*> \author Univ. of California Berkeley
140*> \author Univ. of Colorado Denver
141*> \author NAG Ltd.
142*
143*> \ingroup hetri_3x
144*
145*> \par Contributors:
146* ==================
147*> \verbatim
148*>
149*> June 2017, Igor Kozachenko,
150*> Computer Science Division,
151*> University of California, Berkeley
152*>
153*> \endverbatim
154*
155* =====================================================================
156 SUBROUTINE chetri_3x( UPLO, N, A, LDA, E, IPIV, WORK, NB,
157 $ INFO )
158*
159* -- LAPACK computational routine --
160* -- LAPACK is a software package provided by Univ. of Tennessee, --
161* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
162*
163* .. Scalar Arguments ..
164 CHARACTER UPLO
165 INTEGER INFO, LDA, N, NB
166* ..
167* .. Array Arguments ..
168 INTEGER IPIV( * )
169 COMPLEX A( LDA, * ), E( * ), WORK( N+NB+1, * )
170* ..
171*
172* =====================================================================
173*
174* .. Parameters ..
175 REAL ONE
176 parameter( one = 1.0e+0 )
177 COMPLEX CONE, CZERO
178 parameter( cone = ( 1.0e+0, 0.0e+0 ),
179 $ czero = ( 0.0e+0, 0.0e+0 ) )
180* ..
181* .. Local Scalars ..
182 LOGICAL UPPER
183 INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11
184 REAL AK, AKP1, T
185 COMPLEX AKKP1, D, U01_I_J, U01_IP1_J, U11_I_J,
186 $ u11_ip1_j
187* ..
188* .. External Functions ..
189 LOGICAL LSAME
190 EXTERNAL lsame
191* ..
192* .. External Subroutines ..
193 EXTERNAL cgemm, cheswapr, ctrtri, ctrmm,
194 $ xerbla
195* ..
196* .. Intrinsic Functions ..
197 INTRINSIC abs, conjg, max, real
198* ..
199* .. Executable Statements ..
200*
201* Test the input parameters.
202*
203 info = 0
204 upper = lsame( uplo, 'U' )
205 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
206 info = -1
207 ELSE IF( n.LT.0 ) THEN
208 info = -2
209 ELSE IF( lda.LT.max( 1, n ) ) THEN
210 info = -4
211 END IF
212*
213* Quick return if possible
214*
215 IF( info.NE.0 ) THEN
216 CALL xerbla( 'CHETRI_3X', -info )
217 RETURN
218 END IF
219 IF( n.EQ.0 )
220 $ RETURN
221*
222* Workspace got Non-diag elements of D
223*
224 DO k = 1, n
225 work( k, 1 ) = e( k )
226 END DO
227*
228* Check that the diagonal matrix D is nonsingular.
229*
230 IF( upper ) THEN
231*
232* Upper triangular storage: examine D from bottom to top
233*
234 DO info = n, 1, -1
235 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
236 $ RETURN
237 END DO
238 ELSE
239*
240* Lower triangular storage: examine D from top to bottom.
241*
242 DO info = 1, n
243 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
244 $ RETURN
245 END DO
246 END IF
247*
248 info = 0
249*
250* Splitting Workspace
251* U01 is a block ( N, NB+1 )
252* The first element of U01 is in WORK( 1, 1 )
253* U11 is a block ( NB+1, NB+1 )
254* The first element of U11 is in WORK( N+1, 1 )
255*
256 u11 = n
257*
258* INVD is a block ( N, 2 )
259* The first element of INVD is in WORK( 1, INVD )
260*
261 invd = nb + 2
262
263 IF( upper ) THEN
264*
265* Begin Upper
266*
267* invA = P * inv(U**H) * inv(D) * inv(U) * P**T.
268*
269 CALL ctrtri( uplo, 'U', n, a, lda, info )
270*
271* inv(D) and inv(D) * inv(U)
272*
273 k = 1
274 DO WHILE( k.LE.n )
275 IF( ipiv( k ).GT.0 ) THEN
276* 1 x 1 diagonal NNB
277 work( k, invd ) = one / real( a( k, k ) )
278 work( k, invd+1 ) = czero
279 ELSE
280* 2 x 2 diagonal NNB
281 t = abs( work( k+1, 1 ) )
282 ak = real( a( k, k ) ) / t
283 akp1 = real( a( k+1, k+1 ) ) / t
284 akkp1 = work( k+1, 1 ) / t
285 d = t*( ak*akp1-cone )
286 work( k, invd ) = akp1 / d
287 work( k+1, invd+1 ) = ak / d
288 work( k, invd+1 ) = -akkp1 / d
289 work( k+1, invd ) = conjg( work( k, invd+1 ) )
290 k = k + 1
291 END IF
292 k = k + 1
293 END DO
294*
295* inv(U**H) = (inv(U))**H
296*
297* inv(U**H) * inv(D) * inv(U)
298*
299 cut = n
300 DO WHILE( cut.GT.0 )
301 nnb = nb
302 IF( cut.LE.nnb ) THEN
303 nnb = cut
304 ELSE
305 icount = 0
306* count negative elements,
307 DO i = cut+1-nnb, cut
308 IF( ipiv( i ).LT.0 ) icount = icount + 1
309 END DO
310* need a even number for a clear cut
311 IF( mod( icount, 2 ).EQ.1 ) nnb = nnb + 1
312 END IF
313
314 cut = cut - nnb
315*
316* U01 Block
317*
318 DO i = 1, cut
319 DO j = 1, nnb
320 work( i, j ) = a( i, cut+j )
321 END DO
322 END DO
323*
324* U11 Block
325*
326 DO i = 1, nnb
327 work( u11+i, i ) = cone
328 DO j = 1, i-1
329 work( u11+i, j ) = czero
330 END DO
331 DO j = i+1, nnb
332 work( u11+i, j ) = a( cut+i, cut+j )
333 END DO
334 END DO
335*
336* invD * U01
337*
338 i = 1
339 DO WHILE( i.LE.cut )
340 IF( ipiv( i ).GT.0 ) THEN
341 DO j = 1, nnb
342 work( i, j ) = work( i, invd ) * work( i, j )
343 END DO
344 ELSE
345 DO j = 1, nnb
346 u01_i_j = work( i, j )
347 u01_ip1_j = work( i+1, j )
348 work( i, j ) = work( i, invd ) * u01_i_j
349 $ + work( i, invd+1 ) * u01_ip1_j
350 work( i+1, j ) = work( i+1, invd ) * u01_i_j
351 $ + work( i+1, invd+1 ) * u01_ip1_j
352 END DO
353 i = i + 1
354 END IF
355 i = i + 1
356 END DO
357*
358* invD1 * U11
359*
360 i = 1
361 DO WHILE ( i.LE.nnb )
362 IF( ipiv( cut+i ).GT.0 ) THEN
363 DO j = i, nnb
364 work( u11+i, j ) = work(cut+i,invd) * work(u11+i,j)
365 END DO
366 ELSE
367 DO j = i, nnb
368 u11_i_j = work(u11+i,j)
369 u11_ip1_j = work(u11+i+1,j)
370 work( u11+i, j ) = work(cut+i,invd) * work(u11+i,j)
371 $ + work(cut+i,invd+1) * work(u11+i+1,j)
372 work( u11+i+1, j ) = work(cut+i+1,invd) * u11_i_j
373 $ + work(cut+i+1,invd+1) * u11_ip1_j
374 END DO
375 i = i + 1
376 END IF
377 i = i + 1
378 END DO
379*
380* U11**H * invD1 * U11 -> U11
381*
382 CALL ctrmm( 'L', 'U', 'C', 'U', nnb, nnb,
383 $ cone, a( cut+1, cut+1 ), lda, work( u11+1, 1 ),
384 $ n+nb+1 )
385*
386 DO i = 1, nnb
387 DO j = i, nnb
388 a( cut+i, cut+j ) = work( u11+i, j )
389 END DO
390 END DO
391*
392* U01**H * invD * U01 -> A( CUT+I, CUT+J )
393*
394 CALL cgemm( 'C', 'N', nnb, nnb, cut, cone, a( 1, cut+1 ),
395 $ lda, work, n+nb+1, czero, work(u11+1,1),
396 $ n+nb+1 )
397
398*
399* U11 = U11**H * invD1 * U11 + U01**H * invD * U01
400*
401 DO i = 1, nnb
402 DO j = i, nnb
403 a( cut+i, cut+j ) = a( cut+i, cut+j ) + work(u11+i,j)
404 END DO
405 END DO
406*
407* U01 = U00**H * invD0 * U01
408*
409 CALL ctrmm( 'L', uplo, 'C', 'U', cut, nnb,
410 $ cone, a, lda, work, n+nb+1 )
411
412*
413* Update U01
414*
415 DO i = 1, cut
416 DO j = 1, nnb
417 a( i, cut+j ) = work( i, j )
418 END DO
419 END DO
420*
421* Next Block
422*
423 END DO
424*
425* Apply PERMUTATIONS P and P**T:
426* P * inv(U**H) * inv(D) * inv(U) * P**T.
427* Interchange rows and columns I and IPIV(I) in reverse order
428* from the formation order of IPIV vector for Upper case.
429*
430* ( We can use a loop over IPIV with increment 1,
431* since the ABS value of IPIV(I) represents the row (column)
432* index of the interchange with row (column) i in both 1x1
433* and 2x2 pivot cases, i.e. we don't need separate code branches
434* for 1x1 and 2x2 pivot cases )
435*
436 DO i = 1, n
437 ip = abs( ipiv( i ) )
438 IF( ip.NE.i ) THEN
439 IF (i .LT. ip) CALL cheswapr( uplo, n, a, lda, i ,
440 $ ip )
441 IF (i .GT. ip) CALL cheswapr( uplo, n, a, lda, ip ,
442 $ i )
443 END IF
444 END DO
445*
446 ELSE
447*
448* Begin Lower
449*
450* inv A = P * inv(L**H) * inv(D) * inv(L) * P**T.
451*
452 CALL ctrtri( uplo, 'U', n, a, lda, info )
453*
454* inv(D) and inv(D) * inv(L)
455*
456 k = n
457 DO WHILE ( k .GE. 1 )
458 IF( ipiv( k ).GT.0 ) THEN
459* 1 x 1 diagonal NNB
460 work( k, invd ) = one / real( a( k, k ) )
461 work( k, invd+1 ) = czero
462 ELSE
463* 2 x 2 diagonal NNB
464 t = abs( work( k-1, 1 ) )
465 ak = real( a( k-1, k-1 ) ) / t
466 akp1 = real( a( k, k ) ) / t
467 akkp1 = work( k-1, 1 ) / t
468 d = t*( ak*akp1-cone )
469 work( k-1, invd ) = akp1 / d
470 work( k, invd ) = ak / d
471 work( k, invd+1 ) = -akkp1 / d
472 work( k-1, invd+1 ) = conjg( work( k, invd+1 ) )
473 k = k - 1
474 END IF
475 k = k - 1
476 END DO
477*
478* inv(L**H) = (inv(L))**H
479*
480* inv(L**H) * inv(D) * inv(L)
481*
482 cut = 0
483 DO WHILE( cut.LT.n )
484 nnb = nb
485 IF( (cut + nnb).GT.n ) THEN
486 nnb = n - cut
487 ELSE
488 icount = 0
489* count negative elements,
490 DO i = cut + 1, cut+nnb
491 IF ( ipiv( i ).LT.0 ) icount = icount + 1
492 END DO
493* need a even number for a clear cut
494 IF( mod( icount, 2 ).EQ.1 ) nnb = nnb + 1
495 END IF
496*
497* L21 Block
498*
499 DO i = 1, n-cut-nnb
500 DO j = 1, nnb
501 work( i, j ) = a( cut+nnb+i, cut+j )
502 END DO
503 END DO
504*
505* L11 Block
506*
507 DO i = 1, nnb
508 work( u11+i, i) = cone
509 DO j = i+1, nnb
510 work( u11+i, j ) = czero
511 END DO
512 DO j = 1, i-1
513 work( u11+i, j ) = a( cut+i, cut+j )
514 END DO
515 END DO
516*
517* invD*L21
518*
519 i = n-cut-nnb
520 DO WHILE( i.GE.1 )
521 IF( ipiv( cut+nnb+i ).GT.0 ) THEN
522 DO j = 1, nnb
523 work( i, j ) = work( cut+nnb+i, invd) * work( i, j)
524 END DO
525 ELSE
526 DO j = 1, nnb
527 u01_i_j = work(i,j)
528 u01_ip1_j = work(i-1,j)
529 work(i,j)=work(cut+nnb+i,invd)*u01_i_j+
530 $ work(cut+nnb+i,invd+1)*u01_ip1_j
531 work(i-1,j)=work(cut+nnb+i-1,invd+1)*u01_i_j+
532 $ work(cut+nnb+i-1,invd)*u01_ip1_j
533 END DO
534 i = i - 1
535 END IF
536 i = i - 1
537 END DO
538*
539* invD1*L11
540*
541 i = nnb
542 DO WHILE( i.GE.1 )
543 IF( ipiv( cut+i ).GT.0 ) THEN
544 DO j = 1, nnb
545 work( u11+i, j ) = work( cut+i, invd)*work(u11+i,j)
546 END DO
547
548 ELSE
549 DO j = 1, nnb
550 u11_i_j = work( u11+i, j )
551 u11_ip1_j = work( u11+i-1, j )
552 work( u11+i, j ) = work(cut+i,invd) * work(u11+i,j)
553 $ + work(cut+i,invd+1) * u11_ip1_j
554 work( u11+i-1, j ) = work(cut+i-1,invd+1) * u11_i_j
555 $ + work(cut+i-1,invd) * u11_ip1_j
556 END DO
557 i = i - 1
558 END IF
559 i = i - 1
560 END DO
561*
562* L11**H * invD1 * L11 -> L11
563*
564 CALL ctrmm( 'L', uplo, 'C', 'U', nnb, nnb, cone,
565 $ a( cut+1, cut+1 ), lda, work( u11+1, 1 ),
566 $ n+nb+1 )
567
568*
569 DO i = 1, nnb
570 DO j = 1, i
571 a( cut+i, cut+j ) = work( u11+i, j )
572 END DO
573 END DO
574*
575 IF( (cut+nnb).LT.n ) THEN
576*
577* L21**H * invD2*L21 -> A( CUT+I, CUT+J )
578*
579 CALL cgemm( 'C', 'N', nnb, nnb, n-nnb-cut, cone,
580 $ a( cut+nnb+1, cut+1 ), lda, work, n+nb+1,
581 $ czero, work( u11+1, 1 ), n+nb+1 )
582
583*
584* L11 = L11**H * invD1 * L11 + U01**H * invD * U01
585*
586 DO i = 1, nnb
587 DO j = 1, i
588 a( cut+i, cut+j ) = a( cut+i, cut+j )+work(u11+i,j)
589 END DO
590 END DO
591*
592* L01 = L22**H * invD2 * L21
593*
594 CALL ctrmm( 'L', uplo, 'C', 'U', n-nnb-cut, nnb, cone,
595 $ a( cut+nnb+1, cut+nnb+1 ), lda, work,
596 $ n+nb+1 )
597*
598* Update L21
599*
600 DO i = 1, n-cut-nnb
601 DO j = 1, nnb
602 a( cut+nnb+i, cut+j ) = work( i, j )
603 END DO
604 END DO
605*
606 ELSE
607*
608* L11 = L11**H * invD1 * L11
609*
610 DO i = 1, nnb
611 DO j = 1, i
612 a( cut+i, cut+j ) = work( u11+i, j )
613 END DO
614 END DO
615 END IF
616*
617* Next Block
618*
619 cut = cut + nnb
620*
621 END DO
622*
623* Apply PERMUTATIONS P and P**T:
624* P * inv(L**H) * inv(D) * inv(L) * P**T.
625* Interchange rows and columns I and IPIV(I) in reverse order
626* from the formation order of IPIV vector for Lower case.
627*
628* ( We can use a loop over IPIV with increment -1,
629* since the ABS value of IPIV(I) represents the row (column)
630* index of the interchange with row (column) i in both 1x1
631* and 2x2 pivot cases, i.e. we don't need separate code branches
632* for 1x1 and 2x2 pivot cases )
633*
634 DO i = n, 1, -1
635 ip = abs( ipiv( i ) )
636 IF( ip.NE.i ) THEN
637 IF (i .LT. ip) CALL cheswapr( uplo, n, a, lda, i ,
638 $ ip )
639 IF (i .GT. ip) CALL cheswapr( uplo, n, a, lda, ip ,
640 $ i )
641 END IF
642 END DO
643*
644 END IF
645*
646 RETURN
647*
648* End of CHETRI_3X
649*
650 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
CGEMM
Definition cgemm.f:188
subroutine cheswapr(uplo, n, a, lda, i1, i2)
CHESWAPR applies an elementary permutation on the rows and columns of a Hermitian matrix.
Definition cheswapr.f:100
subroutine chetri_3x(uplo, n, a, lda, e, ipiv, work, nb, info)
CHETRI_3X
Definition chetri_3x.f:158
subroutine ctrmm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
CTRMM
Definition ctrmm.f:177
subroutine ctrtri(uplo, diag, n, a, lda, info)
CTRTRI
Definition ctrtri.f:107