numeric-linalg
Educational material on the SciPy implementation of numerical linear algebra algorithms
Name | Size | Mode | |
.. | |||
lapack/SRC/clahef_rk.f | 41414B | -rw-r--r-- |
0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 0040 0041 0042 0043 0044 0045 0046 0047 0048 0049 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 0080 0081 0082 0083 0084 0085 0086 0087 0088 0089 0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 0110 0111 0112 0113 0114 0115 0116 0117 0118 0119 0120 0121 0122 0123 0124 0125 0126 0127 0128 0129 0130 0131 0132 0133 0134 0135 0136 0137 0138 0139 0140 0141 0142 0143 0144 0145 0146 0147 0148 0149 0150 0151 0152 0153 0154 0155 0156 0157 0158 0159 0160 0161 0162 0163 0164 0165 0166 0167 0168 0169 0170 0171 0172 0173 0174 0175 0176 0177 0178 0179 0180 0181 0182 0183 0184 0185 0186 0187 0188 0189 0190 0191 0192 0193 0194 0195 0196 0197 0198 0199 0200 0201 0202 0203 0204 0205 0206 0207 0208 0209 0210 0211 0212 0213 0214 0215 0216 0217 0218 0219 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 0230 0231 0232 0233 0234 0235 0236 0237 0238 0239 0240 0241 0242 0243 0244 0245 0246 0247 0248 0249 0250 0251 0252 0253 0254 0255 0256 0257 0258 0259 0260 0261 0262 0263 0264 0265 0266 0267 0268 0269 0270 0271 0272 0273 0274 0275 0276 0277 0278 0279 0280 0281 0282 0283 0284 0285 0286 0287 0288 0289 0290 0291 0292 0293 0294 0295 0296 0297 0298 0299 0300 0301 0302 0303 0304 0305 0306 0307 0308 0309 0310 0311 0312 0313 0314 0315 0316 0317 0318 0319 0320 0321 0322 0323 0324 0325 0326 0327 0328 0329 0330 0331 0332 0333 0334 0335 0336 0337 0338 0339 0340 0341 0342 0343 0344 0345 0346 0347 0348 0349 0350 0351 0352 0353 0354 0355 0356 0357 0358 0359 0360 0361 0362 0363 0364 0365 0366 0367 0368 0369 0370 0371 0372 0373 0374 0375 0376 0377 0378 0379 0380 0381 0382 0383 0384 0385 0386 0387 0388 0389 0390 0391 0392 0393 0394 0395 0396 0397 0398 0399 0400 0401 0402 0403 0404 0405 0406 0407 0408 0409 0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 0430 0431 0432 0433 0434 0435 0436 0437 0438 0439 0440 0441 0442 0443 0444 0445 0446 0447 0448 0449 0450 0451 0452 0453 0454 0455 0456 0457 0458 0459 0460 0461 0462 0463 0464 0465 0466 0467 0468 0469 0470 0471 0472 0473 0474 0475 0476 0477 0478 0479 0480 0481 0482 0483 0484 0485 0486 0487 0488 0489 0490 0491 0492 0493 0494 0495 0496 0497 0498 0499 0500 0501 0502 0503 0504 0505 0506 0507 0508 0509 0510 0511 0512 0513 0514 0515 0516 0517 0518 0519 0520 0521 0522 0523 0524 0525 0526 0527 0528 0529 0530 0531 0532 0533 0534 0535 0536 0537 0538 0539 0540 0541 0542 0543 0544 0545 0546 0547 0548 0549 0550 0551 0552 0553 0554 0555 0556 0557 0558 0559 0560 0561 0562 0563 0564 0565 0566 0567 0568 0569 0570 0571 0572 0573 0574 0575 0576 0577 0578 0579 0580 0581 0582 0583 0584 0585 0586 0587 0588 0589 0590 0591 0592 0593 0594 0595 0596 0597 0598 0599 0600 0601 0602 0603 0604 0605 0606 0607 0608 0609 0610 0611 0612 0613 0614 0615 0616 0617 0618 0619 0620 0621 0622 0623 0624 0625 0626 0627 0628 0629 0630 0631 0632 0633 0634 0635 0636 0637 0638 0639 0640 0641 0642 0643 0644 0645 0646 0647 0648 0649 0650 0651 0652 0653 0654 0655 0656 0657 0658 0659 0660 0661 0662 0663 0664 0665 0666 0667 0668 0669 0670 0671 0672 0673 0674 0675 0676 0677 0678 0679 0680 0681 0682 0683 0684 0685 0686 0687 0688 0689 0690 0691 0692 0693 0694 0695 0696 0697 0698 0699 0700 0701 0702 0703 0704 0705 0706 0707 0708 0709 0710 0711 0712 0713 0714 0715 0716 0717 0718 0719 0720 0721 0722 0723 0724 0725 0726 0727 0728 0729 0730 0731 0732 0733 0734 0735 0736 0737 0738 0739 0740 0741 0742 0743 0744 0745 0746 0747 0748 0749 0750 0751 0752 0753 0754 0755 0756 0757 0758 0759 0760 0761 0762 0763 0764 0765 0766 0767 0768 0769 0770 0771 0772 0773 0774 0775 0776 0777 0778 0779 0780 0781 0782 0783 0784 0785 0786 0787 0788 0789 0790 0791 0792 0793 0794 0795 0796 0797 0798 0799 0800 0801 0802 0803 0804 0805 0806 0807 0808 0809 0810 0811 0812 0813 0814 0815 0816 0817 0818 0819 0820 0821 0822 0823 0824 0825 0826 0827 0828 0829 0830 0831 0832 0833 0834 0835 0836 0837 0838 0839 0840 0841 0842 0843 0844 0845 0846 0847 0848 0849 0850 0851 0852 0853 0854 0855 0856 0857 0858 0859 0860 0861 0862 0863 0864 0865 0866 0867 0868 0869 0870 0871 0872 0873 0874 0875 0876 0877 0878 0879 0880 0881 0882 0883 0884 0885 0886 0887 0888 0889 0890 0891 0892 0893 0894 0895 0896 0897 0898 0899 0900 0901 0902 0903 0904 0905 0906 0907 0908 0909 0910 0911 0912 0913 0914 0915 0916 0917 0918 0919 0920 0921 0922 0923 0924 0925 0926 0927 0928 0929 0930 0931 0932 0933 0934 0935 0936 0937 0938 0939 0940 0941 0942 0943 0944 0945 0946 0947 0948 0949 0950 0951 0952 0953 0954 0955 0956 0957 0958 0959 0960 0961 0962 0963 0964 0965 0966 0967 0968 0969 0970 0971 0972 0973 0974 0975 0976 0977 0978 0979 0980 0981 0982 0983 0984 0985 0986 0987 0988 0989 0990 0991 0992 0993 0994 0995 0996 0997 0998 0999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
*> \brief \b CLAHEF_RK computes a partial factorization of a complex Hermitian indefinite matrix using bounded Bunch-Kaufman (rook) diagonal pivoting method. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CLAHEF_RK + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahef_rk.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahef_rk.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahef_rk.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, * INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, KB, LDA, LDW, N, NB * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX A( LDA, * ), E( * ), W( LDW, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> CLAHEF_RK computes a partial factorization of a complex Hermitian *> matrix A using the bounded Bunch-Kaufman (rook) diagonal *> pivoting method. The partial factorization has the form: *> *> A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: *> ( 0 U22 ) ( 0 D ) ( U12**H U22**H ) *> *> A = ( L11 0 ) ( D 0 ) ( L11**H L21**H ) if UPLO = 'L', *> ( L21 I ) ( 0 A22 ) ( 0 I ) *> *> where the order of D is at most NB. The actual order is returned in *> the argument KB, and is either NB or NB-1, or N if N <= NB. *> *> CLAHEF_RK is an auxiliary routine called by CHETRF_RK. It uses *> blocked code (calling Level 3 BLAS) to update the submatrix *> A11 (if UPLO = 'U') or A22 (if UPLO = 'L'). *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the upper or lower triangular part of the *> Hermitian matrix A is stored: *> = 'U': Upper triangular *> = 'L': Lower triangular *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NB *> \verbatim *> NB is INTEGER *> The maximum number of columns of the matrix A that should be *> factored. NB should be at least 2 to allow for 2-by-2 pivot *> blocks. *> \endverbatim *> *> \param[out] KB *> \verbatim *> KB is INTEGER *> The number of columns of A that were actually factored. *> KB is either NB-1 or NB, or N if N <= NB. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> On entry, the Hermitian matrix A. *> If UPLO = 'U': the leading N-by-N upper triangular part *> of A contains the upper triangular part of the matrix A, *> and the strictly lower triangular part of A is not *> referenced. *> *> If UPLO = 'L': the leading N-by-N lower triangular part *> of A contains the lower triangular part of the matrix A, *> and the strictly upper triangular part of A is not *> referenced. *> *> On exit, contains: *> a) ONLY diagonal elements of the Hermitian block diagonal *> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); *> (superdiagonal (or subdiagonal) elements of D *> are stored on exit in array E), and *> b) If UPLO = 'U': factor U in the superdiagonal part of A. *> If UPLO = 'L': factor L in the subdiagonal part of A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[out] E *> \verbatim *> E is COMPLEX array, dimension (N) *> On exit, contains the superdiagonal (or subdiagonal) *> elements of the Hermitian block diagonal matrix D *> with 1-by-1 or 2-by-2 diagonal blocks, where *> If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0; *> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0. *> *> NOTE: For 1-by-1 diagonal block D(k), where *> 1 <= k <= N, the element E(k) is set to 0 in both *> UPLO = 'U' or UPLO = 'L' cases. *> \endverbatim *> *> \param[out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> IPIV describes the permutation matrix P in the factorization *> of matrix A as follows. The absolute value of IPIV(k) *> represents the index of row and column that were *> interchanged with the k-th row and column. The value of UPLO *> describes the order in which the interchanges were applied. *> Also, the sign of IPIV represents the block structure of *> the Hermitian block diagonal matrix D with 1-by-1 or 2-by-2 *> diagonal blocks which correspond to 1 or 2 interchanges *> at each factorization step. *> *> If UPLO = 'U', *> ( in factorization order, k decreases from N to 1 ): *> a) A single positive entry IPIV(k) > 0 means: *> D(k,k) is a 1-by-1 diagonal block. *> If IPIV(k) != k, rows and columns k and IPIV(k) were *> interchanged in the submatrix A(1:N,N-KB+1:N); *> If IPIV(k) = k, no interchange occurred. *> *> *> b) A pair of consecutive negative entries *> IPIV(k) < 0 and IPIV(k-1) < 0 means: *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block. *> (NOTE: negative entries in IPIV appear ONLY in pairs). *> 1) If -IPIV(k) != k, rows and columns *> k and -IPIV(k) were interchanged *> in the matrix A(1:N,N-KB+1:N). *> If -IPIV(k) = k, no interchange occurred. *> 2) If -IPIV(k-1) != k-1, rows and columns *> k-1 and -IPIV(k-1) were interchanged *> in the submatrix A(1:N,N-KB+1:N). *> If -IPIV(k-1) = k-1, no interchange occurred. *> *> c) In both cases a) and b) is always ABS( IPIV(k) ) <= k. *> *> d) NOTE: Any entry IPIV(k) is always NONZERO on output. *> *> If UPLO = 'L', *> ( in factorization order, k increases from 1 to N ): *> a) A single positive entry IPIV(k) > 0 means: *> D(k,k) is a 1-by-1 diagonal block. *> If IPIV(k) != k, rows and columns k and IPIV(k) were *> interchanged in the submatrix A(1:N,1:KB). *> If IPIV(k) = k, no interchange occurred. *> *> b) A pair of consecutive negative entries *> IPIV(k) < 0 and IPIV(k+1) < 0 means: *> D(k:k+1,k:k+1) is a 2-by-2 diagonal block. *> (NOTE: negative entries in IPIV appear ONLY in pairs). *> 1) If -IPIV(k) != k, rows and columns *> k and -IPIV(k) were interchanged *> in the submatrix A(1:N,1:KB). *> If -IPIV(k) = k, no interchange occurred. *> 2) If -IPIV(k+1) != k+1, rows and columns *> k-1 and -IPIV(k-1) were interchanged *> in the submatrix A(1:N,1:KB). *> If -IPIV(k+1) = k+1, no interchange occurred. *> *> c) In both cases a) and b) is always ABS( IPIV(k) ) >= k. *> *> d) NOTE: Any entry IPIV(k) is always NONZERO on output. *> \endverbatim *> *> \param[out] W *> \verbatim *> W is COMPLEX array, dimension (LDW,NB) *> \endverbatim *> *> \param[in] LDW *> \verbatim *> LDW is INTEGER *> The leading dimension of the array W. LDW >= max(1,N). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> *> < 0: If INFO = -k, the k-th argument had an illegal value *> *> > 0: If INFO = k, the matrix A is singular, because: *> If UPLO = 'U': column k in the upper *> triangular part of A contains all zeros. *> If UPLO = 'L': column k in the lower *> triangular part of A contains all zeros. *> *> Therefore D(k,k) is exactly zero, and superdiagonal *> elements of column k of U (or subdiagonal elements of *> column k of L ) are all zeros. The factorization has *> been completed, but the block diagonal matrix D is *> exactly singular, and division by zero will occur if *> it is used to solve a system of equations. *> *> NOTE: INFO only stores the first occurrence of *> a singularity, any subsequent occurrence of singularity *> is not stored in INFO even though the factorization *> always completes. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \ingroup lahef_rk * *> \par Contributors: * ================== *> *> \verbatim *> *> December 2016, Igor Kozachenko, *> Computer Science Division, *> University of California, Berkeley *> *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, *> School of Mathematics, *> University of Manchester *> *> \endverbatim * * ===================================================================== SUBROUTINE CLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, $ INFO ) * * -- LAPACK computational routine -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, KB, LDA, LDW, N, NB * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), W( LDW, * ), E( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) REAL EIGHT, SEVTEN PARAMETER ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 ) COMPLEX CONE, CZERO PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ), $ CZERO = ( 0.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. LOGICAL DONE INTEGER IMAX, ITEMP, II, J, JMAX, K, KK, KKW, $ KP, KSTEP, KW, P REAL ABSAKK, ALPHA, COLMAX, STEMP, R1, ROWMAX, T, $ SFMIN COMPLEX D11, D21, D22, Z * .. * .. External Functions .. LOGICAL LSAME INTEGER ICAMAX REAL SLAMCH EXTERNAL LSAME, ICAMAX, SLAMCH * .. * .. External Subroutines .. EXTERNAL CCOPY, CSSCAL, CGEMM, CGEMV, CLACGV, $ CSWAP * .. * .. Intrinsic Functions .. INTRINSIC ABS, CONJG, AIMAG, MAX, MIN, REAL, SQRT * .. * .. Statement Functions .. REAL CABS1 * .. * .. Statement Function definitions .. CABS1( Z ) = ABS( REAL( Z ) ) + ABS( AIMAG( Z ) ) * .. * .. Executable Statements .. * INFO = 0 * * Initialize ALPHA for use in choosing pivot block size. * ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT * * Compute machine safe minimum * SFMIN = SLAMCH( 'S' ) * IF( LSAME( UPLO, 'U' ) ) THEN * * Factorize the trailing columns of A using the upper triangle * of A and working backwards, and compute the matrix W = U12*D * for use in updating A11 (note that conjg(W) is actually stored) * * Initialize the first entry of array E, where superdiagonal * elements of D are stored * E( 1 ) = CZERO * * K is the main loop index, decreasing from N in steps of 1 or 2 * K = N 10 CONTINUE * * KW is the column of W which corresponds to column K of A * KW = NB + K - N * * Exit from loop * IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 ) $ GO TO 30 * KSTEP = 1 P = K * * Copy column K of A to column KW of W and update it * IF( K.GT.1 ) $ CALL CCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 ) W( K, KW ) = REAL( A( K, K ) ) IF( K.LT.N ) THEN CALL CGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), $ LDA, $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 ) W( K, KW ) = REAL( W( K, KW ) ) END IF * * Determine rows and columns to be interchanged and whether * a 1-by-1 or 2-by-2 pivot block will be used * ABSAKK = ABS( REAL( W( K, KW ) ) ) * * IMAX is the row-index of the largest off-diagonal element in * column K, and COLMAX is its absolute value. * Determine both COLMAX and IMAX. * IF( K.GT.1 ) THEN IMAX = ICAMAX( K-1, W( 1, KW ), 1 ) COLMAX = CABS1( W( IMAX, KW ) ) ELSE COLMAX = ZERO END IF * IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN * * Column K is zero or underflow: set INFO and continue * IF( INFO.EQ.0 ) $ INFO = K KP = K A( K, K ) = REAL( W( K, KW ) ) IF( K.GT.1 ) $ CALL CCOPY( K-1, W( 1, KW ), 1, A( 1, K ), 1 ) * * Set E( K ) to zero * IF( K.GT.1 ) $ E( K ) = CZERO * ELSE * * ============================================================ * * BEGIN pivot search * * Case(1) * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX * (used to handle NaN and Inf) IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN * * no interchange, use 1-by-1 pivot block * KP = K * ELSE * * Lop until pivot found * DONE = .FALSE. * 12 CONTINUE * * BEGIN pivot search loop body * * * Copy column IMAX to column KW-1 of W and update it * IF( IMAX.GT.1 ) $ CALL CCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, $ KW-1 ), $ 1 ) W( IMAX, KW-1 ) = REAL( A( IMAX, IMAX ) ) * CALL CCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, $ W( IMAX+1, KW-1 ), 1 ) CALL CLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 ) * IF( K.LT.N ) THEN CALL CGEMV( 'No transpose', K, N-K, -CONE, $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW, $ CONE, W( 1, KW-1 ), 1 ) W( IMAX, KW-1 ) = REAL( W( IMAX, KW-1 ) ) END IF * * JMAX is the column-index of the largest off-diagonal * element in row IMAX, and ROWMAX is its absolute value. * Determine both ROWMAX and JMAX. * IF( IMAX.NE.K ) THEN JMAX = IMAX + ICAMAX( K-IMAX, W( IMAX+1, KW-1 ), $ 1 ) ROWMAX = CABS1( W( JMAX, KW-1 ) ) ELSE ROWMAX = ZERO END IF * IF( IMAX.GT.1 ) THEN ITEMP = ICAMAX( IMAX-1, W( 1, KW-1 ), 1 ) STEMP = CABS1( W( ITEMP, KW-1 ) ) IF( STEMP.GT.ROWMAX ) THEN ROWMAX = STEMP JMAX = ITEMP END IF END IF * * Case(2) * Equivalent to testing for * ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX * (used to handle NaN and Inf) * IF( .NOT.( ABS( REAL( W( IMAX,KW-1 ) ) ) $ .LT.ALPHA*ROWMAX ) ) THEN * * interchange rows and columns K and IMAX, * use 1-by-1 pivot block * KP = IMAX * * copy column KW-1 of W to column KW of W * CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) * DONE = .TRUE. * * Case(3) * Equivalent to testing for ROWMAX.EQ.COLMAX, * (used to handle NaN and Inf) * ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) ) $ THEN * * interchange rows and columns K-1 and IMAX, * use 2-by-2 pivot block * KP = IMAX KSTEP = 2 DONE = .TRUE. * * Case(4) ELSE * * Pivot not found: set params and repeat * P = IMAX COLMAX = ROWMAX IMAX = JMAX * * Copy updated JMAXth (next IMAXth) column to Kth of W * CALL CCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) * END IF * * * END pivot search loop body * IF( .NOT.DONE ) GOTO 12 * END IF * * END pivot search * * ============================================================ * * KK is the column of A where pivoting step stopped * KK = K - KSTEP + 1 * * KKW is the column of W which corresponds to column KK of A * KKW = NB + KK - N * * Interchange rows and columns P and K. * Updated column P is already stored in column KW of W. * IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN * * Copy non-updated column K to column P of submatrix A * at step K. No need to copy element into columns * K and K-1 of A for 2-by-2 pivot, since these columns * will be later overwritten. * A( P, P ) = REAL( A( K, K ) ) CALL CCOPY( K-1-P, A( P+1, K ), 1, A( P, P+1 ), $ LDA ) CALL CLACGV( K-1-P, A( P, P+1 ), LDA ) IF( P.GT.1 ) $ CALL CCOPY( P-1, A( 1, K ), 1, A( 1, P ), 1 ) * * Interchange rows K and P in the last K+1 to N columns of A * (columns K and K-1 of A for 2-by-2 pivot will be * later overwritten). Interchange rows K and P * in last KKW to NB columns of W. * IF( K.LT.N ) $ CALL CSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), $ LDA ) CALL CSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), $ LDW ) END IF * * Interchange rows and columns KP and KK. * Updated column KP is already stored in column KKW of W. * IF( KP.NE.KK ) THEN * * Copy non-updated column KK to column KP of submatrix A * at step K. No need to copy element into column K * (or K and K-1 for 2-by-2 pivot) of A, since these columns * will be later overwritten. * A( KP, KP ) = REAL( A( KK, KK ) ) CALL CCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), $ LDA ) CALL CLACGV( KK-1-KP, A( KP, KP+1 ), LDA ) IF( KP.GT.1 ) $ CALL CCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) * * Interchange rows KK and KP in last K+1 to N columns of A * (columns K (or K and K-1 for 2-by-2 pivot) of A will be * later overwritten). Interchange rows KK and KP * in last KKW to NB columns of W. * IF( K.LT.N ) $ CALL CSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), $ LDA ) CALL CSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ), $ LDW ) END IF * IF( KSTEP.EQ.1 ) THEN * * 1-by-1 pivot block D(k): column kw of W now holds * * W(kw) = U(k)*D(k), * * where U(k) is the k-th column of U * * (1) Store subdiag. elements of column U(k) * and 1-by-1 block D(k) in column k of A. * (NOTE: Diagonal element U(k,k) is a UNIT element * and not stored) * A(k,k) := D(k,k) = W(k,kw) * A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k) * * (NOTE: No need to use for Hermitian matrix * A( K, K ) = REAL( W( K, K) ) to separately copy diagonal * element D(k,k) from W (potentially saves only one load)) CALL CCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) IF( K.GT.1 ) THEN * * (NOTE: No need to check if A(k,k) is NOT ZERO, * since that was ensured earlier in pivot search: * case A(k,k) = 0 falls into 2x2 pivot case(3)) * * Handle division by a small number * T = REAL( A( K, K ) ) IF( ABS( T ).GE.SFMIN ) THEN R1 = ONE / T CALL CSSCAL( K-1, R1, A( 1, K ), 1 ) ELSE DO 14 II = 1, K-1 A( II, K ) = A( II, K ) / T 14 CONTINUE END IF * * (2) Conjugate column W(kw) * CALL CLACGV( K-1, W( 1, KW ), 1 ) * * Store the superdiagonal element of D in array E * E( K ) = CZERO * END IF * ELSE * * 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold * * ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k) * * where U(k) and U(k-1) are the k-th and (k-1)-th columns * of U * * (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2 * block D(k-1:k,k-1:k) in columns k-1 and k of A. * (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT * block and not stored) * A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw) * A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) = * = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) ) * IF( K.GT.2 ) THEN * * Factor out the columns of the inverse of 2-by-2 pivot * block D, so that each column contains 1, to reduce the * number of FLOPS when we multiply panel * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). * * D**(-1) = ( d11 cj(d21) )**(-1) = * ( d21 d22 ) * * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = * ( (-d21) ( d11 ) ) * * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * * * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = * ( ( -1 ) ( d11/conj(d21) ) ) * * = 1/(|d21|**2) * 1/(D22*D11-1) * * * * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * Handle division by a small number. (NOTE: order of * operations is important) * * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) ) * ( (( -1 ) ) (( D22 ) ) ), * * where D11 = d22/d21, * D22 = d11/conj(d21), * D21 = d21, * T = 1/(D22*D11-1). * * (NOTE: No need to check for division by ZERO, * since that was ensured earlier in pivot search: * (a) d21 != 0 in 2x2 pivot case(4), * since |d21| should be larger than |d11| and |d22|; * (b) (D22*D11 - 1) != 0, since from (a), * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) * D21 = W( K-1, KW ) D11 = W( K, KW ) / CONJG( D21 ) D22 = W( K-1, KW-1 ) / D21 T = ONE / ( REAL( D11*D22 )-ONE ) * * Update elements in columns A(k-1) and A(k) as * dot products of rows of ( W(kw-1) W(kw) ) and columns * of D**(-1) * DO 20 J = 1, K - 2 A( J, K-1 ) = T*( ( D11*W( J, KW-1 )-W( J, KW ) ) / $ D21 ) A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) / $ CONJG( D21 ) ) 20 CONTINUE END IF * * Copy diagonal elements of D(K) to A, * copy superdiagonal element of D(K) to E(K) and * ZERO out superdiagonal entry of A * A( K-1, K-1 ) = W( K-1, KW-1 ) A( K-1, K ) = CZERO A( K, K ) = W( K, KW ) E( K ) = W( K-1, KW ) E( K-1 ) = CZERO * * (2) Conjugate columns W(kw) and W(kw-1) * CALL CLACGV( K-1, W( 1, KW ), 1 ) CALL CLACGV( K-2, W( 1, KW-1 ), 1 ) * END IF * * End column K is nonsingular * END IF * * Store details of the interchanges in IPIV * IF( KSTEP.EQ.1 ) THEN IPIV( K ) = KP ELSE IPIV( K ) = -P IPIV( K-1 ) = -KP END IF * * Decrease K and return to the start of the main loop * K = K - KSTEP GO TO 10 * 30 CONTINUE * * Update the upper triangle of A11 (= A(1:k,1:k)) as * * A11 := A11 - U12*D*U12**H = A11 - U12*W**H * * (note that conjg(W) is actually stored) * CALL CGEMMTR( 'Upper', 'No transpose', 'Transpose', K, N-K, $ -CONE, A( 1, K+1 ), LDA, W( 1, KW+1 ), LDW, $ CONE, A( 1, 1 ), LDA ) * * Set KB to the number of columns factorized * KB = N - K * ELSE * * Factorize the leading columns of A using the lower triangle * of A and working forwards, and compute the matrix W = L21*D * for use in updating A22 (note that conjg(W) is actually stored) * * Initialize the unused last entry of the subdiagonal array E. * E( N ) = CZERO * * K is the main loop index, increasing from 1 in steps of 1 or 2 * K = 1 70 CONTINUE * * Exit from loop * IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N ) $ GO TO 90 * KSTEP = 1 P = K * * Copy column K of A to column K of W and update column K of W * W( K, K ) = REAL( A( K, K ) ) IF( K.LT.N ) $ CALL CCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 ) IF( K.GT.1 ) THEN CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 ) W( K, K ) = REAL( W( K, K ) ) END IF * * Determine rows and columns to be interchanged and whether * a 1-by-1 or 2-by-2 pivot block will be used * ABSAKK = ABS( REAL( W( K, K ) ) ) * * IMAX is the row-index of the largest off-diagonal element in * column K, and COLMAX is its absolute value. * Determine both COLMAX and IMAX. * IF( K.LT.N ) THEN IMAX = K + ICAMAX( N-K, W( K+1, K ), 1 ) COLMAX = CABS1( W( IMAX, K ) ) ELSE COLMAX = ZERO END IF * IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN * * Column K is zero or underflow: set INFO and continue * IF( INFO.EQ.0 ) $ INFO = K KP = K A( K, K ) = REAL( W( K, K ) ) IF( K.LT.N ) $ CALL CCOPY( N-K, W( K+1, K ), 1, A( K+1, K ), 1 ) * * Set E( K ) to zero * IF( K.LT.N ) $ E( K ) = CZERO * ELSE * * ============================================================ * * BEGIN pivot search * * Case(1) * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX * (used to handle NaN and Inf) * IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN * * no interchange, use 1-by-1 pivot block * KP = K * ELSE * DONE = .FALSE. * * Loop until pivot found * 72 CONTINUE * * BEGIN pivot search loop body * * * Copy column IMAX to column k+1 of W and update it * CALL CCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), $ 1) CALL CLACGV( IMAX-K, W( K, K+1 ), 1 ) W( IMAX, K+1 ) = REAL( A( IMAX, IMAX ) ) * IF( IMAX.LT.N ) $ CALL CCOPY( N-IMAX, A( IMAX+1, IMAX ), 1, $ W( IMAX+1, K+1 ), 1 ) * IF( K.GT.1 ) THEN CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW, $ CONE, W( K, K+1 ), 1 ) W( IMAX, K+1 ) = REAL( W( IMAX, K+1 ) ) END IF * * JMAX is the column-index of the largest off-diagonal * element in row IMAX, and ROWMAX is its absolute value. * Determine both ROWMAX and JMAX. * IF( IMAX.NE.K ) THEN JMAX = K - 1 + ICAMAX( IMAX-K, W( K, K+1 ), 1 ) ROWMAX = CABS1( W( JMAX, K+1 ) ) ELSE ROWMAX = ZERO END IF * IF( IMAX.LT.N ) THEN ITEMP = IMAX + ICAMAX( N-IMAX, W( IMAX+1, K+1 ), $ 1) STEMP = CABS1( W( ITEMP, K+1 ) ) IF( STEMP.GT.ROWMAX ) THEN ROWMAX = STEMP JMAX = ITEMP END IF END IF * * Case(2) * Equivalent to testing for * ABS( REAL( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX * (used to handle NaN and Inf) * IF( .NOT.( ABS( REAL( W( IMAX,K+1 ) ) ) $ .LT.ALPHA*ROWMAX ) ) THEN * * interchange rows and columns K and IMAX, * use 1-by-1 pivot block * KP = IMAX * * copy column K+1 of W to column K of W * CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), $ 1 ) * DONE = .TRUE. * * Case(3) * Equivalent to testing for ROWMAX.EQ.COLMAX, * (used to handle NaN and Inf) * ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) ) $ THEN * * interchange rows and columns K+1 and IMAX, * use 2-by-2 pivot block * KP = IMAX KSTEP = 2 DONE = .TRUE. * * Case(4) ELSE * * Pivot not found: set params and repeat * P = IMAX COLMAX = ROWMAX IMAX = JMAX * * Copy updated JMAXth (next IMAXth) column to Kth of W * CALL CCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), $ 1 ) * END IF * * * End pivot search loop body * IF( .NOT.DONE ) GOTO 72 * END IF * * END pivot search * * ============================================================ * * KK is the column of A where pivoting step stopped * KK = K + KSTEP - 1 * * Interchange rows and columns P and K (only for 2-by-2 pivot). * Updated column P is already stored in column K of W. * IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN * * Copy non-updated column KK-1 to column P of submatrix A * at step K. No need to copy element into columns * K and K+1 of A for 2-by-2 pivot, since these columns * will be later overwritten. * A( P, P ) = REAL( A( K, K ) ) CALL CCOPY( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) CALL CLACGV( P-K-1, A( P, K+1 ), LDA ) IF( P.LT.N ) $ CALL CCOPY( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) * * Interchange rows K and P in first K-1 columns of A * (columns K and K+1 of A for 2-by-2 pivot will be * later overwritten). Interchange rows K and P * in first KK columns of W. * IF( K.GT.1 ) $ CALL CSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) CALL CSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW ) END IF * * Interchange rows and columns KP and KK. * Updated column KP is already stored in column KK of W. * IF( KP.NE.KK ) THEN * * Copy non-updated column KK to column KP of submatrix A * at step K. No need to copy element into column K * (or K and K+1 for 2-by-2 pivot) of A, since these columns * will be later overwritten. * A( KP, KP ) = REAL( A( KK, KK ) ) CALL CCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), $ LDA ) CALL CLACGV( KP-KK-1, A( KP, KK+1 ), LDA ) IF( KP.LT.N ) $ CALL CCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), $ 1 ) * * Interchange rows KK and KP in first K-1 columns of A * (column K (or K and K+1 for 2-by-2 pivot) of A will be * later overwritten). Interchange rows KK and KP * in first KK columns of W. * IF( K.GT.1 ) $ CALL CSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) CALL CSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW ) END IF * IF( KSTEP.EQ.1 ) THEN * * 1-by-1 pivot block D(k): column k of W now holds * * W(k) = L(k)*D(k), * * where L(k) is the k-th column of L * * (1) Store subdiag. elements of column L(k) * and 1-by-1 block D(k) in column k of A. * (NOTE: Diagonal element L(k,k) is a UNIT element * and not stored) * A(k,k) := D(k,k) = W(k,k) * A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k) * * (NOTE: No need to use for Hermitian matrix * A( K, K ) = REAL( W( K, K) ) to separately copy diagonal * element D(k,k) from W (potentially saves only one load)) CALL CCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) IF( K.LT.N ) THEN * * (NOTE: No need to check if A(k,k) is NOT ZERO, * since that was ensured earlier in pivot search: * case A(k,k) = 0 falls into 2x2 pivot case(3)) * * Handle division by a small number * T = REAL( A( K, K ) ) IF( ABS( T ).GE.SFMIN ) THEN R1 = ONE / T CALL CSSCAL( N-K, R1, A( K+1, K ), 1 ) ELSE DO 74 II = K + 1, N A( II, K ) = A( II, K ) / T 74 CONTINUE END IF * * (2) Conjugate column W(k) * CALL CLACGV( N-K, W( K+1, K ), 1 ) * * Store the subdiagonal element of D in array E * E( K ) = CZERO * END IF * ELSE * * 2-by-2 pivot block D(k): columns k and k+1 of W now hold * * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) * * where L(k) and L(k+1) are the k-th and (k+1)-th columns * of L * * (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2 * block D(k:k+1,k:k+1) in columns k and k+1 of A. * NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT * block and not stored. * A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1) * A(k+2:N,k:k+1) := L(k+2:N,k:k+1) = * = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) ) * IF( K.LT.N-1 ) THEN * * Factor out the columns of the inverse of 2-by-2 pivot * block D, so that each column contains 1, to reduce the * number of FLOPS when we multiply panel * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). * * D**(-1) = ( d11 cj(d21) )**(-1) = * ( d21 d22 ) * * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = * ( (-d21) ( d11 ) ) * * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * * * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = * ( ( -1 ) ( d11/conj(d21) ) ) * * = 1/(|d21|**2) * 1/(D22*D11-1) * * * * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = * ( ( -1 ) ( D22 ) ) * * Handle division by a small number. (NOTE: order of * operations is important) * * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) ) * ( (( -1 ) ) (( D22 ) ) ), * * where D11 = d22/d21, * D22 = d11/conj(d21), * D21 = d21, * T = 1/(D22*D11-1). * * (NOTE: No need to check for division by ZERO, * since that was ensured earlier in pivot search: * (a) d21 != 0 in 2x2 pivot case(4), * since |d21| should be larger than |d11| and |d22|; * (b) (D22*D11 - 1) != 0, since from (a), * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) * D21 = W( K+1, K ) D11 = W( K+1, K+1 ) / D21 D22 = W( K, K ) / CONJG( D21 ) T = ONE / ( REAL( D11*D22 )-ONE ) * * Update elements in columns A(k) and A(k+1) as * dot products of rows of ( W(k) W(k+1) ) and columns * of D**(-1) * DO 80 J = K + 2, N A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) / $ CONJG( D21 ) ) A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) / $ D21 ) 80 CONTINUE END IF * * Copy diagonal elements of D(K) to A, * copy subdiagonal element of D(K) to E(K) and * ZERO out subdiagonal entry of A * A( K, K ) = W( K, K ) A( K+1, K ) = CZERO A( K+1, K+1 ) = W( K+1, K+1 ) E( K ) = W( K+1, K ) E( K+1 ) = CZERO * * (2) Conjugate columns W(k) and W(k+1) * CALL CLACGV( N-K, W( K+1, K ), 1 ) CALL CLACGV( N-K-1, W( K+2, K+1 ), 1 ) * END IF * * End column K is nonsingular * END IF * * Store details of the interchanges in IPIV * IF( KSTEP.EQ.1 ) THEN IPIV( K ) = KP ELSE IPIV( K ) = -P IPIV( K+1 ) = -KP END IF * * Increase K and return to the start of the main loop * K = K + KSTEP GO TO 70 * 90 CONTINUE * * Update the lower triangle of A22 (= A(k:n,k:n)) as * * A22 := A22 - L21*D*L21**H = A22 - L21*W**H * * (note that conjg(W) is actually stored) * CALL CGEMMTR( 'Lower', 'No transpose', 'Transpose', N-K+1, $ K-1, -CONE, A( K, 1 ), LDA, W( K, 1 ), LDW, $ CONE, A( K, K ), LDA ) * * Set KB to the number of columns factorized * KB = K - 1 * END IF RETURN * * End of CLAHEF_RK * END