OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
clahef_rk.f
Go to the documentation of this file.
1*> \brief \b CLAHEF_RK computes a partial factorization of a complex Hermitian indefinite matrix using bounded Bunch-Kaufman (rook) diagonal pivoting method.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> \htmlonly
9*> Download CLAHEF_RK + dependencies
10*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahef_rk.f">
11*> [TGZ]</a>
12*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahef_rk.f">
13*> [ZIP]</a>
14*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahef_rk.f">
15*> [TXT]</a>
16*> \endhtmlonly
17*
18* Definition:
19* ===========
20*
21* SUBROUTINE CLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW,
22* INFO )
23*
24* .. Scalar Arguments ..
25* CHARACTER UPLO
26* INTEGER INFO, KB, LDA, LDW, N, NB
27* ..
28* .. Array Arguments ..
29* INTEGER IPIV( * )
30* COMPLEX A( LDA, * ), E( * ), W( LDW, * )
31* ..
32*
33*
34*> \par Purpose:
35* =============
36*>
37*> \verbatim
38*> CLAHEF_RK computes a partial factorization of a complex Hermitian
39*> matrix A using the bounded Bunch-Kaufman (rook) diagonal
40*> pivoting method. The partial factorization has the form:
41*>
42*> A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or:
43*> ( 0 U22 ) ( 0 D ) ( U12**H U22**H )
44*>
45*> A = ( L11 0 ) ( D 0 ) ( L11**H L21**H ) if UPLO = 'L',
46*> ( L21 I ) ( 0 A22 ) ( 0 I )
47*>
48*> where the order of D is at most NB. The actual order is returned in
49*> the argument KB, and is either NB or NB-1, or N if N <= NB.
50*>
51*> CLAHEF_RK is an auxiliary routine called by CHETRF_RK. It uses
52*> blocked code (calling Level 3 BLAS) to update the submatrix
53*> A11 (if UPLO = 'U') or A22 (if UPLO = 'L').
54*> \endverbatim
55*
56* Arguments:
57* ==========
58*
59*> \param[in] UPLO
60*> \verbatim
61*> UPLO is CHARACTER*1
62*> Specifies whether the upper or lower triangular part of the
63*> Hermitian matrix A is stored:
64*> = 'U': Upper triangular
65*> = 'L': Lower triangular
66*> \endverbatim
67*>
68*> \param[in] N
69*> \verbatim
70*> N is INTEGER
71*> The order of the matrix A. N >= 0.
72*> \endverbatim
73*>
74*> \param[in] NB
75*> \verbatim
76*> NB is INTEGER
77*> The maximum number of columns of the matrix A that should be
78*> factored. NB should be at least 2 to allow for 2-by-2 pivot
79*> blocks.
80*> \endverbatim
81*>
82*> \param[out] KB
83*> \verbatim
84*> KB is INTEGER
85*> The number of columns of A that were actually factored.
86*> KB is either NB-1 or NB, or N if N <= NB.
87*> \endverbatim
88*>
89*> \param[in,out] A
90*> \verbatim
91*> A is COMPLEX array, dimension (LDA,N)
92*> On entry, the Hermitian matrix A.
93*> If UPLO = 'U': the leading N-by-N upper triangular part
94*> of A contains the upper triangular part of the matrix A,
95*> and the strictly lower triangular part of A is not
96*> referenced.
97*>
98*> If UPLO = 'L': the leading N-by-N lower triangular part
99*> of A contains the lower triangular part of the matrix A,
100*> and the strictly upper triangular part of A is not
101*> referenced.
102*>
103*> On exit, contains:
104*> a) ONLY diagonal elements of the Hermitian block diagonal
105*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k);
106*> (superdiagonal (or subdiagonal) elements of D
107*> are stored on exit in array E), and
108*> b) If UPLO = 'U': factor U in the superdiagonal part of A.
109*> If UPLO = 'L': factor L in the subdiagonal part of A.
110*> \endverbatim
111*>
112*> \param[in] LDA
113*> \verbatim
114*> LDA is INTEGER
115*> The leading dimension of the array A. LDA >= max(1,N).
116*> \endverbatim
117*>
118*> \param[out] E
119*> \verbatim
120*> E is COMPLEX array, dimension (N)
121*> On exit, contains the superdiagonal (or subdiagonal)
122*> elements of the Hermitian block diagonal matrix D
123*> with 1-by-1 or 2-by-2 diagonal blocks, where
124*> If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0;
125*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0.
126*>
127*> NOTE: For 1-by-1 diagonal block D(k), where
128*> 1 <= k <= N, the element E(k) is set to 0 in both
129*> UPLO = 'U' or UPLO = 'L' cases.
130*> \endverbatim
131*>
132*> \param[out] IPIV
133*> \verbatim
134*> IPIV is INTEGER array, dimension (N)
135*> IPIV describes the permutation matrix P in the factorization
136*> of matrix A as follows. The absolute value of IPIV(k)
137*> represents the index of row and column that were
138*> interchanged with the k-th row and column. The value of UPLO
139*> describes the order in which the interchanges were applied.
140*> Also, the sign of IPIV represents the block structure of
141*> the Hermitian block diagonal matrix D with 1-by-1 or 2-by-2
142*> diagonal blocks which correspond to 1 or 2 interchanges
143*> at each factorization step.
144*>
145*> If UPLO = 'U',
146*> ( in factorization order, k decreases from N to 1 ):
147*> a) A single positive entry IPIV(k) > 0 means:
148*> D(k,k) is a 1-by-1 diagonal block.
149*> If IPIV(k) != k, rows and columns k and IPIV(k) were
150*> interchanged in the submatrix A(1:N,N-KB+1:N);
151*> If IPIV(k) = k, no interchange occurred.
152*>
153*>
154*> b) A pair of consecutive negative entries
155*> IPIV(k) < 0 and IPIV(k-1) < 0 means:
156*> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
157*> (NOTE: negative entries in IPIV appear ONLY in pairs).
158*> 1) If -IPIV(k) != k, rows and columns
159*> k and -IPIV(k) were interchanged
160*> in the matrix A(1:N,N-KB+1:N).
161*> If -IPIV(k) = k, no interchange occurred.
162*> 2) If -IPIV(k-1) != k-1, rows and columns
163*> k-1 and -IPIV(k-1) were interchanged
164*> in the submatrix A(1:N,N-KB+1:N).
165*> If -IPIV(k-1) = k-1, no interchange occurred.
166*>
167*> c) In both cases a) and b) is always ABS( IPIV(k) ) <= k.
168*>
169*> d) NOTE: Any entry IPIV(k) is always NONZERO on output.
170*>
171*> If UPLO = 'L',
172*> ( in factorization order, k increases from 1 to N ):
173*> a) A single positive entry IPIV(k) > 0 means:
174*> D(k,k) is a 1-by-1 diagonal block.
175*> If IPIV(k) != k, rows and columns k and IPIV(k) were
176*> interchanged in the submatrix A(1:N,1:KB).
177*> If IPIV(k) = k, no interchange occurred.
178*>
179*> b) A pair of consecutive negative entries
180*> IPIV(k) < 0 and IPIV(k+1) < 0 means:
181*> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
182*> (NOTE: negative entries in IPIV appear ONLY in pairs).
183*> 1) If -IPIV(k) != k, rows and columns
184*> k and -IPIV(k) were interchanged
185*> in the submatrix A(1:N,1:KB).
186*> If -IPIV(k) = k, no interchange occurred.
187*> 2) If -IPIV(k+1) != k+1, rows and columns
188*> k-1 and -IPIV(k-1) were interchanged
189*> in the submatrix A(1:N,1:KB).
190*> If -IPIV(k+1) = k+1, no interchange occurred.
191*>
192*> c) In both cases a) and b) is always ABS( IPIV(k) ) >= k.
193*>
194*> d) NOTE: Any entry IPIV(k) is always NONZERO on output.
195*> \endverbatim
196*>
197*> \param[out] W
198*> \verbatim
199*> W is COMPLEX array, dimension (LDW,NB)
200*> \endverbatim
201*>
202*> \param[in] LDW
203*> \verbatim
204*> LDW is INTEGER
205*> The leading dimension of the array W. LDW >= max(1,N).
206*> \endverbatim
207*>
208*> \param[out] INFO
209*> \verbatim
210*> INFO is INTEGER
211*> = 0: successful exit
212*>
213*> < 0: If INFO = -k, the k-th argument had an illegal value
214*>
215*> > 0: If INFO = k, the matrix A is singular, because:
216*> If UPLO = 'U': column k in the upper
217*> triangular part of A contains all zeros.
218*> If UPLO = 'L': column k in the lower
219*> triangular part of A contains all zeros.
220*>
221*> Therefore D(k,k) is exactly zero, and superdiagonal
222*> elements of column k of U (or subdiagonal elements of
223*> column k of L ) are all zeros. The factorization has
224*> been completed, but the block diagonal matrix D is
225*> exactly singular, and division by zero will occur if
226*> it is used to solve a system of equations.
227*>
228*> NOTE: INFO only stores the first occurrence of
229*> a singularity, any subsequent occurrence of singularity
230*> is not stored in INFO even though the factorization
231*> always completes.
232*> \endverbatim
233*
234* Authors:
235* ========
236*
237*> \author Univ. of Tennessee
238*> \author Univ. of California Berkeley
239*> \author Univ. of Colorado Denver
240*> \author NAG Ltd.
241*
242*> \ingroup complexHEcomputational
243*
244*> \par Contributors:
245* ==================
246*>
247*> \verbatim
248*>
249*> December 2016, Igor Kozachenko,
250*> Computer Science Division,
251*> University of California, Berkeley
252*>
253*> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
254*> School of Mathematics,
255*> University of Manchester
256*>
257*> \endverbatim
258*
259* =====================================================================
260 SUBROUTINE clahef_rk( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW,
261 $ INFO )
262*
263* -- LAPACK computational routine --
264* -- LAPACK is a software package provided by Univ. of Tennessee, --
265* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
266*
267* .. Scalar Arguments ..
268 CHARACTER UPLO
269 INTEGER INFO, KB, LDA, LDW, N, NB
270* ..
271* .. Array Arguments ..
272 INTEGER IPIV( * )
273 COMPLEX A( LDA, * ), W( LDW, * ), E( * )
274* ..
275*
276* =====================================================================
277*
278* .. Parameters ..
279 REAL ZERO, ONE
280 parameter( zero = 0.0e+0, one = 1.0e+0 )
281 REAL EIGHT, SEVTEN
282 parameter( eight = 8.0e+0, sevten = 17.0e+0 )
283 COMPLEX CONE, CZERO
284 parameter( cone = ( 1.0e+0, 0.0e+0 ),
285 $ czero = ( 0.0e+0, 0.0e+0 ) )
286* ..
287* .. Local Scalars ..
288 LOGICAL DONE
289 INTEGER IMAX, ITEMP, II, J, JB, JJ, JMAX, K, KK, KKW,
290 $ kp, kstep, kw, p
291 REAL ABSAKK, ALPHA, COLMAX, STEMP, R1, ROWMAX, T,
292 $ sfmin
293 COMPLEX D11, D21, D22, Z
294* ..
295* .. External Functions ..
296 LOGICAL LSAME
297 INTEGER ICAMAX
298 REAL SLAMCH
299 EXTERNAL lsame, icamax, slamch
300* ..
301* .. External Subroutines ..
302 EXTERNAL ccopy, csscal, cgemm, cgemv, clacgv, cswap
303* ..
304* .. Intrinsic Functions ..
305 INTRINSIC abs, conjg, aimag, max, min, real, sqrt
306* ..
307* .. Statement Functions ..
308 REAL CABS1
309* ..
310* .. Statement Function definitions ..
311 cabs1( z ) = abs( real( z ) ) + abs( aimag( z ) )
312* ..
313* .. Executable Statements ..
314*
315 info = 0
316*
317* Initialize ALPHA for use in choosing pivot block size.
318*
319 alpha = ( one+sqrt( sevten ) ) / eight
320*
321* Compute machine safe minimum
322*
323 sfmin = slamch( 's' )
324*
325 IF( LSAME( UPLO, 'u' ) ) THEN
326*
327* Factorize the trailing columns of A using the upper triangle
328* of A and working backwards, and compute the matrix W = U12*D
329* for use in updating A11 (note that conjg(W) is actually stored)
330*
331* Initialize the first entry of array E, where superdiagonal
332* elements of D are stored
333*
334 E( 1 ) = CZERO
335*
336* K is the main loop index, decreasing from N in steps of 1 or 2
337*
338 K = N
339 10 CONTINUE
340*
341* KW is the column of W which corresponds to column K of A
342*
343 KW = NB + K - N
344*
345* Exit from loop
346*
347.LE..AND..LT..OR..LT. IF( ( KN-NB+1 NBN ) K1 )
348 $ GO TO 30
349*
350 KSTEP = 1
351 P = K
352*
353* Copy column K of A to column KW of W and update it
354*
355.GT. IF( K1 )
356 $ CALL CCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 )
357 W( K, KW ) = REAL( A( K, K ) )
358.LT. IF( KN ) THEN
359 CALL CGEMV( 'no transpose', K, N-K, -CONE, A( 1, K+1 ), LDA,
360 $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
361 W( K, KW ) = REAL( W( K, KW ) )
362 END IF
363*
364* Determine rows and columns to be interchanged and whether
365* a 1-by-1 or 2-by-2 pivot block will be used
366*
367 ABSAKK = ABS( REAL( W( K, KW ) ) )
368*
369* IMAX is the row-index of the largest off-diagonal element in
370* column K, and COLMAX is its absolute value.
371* Determine both COLMAX and IMAX.
372*
373.GT. IF( K1 ) THEN
374 IMAX = ICAMAX( K-1, W( 1, KW ), 1 )
375 COLMAX = CABS1( W( IMAX, KW ) )
376 ELSE
377 COLMAX = ZERO
378 END IF
379*
380.EQ. IF( MAX( ABSAKK, COLMAX )ZERO ) THEN
381*
382* Column K is zero or underflow: set INFO and continue
383*
384.EQ. IF( INFO0 )
385 $ INFO = K
386 KP = K
387 A( K, K ) = REAL( W( K, KW ) )
388.GT. IF( K1 )
389 $ CALL CCOPY( K-1, W( 1, KW ), 1, A( 1, K ), 1 )
390*
391* Set E( K ) to zero
392*
393.GT. IF( K1 )
394 $ E( K ) = CZERO
395*
396 ELSE
397*
398* ============================================================
399*
400* BEGIN pivot search
401*
402* Case(1)
403* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
404* (used to handle NaN and Inf)
405.NOT..LT. IF( ( ABSAKKALPHA*COLMAX ) ) THEN
406*
407* no interchange, use 1-by-1 pivot block
408*
409 KP = K
410*
411 ELSE
412*
413* Lop until pivot found
414*
415 DONE = .FALSE.
416*
417 12 CONTINUE
418*
419* BEGIN pivot search loop body
420*
421*
422* Copy column IMAX to column KW-1 of W and update it
423*
424.GT. IF( IMAX1 )
425 $ CALL CCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ),
426 $ 1 )
427 W( IMAX, KW-1 ) = REAL( A( IMAX, IMAX ) )
428*
429 CALL CCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
430 $ W( IMAX+1, KW-1 ), 1 )
431 CALL CLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 )
432*
433.LT. IF( KN ) THEN
434 CALL CGEMV( 'no transpose', K, N-K, -CONE,
435 $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
436 $ CONE, W( 1, KW-1 ), 1 )
437 W( IMAX, KW-1 ) = REAL( W( IMAX, KW-1 ) )
438 END IF
439*
440* JMAX is the column-index of the largest off-diagonal
441* element in row IMAX, and ROWMAX is its absolute value.
442* Determine both ROWMAX and JMAX.
443*
444.NE. IF( IMAXK ) THEN
445 JMAX = IMAX + ICAMAX( K-IMAX, W( IMAX+1, KW-1 ),
446 $ 1 )
447 ROWMAX = CABS1( W( JMAX, KW-1 ) )
448 ELSE
449 ROWMAX = ZERO
450 END IF
451*
452.GT. IF( IMAX1 ) THEN
453 ITEMP = ICAMAX( IMAX-1, W( 1, KW-1 ), 1 )
454 STEMP = CABS1( W( ITEMP, KW-1 ) )
455.GT. IF( STEMPROWMAX ) THEN
456 ROWMAX = STEMP
457 JMAX = ITEMP
458 END IF
459 END IF
460*
461* Case(2)
462* Equivalent to testing for
463* ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX
464* (used to handle NaN and Inf)
465*
466.NOT. IF( ( ABS( REAL( W( IMAX,KW-1 ) ) )
467.LT. $ ALPHA*ROWMAX ) ) THEN
468*
469* interchange rows and columns K and IMAX,
470* use 1-by-1 pivot block
471*
472 KP = IMAX
473*
474* copy column KW-1 of W to column KW of W
475*
476 CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
477*
478 DONE = .TRUE.
479*
480* Case(3)
481* Equivalent to testing for ROWMAX.EQ.COLMAX,
482* (used to handle NaN and Inf)
483*
484.EQ..OR..LE. ELSE IF( ( PJMAX ) ( ROWMAXCOLMAX ) )
485 $ THEN
486*
487* interchange rows and columns K-1 and IMAX,
488* use 2-by-2 pivot block
489*
490 KP = IMAX
491 KSTEP = 2
492 DONE = .TRUE.
493*
494* Case(4)
495 ELSE
496*
497* Pivot not found: set params and repeat
498*
499 P = IMAX
500 COLMAX = ROWMAX
501 IMAX = JMAX
502*
503* Copy updated JMAXth (next IMAXth) column to Kth of W
504*
505 CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
506*
507 END IF
508*
509*
510* END pivot search loop body
511*
512.NOT. IF( DONE ) GOTO 12
513*
514 END IF
515*
516* END pivot search
517*
518* ============================================================
519*
520* KK is the column of A where pivoting step stopped
521*
522 KK = K - KSTEP + 1
523*
524* KKW is the column of W which corresponds to column KK of A
525*
526 KKW = NB + KK - N
527*
528* Interchange rows and columns P and K.
529* Updated column P is already stored in column KW of W.
530*
531.EQ..AND..NE. IF( ( KSTEP2 ) ( PK ) ) THEN
532*
533* Copy non-updated column K to column P of submatrix A
534* at step K. No need to copy element into columns
535* K and K-1 of A for 2-by-2 pivot, since these columns
536* will be later overwritten.
537*
538 A( P, P ) = REAL( A( K, K ) )
539 CALL CCOPY( K-1-P, A( P+1, K ), 1, A( P, P+1 ),
540 $ LDA )
541 CALL CLACGV( K-1-P, A( P, P+1 ), LDA )
542.GT. IF( P1 )
543 $ CALL CCOPY( P-1, A( 1, K ), 1, A( 1, P ), 1 )
544*
545* Interchange rows K and P in the last K+1 to N columns of A
546* (columns K and K-1 of A for 2-by-2 pivot will be
547* later overwritten). Interchange rows K and P
548* in last KKW to NB columns of W.
549*
550.LT. IF( KN )
551 $ CALL CSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ),
552 $ LDA )
553 CALL CSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ),
554 $ LDW )
555 END IF
556*
557* Interchange rows and columns KP and KK.
558* Updated column KP is already stored in column KKW of W.
559*
560.NE. IF( KPKK ) THEN
561*
562* Copy non-updated column KK to column KP of submatrix A
563* at step K. No need to copy element into column K
564* (or K and K-1 for 2-by-2 pivot) of A, since these columns
565* will be later overwritten.
566*
567 A( KP, KP ) = REAL( A( KK, KK ) )
568 CALL CCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
569 $ LDA )
570 CALL CLACGV( KK-1-KP, A( KP, KP+1 ), LDA )
571.GT. IF( KP1 )
572 $ CALL CCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
573*
574* Interchange rows KK and KP in last K+1 to N columns of A
575* (columns K (or K and K-1 for 2-by-2 pivot) of A will be
576* later overwritten). Interchange rows KK and KP
577* in last KKW to NB columns of W.
578*
579.LT. IF( KN )
580 $ CALL CSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ),
581 $ LDA )
582 CALL CSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
583 $ LDW )
584 END IF
585*
586.EQ. IF( KSTEP1 ) THEN
587*
588* 1-by-1 pivot block D(k): column kw of W now holds
589*
590* W(kw) = U(k)*D(k),
591*
592* where U(k) is the k-th column of U
593*
594* (1) Store subdiag. elements of column U(k)
595* and 1-by-1 block D(k) in column k of A.
596* (NOTE: Diagonal element U(k,k) is a UNIT element
597* and not stored)
598* A(k,k) := D(k,k) = W(k,kw)
599* A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k)
600*
601* (NOTE: No need to use for Hermitian matrix
602* A( K, K ) = REAL( W( K, K) ) to separately copy diagonal
603* element D(k,k) from W (potentially saves only one load))
604 CALL CCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
605.GT. IF( K1 ) THEN
606*
607* (NOTE: No need to check if A(k,k) is NOT ZERO,
608* since that was ensured earlier in pivot search:
609* case A(k,k) = 0 falls into 2x2 pivot case(3))
610*
611* Handle division by a small number
612*
613 T = REAL( A( K, K ) )
614.GE. IF( ABS( T )SFMIN ) THEN
615 R1 = ONE / T
616 CALL CSSCAL( K-1, R1, A( 1, K ), 1 )
617 ELSE
618 DO 14 II = 1, K-1
619 A( II, K ) = A( II, K ) / T
620 14 CONTINUE
621 END IF
622*
623* (2) Conjugate column W(kw)
624*
625 CALL CLACGV( K-1, W( 1, KW ), 1 )
626*
627* Store the superdiagonal element of D in array E
628*
629 E( K ) = CZERO
630*
631 END IF
632*
633 ELSE
634*
635* 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold
636*
637* ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k)
638*
639* where U(k) and U(k-1) are the k-th and (k-1)-th columns
640* of U
641*
642* (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2
643* block D(k-1:k,k-1:k) in columns k-1 and k of A.
644* (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT
645* block and not stored)
646* A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw)
647* A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) =
648* = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) )
649*
650.GT. IF( K2 ) THEN
651*
652* Factor out the columns of the inverse of 2-by-2 pivot
653* block D, so that each column contains 1, to reduce the
654* number of FLOPS when we multiply panel
655* ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
656*
657* D**(-1) = ( d11 cj(d21) )**(-1) =
658* ( d21 d22 )
659*
660* = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
661* ( (-d21) ( d11 ) )
662*
663* = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
664*
665* * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
666* ( ( -1 ) ( d11/conj(d21) ) )
667*
668* = 1/(|d21|**2) * 1/(D22*D11-1) *
669*
670* * ( d21*( D11 ) conj(d21)*( -1 ) ) =
671* ( ( -1 ) ( D22 ) )
672*
673* = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
674* ( ( -1 ) ( D22 ) )
675*
676* = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
677* ( ( -1 ) ( D22 ) )
678*
679* Handle division by a small number. (NOTE: order of
680* operations is important)
681*
682* = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) )
683* ( (( -1 ) ) (( D22 ) ) ),
684*
685* where D11 = d22/d21,
686* D22 = d11/conj(d21),
687* D21 = d21,
688* T = 1/(D22*D11-1).
689*
690* (NOTE: No need to check for division by ZERO,
691* since that was ensured earlier in pivot search:
692* (a) d21 != 0 in 2x2 pivot case(4),
693* since |d21| should be larger than |d11| and |d22|;
694* (b) (D22*D11 - 1) != 0, since from (a),
695* both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
696*
697 D21 = W( K-1, KW )
698 D11 = W( K, KW ) / CONJG( D21 )
699 D22 = W( K-1, KW-1 ) / D21
700 T = ONE / ( REAL( D11*D22 )-ONE )
701*
702* Update elements in columns A(k-1) and A(k) as
703* dot products of rows of ( W(kw-1) W(kw) ) and columns
704* of D**(-1)
705*
706 DO 20 J = 1, K - 2
707 A( J, K-1 ) = T*( ( D11*W( J, KW-1 )-W( J, KW ) ) /
708 $ D21 )
709 A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) /
710 $ CONJG( D21 ) )
711 20 CONTINUE
712 END IF
713*
714* Copy diagonal elements of D(K) to A,
715* copy superdiagonal element of D(K) to E(K) and
716* ZERO out superdiagonal entry of A
717*
718 A( K-1, K-1 ) = W( K-1, KW-1 )
719 A( K-1, K ) = CZERO
720 A( K, K ) = W( K, KW )
721 E( K ) = W( K-1, KW )
722 E( K-1 ) = CZERO
723*
724* (2) Conjugate columns W(kw) and W(kw-1)
725*
726 CALL CLACGV( K-1, W( 1, KW ), 1 )
727 CALL CLACGV( K-2, W( 1, KW-1 ), 1 )
728*
729 END IF
730*
731* End column K is nonsingular
732*
733 END IF
734*
735* Store details of the interchanges in IPIV
736*
737.EQ. IF( KSTEP1 ) THEN
738 IPIV( K ) = KP
739 ELSE
740 IPIV( K ) = -P
741 IPIV( K-1 ) = -KP
742 END IF
743*
744* Decrease K and return to the start of the main loop
745*
746 K = K - KSTEP
747 GO TO 10
748*
749 30 CONTINUE
750*
751* Update the upper triangle of A11 (= A(1:k,1:k)) as
752*
753* A11 := A11 - U12*D*U12**H = A11 - U12*W**H
754*
755* computing blocks of NB columns at a time (note that conjg(W) is
756* actually stored)
757*
758 DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
759 JB = MIN( NB, K-J+1 )
760*
761* Update the upper triangle of the diagonal block
762*
763 DO 40 JJ = J, J + JB - 1
764 A( JJ, JJ ) = REAL( A( JJ, JJ ) )
765 CALL CGEMV( 'no transpose', JJ-J+1, N-K, -CONE,
766 $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
767 $ A( J, JJ ), 1 )
768 A( JJ, JJ ) = REAL( A( JJ, JJ ) )
769 40 CONTINUE
770*
771* Update the rectangular superdiagonal block
772*
773.GE. IF( J2 )
774 $ CALL CGEMM( 'no transpose', 'transpose', J-1, JB, N-K,
775 $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
776 $ CONE, A( 1, J ), LDA )
777 50 CONTINUE
778*
779* Set KB to the number of columns factorized
780*
781 KB = N - K
782*
783 ELSE
784*
785* Factorize the leading columns of A using the lower triangle
786* of A and working forwards, and compute the matrix W = L21*D
787* for use in updating A22 (note that conjg(W) is actually stored)
788*
789* Initialize the unused last entry of the subdiagonal array E.
790*
791 E( N ) = CZERO
792*
793* K is the main loop index, increasing from 1 in steps of 1 or 2
794*
795 K = 1
796 70 CONTINUE
797*
798* Exit from loop
799*
800.GE..AND..LT..OR..GT. IF( ( KNB NBN ) KN )
801 $ GO TO 90
802*
803 KSTEP = 1
804 P = K
805*
806* Copy column K of A to column K of W and update column K of W
807*
808 W( K, K ) = REAL( A( K, K ) )
809.LT. IF( KN )
810 $ CALL CCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 )
811.GT. IF( K1 ) THEN
812 CALL CGEMV( 'no transpose', N-K+1, K-1, -CONE, A( K, 1 ),
813 $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 )
814 W( K, K ) = REAL( W( K, K ) )
815 END IF
816*
817* Determine rows and columns to be interchanged and whether
818* a 1-by-1 or 2-by-2 pivot block will be used
819*
820 ABSAKK = ABS( REAL( W( K, K ) ) )
821*
822* IMAX is the row-index of the largest off-diagonal element in
823* column K, and COLMAX is its absolute value.
824* Determine both COLMAX and IMAX.
825*
826.LT. IF( KN ) THEN
827 IMAX = K + ICAMAX( N-K, W( K+1, K ), 1 )
828 COLMAX = CABS1( W( IMAX, K ) )
829 ELSE
830 COLMAX = ZERO
831 END IF
832*
833.EQ. IF( MAX( ABSAKK, COLMAX )ZERO ) THEN
834*
835* Column K is zero or underflow: set INFO and continue
836*
837.EQ. IF( INFO0 )
838 $ INFO = K
839 KP = K
840 A( K, K ) = REAL( W( K, K ) )
841.LT. IF( KN )
842 $ CALL CCOPY( N-K, W( K+1, K ), 1, A( K+1, K ), 1 )
843*
844* Set E( K ) to zero
845*
846.LT. IF( KN )
847 $ E( K ) = CZERO
848*
849 ELSE
850*
851* ============================================================
852*
853* BEGIN pivot search
854*
855* Case(1)
856* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
857* (used to handle NaN and Inf)
858*
859.NOT..LT. IF( ( ABSAKKALPHA*COLMAX ) ) THEN
860*
861* no interchange, use 1-by-1 pivot block
862*
863 KP = K
864*
865 ELSE
866*
867 DONE = .FALSE.
868*
869* Loop until pivot found
870*
871 72 CONTINUE
872*
873* BEGIN pivot search loop body
874*
875*
876* Copy column IMAX to column k+1 of W and update it
877*
878 CALL CCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1)
879 CALL CLACGV( IMAX-K, W( K, K+1 ), 1 )
880 W( IMAX, K+1 ) = REAL( A( IMAX, IMAX ) )
881*
882.LT. IF( IMAXN )
883 $ CALL CCOPY( N-IMAX, A( IMAX+1, IMAX ), 1,
884 $ W( IMAX+1, K+1 ), 1 )
885*
886.GT. IF( K1 ) THEN
887 CALL CGEMV( 'no transpose', N-K+1, K-1, -CONE,
888 $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW,
889 $ CONE, W( K, K+1 ), 1 )
890 W( IMAX, K+1 ) = REAL( W( IMAX, K+1 ) )
891 END IF
892*
893* JMAX is the column-index of the largest off-diagonal
894* element in row IMAX, and ROWMAX is its absolute value.
895* Determine both ROWMAX and JMAX.
896*
897.NE. IF( IMAXK ) THEN
898 JMAX = K - 1 + ICAMAX( IMAX-K, W( K, K+1 ), 1 )
899 ROWMAX = CABS1( W( JMAX, K+1 ) )
900 ELSE
901 ROWMAX = ZERO
902 END IF
903*
904.LT. IF( IMAXN ) THEN
905 ITEMP = IMAX + ICAMAX( N-IMAX, W( IMAX+1, K+1 ), 1)
906 STEMP = CABS1( W( ITEMP, K+1 ) )
907.GT. IF( STEMPROWMAX ) THEN
908 ROWMAX = STEMP
909 JMAX = ITEMP
910 END IF
911 END IF
912*
913* Case(2)
914* Equivalent to testing for
915* ABS( REAL( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX
916* (used to handle NaN and Inf)
917*
918.NOT. IF( ( ABS( REAL( W( IMAX,K+1 ) ) )
919.LT. $ ALPHA*ROWMAX ) ) THEN
920*
921* interchange rows and columns K and IMAX,
922* use 1-by-1 pivot block
923*
924 KP = IMAX
925*
926* copy column K+1 of W to column K of W
927*
928 CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
929*
930 DONE = .TRUE.
931*
932* Case(3)
933* Equivalent to testing for ROWMAX.EQ.COLMAX,
934* (used to handle NaN and Inf)
935*
936.EQ..OR..LE. ELSE IF( ( PJMAX ) ( ROWMAXCOLMAX ) )
937 $ THEN
938*
939* interchange rows and columns K+1 and IMAX,
940* use 2-by-2 pivot block
941*
942 KP = IMAX
943 KSTEP = 2
944 DONE = .TRUE.
945*
946* Case(4)
947 ELSE
948*
949* Pivot not found: set params and repeat
950*
951 P = IMAX
952 COLMAX = ROWMAX
953 IMAX = JMAX
954*
955* Copy updated JMAXth (next IMAXth) column to Kth of W
956*
957 CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
958*
959 END IF
960*
961*
962* End pivot search loop body
963*
964.NOT. IF( DONE ) GOTO 72
965*
966 END IF
967*
968* END pivot search
969*
970* ============================================================
971*
972* KK is the column of A where pivoting step stopped
973*
974 KK = K + KSTEP - 1
975*
976* Interchange rows and columns P and K (only for 2-by-2 pivot).
977* Updated column P is already stored in column K of W.
978*
979.EQ..AND..NE. IF( ( KSTEP2 ) ( PK ) ) THEN
980*
981* Copy non-updated column KK-1 to column P of submatrix A
982* at step K. No need to copy element into columns
983* K and K+1 of A for 2-by-2 pivot, since these columns
984* will be later overwritten.
985*
986 A( P, P ) = REAL( A( K, K ) )
987 CALL CCOPY( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA )
988 CALL CLACGV( P-K-1, A( P, K+1 ), LDA )
989.LT. IF( PN )
990 $ CALL CCOPY( N-P, A( P+1, K ), 1, A( P+1, P ), 1 )
991*
992* Interchange rows K and P in first K-1 columns of A
993* (columns K and K+1 of A for 2-by-2 pivot will be
994* later overwritten). Interchange rows K and P
995* in first KK columns of W.
996*
997.GT. IF( K1 )
998 $ CALL CSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA )
999 CALL CSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW )
1000 END IF
1001*
1002* Interchange rows and columns KP and KK.
1003* Updated column KP is already stored in column KK of W.
1004*
1005.NE. IF( KPKK ) THEN
1006*
1007* Copy non-updated column KK to column KP of submatrix A
1008* at step K. No need to copy element into column K
1009* (or K and K+1 for 2-by-2 pivot) of A, since these columns
1010* will be later overwritten.
1011*
1012 A( KP, KP ) = REAL( A( KK, KK ) )
1013 CALL CCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
1014 $ LDA )
1015 CALL CLACGV( KP-KK-1, A( KP, KK+1 ), LDA )
1016.LT. IF( KPN )
1017 $ CALL CCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
1018*
1019* Interchange rows KK and KP in first K-1 columns of A
1020* (column K (or K and K+1 for 2-by-2 pivot) of A will be
1021* later overwritten). Interchange rows KK and KP
1022* in first KK columns of W.
1023*
1024.GT. IF( K1 )
1025 $ CALL CSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
1026 CALL CSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
1027 END IF
1028*
1029.EQ. IF( KSTEP1 ) THEN
1030*
1031* 1-by-1 pivot block D(k): column k of W now holds
1032*
1033* W(k) = L(k)*D(k),
1034*
1035* where L(k) is the k-th column of L
1036*
1037* (1) Store subdiag. elements of column L(k)
1038* and 1-by-1 block D(k) in column k of A.
1039* (NOTE: Diagonal element L(k,k) is a UNIT element
1040* and not stored)
1041* A(k,k) := D(k,k) = W(k,k)
1042* A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k)
1043*
1044* (NOTE: No need to use for Hermitian matrix
1045* A( K, K ) = REAL( W( K, K) ) to separately copy diagonal
1046* element D(k,k) from W (potentially saves only one load))
1047 CALL CCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
1048.LT. IF( KN ) THEN
1049*
1050* (NOTE: No need to check if A(k,k) is NOT ZERO,
1051* since that was ensured earlier in pivot search:
1052* case A(k,k) = 0 falls into 2x2 pivot case(3))
1053*
1054* Handle division by a small number
1055*
1056 T = REAL( A( K, K ) )
1057.GE. IF( ABS( T )SFMIN ) THEN
1058 R1 = ONE / T
1059 CALL CSSCAL( N-K, R1, A( K+1, K ), 1 )
1060 ELSE
1061 DO 74 II = K + 1, N
1062 A( II, K ) = A( II, K ) / T
1063 74 CONTINUE
1064 END IF
1065*
1066* (2) Conjugate column W(k)
1067*
1068 CALL CLACGV( N-K, W( K+1, K ), 1 )
1069*
1070* Store the subdiagonal element of D in array E
1071*
1072 E( K ) = CZERO
1073*
1074 END IF
1075*
1076 ELSE
1077*
1078* 2-by-2 pivot block D(k): columns k and k+1 of W now hold
1079*
1080* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
1081*
1082* where L(k) and L(k+1) are the k-th and (k+1)-th columns
1083* of L
1084*
1085* (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2
1086* block D(k:k+1,k:k+1) in columns k and k+1 of A.
1087* NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT
1088* block and not stored.
1089* A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1)
1090* A(k+2:N,k:k+1) := L(k+2:N,k:k+1) =
1091* = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) )
1092*
1093.LT. IF( KN-1 ) THEN
1094*
1095* Factor out the columns of the inverse of 2-by-2 pivot
1096* block D, so that each column contains 1, to reduce the
1097* number of FLOPS when we multiply panel
1098* ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
1099*
1100* D**(-1) = ( d11 cj(d21) )**(-1) =
1101* ( d21 d22 )
1102*
1103* = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
1104* ( (-d21) ( d11 ) )
1105*
1106* = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
1107*
1108* * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
1109* ( ( -1 ) ( d11/conj(d21) ) )
1110*
1111* = 1/(|d21|**2) * 1/(D22*D11-1) *
1112*
1113* * ( d21*( D11 ) conj(d21)*( -1 ) ) =
1114* ( ( -1 ) ( D22 ) )
1115*
1116* = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
1117* ( ( -1 ) ( D22 ) )
1118*
1119* = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
1120* ( ( -1 ) ( D22 ) )
1121*
1122* Handle division by a small number. (NOTE: order of
1123* operations is important)
1124*
1125* = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) )
1126* ( (( -1 ) ) (( D22 ) ) ),
1127*
1128* where D11 = d22/d21,
1129* D22 = d11/conj(d21),
1130* D21 = d21,
1131* T = 1/(D22*D11-1).
1132*
1133* (NOTE: No need to check for division by ZERO,
1134* since that was ensured earlier in pivot search:
1135* (a) d21 != 0 in 2x2 pivot case(4),
1136* since |d21| should be larger than |d11| and |d22|;
1137* (b) (D22*D11 - 1) != 0, since from (a),
1138* both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
1139*
1140 D21 = W( K+1, K )
1141 D11 = W( K+1, K+1 ) / D21
1142 D22 = W( K, K ) / CONJG( D21 )
1143 T = ONE / ( REAL( D11*D22 )-ONE )
1144*
1145* Update elements in columns A(k) and A(k+1) as
1146* dot products of rows of ( W(k) W(k+1) ) and columns
1147* of D**(-1)
1148*
1149 DO 80 J = K + 2, N
1150 A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) /
1151 $ CONJG( D21 ) )
1152 A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) /
1153 $ D21 )
1154 80 CONTINUE
1155 END IF
1156*
1157* Copy diagonal elements of D(K) to A,
1158* copy subdiagonal element of D(K) to E(K) and
1159* ZERO out subdiagonal entry of A
1160*
1161 A( K, K ) = W( K, K )
1162 A( K+1, K ) = CZERO
1163 A( K+1, K+1 ) = W( K+1, K+1 )
1164 E( K ) = W( K+1, K )
1165 E( K+1 ) = CZERO
1166*
1167* (2) Conjugate columns W(k) and W(k+1)
1168*
1169 CALL CLACGV( N-K, W( K+1, K ), 1 )
1170 CALL CLACGV( N-K-1, W( K+2, K+1 ), 1 )
1171*
1172 END IF
1173*
1174* End column K is nonsingular
1175*
1176 END IF
1177*
1178* Store details of the interchanges in IPIV
1179*
1180.EQ. IF( KSTEP1 ) THEN
1181 IPIV( K ) = KP
1182 ELSE
1183 IPIV( K ) = -P
1184 IPIV( K+1 ) = -KP
1185 END IF
1186*
1187* Increase K and return to the start of the main loop
1188*
1189 K = K + KSTEP
1190 GO TO 70
1191*
1192 90 CONTINUE
1193*
1194* Update the lower triangle of A22 (= A(k:n,k:n)) as
1195*
1196* A22 := A22 - L21*D*L21**H = A22 - L21*W**H
1197*
1198* computing blocks of NB columns at a time (note that conjg(W) is
1199* actually stored)
1200*
1201 DO 110 J = K, N, NB
1202 JB = MIN( NB, N-J+1 )
1203*
1204* Update the lower triangle of the diagonal block
1205*
1206 DO 100 JJ = J, J + JB - 1
1207 A( JJ, JJ ) = REAL( A( JJ, JJ ) )
1208 CALL CGEMV( 'no transpose', J+JB-JJ, K-1, -CONE,
1209 $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
1210 $ A( JJ, JJ ), 1 )
1211 A( JJ, JJ ) = REAL( A( JJ, JJ ) )
1212 100 CONTINUE
1213*
1214* Update the rectangular subdiagonal block
1215*
1216.LE. IF( J+JBN )
1217 $ CALL CGEMM( 'no transpose', 'transpose', N-J-JB+1, JB,
1218 $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
1219 $ LDW, CONE, A( J+JB, J ), LDA )
1220 110 CONTINUE
1221*
1222* Set KB to the number of columns factorized
1223*
1224 KB = K - 1
1225*
1226 END IF
1227 RETURN
1228*
1229* End of CLAHEF_RK
1230*
1231 END
subroutine clahef_rk(uplo, n, nb, kb, a, lda, e, ipiv, w, ldw, info)
CLAHEF_RK computes a partial factorization of a complex Hermitian indefinite matrix using bounded Bun...
Definition clahef_rk.f:262
subroutine clacgv(n, x, incx)
CLACGV conjugates a complex vector.
Definition clacgv.f:74
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
Definition cswap.f:81
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
Definition ccopy.f:81
subroutine cgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
CGEMV
Definition cgemv.f:158
subroutine cgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
CGEMM
Definition cgemm.f:187
#define min(a, b)
Definition macros.h:20
#define max(a, b)
Definition macros.h:21