diff options
author | Julie <julie@cs.utk.edu> | 2016-11-15 20:39:35 -0800 |
---|---|---|
committer | Julie <julie@cs.utk.edu> | 2016-11-15 20:39:35 -0800 |
commit | ead2c73f1a6dad1342bf32987c0b2f2eaf61f18a (patch) | |
tree | b82e9ad49e12960ad410a418d03d68adc7e2e653 /SRC | |
parent | 39698bc46ca55081ebd94c81c5c95771c9f125cd (diff) | |
download | lapack-ead2c73f1a6dad1342bf32987c0b2f2eaf61f18a.tar.gz lapack-ead2c73f1a6dad1342bf32987c0b2f2eaf61f18a.tar.bz2 lapack-ead2c73f1a6dad1342bf32987c0b2f2eaf61f18a.zip |
Added (S,D,C,Z) (SY,HE) routines, drivers for new rook code
Close #82
Added routines for new factorization code for symmetric indefinite
( or Hermitian indefinite ) matrices with bounded Bunch-Kaufman
( rook ) pivoting algorithm.
New more efficient storage format for factors U ( or L ),
block-diagonal matrix D, and pivoting information stored in IPIV:
factor L is stored explicitly in lower triangle of A;
diagonal of D is stored on the diagonal of A;
subdiagonal elements of D are stored in array E;
IPIV format is the same as in *_ROOK routines, but differs
from SY Bunch-Kaufman routines (e.g. *SYTRF).
The factorization output of these new rook _RK routines is not
compatible
with the existing _ROOK routines and vice versa. This new factorization
format is designed in such a way, that there is a possibility in the
future
to write new Bunch-Kaufman routines that conform to this new
factorization format.
Then the future Bunch-Kaufman routines could share solver
*TRS_3,inversion *TRI_3
and condition estimator *CON_3.
To convert between the factorization formats in both ways the following
routines
are developed:
CONVERSION ROUTINES BETWEEN FACTORIZATION FORMATS
DOUBLE PRECISION (symmetric indefinite matrices):
new file: SRC/dsyconvf.f
new file: SRC/dsyconvf_rook.f
REAL (symmetric indefinite matrices):
new file: SRC/csyconvf.f
new file: SRC/csyconvf_rook.f
COMPLEX*16 (symmetric indefinite and Hermitian indefinite matrices):
new file: SRC/zsyconvf.f
new file: SRC/zsyconvf_rook.f
COMPLEX (symmetric indefinite and Hermitian indefinite matrices):
new file: SRC/ssyconvf.f
new file: SRC/ssyconvf_rook.f
*SYCONVF routine converts between old Bunch-Kaufman storage format (
denote (L1,D1,IPIV1) )
that is used by *SYTRF and new rook storage format ( denote (L2,D2,
IPIV2))
that is used by *SYTRF_RK
*SYCONVF_ROOK routine between old rook storage format ( denote
(L1,D1,IPIV2) )
that is used by *SYTRF_ROOK and new rook storage format ( denote
(L2,D2, IPIV2))
that is used by *SYTRF_RK
ROUTINES AND DRIVERS
DOUBLE PRECISION (symmetric indefinite matrices):
new file: SRC/dsytf2_rk.f BLAS2 unblocked factorization
new file: SRC/dlasyf_rk.f BLAS3 auxiliary blocked partial
factorization
new file: SRC/dsytrf_rk.f BLAS3 blocked factorization
new file: SRC/dsytrs_3.f BLAS3 solver
new file: SRC/dsycon_3.f BLAS3 condition number estimator
new file: SRC/dsytri_3.f BLAS3 inversion, sets the size of work array
and calls *sytri_3x
new file: SRC/dsytri_3x.f BLAS3 auxiliary inversion, actually
computes blocked inversion
new file: SRC/dsysv_rk.f BLAS3 solver driver
REAL (symmetric indefinite matrices):
new file: SRC/ssytf2_rk.f BLAS2 unblocked factorization
new file: SRC/slasyf_rk.f BLAS3 auxiliary blocked partial
factorization
new file: SRC/ssytrf_rk.f BLAS3 blocked factorization
new file: SRC/ssytrs_3.f BLAS3 solver
new file: SRC/ssycon_3.f BLAS3 condition number estimator
new file: SRC/ssytri_3.f BLAS3 inversion, sets the size of work array
and calls *sytri_3x
new file: SRC/ssytri_3x.f BLAS3 auxiliary inversion, actually
computes blocked inversion
new file: SRC/ssysv_rk.f BLAS3 solver driver
COMPLEX*16 (symmetric indefinite matrices):
new file: SRC/zsytf2_rk.f BLAS2 unblocked factorization
new file: SRC/zlasyf_rk.f BLAS3 auxiliary blocked partial
factorization
new file: SRC/zsytrf_rk.f BLAS3 blocked factorization
new file: SRC/zsytrs_3.f BLAS3 solver
new file: SRC/zsycon_3.f BLAS3 condition number estimator
new file: SRC/zsytri_3.f BLAS3 inversion, sets the size of work array
and calls *sytri_3x
new file: SRC/zsytri_3x.f BLAS3 auxiliary inversion, actually
computes blocked inversion
new file: SRC/zsysv_rk.f BLAS3 solver driver
COMPLEX*16 (Hermitian indefinite matrices):
new file: SRC/zhetf2_rk.f BLAS2 unblocked factorization
new file: SRC/zlahef_rk.f BLAS3 auxiliary blocked partial
factorization
new file: SRC/zhetrf_rk.f BLAS3 blocked factorization
new file: SRC/zhetrs_3.f BLAS3 solver
new file: SRC/zhecon_3.f BLAS3 condition number estimator
new file: SRC/zhetri_3.f BLAS3 inversion, sets the size of work array
and calls *sytri_3x
new file: SRC/zhetri_3x.f BLAS3 auxiliary inversion, actually
computes blocked inversion
new file: SRC/zhesv_rk.f BLAS3 solver driver
COMPLEX (symmetric indefinite matrices):
new file: SRC/csytf2_rk.f BLAS2 unblocked factorization
new file: SRC/clasyf_rk.f BLAS3 auxiliary blocked partial
factorization
new file: SRC/csytrf_rk.f BLAS3 blocked factorization
new file: SRC/csytrs_3.f BLAS3 solver
new file: SRC/csycon_3.f BLAS3 condition number estimator
new file: SRC/csytri_3.f BLAS3 inversion, sets the size of work array
and calls *sytri_3x
new file: SRC/csytri_3x.f BLAS3 auxiliary inversion, actually
computes blocked inversion
new file: SRC/csysv_rk.f BLAS3 solver driver
COMPLEX (Hermitian indefinite matrices):
new file: SRC/chetf2_rk.f BLAS2 unblocked factorization
new file: SRC/clahef_rk.f BLAS3 auxiliary blocked partial
factorization
new file: SRC/chetrf_rk.f BLAS3 blocked factorization
new file: SRC/chetrs_3.f BLAS3 solver
new file: SRC/checon_3.f BLAS3 condition number estimator
new file: SRC/chetri_3.f BLAS3 inversion, sets the size of work array
and calls *sytri_3x
new file: SRC/chetri_3x.f BLAS3 auxiliary inversion, actually
computes blocked inversion
new file: SRC/chesv_rk.f BLAS3 solver driver
MISC
modified: SRC/CMakeLists.txt
modified: SRC/Makefile
TEST CODE
modified: TESTING/LIN/CMakeLists.txt
modified: TESTING/LIN/Makefile
modified: TESTING/LIN/aladhd.f
modified: TESTING/LIN/alaerh.f
modified: TESTING/LIN/alahd.f
DOUBLE PRECISION (symmetric indefinite matrices):
modified: TESTING/LIN/dchkaa.f
modified: TESTING/LIN/derrsy.f
modified: TESTING/LIN/derrsyx.f
modified: TESTING/LIN/derrvx.f
modified: TESTING/LIN/derrvxx.f
modified: TESTING/dtest.in
new file: TESTING/LIN/dchksy_rk.f
new file: TESTING/LIN/ddrvsy_rk.f
new file: TESTING/LIN/dsyt01_3.f
REAL (symmetric indefinite matrices):
modified: TESTING/LIN/schkaa.f
modified: TESTING/LIN/serrsy.f
modified: TESTING/LIN/serrsyx.f
modified: TESTING/LIN/serrvx.f
modified: TESTING/LIN/serrvxx.f
modified: TESTING/stest.in
new file: TESTING/LIN/schksy_rk.f
new file: TESTING/LIN/sdrvsy_rk.f
new file: TESTING/LIN/ssyt01_3.f
COMPLEX*16 (symmetric indefinite and Hermitian indefinite matrices):
modified: TESTING/LIN/zchkaa.f
modified: TESTING/LIN/zerrsy.f
modified: TESTING/LIN/zerrsyx.f
modified: TESTING/LIN/zerrhe.f
modified: TESTING/LIN/zerrhex.f
modified: TESTING/LIN/zerrvx.f
modified: TESTING/LIN/zerrvxx.f
modified: TESTING/ztest.in
new file: TESTING/LIN/zchksy_rk.f
new file: TESTING/LIN/zdrvsy_rk.f
new file: TESTING/LIN/zsyt01_3.f
new file: TESTING/LIN/zchkhe_rk.f
new file: TESTING/LIN/zdrvhe_rk.f
new file: TESTING/LIN/zhet01_3.f
COMPLEX (symmetric indefinite and Hermitian indefinite matrices):
modified: TESTING/LIN/cchkaa.f
modified: TESTING/LIN/cerrsy.f
modified: TESTING/LIN/cerrsyx.f
modified: TESTING/LIN/cerrhe.f
modified: TESTING/LIN/cerrhex.f
modified: TESTING/LIN/cerrvx.f
modified: TESTING/LIN/cerrvxx.f
modified: TESTING/ctest.in
new file: TESTING/LIN/cchksy_rk.f
new file: TESTING/LIN/cdrvsy_rk.f
new file: TESTING/LIN/csyt01_3.f
new file: TESTING/LIN/cchkhe_rk.f
new file: TESTING/LIN/cdrvhe_rk.f
new file: TESTING/LIN/chet01_3.f
Diffstat (limited to 'SRC')
61 files changed, 30909 insertions, 895 deletions
diff --git a/SRC/CMakeLists.txt b/SRC/CMakeLists.txt index 35dba277..02a9b3da 100644 --- a/SRC/CMakeLists.txt +++ b/SRC/CMakeLists.txt @@ -114,7 +114,8 @@ set(SLASRC slaqtr.f slar1v.f slar2v.f ilaslr.f ilaslc.f slarf.f slarfb.f slarfg.f slarfgp.f slarft.f slarfx.f slargv.f slarrv.f slartv.f - slarz.f slarzb.f slarzt.f slaswp.f slasy2.f slasyf.f slasyf_rook.f slasyf_aa.f + slarz.f slarzb.f slarzt.f slaswp.f slasy2.f + slasyf.f slasyf_rook.f slasyf_rk.f slasyf_aa.f slatbs.f slatdf.f slatps.f slatrd.f slatrs.f slatrz.f slauu2.f slauum.f sopgtr.f sopmtr.f sorg2l.f sorg2r.f sorgbr.f sorghr.f sorgl2.f sorglq.f sorgql.f sorgqr.f sorgr2.f @@ -134,10 +135,14 @@ set(SLASRC sstevx.f ssycon.f ssyev.f ssyevd.f ssyevr.f ssyevx.f ssygs2.f ssygst.f ssygv.f ssygvd.f ssygvx.f ssyrfs.f ssysv.f ssysvx.f ssytd2.f ssytf2.f ssytrd.f ssytrf.f ssytri.f ssytri2.f ssytri2x.f - ssyswapr.f ssytrs.f ssytrs2.f ssyconv.f + ssyswapr.f ssytrs.f ssytrs2.f + ssyconv.f ssyconvf.f ssyconvf_rook.f ssysv_aa.f ssytrf_aa.f ssytrs_aa.f ssytf2_rook.f ssytrf_rook.f ssytrs_rook.f ssytri_rook.f ssycon_rook.f ssysv_rook.f + ssytf2_rk.f ssytrf_rk.f ssytrs_3.f + ssytri_3.f ssytri_3x.f ssycon_3.f ssysv_rk.f + ssysv_aa.f ssytrf_aa.f ssytrs_aa.f stbcon.f stbrfs.f stbtrs.f stgevc.f stgex2.f stgexc.f stgsen.f stgsja.f stgsna.f stgsy2.f stgsyl.f stpcon.f stprfs.f stptri.f @@ -189,8 +194,11 @@ set(CLASRC chetf2.f chetrd.f chetrf.f chetri.f chetri2.f chetri2x.f cheswapr.f chetrs.f chetrs2.f + chetf2_rook.f chetrf_rook.f chetri_rook.f + chetrs_rook.f checon_rook.f chesv_rook.f + chetf2_rk.f chetrf_rk.f chetri_3.f chetri_3x.f + chetrs_3.f checon_3.f chesv_rk.f chesv_aa.f chetrf_aa.f chetrs_aa.f - chetf2_rook.f chetrf_rook.f chetri_rook.f chetrs_rook.f checon_rook.f chesv_rook.f chgeqz.f chpcon.f chpev.f chpevd.f chpevx.f chpgst.f chpgv.f chpgvd.f chpgvx.f chprfs.f chpsv.f chpsvx.f @@ -198,7 +206,7 @@ set(CLASRC clacgv.f clacon.f clacn2.f clacp2.f clacpy.f clacrm.f clacrt.f cladiv.f claed0.f claed7.f claed8.f claein.f claesy.f claev2.f clags2.f clagtm.f - clahef.f clahef_rook.f clahef_aa.f clahqr.f + clahef.f clahef_rook.f clahef_rk.f clahef_aa.f clahqr.f clahr2.f claic1.f clals0.f clalsa.f clalsd.f clangb.f clange.f clangt.f clanhb.f clanhe.f clanhp.f clanhs.f clanht.f clansb.f clansp.f clansy.f clantb.f @@ -209,7 +217,7 @@ set(CLASRC clarf.f clarfb.f clarfg.f clarfgp.f clarft.f clarfx.f clargv.f clarnv.f clarrv.f clartg.f clartv.f clarz.f clarzb.f clarzt.f clascl.f claset.f clasr.f classq.f - claswp.f clasyf.f clasyf_rook.f clatbs.f clatdf.f clatps.f clatrd.f clatrs.f clatrz.f + claswp.f clasyf.f clasyf_rook.f clasyf_rk.f clatbs.f clatdf.f clatps.f clatrd.f clatrs.f clatrz.f clauu2.f clauum.f cpbcon.f cpbequ.f cpbrfs.f cpbstf.f cpbsv.f cpbsvx.f cpbtf2.f cpbtrf.f cpbtrs.f cpocon.f cpoequ.f cporfs.f cposv.f cposvx.f cpotf2.f cpotrf.f cpotrf2.f cpotri.f cpotrs.f cpstrf.f cpstf2.f @@ -220,9 +228,12 @@ set(CLASRC cstegr.f cstein.f csteqr.f csycon.f csymv.f csyr.f csyrfs.f csysv.f csysvx.f csytf2.f csytrf.f csytri.f csytri2.f csytri2x.f csyswapr.f - csytrs.f csytrs2.f csyconv.f + csytrs.f csytrs2.f + csyconv.f csyconvf.f csyconvf_rook.f csytf2_rook.f csytrf_rook.f csytrs_rook.f csytri_rook.f csycon_rook.f csysv_rook.f + csytf2_rk.f csytrf_rk.f csytrs_3.f + csytri_3.f csytri_3x.f csycon_3.f csysv_rk.f ctbcon.f ctbrfs.f ctbtrs.f ctgevc.f ctgex2.f ctgexc.f ctgsen.f ctgsja.f ctgsna.f ctgsy2.f ctgsyl.f ctpcon.f ctprfs.f ctptri.f @@ -283,7 +294,8 @@ set(DLASRC dlaqtr.f dlar1v.f dlar2v.f iladlr.f iladlc.f dlarf.f dlarfb.f dlarfg.f dlarfgp.f dlarft.f dlarfx.f dlargv.f dlarrv.f dlartv.f - dlarz.f dlarzb.f dlarzt.f dlaswp.f dlasy2.f dlasyf.f dlasyf_rook.f dlasyf_aa.f + dlarz.f dlarzb.f dlarzt.f dlaswp.f dlasy2.f + dlasyf.f dlasyf_rook.f dlasyf_rk.f dlasyf_aa.f dlatbs.f dlatdf.f dlatps.f dlatrd.f dlatrs.f dlatrz.f dlauu2.f dlauum.f dopgtr.f dopmtr.f dorg2l.f dorg2r.f dorgbr.f dorghr.f dorgl2.f dorglq.f dorgql.f dorgqr.f dorgr2.f @@ -304,10 +316,13 @@ set(DLASRC dsyevx.f dsygs2.f dsygst.f dsygv.f dsygvd.f dsygvx.f dsyrfs.f dsysv.f dsysvx.f dsytd2.f dsytf2.f dsytrd.f dsytrf.f dsytri.f dsytrs.f dsytrs2.f - dsytri2.f dsytri2x.f dsyswapr.f dsyconv.f - dsysv_aa.f dsytrf_aa.f dsytrs_aa.f + dsytri2.f dsytri2x.f dsyswapr.f + dsyconv.f dsyconvf.f dsyconvf_rook.f dsytf2_rook.f dsytrf_rook.f dsytrs_rook.f dsytri_rook.f dsycon_rook.f dsysv_rook.f + dsytf2_rk.f dsytrf_rk.f dsytrs_3.f + dsytri_3.f dsytri_3x.f dsycon_3.f dsysv_rk.f + dsysv_aa.f dsytrf_aa.f dsytrs_aa.f dtbcon.f dtbrfs.f dtbtrs.f dtgevc.f dtgex2.f dtgexc.f dtgsen.f dtgsja.f dtgsna.f dtgsy2.f dtgsyl.f dtpcon.f dtprfs.f dtptri.f @@ -358,8 +373,11 @@ set(ZLASRC zhetf2.f zhetrd.f zhetrf.f zhetri.f zhetri2.f zhetri2x.f zheswapr.f zhetrs.f zhetrs2.f + zhetf2_rook.f zhetrf_rook.f zhetri_rook.f + zhetrs_rook.f zhecon_rook.f zhesv_rook.f + zhetf2_rk.f zhetrf_rk.f zhetri_3.f zhetri_3x.f + zhetrs_3.f zhecon_3.f zhesv_rk.f zhesv_aa.f zhetrf_aa.f zhetrs_aa.f - zhetf2_rook.f zhetrf_rook.f zhetri_rook.f zhetrs_rook.f zhecon_rook.f zhesv_rook.f zhgeqz.f zhpcon.f zhpev.f zhpevd.f zhpevx.f zhpgst.f zhpgv.f zhpgvd.f zhpgvx.f zhprfs.f zhpsv.f zhpsvx.f @@ -367,7 +385,7 @@ set(ZLASRC zlacgv.f zlacon.f zlacn2.f zlacp2.f zlacpy.f zlacrm.f zlacrt.f zladiv.f zlaed0.f zlaed7.f zlaed8.f zlaein.f zlaesy.f zlaev2.f zlags2.f zlagtm.f - zlahef.f zlahef_rook.f zlahef_aa.f zlahqr.f + zlahef.f zlahef_rook.f zlahef_rk.f zlahef_aa.f zlahqr.f zlahr2.f zlaic1.f zlals0.f zlalsa.f zlalsd.f zlangb.f zlange.f zlangt.f zlanhb.f zlanhe.f @@ -380,7 +398,7 @@ set(ZLASRC zlarfg.f zlarfgp.f zlarft.f zlarfx.f zlargv.f zlarnv.f zlarrv.f zlartg.f zlartv.f zlarz.f zlarzb.f zlarzt.f zlascl.f zlaset.f zlasr.f - zlassq.f zlaswp.f zlasyf.f zlasyf_rook.f + zlassq.f zlaswp.f zlasyf.f zlasyf_rook.f zlasyf_rk.f zlatbs.f zlatdf.f zlatps.f zlatrd.f zlatrs.f zlatrz.f zlauu2.f zlauum.f zpbcon.f zpbequ.f zpbrfs.f zpbstf.f zpbsv.f zpbsvx.f zpbtf2.f zpbtrf.f zpbtrs.f zpocon.f zpoequ.f zporfs.f @@ -392,9 +410,12 @@ set(ZLASRC zstegr.f zstein.f zsteqr.f zsycon.f zsymv.f zsyr.f zsyrfs.f zsysv.f zsysvx.f zsytf2.f zsytrf.f zsytri.f zsytri2.f zsytri2x.f zsyswapr.f - zsytrs.f zsytrs2.f zsyconv.f + zsytrs.f zsytrs2.f + zsyconv.f zsyconvf.f zsyconvf_rook.f zsytf2_rook.f zsytrf_rook.f zsytrs_rook.f zsytri_rook.f zsycon_rook.f zsysv_rook.f + zsytf2_rk.f zsytrf_rk.f zsytrs_3.f + zsytri_3.f zsytri_3x.f zsycon_3.f zsysv_rk.f ztbcon.f ztbrfs.f ztbtrs.f ztgevc.f ztgex2.f ztgexc.f ztgsen.f ztgsja.f ztgsna.f ztgsy2.f ztgsyl.f ztpcon.f ztprfs.f ztptri.f diff --git a/SRC/Makefile b/SRC/Makefile index 33058ec8..01cf7021 100644 --- a/SRC/Makefile +++ b/SRC/Makefile @@ -123,6 +123,7 @@ SLASRC = \ slarf.o slarfb.o slarfg.o slarfgp.o slarft.o slarfx.o slargv.o \ slarrv.o slartv.o \ slarz.o slarzb.o slarzt.o slaswp.o slasy2.o slasyf.o slasyf_rook.o \ + slasyf_rk.o \ slatbs.o slatdf.o slatps.o slatrd.o slatrs.o slatrz.o \ slauu2.o slauum.o sopgtr.o sopmtr.o sorg2l.o sorg2r.o \ sorgbr.o sorghr.o sorgl2.o sorglq.o sorgql.o sorgqr.o sorgr2.o \ @@ -143,10 +144,12 @@ SLASRC = \ ssycon.o ssyev.o ssyevd.o ssyevr.o ssyevx.o ssygs2.o \ ssygst.o ssygv.o ssygvd.o ssygvx.o ssyrfs.o ssysv.o ssysvx.o \ ssytd2.o ssytf2.o ssytrd.o ssytrf.o ssytri.o ssytri2.o ssytri2x.o \ - ssyswapr.o ssytrs.o ssytrs2.o ssyconv.o \ + ssyswapr.o ssytrs.o ssytrs2.o ssyconv.o ssyconvf_rook.o \ ssytf2_rook.o ssytrf_rook.o ssytrs_rook.o \ - slasyf_aa.o ssysv_aa.o ssytrf_aa.o ssytrs_aa.o \ ssytri_rook.o ssycon_rook.o ssysv_rook.o \ + ssytf2_rk.o ssytrf_rk.o ssytrs_3.o \ + ssytri_3.o ssytri_3x.o ssycon_3.o ssysv_rk.o \ + slasyf_aa.o ssysv_aa.o ssytrf_aa.o ssytrs_aa.o \ stbcon.o \ stbrfs.o stbtrs.o stgevc.o stgex2.o stgexc.o stgsen.o \ stgsja.o stgsna.o stgsy2.o stgsyl.o stpcon.o stprfs.o stptri.o \ @@ -200,7 +203,10 @@ CLASRC = \ chetf2.o chetrd.o \ chetrf.o chetri.o chetri2.o chetri2x.o cheswapr.o \ chetrs.o chetrs2.o \ - chetf2_rook.o chetrf_rook.o chetri_rook.o chetrs_rook.o checon_rook.o chesv_rook.o \ + chetf2_rook.o chetrf_rook.o chetri_rook.o \ + chetrs_rook.o checon_rook.o chesv_rook.o \ + chetf2_rk.o chetrf_rk.o chetri_3.o chetri_3x.o \ + chetrs_3.o checon_3.o chesv_rk.o \ chesv_aa.o chetrf_aa.o chetrs_aa.o clahef_aa.o\ chgeqz.o chpcon.o chpev.o chpevd.o \ chpevx.o chpgst.o chpgv.o chpgvd.o chpgvx.o chprfs.o chpsv.o \ @@ -209,7 +215,7 @@ CLASRC = \ clacgv.o clacon.o clacn2.o clacp2.o clacpy.o clacrm.o clacrt.o cladiv.o \ claed0.o claed7.o claed8.o \ claein.o claesy.o claev2.o clags2.o clagtm.o \ - clahef.o clahef_rook.o clahqr.o \ + clahef.o clahef_rook.o clahef_rk.o clahqr.o \ clahr2.o claic1.o clals0.o clalsa.o clalsd.o clangb.o clange.o clangt.o \ clanhb.o clanhe.o \ clanhp.o clanhs.o clanht.o clansb.o clansp.o clansy.o clantb.o \ @@ -220,7 +226,8 @@ CLASRC = \ clarf.o clarfb.o clarfg.o clarft.o clarfgp.o \ clarfx.o clargv.o clarnv.o clarrv.o clartg.o clartv.o \ clarz.o clarzb.o clarzt.o clascl.o claset.o clasr.o classq.o \ - claswp.o clasyf.o clasyf_rook.o clatbs.o clatdf.o clatps.o clatrd.o clatrs.o clatrz.o \ + claswp.o clasyf.o clasyf_rook.o clasyf_rk.o \ + clatbs.o clatdf.o clatps.o clatrd.o clatrs.o clatrz.o \ clauu2.o clauum.o cpbcon.o cpbequ.o cpbrfs.o cpbstf.o cpbsv.o \ cpbsvx.o cpbtf2.o cpbtrf.o cpbtrs.o cpocon.o cpoequ.o cporfs.o \ cposv.o cposvx.o cpotf2.o cpotri.o cpstrf.o cpstf2.o \ @@ -231,9 +238,12 @@ CLASRC = \ cstegr.o cstein.o csteqr.o \ csycon.o csymv.o \ csyr.o csyrfs.o csysv.o csysvx.o csytf2.o csytrf.o csytri.o csytri2.o csytri2x.o \ - csyswapr.o csytrs.o csytrs2.o csyconv.o \ + csyswapr.o csytrs.o csytrs2.o \ + csyconv.o csyconvf.o csyconvf_rook.o \ csytf2_rook.o csytrf_rook.o csytrs_rook.o \ csytri_rook.o csycon_rook.o csysv_rook.o \ + csytf2_rk.o csytrf_rk.o csytrs_3.o \ + csytri_3.o csytri_3x.o csycon_3.o csysv_rk.o \ ctbcon.o ctbrfs.o ctbtrs.o ctgevc.o ctgex2.o \ ctgexc.o ctgsen.o ctgsja.o ctgsna.o ctgsy2.o ctgsyl.o ctpcon.o \ ctprfs.o ctptri.o \ @@ -298,7 +308,8 @@ DLASRC = \ dlaqtr.o dlar1v.o dlar2v.o iladlr.o iladlc.o \ dlarf.o dlarfb.o dlarfg.o dlarfgp.o dlarft.o dlarfx.o \ dlargv.o dlarrv.o dlartv.o \ - dlarz.o dlarzb.o dlarzt.o dlaswp.o dlasy2.o dlasyf.o dlasyf_rook.o \ + dlarz.o dlarzb.o dlarzt.o dlaswp.o dlasy2.o \ + dlasyf.o dlasyf_rook.o dlasyf_rk.o \ dlatbs.o dlatdf.o dlatps.o dlatrd.o dlatrs.o dlatrz.o dlauu2.o \ dlauum.o dopgtr.o dopmtr.o dorg2l.o dorg2r.o \ dorgbr.o dorghr.o dorgl2.o dorglq.o dorgql.o dorgqr.o dorgr2.o \ @@ -320,10 +331,13 @@ DLASRC = \ dsyevx.o dsygs2.o dsygst.o dsygv.o dsygvd.o dsygvx.o dsyrfs.o \ dsysv.o dsysvx.o \ dsytd2.o dsytf2.o dsytrd.o dsytrf.o dsytri.o dsytri2.o dsytri2x.o \ - dsyswapr.o dsytrs.o dsytrs2.o dsyconv.o \ + dsyswapr.o dsytrs.o dsytrs2.o \ + dsyconv.o dsyconvf.o dsyconvf_rook.o \ dsytf2_rook.o dsytrf_rook.o dsytrs_rook.o \ - dlasyf_aa.o dsysv_aa.o dsytrf_aa.o dsytrs_aa.o \ dsytri_rook.o dsycon_rook.o dsysv_rook.o \ + dsytf2_rk.o dsytrf_rk.o dsytrs_3.o \ + dsytri_3.o dsytri_3x.o dsycon_3.o dsysv_rk.o \ + dlasyf_aa.o dsysv_aa.o dsytrf_aa.o dsytrs_aa.o \ dtbcon.o dtbrfs.o dtbtrs.o dtgevc.o dtgex2.o dtgexc.o dtgsen.o \ dtgsja.o dtgsna.o dtgsy2.o dtgsyl.o dtpcon.o dtprfs.o dtptri.o \ dtptrs.o \ @@ -376,7 +390,10 @@ ZLASRC = \ zhetf2.o zhetrd.o \ zhetrf.o zhetri.o zhetri2.o zhetri2x.o zheswapr.o \ zhetrs.o zhetrs2.o \ - zhetf2_rook.o zhetrf_rook.o zhetri_rook.o zhetrs_rook.o zhecon_rook.o zhesv_rook.o \ + zhetf2_rook.o zhetrf_rook.o zhetri_rook.o \ + zhetrs_rook.o zhecon_rook.o zhesv_rook.o \ + zhetf2_rk.o zhetrf_rk.o zhetri_3.o zhetri_3x.o \ + zhetrs_3.o zhecon_3.o zhesv_rk.o \ zhesv_aa.o zhetrf_aa.o zhetrs_aa.o zlahef_aa.o \ zhgeqz.o zhpcon.o zhpev.o zhpevd.o \ zhpevx.o zhpgst.o zhpgv.o zhpgvd.o zhpgvx.o zhprfs.o zhpsv.o \ @@ -385,7 +402,7 @@ ZLASRC = \ zlacgv.o zlacon.o zlacn2.o zlacp2.o zlacpy.o zlacrm.o zlacrt.o zladiv.o \ zlaed0.o zlaed7.o zlaed8.o \ zlaein.o zlaesy.o zlaev2.o zlags2.o zlagtm.o \ - zlahef.o zlahef_rook.o zlahqr.o \ + zlahef.o zlahef_rook.o zlahef_rk.o zlahqr.o \ zlahr2.o zlaic1.o zlals0.o zlalsa.o zlalsd.o zlangb.o zlange.o \ zlangt.o zlanhb.o \ zlanhe.o \ @@ -398,7 +415,7 @@ ZLASRC = \ zlarfg.o zlarft.o zlarfgp.o \ zlarfx.o zlargv.o zlarnv.o zlarrv.o zlartg.o zlartv.o \ zlarz.o zlarzb.o zlarzt.o zlascl.o zlaset.o zlasr.o \ - zlassq.o zlaswp.o zlasyf.o zlasyf_rook.o \ + zlassq.o zlaswp.o zlasyf.o zlasyf_rook.o zlasyf_rk.o \ zlatbs.o zlatdf.o zlatps.o zlatrd.o zlatrs.o zlatrz.o zlauu2.o \ zlauum.o zpbcon.o zpbequ.o zpbrfs.o zpbstf.o zpbsv.o \ zpbsvx.o zpbtf2.o zpbtrf.o zpbtrs.o zpocon.o zpoequ.o zporfs.o \ @@ -410,9 +427,12 @@ ZLASRC = \ zstegr.o zstein.o zsteqr.o \ zsycon.o zsymv.o \ zsyr.o zsyrfs.o zsysv.o zsysvx.o zsytf2.o zsytrf.o zsytri.o zsytri2.o zsytri2x.o \ - zsyswapr.o zsytrs.o zsytrs2.o zsyconv.o \ + zsyswapr.o zsytrs.o zsytrs2.o \ + zsyconv.o zsyconvf.o zsyconvf_rook.o \ zsytf2_rook.o zsytrf_rook.o zsytrs_rook.o \ zsytri_rook.o zsycon_rook.o zsysv_rook.o \ + zsytf2_rk.o zsytrf_rk.o zsytrs_3.o \ + zsytri_3.o zsytri_3x.o zsycon_3.o zsysv_rk.o \ ztbcon.o ztbrfs.o ztbtrs.o ztgevc.o ztgex2.o \ ztgexc.o ztgsen.o ztgsja.o ztgsna.o ztgsy2.o ztgsyl.o ztpcon.o \ ztprfs.o ztptri.o \ @@ -530,4 +550,3 @@ sla_wwaddw.o: sla_wwaddw.f ; $(FORTRAN) $(NOOPT) -c $< -o $@ dla_wwaddw.o: dla_wwaddw.f ; $(FORTRAN) $(NOOPT) -c $< -o $@ cla_wwaddw.o: cla_wwaddw.f ; $(FORTRAN) $(NOOPT) -c $< -o $@ zla_wwaddw.o: zla_wwaddw.f ; $(FORTRAN) $(NOOPT) -c $< -o $@ - diff --git a/SRC/checon_3.f b/SRC/checon_3.f new file mode 100644 index 00000000..438ee3ae --- /dev/null +++ b/SRC/checon_3.f @@ -0,0 +1,285 @@ +*> \brief \b CHECON_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHECON_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/checon_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/checon_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/checon_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHECON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, +* WORK, IWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* REAL ANORM, RCOND +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ), IWORK( * ) +* COMPLEX A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHECON_3 estimates the reciprocal of the condition number (in the +*> 1-norm) of a complex Hermitian matrix A using the factorization +*> computed by CHETRF_RK or CHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> An estimate is obtained for norm(inv(A)), and the reciprocal of the +*> condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). +*> This routine uses BLAS3 solver CHETRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**H)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**H)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by CHETRF_RK and CHETRF_BK: +*> 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 +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CHETRF_RK or CHETRF_BK. +*> \endverbatim +*> +*> \param[in] ANORM +*> \verbatim +*> ANORM is REAL +*> The 1-norm of the original matrix A. +*> \endverbatim +*> +*> \param[out] RCOND +*> \verbatim +*> RCOND is REAL +*> The reciprocal of the condition number of the matrix A, +*> computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an +*> estimate of the 1-norm of inv(A) computed in this routine. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension (2*N) +*> \endverbatim +*> +*> \param[out] IWORK +*> \verbatim +*> IWORK is INTEGER array, dimension (N) +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 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 CHECON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, + $ WORK, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N + REAL ANORM, RCOND +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE, ZERO + PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, KASE + REAL AINVNM +* .. +* .. Local Arrays .. + INTEGER ISAVE( 3 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL CHETRS_3, CLACN2, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( ANORM.LT.ZERO ) THEN + INFO = -7 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHECON_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + RCOND = ZERO + IF( N.EQ.0 ) THEN + RCOND = ONE + RETURN + ELSE IF( ANORM.LE.ZERO ) THEN + RETURN + END IF +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO I = N, 1, -1 + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO I = 1, N + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + END IF +* +* Estimate the 1-norm of the inverse. +* + KASE = 0 + 30 CONTINUE + CALL CLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE ) + IF( KASE.NE.0 ) THEN +* +* Multiply by inv(L*D*L**H) or inv(U*D*U**H). +* + CALL CHETRS_3( UPLO, N, 1, A, LDA, E, IPIV, WORK, N, INFO ) + GO TO 30 + END IF +* +* Compute the estimate of the reciprocal condition number. +* + IF( AINVNM.NE.ZERO ) + $ RCOND = ( ONE / AINVNM ) / ANORM +* + RETURN +* +* End of CHECON_3 +* + END diff --git a/SRC/chesv_rk.f b/SRC/chesv_rk.f new file mode 100644 index 00000000..ac02082e --- /dev/null +++ b/SRC/chesv_rk.f @@ -0,0 +1,316 @@ +*> \brief <b> CHESV_RK computes the solution to system of linear equations A * X = B for SY matrices</b> +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHESV_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chesv_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chesv_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chesv_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHESV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* WORK, LWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHESV_RK computes the solution to a complex system of linear +*> equations A * X = B, where A is an N-by-N Hermitian matrix +*> and X and B are N-by-NRHS matrices. +*> +*> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used +*> to factor A as +*> A = P*U*D*(U**H)*(P**T), if UPLO = 'U', or +*> A = P*L*D*(L**H)*(P**T), if UPLO = 'L', +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> CHETRF_RK is called to compute the factorization of a complex +*> Hermitian matrix. The factored form of A is then used to solve +*> the system of equations A * X = B by calling BLAS3 routine CHETRS_3. +*> \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 triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The number of linear equations, i.e., the order of the +*> matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \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, if INFO = 0, diagonal of the block diagonal +*> matrix D and factors U or L as computed by CHETRF_RK: +*> 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. +*> +*> For more info see the description of CHETRF_RK routine. +*> \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 output computed by the factorization +*> routine CHETRF_RK, i.e. 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. +*> +*> For more info see the description of CHETRF_RK routine. +*> \endverbatim +*> +*> \param[out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D, +*> as determined by CHETRF_RK. +*> +*> For more info see the description of CHETRF_RK routine. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX array, dimension (LDB,NRHS) +*> On entry, the N-by-NRHS right hand side matrix B. +*> On exit, if INFO = 0, the N-by-NRHS solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension ( MAX(1,LWORK) ). +*> Work array used in the factorization stage. +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= 1. For best performance +*> of factorization stage LWORK >= max(1,N*NB), where NB is +*> the optimal blocksize for CHETRF_RK. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array for factorization stage, returns this value as +*> the first entry of the WORK array, and no error message +*> related to LWORK is issued by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexHEsolve +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CHESV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, WORK, + $ LWORK, INFO ) +* +* -- LAPACK driver routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY + INTEGER LWKOPT +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, CHETRF_RK, CHETRS_3 +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -11 + END IF +* + IF( INFO.EQ.0 ) THEN + IF( N.EQ.0 ) THEN + LWKOPT = 1 + ELSE + CALL CHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO ) + LWKOPT = WORK(1) + END IF + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHESV_RK ', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* +* Compute the factorization A = U*D*U**T or A = L*D*L**T. +* + CALL CHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO ) +* + IF( INFO.EQ.0 ) THEN +* +* Solve the system A*X = B with BLAS3 solver, overwriting B with X. +* + CALL CHETRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO ) +* + END IF +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of CHESV_RK +* + END diff --git a/SRC/chetf2_rk.f b/SRC/chetf2_rk.f new file mode 100644 index 00000000..18afea06 --- /dev/null +++ b/SRC/chetf2_rk.f @@ -0,0 +1,1039 @@ +*> \brief \b CHETF2_RK computes the factorization of a complex Hermitian indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHETF2_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetf2_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetf2_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetf2_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHETF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E ( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHETF2_RK computes the factorization of a complex Hermitian matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the unblocked version of the algorithm, calling Level 2 BLAS. +*> For more information see Further Details section. +*> \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,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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put further details +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 +*> +*> 01-01-96 - Based on modifications by +*> J. Lewis, Boeing Computer Services Company +*> A. Petitet, Computer Science Dept., +*> Univ. of Tenn., Knoxville abd , USA +*> \endverbatim +* +* ===================================================================== + SUBROUTINE CHETF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), 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 CZERO + PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL DONE, UPPER + INTEGER I, II, IMAX, ITEMP, J, JMAX, K, KK, KP, KSTEP, + $ P + REAL ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, STEMP, + $ ROWMAX, TT, SFMIN + COMPLEX D12, D21, T, WK, WKM1, WKP1, Z +* .. +* .. External Functions .. +* + LOGICAL LSAME + INTEGER ICAMAX + REAL SLAMCH, SLAPY2 + EXTERNAL LSAME, ICAMAX, SLAMCH, SLAPY2 +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, CSSCAL, CHER, CSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, REAL, SQRT +* .. +* .. Statement Functions .. + REAL CABS1 +* .. +* .. Statement Function definitions .. + CABS1( Z ) = ABS( REAL( Z ) ) + ABS( AIMAG( Z ) ) +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHETF2_RK', -INFO ) + RETURN + END IF +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = SLAMCH( 'S' ) +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**H using the upper triangle of A +* +* Initilize 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 to 1 in steps of +* 1 or 2 +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 34 + KSTEP = 1 + P = K +* +* 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( A( 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.GT.1 ) THEN + IMAX = ICAMAX( K-1, A( 1, K ), 1 ) + COLMAX = CABS1( A( 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( A( K, K ) ) +* +* 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 +* + DONE = .FALSE. +* +* Loop until pivot found +* + 12 CONTINUE +* +* BEGIN pivot search loop body +* +* +* 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, A( IMAX, IMAX+1 ), + $ LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = ICAMAX( IMAX-1, A( 1, IMAX ), 1 ) + STEMP = CABS1( A( ITEMP, IMAX ) ) + 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( A( IMAX, IMAX ) ) ) + $ .LT.ALPHA*ROWMAX ) ) THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + 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 + 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 +* +* For only a 2x2 pivot, interchange rows and columns K and P +* in the leading submatrix A(1:k,1:k) +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* (1) Swap columnar parts + IF( P.GT.1 ) + $ CALL CSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 ) +* (2) Swap and conjugate middle parts + DO 14 J = P + 1, K - 1 + T = CONJG( A( J, K ) ) + A( J, K ) = CONJG( A( P, J ) ) + A( P, J ) = T + 14 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( P, K ) = CONJG( A( P, K ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = REAL( A( K, K ) ) + A( K, K ) = REAL( A( P, P ) ) + A( P, P ) = R1 +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL CSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), LDA ) +* + END IF +* +* For both 1x1 and 2x2 pivots, interchange rows and +* columns KK and KP in the leading submatrix A(1:k,1:k) +* + IF( KP.NE.KK ) THEN +* (1) Swap columnar parts + IF( KP.GT.1 ) + $ CALL CSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) +* (2) Swap and conjugate middle parts + DO 15 J = KP + 1, KK - 1 + T = CONJG( A( J, KK ) ) + A( J, KK ) = CONJG( A( KP, J ) ) + A( KP, J ) = T + 15 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( KP, KK ) = CONJG( A( KP, KK ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = REAL( A( KK, KK ) ) + A( KK, KK ) = REAL( A( KP, KP ) ) + A( KP, KP ) = R1 +* + IF( KSTEP.EQ.2 ) THEN +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = REAL( A( K, K ) ) +* (5) Swap row elements + T = A( K-1, K ) + A( K-1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL CSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) +* + ELSE +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = REAL( A( K, K ) ) + IF( KSTEP.EQ.2 ) + $ A( K-1, K-1 ) = REAL( A( K-1, K-1 ) ) + END IF +* +* Update the leading submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* + IF( K.GT.1 ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) and +* store U(k) in column k +* + IF( ABS( REAL( A( K, K ) ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*1/D(k)*W(k)**T +* + D11 = ONE / REAL( A( K, K ) ) + CALL CHER( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) +* +* Store U(k) in column k +* + CALL CSSCAL( K-1, D11, A( 1, K ), 1 ) + ELSE +* +* Store L(k) in column K +* + D11 = REAL( A( K, K ) ) + DO 16 II = 1, K - 1 + A( II, K ) = A( II, K ) / D11 + 16 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL CHER( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = CZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k-1 now hold +* +* ( W(k-1) W(k) ) = ( 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 +* +* Perform a rank-2 update of A(1:k-2,1:k-2) as +* +* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T +* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.GT.2 ) THEN +* D = |A12| + D = SLAPY2( REAL( A( K-1, K ) ), + $ AIMAG( A( K-1, K ) ) ) + D11 = A( K, K ) / D + D22 = A( K-1, K-1 ) / D + D12 = A( K-1, K ) / D + TT = ONE / ( D11*D22-ONE ) +* + DO 30 J = K - 2, 1, -1 +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WKM1 = TT*( D11*A( J, K-1 )-CONJG( D12 )* + $ A( J, K ) ) + WK = TT*( D22*A( J, K )-D12*A( J, K-1 ) ) +* +* Perform a rank-2 update of A(1:k-2,1:k-2) +* + DO 20 I = J, 1, -1 + A( I, J ) = A( I, J ) - + $ ( A( I, K ) / D )*CONJG( WK ) - + $ ( A( I, K-1 ) / D )*CONJG( WKM1 ) + 20 CONTINUE +* +* Store U(k) and U(k-1) in cols k and k-1 for row J +* + A( J, K ) = WK / D + A( J, K-1 ) = WKM1 / D +* (*) Make sure that diagonal element of pivot is real + A( J, J ) = CMPLX( REAL( A( J, J ) ), ZERO ) +* + 30 CONTINUE +* + END IF +* +* Copy superdiagonal elements of D(K) to E(K) and +* ZERO out superdiagonal entry of A +* + E( K ) = A( K-1, K ) + E( K-1 ) = CZERO + A( K-1, K ) = CZERO +* + 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 +* + 34 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**H using the lower triangle of A +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = CZERO +* +* K is the main loop index, increasing from 1 to N in steps of +* 1 or 2 +* + K = 1 + 40 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 64 + KSTEP = 1 + P = K +* +* 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( A( 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, A( K+1, K ), 1 ) + COLMAX = CABS1( A( 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( A( K, K ) ) +* +* 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 +* + 42 CONTINUE +* +* BEGIN pivot search loop body +* +* +* 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, A( IMAX, K ), LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + ICAMAX( N-IMAX, A( IMAX+1, IMAX ), + $ 1 ) + STEMP = CABS1( A( ITEMP, IMAX ) ) + 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( A( IMAX, IMAX ) ) ) + $ .LT.ALPHA*ROWMAX ) ) THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + 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 + END IF +* +* +* END pivot search loop body +* + IF( .NOT.DONE ) GOTO 42 +* + END IF +* +* END pivot search +* +* ============================================================ +* +* KK is the column of A where pivoting step stopped +* + KK = K + KSTEP - 1 +* +* For only a 2x2 pivot, interchange rows and columns K and P +* in the trailing submatrix A(k:n,k:n) +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* (1) Swap columnar parts + IF( P.LT.N ) + $ CALL CSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) +* (2) Swap and conjugate middle parts + DO 44 J = K + 1, P - 1 + T = CONJG( A( J, K ) ) + A( J, K ) = CONJG( A( P, J ) ) + A( P, J ) = T + 44 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( P, K ) = CONJG( A( P, K ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = REAL( A( K, K ) ) + A( K, K ) = REAL( A( P, P ) ) + A( P, P ) = R1 +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL CSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) +* + END IF +* +* For both 1x1 and 2x2 pivots, interchange rows and +* columns KK and KP in the trailing submatrix A(k:n,k:n) +* + IF( KP.NE.KK ) THEN +* (1) Swap columnar parts + IF( KP.LT.N ) + $ CALL CSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) +* (2) Swap and conjugate middle parts + DO 45 J = KK + 1, KP - 1 + T = CONJG( A( J, KK ) ) + A( J, KK ) = CONJG( A( KP, J ) ) + A( KP, J ) = T + 45 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( KP, KK ) = CONJG( A( KP, KK ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = REAL( A( KK, KK ) ) + A( KK, KK ) = REAL( A( KP, KP ) ) + A( KP, KP ) = R1 +* + IF( KSTEP.EQ.2 ) THEN +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = REAL( A( K, K ) ) +* (5) Swap row elements + T = A( K+1, K ) + A( K+1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL CSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) +* + ELSE +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = REAL( A( K, K ) ) + IF( KSTEP.EQ.2 ) + $ A( K+1, K+1 ) = REAL( A( K+1, K+1 ) ) + END IF +* +* Update the trailing submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k of A now holds +* +* W(k) = L(k)*D(k), +* +* where L(k) is the k-th column of L +* + IF( K.LT.N ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) and +* store L(k) in column k +* +* Handle division by a small number +* + IF( ABS( REAL( A( K, K ) ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* + D11 = ONE / REAL( A( K, K ) ) + CALL CHER( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) +* +* Store L(k) in column k +* + CALL CSSCAL( N-K, D11, A( K+1, K ), 1 ) + ELSE +* +* Store L(k) in column k +* + D11 = REAL( A( K, K ) ) + DO 46 II = K + 1, N + A( II, K ) = A( II, K ) / D11 + 46 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL CHER( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) + END IF +* +* 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 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 +* +* +* Perform a rank-2 update of A(k+2:n,k+2:n) as +* +* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T +* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.LT.N-1 ) THEN +* D = |A21| + D = SLAPY2( REAL( A( K+1, K ) ), + $ AIMAG( A( K+1, K ) ) ) + D11 = REAL( A( K+1, K+1 ) ) / D + D22 = REAL( A( K, K ) ) / D + D21 = A( K+1, K ) / D + TT = ONE / ( D11*D22-ONE ) +* + DO 60 J = K + 2, N +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WK = TT*( D11*A( J, K )-D21*A( J, K+1 ) ) + WKP1 = TT*( D22*A( J, K+1 )-CONJG( D21 )* + $ A( J, K ) ) +* +* Perform a rank-2 update of A(k+2:n,k+2:n) +* + DO 50 I = J, N + A( I, J ) = A( I, J ) - + $ ( A( I, K ) / D )*CONJG( WK ) - + $ ( A( I, K+1 ) / D )*CONJG( WKP1 ) + 50 CONTINUE +* +* Store L(k) and L(k+1) in cols k and k+1 for row J +* + A( J, K ) = WK / D + A( J, K+1 ) = WKP1 / D +* (*) Make sure that diagonal element of pivot is real + A( J, J ) = CMPLX( REAL( A( J, J ) ), ZERO ) +* + 60 CONTINUE +* + END IF +* +* Copy subdiagonal elements of D(K) to E(K) and +* ZERO out subdiagonal entry of A +* + E( K ) = A( K+1, K ) + E( K+1 ) = CZERO + A( K+1, K ) = CZERO +* + 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 40 +* + 64 CONTINUE +* + END IF +* + RETURN +* +* End of CHETF2_RK +* + END diff --git a/SRC/chetrf_rk.f b/SRC/chetrf_rk.f new file mode 100644 index 00000000..458b0ad5 --- /dev/null +++ b/SRC/chetrf_rk.f @@ -0,0 +1,498 @@ +*> \brief \b CHETRF_RK computes the factorization of a complex Hermitian indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS3 blocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHETRF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHETRF_RK computes the factorization of a complex Hermitian matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> For more information see Further Details section. +*> \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,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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension ( MAX(1,LWORK) ). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >=1. For best performance +*> LWORK >= N*NB, where NB is the block size returned +*> by ILAENV. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array, returns this value as the first entry of the WORK +*> array, and no error message related to LWORK is issued +*> by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put correct description +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY, UPPER + INTEGER I, IINFO, IP, IWS, K, KB, LDWORK, LWKOPT, + $ NB, NBMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL CLAHEF_RK, CHETF2_RK, CSWAP, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.EQ.0 ) THEN +* +* Determine the block size +* + NB = ILAENV( 1, 'CHETRF_RK', UPLO, N, -1, -1, -1 ) + LWKOPT = N*NB + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHETRF_RK', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* + NBMIN = 2 + LDWORK = N + IF( NB.GT.1 .AND. NB.LT.N ) THEN + IWS = LDWORK*NB + IF( LWORK.LT.IWS ) THEN + NB = MAX( LWORK / LDWORK, 1 ) + NBMIN = MAX( 2, ILAENV( 2, 'CHETRF_RK', + $ UPLO, N, -1, -1, -1 ) ) + END IF + ELSE + IWS = 1 + END IF + IF( NB.LT.NBMIN ) + $ NB = N +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* K is the main loop index, decreasing from N to 1 in steps of +* KB, where KB is the number of columns factorized by CLAHEF_RK; +* KB is either NB or NB-1, or K for the last block +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 15 +* + IF( K.GT.NB ) THEN +* +* Factorize columns k-kb+1:k of A and use blocked code to +* update columns 1:k-kb +* + CALL CLAHEF_RK( UPLO, K, NB, KB, A, LDA, E, + $ IPIV, WORK, LDWORK, IINFO ) + ELSE +* +* Use unblocked code to factorize columns 1:k of A +* + CALL CHETF2_RK( UPLO, K, A, LDA, E, IPIV, IINFO ) + KB = K + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO +* +* No need to adjust IPIV +* +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k-kb+1:k and apply row permutations to the +* last k+1 colunms k+1:N after that block +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.LT.N ) THEN + DO I = K, ( K - KB + 1 ), -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL CSWAP( N-K, A( I, K+1 ), LDA, + $ A( IP, K+1 ), LDA ) + END IF + END DO + END IF +* +* Decrease K and return to the start of the main loop +* + K = K - KB + GO TO 10 +* +* This label is the exit from main loop over K decreasing +* from N to 1 in steps of KB +* + 15 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* K is the main loop index, increasing from 1 to N in steps of +* KB, where KB is the number of columns factorized by CLAHEF_RK; +* KB is either NB or NB-1, or N-K+1 for the last block +* + K = 1 + 20 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 35 +* + IF( K.LE.N-NB ) THEN +* +* Factorize columns k:k+kb-1 of A and use blocked code to +* update columns k+kb:n +* + CALL CLAHEF_RK( UPLO, N-K+1, NB, KB, A( K, K ), LDA, E( K ), + $ IPIV( K ), WORK, LDWORK, IINFO ) + + + ELSE +* +* Use unblocked code to factorize columns k:n of A +* + CALL CHETF2_RK( UPLO, N-K+1, A( K, K ), LDA, E( K ), + $ IPIV( K ), IINFO ) + KB = N - K + 1 +* + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO + K - 1 +* +* Adjust IPIV +* + DO I = K, K + KB - 1 + IF( IPIV( I ).GT.0 ) THEN + IPIV( I ) = IPIV( I ) + K - 1 + ELSE + IPIV( I ) = IPIV( I ) - K + 1 + END IF + END DO +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k:k+kb-1 and apply row permutations to the +* first k-1 colunms 1:k-1 before that block +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.GT.1 ) THEN + DO I = K, ( K + KB - 1 ), 1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL CSWAP( K-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END DO + END IF +* +* Increase K and return to the start of the main loop +* + K = K + KB + GO TO 20 +* +* This label is the exit from main loop over K increasing +* from 1 to N in steps of KB +* + 35 CONTINUE +* +* End Lower +* + END IF +* + WORK( 1 ) = LWKOPT + RETURN +* +* End of CHETRF_RK +* + END diff --git a/SRC/chetri_3.f b/SRC/chetri_3.f new file mode 100644 index 00000000..3a479172 --- /dev/null +++ b/SRC/chetri_3.f @@ -0,0 +1,248 @@ +*> \brief \b CHETRI_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHETRI_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHETRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHETRI_3 computes the inverse of a complex Hermitian indefinite +*> matrix A using the factorization computed by CHETRF_RK or CHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> CHETRI_3 sets the leading dimension of the workspace before calling +*> CHETRI_3X that actually computes the inverse. This is the blocked +*> version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by CHETRF_RK and CHETRF_BK: +*> 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 +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the Hermitian inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CHETRF_RK or CHETRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension (N+NB+1)*(NB+3). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= (N+NB+1)*(NB+3). +*> +*> If LDWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the optimal +*> size of the WORK array, returns this value as the first +*> entry of the WORK array, and no error message related to +*> LWORK is issued by XERBLA. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE CHETRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL UPPER, LQUERY + INTEGER LWKOPT, NB +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL CHETRI_3X +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) +* +* Determine the block size +* + NB = MAX( 1, ILAENV( 1, 'CHETRI_3', UPLO, N, -1, -1, -1 ) ) + LWKOPT = ( N+NB+1 ) * ( NB+3 ) +* + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF ( LWORK .LT. LWKOPT .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHETRI_3', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + WORK( 1 ) = LWKOPT + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + CALL CHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of CHETRI_3 +* + END diff --git a/SRC/chetri_3x.f b/SRC/chetri_3x.f new file mode 100644 index 00000000..f6584bd3 --- /dev/null +++ b/SRC/chetri_3x.f @@ -0,0 +1,649 @@ +*> \brief \b CHETRI_3X +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHETRI_3X + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri_3x.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri_3x.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri_3x.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHETRI_3X computes the inverse of a complex Hermitian indefinite +*> matrix A using the factorization computed by CHETRF_RK or CHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by CHETRF_RK and CHETRF_BK: +*> 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 +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the Hermitian inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CHETRF_RK or CHETRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension (N+NB+1,NB+3). +*> \endverbatim +*> +*> \param[in] NB +*> \verbatim +*> NB is INTEGER +*> Block size. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE CHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE + PARAMETER ( ONE = 1.0E+0 ) + COMPLEX CONE, CZERO + PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ), + $ CZERO = ( 0.0E+0, 0.0E+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11 + REAL AK, AKP1, T + COMPLEX AKKP1, D, U01_I_J, U01_IP1_J, U11_I_J, + $ U11_IP1_J +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL CGEMM, CHESWAPR, CTRTRI, CTRMM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, CONJG, MAX, REAL +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF +* +* Quick return if possible +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHETRI_3X', -INFO ) + RETURN + END IF + IF( N.EQ.0 ) + $ RETURN +* +* Workspace got Non-diag elements of D +* + DO K = 1, N + WORK( K, 1 ) = E( K ) + END DO +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO INFO = N, 1, -1 + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO INFO = 1, N + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + END IF +* + INFO = 0 +* +* Splitting Workspace +* U01 is a block ( N, NB+1 ) +* The first element of U01 is in WORK( 1, 1 ) +* U11 is a block ( NB+1, NB+1 ) +* The first element of U11 is in WORK( N+1, 1 ) +* + U11 = N +* +* INVD is a block ( N, 2 ) +* The first element of INVD is in WORK( 1, INVD ) +* + INVD = NB + 2 + + IF( UPPER ) THEN +* +* Begin Upper +* +* invA = P * inv(U**H) * inv(D) * inv(U) * P**T. +* + CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(U) +* + K = 1 + DO WHILE( K.LE.N ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / REAL( A( K, K ) ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = ABS( WORK( K+1, 1 ) ) + AK = REAL( A( K, K ) ) / T + AKP1 = REAL( A( K+1, K+1 ) ) / T + AKKP1 = WORK( K+1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K, INVD ) = AKP1 / D + WORK( K+1, INVD+1 ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K+1, INVD ) = CONJG( WORK( K, INVD+1 ) ) + K = K + 1 + END IF + K = K + 1 + END DO +* +* inv(U**H) = (inv(U))**H +* +* inv(U**H) * inv(D) * inv(U) +* + CUT = N + DO WHILE( CUT.GT.0 ) + NNB = NB + IF( CUT.LE.NNB ) THEN + NNB = CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT+1-NNB, CUT + IF( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF + + CUT = CUT - NNB +* +* U01 Block +* + DO I = 1, CUT + DO J = 1, NNB + WORK( I, J ) = A( I, CUT+J ) + END DO + END DO +* +* U11 Block +* + DO I = 1, NNB + WORK( U11+I, I ) = CONE + DO J = 1, I-1 + WORK( U11+I, J ) = CZERO + END DO + DO J = I+1, NNB + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD * U01 +* + I = 1 + DO WHILE( I.LE.CUT ) + IF( IPIV( I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( I, INVD ) * WORK( I, J ) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK( I, J ) + U01_IP1_J = WORK( I+1, J ) + WORK( I, J ) = WORK( I, INVD ) * U01_I_J + $ + WORK( I, INVD+1 ) * U01_IP1_J + WORK( I+1, J ) = WORK( I+1, INVD ) * U01_I_J + $ + WORK( I+1, INVD+1 ) * U01_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* invD1 * U11 +* + I = 1 + DO WHILE ( I.LE.NNB ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = I, NNB + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + END DO + ELSE + DO J = I, NNB + U11_I_J = WORK(U11+I,J) + U11_IP1_J = WORK(U11+I+1,J) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * WORK(U11+I+1,J) + WORK( U11+I+1, J ) = WORK(CUT+I+1,INVD) * U11_I_J + $ + WORK(CUT+I+1,INVD+1) * U11_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* U11**H * invD1 * U11 -> U11 +* + CALL CTRMM( 'L', 'U', 'C', 'U', NNB, NNB, + $ CONE, A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* +* U01**H * invD * U01 -> A( CUT+I, CUT+J ) +* + CALL CGEMM( 'C', 'N', NNB, NNB, CUT, CONE, A( 1, CUT+1 ), + $ LDA, WORK, N+NB+1, CZERO, WORK(U11+1,1), + $ N+NB+1 ) + +* +* U11 = U11**H * invD1 * U11 + U01**H * invD * U01 +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J ) + WORK(U11+I,J) + END DO + END DO +* +* U01 = U00**H * invD0 * U01 +* + CALL CTRMM( 'L', UPLO, 'C', 'U', CUT, NNB, + $ CONE, A, LDA, WORK, N+NB+1 ) + +* +* Update U01 +* + DO I = 1, CUT + DO J = 1, NNB + A( I, CUT+J ) = WORK( I, J ) + END DO + END DO +* +* Next Block +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(U**H) * inv(D) * inv(U) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Upper case. +* +* ( We can use a loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = 1, N + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* inv A = P * inv(L**H) * inv(D) * inv(L) * P**T. +* + CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(L) +* + K = N + DO WHILE ( K .GE. 1 ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / REAL( A( K, K ) ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = ABS( WORK( K-1, 1 ) ) + AK = REAL( A( K-1, K-1 ) ) / T + AKP1 = REAL( A( K, K ) ) / T + AKKP1 = WORK( K-1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K-1, INVD ) = AKP1 / D + WORK( K, INVD ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K-1, INVD+1 ) = CONJG( WORK( K, INVD+1 ) ) + K = K - 1 + END IF + K = K - 1 + END DO +* +* inv(L**H) = (inv(L))**H +* +* inv(L**H) * inv(D) * inv(L) +* + CUT = 0 + DO WHILE( CUT.LT.N ) + NNB = NB + IF( (CUT + NNB).GT.N ) THEN + NNB = N - CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT + 1, CUT+NNB + IF ( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF +* +* L21 Block +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + WORK( I, J ) = A( CUT+NNB+I, CUT+J ) + END DO + END DO +* +* L11 Block +* + DO I = 1, NNB + WORK( U11+I, I) = CONE + DO J = I+1, NNB + WORK( U11+I, J ) = CZERO + END DO + DO J = 1, I-1 + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD*L21 +* + I = N-CUT-NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+NNB+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( CUT+NNB+I, INVD) * WORK( I, J) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK(I,J) + U01_IP1_J = WORK(I-1,J) + WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ + $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J + WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ + $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* invD1*L11 +* + I = NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( U11+I, J ) = WORK( CUT+I, INVD)*WORK(U11+I,J) + END DO + + ELSE + DO J = 1, NNB + U11_I_J = WORK( U11+I, J ) + U11_IP1_J = WORK( U11+I-1, J ) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * U11_IP1_J + WORK( U11+I-1, J ) = WORK(CUT+I-1,INVD+1) * U11_I_J + $ + WORK(CUT+I-1,INVD) * U11_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* L11**H * invD1 * L11 -> L11 +* + CALL CTRMM( 'L', UPLO, 'C', 'U', NNB, NNB, CONE, + $ A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) + +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* + IF( (CUT+NNB).LT.N ) THEN +* +* L21**H * invD2*L21 -> A( CUT+I, CUT+J ) +* + CALL CGEMM( 'C', 'N', NNB, NNB, N-NNB-CUT, CONE, + $ A( CUT+NNB+1, CUT+1 ), LDA, WORK, N+NB+1, + $ CZERO, WORK( U11+1, 1 ), N+NB+1 ) + +* +* L11 = L11**H * invD1 * L11 + U01**H * invD * U01 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J )+WORK(U11+I,J) + END DO + END DO +* +* L01 = L22**H * invD2 * L21 +* + CALL CTRMM( 'L', UPLO, 'C', 'U', N-NNB-CUT, NNB, CONE, + $ A( CUT+NNB+1, CUT+NNB+1 ), LDA, WORK, + $ N+NB+1 ) +* +* Update L21 +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + A( CUT+NNB+I, CUT+J ) = WORK( I, J ) + END DO + END DO +* + ELSE +* +* L11 = L11**H * invD1 * L11 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO + END IF +* +* Next Block +* + CUT = CUT + NNB +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(L**H) * inv(D) * inv(L) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Lower case. +* +* ( We can use a loop over IPIV with increment -1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = N, 1, -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + END IF +* + RETURN +* +* End of CHETRI_3X +* + END diff --git a/SRC/chetrs_3.f b/SRC/chetrs_3.f new file mode 100644 index 00000000..2799aa24 --- /dev/null +++ b/SRC/chetrs_3.f @@ -0,0 +1,374 @@ +*> \brief \b CHETRS_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CHETRS_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrs_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrs_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrs_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CHETRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CHETRS_3 solves a system of linear equations A * X = B with a complex +*> Hermitian matrix A using the factorization computed +*> by CHETRF_RK or CHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This algorithm is using Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**H)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**H)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by CHETRF_RK and CHETRF_BK: +*> 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 +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CHETRF_RK or CHETRF_BK. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX array, dimension (LDB,NRHS) +*> On entry, the right hand side matrix B. +*> On exit, the solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CHETRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX ONE + PARAMETER ( ONE = ( 1.0E+0,0.0E+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, J, K, KP + REAL S + COMPLEX AK, AKM1, AKM1K, BK, BKM1, DENOM +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL CSSCAL, CSWAP, CTRSM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, CONJG, MAX, REAL +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CHETRS_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 .OR. NRHS.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin Upper +* +* Solve A*X = B, where A = U*D*U**H. +* +* P**T * B +* +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (U \P**T * B) -> B [ (U \P**T * B) ] +* + CALL CTRSM( 'L', 'U', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (U \P**T * B) ] +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN + S = REAL( ONE ) / REAL( A( I, I ) ) + CALL CSSCAL( NRHS, S, B( I, 1 ), LDB ) + ELSE IF ( I.GT.1 ) THEN + AKM1K = E( I ) + AKM1 = A( I-1, I-1 ) / AKM1K + AK = A( I, I ) / CONJG( AKM1K ) + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I-1, J ) / AKM1K + BK = B( I, J ) / CONJG( AKM1K ) + B( I-1, J ) = ( AK*BKM1-BK ) / DENOM + B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* Compute (U**H \ B) -> B [ U**H \ (D \ (U \P**T * B) ) ] +* + CALL CTRSM( 'L', 'U', 'C', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (U**H \ (D \ (U \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* Solve A*X = B, where A = L*D*L**H. +* +* P**T * B +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (L \P**T * B) -> B [ (L \P**T * B) ] +* + CALL CTRSM( 'L', 'L', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (L \P**T * B) ] +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN + S = REAL( ONE ) / REAL( A( I, I ) ) + CALL CSSCAL( NRHS, S, B( I, 1 ), LDB ) + ELSE IF( I.LT.N ) THEN + AKM1K = E( I ) + AKM1 = A( I, I ) / CONJG( AKM1K ) + AK = A( I+1, I+1 ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I, J ) / CONJG( AKM1K ) + BK = B( I+1, J ) / AKM1K + B( I, J ) = ( AK*BKM1-BK ) / DENOM + B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* Compute (L**H \ B) -> B [ L**H \ (D \ (L \P**T * B) ) ] +* + CALL CTRSM('L', 'L', 'C', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (L**H \ (D \ (L \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* END Lower +* + END IF +* + RETURN +* +* End of CHETRS_3 +* + END diff --git a/SRC/chetrs_aa_REMOTE_88628.f b/SRC/chetrs_aa_REMOTE_88628.f deleted file mode 100644 index 33f32fac..00000000 --- a/SRC/chetrs_aa_REMOTE_88628.f +++ /dev/null @@ -1,292 +0,0 @@ -*> \brief \b CHETRS_AASEN -* -* =========== DOCUMENTATION =========== -* -* Online html documentation available at -* http://www.netlib.org/lapack/explore-html/ -* -*> \htmlonly -*> Download CHETRS_AASEN + dependencies -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrs_aasen.f"> -*> [TGZ]</a> -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrs_aasen.f"> -*> [ZIP]</a> -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrs_aasen.f"> -*> [TXT]</a> -*> \endhtmlonly -* -* Definition: -* =========== -* -* SUBROUTINE CHETRS_AASEN( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, -* WORK, LWORK, INFO ) -* -* .. Scalar Arguments .. -* CHARACTER UPLO -* INTEGER N, NRHS, LDA, LDB, LWORK, INFO -* .. -* .. Array Arguments .. -* INTEGER IPIV( * ) -* COMPLEX A( LDA, * ), B( LDB, * ), WORK( * ) -* .. -* -* -*> \par Purpose: -* ============= -*> -*> \verbatim -*> -*> CHETRS_AASEN solves a system of linear equations A*X = B with a real -*> hermitian matrix A using the factorization A = U*T*U**T or -*> A = L*T*L**T computed by CHETRF_AASEN. -*> \endverbatim -* -* Arguments: -* ========== -* -*> \param[in] UPLO -*> \verbatim -*> UPLO is CHARACTER*1 -*> Specifies whether the details of the factorization are stored -*> as an upper or lower triangular matrix. -*> = 'U': Upper triangular, form is A = U*T*U**T; -*> = 'L': Lower triangular, form is A = L*T*L**T. -*> \endverbatim -*> -*> \param[in] N -*> \verbatim -*> N is INTEGER -*> The order of the matrix A. N >= 0. -*> \endverbatim -*> -*> \param[in] NRHS -*> \verbatim -*> NRHS is INTEGER -*> The number of right hand sides, i.e., the number of columns -*> of the matrix B. NRHS >= 0. -*> \endverbatim -*> -*> \param[in,out] A -*> \verbatim -*> A is COMPLEX array, dimension (LDA,N) -*> Details of factors computed by CHETRF_AASEN. -*> \endverbatim -*> -*> \param[in] LDA -*> \verbatim -*> LDA is INTEGER -*> The leading dimension of the array A. LDA >= max(1,N). -*> \endverbatim -*> -*> \param[in] IPIV -*> \verbatim -*> IPIV is INTEGER array, dimension (N) -*> Details of the interchanges as computed by CHETRF_AASEN. -*> \endverbatim -*> -*> \param[in,out] B -*> \verbatim -*> B is COMPLEX array, dimension (LDB,NRHS) -*> On entry, the right hand side matrix B. -*> On exit, the solution matrix X. -*> \endverbatim -*> -*> \param[in] LDB -*> \verbatim -*> LDB is INTEGER -*> The leading dimension of the array B. LDB >= max(1,N). -*> \endverbatim -*> -*> \param[in] WORK -*> \verbatim -*> WORK is DOUBLE array, dimension (MAX(1,LWORK)) -*> \endverbatim -*> -*> \param[in] LWORK -*> \verbatim -*> LWORK is INTEGER, LWORK >= 3*N-2. -*> -*> \param[out] INFO -*> \verbatim -*> INFO is INTEGER -*> = 0: successful exit -*> < 0: if INFO = -i, the i-th argument had an illegal value -*> \endverbatim -* -* Authors: -* ======== -* -*> \author Univ. of Tennessee -*> \author Univ. of California Berkeley -*> \author Univ. of Colorado Denver -*> \author NAG Ltd. -* -*> \date November 2016 -* -*> \ingroup complexSYcomputational -* -* @generated from zhetrs_aasen.f, fortran z -> c, Fri Sep 23 00:09:52 2016 -* -* ===================================================================== - SUBROUTINE CHETRS_AASEN( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, - $ WORK, LWORK, INFO ) -* -* -- LAPACK computational routine (version 3.4.0) -- -* -- LAPACK is a software package provided by Univ. of Tennessee, -- -* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- -* November 2016 -* - IMPLICIT NONE -* -* .. Scalar Arguments .. - CHARACTER UPLO - INTEGER N, NRHS, LDA, LDB, LWORK, INFO -* .. -* .. Array Arguments .. - INTEGER IPIV( * ) - COMPLEX A( LDA, * ), B( LDB, * ), WORK( * ) -* .. -* -* ===================================================================== -* - COMPLEX ONE - PARAMETER ( ONE = 1.0E+0 ) -* .. -* .. Local Scalars .. - LOGICAL UPPER - INTEGER K, KP -* .. -* .. External Functions .. - LOGICAL LSAME - EXTERNAL LSAME -* .. -* .. External Subroutines .. - EXTERNAL CGTSV, CSWAP, CTRSM, XERBLA -* .. -* .. Intrinsic Functions .. - INTRINSIC MAX -* .. -* .. Executable Statements .. -* - INFO = 0 - UPPER = LSAME( UPLO, 'U' ) - IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN - INFO = -1 - ELSE IF( N.LT.0 ) THEN - INFO = -2 - ELSE IF( NRHS.LT.0 ) THEN - INFO = -3 - ELSE IF( LDA.LT.MAX( 1, N ) ) THEN - INFO = -5 - ELSE IF( LDB.LT.MAX( 1, N ) ) THEN - INFO = -8 - ELSE IF( LWORK.LT.(3*N-2) ) THEN - INFO = -10 - END IF - IF( INFO.NE.0 ) THEN - CALL XERBLA( 'CHETRS_AASEN', -INFO ) - RETURN - END IF -* -* Quick return if possible -* - IF( N.EQ.0 .OR. NRHS.EQ.0 ) - $ RETURN -* - IF( UPPER ) THEN -* -* Solve A*X = B, where A = U*T*U**T. -* -* P**T * B -* - K = 1 - DO WHILE ( K.LE.N ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K + 1 - END DO -* -* Compute (U \P**T * B) -> B [ (U \P**T * B) ] -* - CALL CTRSM('L', 'U', 'C', 'U', N-1, NRHS, ONE, A( 1, 2 ), LDA, - $ B( 2, 1 ), LDB) -* -* Compute T \ B -> B [ T \ (U \P**T * B) ] -* - CALL CLACPY( 'F', 1, N, A(1, 1), LDA+1, WORK(N), 1) - IF( N.GT.1 ) THEN - CALL CLACPY( 'F', 1, N-1, A( 1, 2 ), LDA+1, WORK( 2*N ), 1) - CALL CLACPY( 'F', 1, N-1, A( 1, 2 ), LDA+1, WORK( 1 ), 1) - CALL CLACGV( N-1, WORK( 1 ), 1 ) - END IF - CALL CGTSV(N, NRHS, WORK(1), WORK(N), WORK(2*N), B, LDB, - $ INFO) -* -* Compute (U**T \ B) -> B [ U**T \ (T \ (U \P**T * B) ) ] -* - CALL CTRSM( 'L', 'U', 'N', 'U', N-1, NRHS, ONE, A( 1, 2 ), LDA, - $ B(2, 1), LDB) -* -* Pivot, P * B [ P * (U**T \ (T \ (U \P**T * B) )) ] -* - K = N - DO WHILE ( K.GE.1 ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K - 1 - END DO -* - ELSE -* -* Solve A*X = B, where A = L*T*L**T. -* -* Pivot, P**T * B -* - K = 1 - DO WHILE ( K.LE.N ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K + 1 - END DO -* -* Compute (L \P**T * B) -> B [ (L \P**T * B) ] -* - CALL CTRSM( 'L', 'L', 'N', 'U', N-1, NRHS, ONE, A( 2, 1), LDA, - $ B(2, 1), LDB) -* -* Compute T \ B -> B [ T \ (L \P**T * B) ] -* - CALL CLACPY( 'F', 1, N, A(1, 1), LDA+1, WORK(N), 1) - IF( N.GT.1 ) THEN - CALL CLACPY( 'F', 1, N-1, A( 2, 1 ), LDA+1, WORK( 1 ), 1) - CALL CLACPY( 'F', 1, N-1, A( 2, 1 ), LDA+1, WORK( 2*N ), 1) - CALL CLACGV( N-1, WORK( 2*N ), 1 ) - END IF - CALL CGTSV(N, NRHS, WORK(1), WORK(N), WORK(2*N), B, LDB, - $ INFO) -* -* Compute (L**T \ B) -> B [ L**T \ (T \ (L \P**T * B) ) ] -* - CALL CTRSM( 'L', 'L', 'C', 'U', N-1, NRHS, ONE, A( 2, 1 ), LDA, - $ B( 2, 1 ), LDB) -* -* Pivot, P * B [ P * (L**T \ (T \ (L \P**T * B) )) ] -* - K = N - DO WHILE ( K.GE.1 ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K - 1 - END DO -* - END IF -* - RETURN -* -* End of CHETRS_AASEN -* - END diff --git a/SRC/chetrs_aa_REMOTE_88868.f b/SRC/chetrs_aa_REMOTE_88868.f deleted file mode 100644 index 33f32fac..00000000 --- a/SRC/chetrs_aa_REMOTE_88868.f +++ /dev/null @@ -1,292 +0,0 @@ -*> \brief \b CHETRS_AASEN -* -* =========== DOCUMENTATION =========== -* -* Online html documentation available at -* http://www.netlib.org/lapack/explore-html/ -* -*> \htmlonly -*> Download CHETRS_AASEN + dependencies -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrs_aasen.f"> -*> [TGZ]</a> -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrs_aasen.f"> -*> [ZIP]</a> -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrs_aasen.f"> -*> [TXT]</a> -*> \endhtmlonly -* -* Definition: -* =========== -* -* SUBROUTINE CHETRS_AASEN( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, -* WORK, LWORK, INFO ) -* -* .. Scalar Arguments .. -* CHARACTER UPLO -* INTEGER N, NRHS, LDA, LDB, LWORK, INFO -* .. -* .. Array Arguments .. -* INTEGER IPIV( * ) -* COMPLEX A( LDA, * ), B( LDB, * ), WORK( * ) -* .. -* -* -*> \par Purpose: -* ============= -*> -*> \verbatim -*> -*> CHETRS_AASEN solves a system of linear equations A*X = B with a real -*> hermitian matrix A using the factorization A = U*T*U**T or -*> A = L*T*L**T computed by CHETRF_AASEN. -*> \endverbatim -* -* Arguments: -* ========== -* -*> \param[in] UPLO -*> \verbatim -*> UPLO is CHARACTER*1 -*> Specifies whether the details of the factorization are stored -*> as an upper or lower triangular matrix. -*> = 'U': Upper triangular, form is A = U*T*U**T; -*> = 'L': Lower triangular, form is A = L*T*L**T. -*> \endverbatim -*> -*> \param[in] N -*> \verbatim -*> N is INTEGER -*> The order of the matrix A. N >= 0. -*> \endverbatim -*> -*> \param[in] NRHS -*> \verbatim -*> NRHS is INTEGER -*> The number of right hand sides, i.e., the number of columns -*> of the matrix B. NRHS >= 0. -*> \endverbatim -*> -*> \param[in,out] A -*> \verbatim -*> A is COMPLEX array, dimension (LDA,N) -*> Details of factors computed by CHETRF_AASEN. -*> \endverbatim -*> -*> \param[in] LDA -*> \verbatim -*> LDA is INTEGER -*> The leading dimension of the array A. LDA >= max(1,N). -*> \endverbatim -*> -*> \param[in] IPIV -*> \verbatim -*> IPIV is INTEGER array, dimension (N) -*> Details of the interchanges as computed by CHETRF_AASEN. -*> \endverbatim -*> -*> \param[in,out] B -*> \verbatim -*> B is COMPLEX array, dimension (LDB,NRHS) -*> On entry, the right hand side matrix B. -*> On exit, the solution matrix X. -*> \endverbatim -*> -*> \param[in] LDB -*> \verbatim -*> LDB is INTEGER -*> The leading dimension of the array B. LDB >= max(1,N). -*> \endverbatim -*> -*> \param[in] WORK -*> \verbatim -*> WORK is DOUBLE array, dimension (MAX(1,LWORK)) -*> \endverbatim -*> -*> \param[in] LWORK -*> \verbatim -*> LWORK is INTEGER, LWORK >= 3*N-2. -*> -*> \param[out] INFO -*> \verbatim -*> INFO is INTEGER -*> = 0: successful exit -*> < 0: if INFO = -i, the i-th argument had an illegal value -*> \endverbatim -* -* Authors: -* ======== -* -*> \author Univ. of Tennessee -*> \author Univ. of California Berkeley -*> \author Univ. of Colorado Denver -*> \author NAG Ltd. -* -*> \date November 2016 -* -*> \ingroup complexSYcomputational -* -* @generated from zhetrs_aasen.f, fortran z -> c, Fri Sep 23 00:09:52 2016 -* -* ===================================================================== - SUBROUTINE CHETRS_AASEN( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, - $ WORK, LWORK, INFO ) -* -* -- LAPACK computational routine (version 3.4.0) -- -* -- LAPACK is a software package provided by Univ. of Tennessee, -- -* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- -* November 2016 -* - IMPLICIT NONE -* -* .. Scalar Arguments .. - CHARACTER UPLO - INTEGER N, NRHS, LDA, LDB, LWORK, INFO -* .. -* .. Array Arguments .. - INTEGER IPIV( * ) - COMPLEX A( LDA, * ), B( LDB, * ), WORK( * ) -* .. -* -* ===================================================================== -* - COMPLEX ONE - PARAMETER ( ONE = 1.0E+0 ) -* .. -* .. Local Scalars .. - LOGICAL UPPER - INTEGER K, KP -* .. -* .. External Functions .. - LOGICAL LSAME - EXTERNAL LSAME -* .. -* .. External Subroutines .. - EXTERNAL CGTSV, CSWAP, CTRSM, XERBLA -* .. -* .. Intrinsic Functions .. - INTRINSIC MAX -* .. -* .. Executable Statements .. -* - INFO = 0 - UPPER = LSAME( UPLO, 'U' ) - IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN - INFO = -1 - ELSE IF( N.LT.0 ) THEN - INFO = -2 - ELSE IF( NRHS.LT.0 ) THEN - INFO = -3 - ELSE IF( LDA.LT.MAX( 1, N ) ) THEN - INFO = -5 - ELSE IF( LDB.LT.MAX( 1, N ) ) THEN - INFO = -8 - ELSE IF( LWORK.LT.(3*N-2) ) THEN - INFO = -10 - END IF - IF( INFO.NE.0 ) THEN - CALL XERBLA( 'CHETRS_AASEN', -INFO ) - RETURN - END IF -* -* Quick return if possible -* - IF( N.EQ.0 .OR. NRHS.EQ.0 ) - $ RETURN -* - IF( UPPER ) THEN -* -* Solve A*X = B, where A = U*T*U**T. -* -* P**T * B -* - K = 1 - DO WHILE ( K.LE.N ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K + 1 - END DO -* -* Compute (U \P**T * B) -> B [ (U \P**T * B) ] -* - CALL CTRSM('L', 'U', 'C', 'U', N-1, NRHS, ONE, A( 1, 2 ), LDA, - $ B( 2, 1 ), LDB) -* -* Compute T \ B -> B [ T \ (U \P**T * B) ] -* - CALL CLACPY( 'F', 1, N, A(1, 1), LDA+1, WORK(N), 1) - IF( N.GT.1 ) THEN - CALL CLACPY( 'F', 1, N-1, A( 1, 2 ), LDA+1, WORK( 2*N ), 1) - CALL CLACPY( 'F', 1, N-1, A( 1, 2 ), LDA+1, WORK( 1 ), 1) - CALL CLACGV( N-1, WORK( 1 ), 1 ) - END IF - CALL CGTSV(N, NRHS, WORK(1), WORK(N), WORK(2*N), B, LDB, - $ INFO) -* -* Compute (U**T \ B) -> B [ U**T \ (T \ (U \P**T * B) ) ] -* - CALL CTRSM( 'L', 'U', 'N', 'U', N-1, NRHS, ONE, A( 1, 2 ), LDA, - $ B(2, 1), LDB) -* -* Pivot, P * B [ P * (U**T \ (T \ (U \P**T * B) )) ] -* - K = N - DO WHILE ( K.GE.1 ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K - 1 - END DO -* - ELSE -* -* Solve A*X = B, where A = L*T*L**T. -* -* Pivot, P**T * B -* - K = 1 - DO WHILE ( K.LE.N ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K + 1 - END DO -* -* Compute (L \P**T * B) -> B [ (L \P**T * B) ] -* - CALL CTRSM( 'L', 'L', 'N', 'U', N-1, NRHS, ONE, A( 2, 1), LDA, - $ B(2, 1), LDB) -* -* Compute T \ B -> B [ T \ (L \P**T * B) ] -* - CALL CLACPY( 'F', 1, N, A(1, 1), LDA+1, WORK(N), 1) - IF( N.GT.1 ) THEN - CALL CLACPY( 'F', 1, N-1, A( 2, 1 ), LDA+1, WORK( 1 ), 1) - CALL CLACPY( 'F', 1, N-1, A( 2, 1 ), LDA+1, WORK( 2*N ), 1) - CALL CLACGV( N-1, WORK( 2*N ), 1 ) - END IF - CALL CGTSV(N, NRHS, WORK(1), WORK(N), WORK(2*N), B, LDB, - $ INFO) -* -* Compute (L**T \ B) -> B [ L**T \ (T \ (L \P**T * B) ) ] -* - CALL CTRSM( 'L', 'L', 'C', 'U', N-1, NRHS, ONE, A( 2, 1 ), LDA, - $ B( 2, 1 ), LDB) -* -* Pivot, P * B [ P * (L**T \ (T \ (L \P**T * B) )) ] -* - K = N - DO WHILE ( K.GE.1 ) - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - K = K - 1 - END DO -* - END IF -* - RETURN -* -* End of CHETRS_AASEN -* - END diff --git a/SRC/clahef_rk.f b/SRC/clahef_rk.f new file mode 100644 index 00000000..c981a9c8 --- /dev/null +++ b/SRC/clahef_rk.f @@ -0,0 +1,1234 @@ +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexHEcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. 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, JB, JJ, 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) +* +* Initilize 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 +* +* computing blocks of NB columns at a time (note that conjg(W) is +* actually stored) +* + DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB + JB = MIN( NB, K-J+1 ) +* +* Update the upper triangle of the diagonal block +* + DO 40 JJ = J, J + JB - 1 + A( JJ, JJ ) = REAL( A( JJ, JJ ) ) + CALL CGEMV( 'No transpose', JJ-J+1, N-K, -CONE, + $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE, + $ A( J, JJ ), 1 ) + A( JJ, JJ ) = REAL( A( JJ, JJ ) ) + 40 CONTINUE +* +* Update the rectangular superdiagonal block +* + IF( J.GE.2 ) + $ CALL CGEMM( 'No transpose', 'Transpose', J-1, JB, N-K, + $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW, + $ CONE, A( 1, J ), LDA ) + 50 CONTINUE +* +* 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) +* +* Initilize 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 +* +* computing blocks of NB columns at a time (note that conjg(W) is +* actually stored) +* + DO 110 J = K, N, NB + JB = MIN( NB, N-J+1 ) +* +* Update the lower triangle of the diagonal block +* + DO 100 JJ = J, J + JB - 1 + A( JJ, JJ ) = REAL( A( JJ, JJ ) ) + CALL CGEMV( 'No transpose', J+JB-JJ, K-1, -CONE, + $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE, + $ A( JJ, JJ ), 1 ) + A( JJ, JJ ) = REAL( A( JJ, JJ ) ) + 100 CONTINUE +* +* Update the rectangular subdiagonal block +* + IF( J+JB.LE.N ) + $ CALL CGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, + $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ), + $ LDW, CONE, A( J+JB, J ), LDA ) + 110 CONTINUE +* +* Set KB to the number of columns factorized +* + KB = K - 1 +* + END IF + RETURN +* +* End of CLAHEF_RK +* + END diff --git a/SRC/clasyf_rk.f b/SRC/clasyf_rk.f new file mode 100644 index 00000000..ac181200 --- /dev/null +++ b/SRC/clasyf_rk.f @@ -0,0 +1,974 @@ +*> \brief \b CLASYF_RK computes a partial factorization of a complex symmetric 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 CLASYF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clasyf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clasyf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clasyf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CLASYF_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 +*> CLASYF_RK computes a partial factorization of a complex symmetric +*> 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**T U22**T ) +*> +*> A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) 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. +*> +*> CLASYF_RK is an auxiliary routine called by CSYTRF_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 +*> symmetric 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 symmetric 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 symmetric 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 symmetric 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 symmetric 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. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CLASYF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, KB, LDA, LDW, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* ===================================================================== +* +* .. 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, J, JB, JJ, JMAX, K, KK, KW, KKW, + $ KP, KSTEP, P, II + REAL ABSAKK, ALPHA, COLMAX, ROWMAX, SFMIN, STEMP + COMPLEX D11, D12, D21, D22, R1, T, Z +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ICAMAX + REAL SLAMCH + EXTERNAL LSAME, ICAMAX, SLAMCH +* .. +* .. External Subroutines .. + EXTERNAL CCOPY, CGEMM, CGEMV, CSCAL, CSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, 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 +* +* Initilize 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 +* + CALL CCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 ) + IF( K.LT.N ) + $ CALL CGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), + $ LDA, W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( 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 + CALL CCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = CZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* +* Copy column IMAX to column KW-1 of W and update it +* + CALL CCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 ) + CALL CCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, + $ W( IMAX+1, KW-1 ), 1 ) +* + IF( K.LT.N ) + $ CALL CGEMV( 'No transpose', K, N-K, -CONE, + $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW, + $ CONE, W( 1, KW-1 ), 1 ) +* +* 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 +* +* Equivalent to testing for +* CABS1( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.(CABS1( 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. +* +* 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. + 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 +* +* ============================================================ +* + KK = K - KSTEP + 1 +* +* KKW is the column of W which corresponds to column KK of A +* + KKW = NB + KK - N +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL CCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA ) + CALL CCOPY( P, A( 1, K ), 1, A( 1, P ), 1 ) +* +* Interchange rows K and P in last N-K+1 columns of A +* and last N-K+2 columns of W +* + CALL CSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA ) + CALL CSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW ) + END IF +* +* Updated column KP is already stored in column KKW of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL CCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + CALL CCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 ) +* +* Interchange rows KK and KP in last N-KK+1 columns +* of A and W +* + CALL CSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), 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(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* +* Store U(k) in column k of A +* + CALL CCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) + IF( K.GT.1 ) THEN + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN + R1 = CONE / A( K, K ) + CALL CSCAL( K-1, R1, A( 1, K ), 1 ) + ELSE IF( A( K, K ).NE.CZERO ) THEN + DO 14 II = 1, K - 1 + A( II, K ) = A( II, K ) / A( K, K ) + 14 CONTINUE + END IF +* +* 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(k-1) W(k) ) = ( 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 +* + IF( K.GT.2 ) THEN +* +* Store U(k) and U(k-1) in columns k and k-1 of A +* + D12 = W( K-1, KW ) + D11 = W( K, KW ) / D12 + D22 = W( K-1, KW-1 ) / D12 + T = CONE / ( D11*D22-CONE ) + DO 20 J = 1, K - 2 + A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) / + $ D12 ) + A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) / + $ D12 ) + 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 +* + 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**T = A11 - U12*W**T +* +* computing blocks of NB columns at a time +* + DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB + JB = MIN( NB, K-J+1 ) +* +* Update the upper triangle of the diagonal block +* + DO 40 JJ = J, J + JB - 1 + CALL CGEMV( 'No transpose', JJ-J+1, N-K, -CONE, + $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE, + $ A( J, JJ ), 1 ) + 40 CONTINUE +* +* Update the rectangular superdiagonal block +* + IF( J.GE.2 ) + $ CALL CGEMM( 'No transpose', 'Transpose', J-1, JB, + $ N-K, -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), + $ LDW, CONE, A( 1, J ), LDA ) + 50 CONTINUE +* +* 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 +* +* Initilize 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 it +* + CALL CCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 ) + IF( K.GT.1 ) + $ CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), + $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( 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 + CALL CCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = CZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 CCOPY( N-IMAX+1, A( IMAX, IMAX ), 1, + $ W( IMAX, K+1 ), 1 ) + IF( K.GT.1 ) + $ CALL CGEMV( 'No transpose', N-K+1, K-1, -CONE, + $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW, + $ CONE, W( K, K+1 ), 1 ) +* +* 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 +* +* Equivalent to testing for +* CABS1( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.( CABS1( 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. +* +* 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. + 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 +* +* ============================================================ +* + KK = K + KSTEP - 1 +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL CCOPY( P-K, A( K, K ), 1, A( P, K ), LDA ) + CALL CCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 ) +* +* Interchange rows K and P in first K columns of A +* and first K+1 columns of W +* + CALL CSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA ) + CALL CSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW ) + END IF +* +* Updated column KP is already stored in column KK of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL CCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA ) + CALL CCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 ) +* +* Interchange rows KK and KP in first KK columns of A and W +* + CALL CSWAP( KK, 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 +* +* Store L(k) in column k of A +* + CALL CCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) + IF( K.LT.N ) THEN + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN + R1 = CONE / A( K, K ) + CALL CSCAL( N-K, R1, A( K+1, K ), 1 ) + ELSE IF( A( K, K ).NE.CZERO ) THEN + DO 74 II = K + 1, N + A( II, K ) = A( II, K ) / A( K, K ) + 74 CONTINUE + END IF +* +* 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 +* + IF( K.LT.N-1 ) THEN +* +* Store L(k) and L(k+1) in columns k and k+1 of A +* + D21 = W( K+1, K ) + D11 = W( K+1, K+1 ) / D21 + D22 = W( K, K ) / D21 + T = CONE / ( D11*D22-CONE ) + DO 80 J = K + 2, N + A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) / + $ 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 +* + 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**T = A22 - L21*W**T +* +* computing blocks of NB columns at a time +* + DO 110 J = K, N, NB + JB = MIN( NB, N-J+1 ) +* +* Update the lower triangle of the diagonal block +* + DO 100 JJ = J, J + JB - 1 + CALL CGEMV( 'No transpose', J+JB-JJ, K-1, -CONE, + $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE, + $ A( JJ, JJ ), 1 ) + 100 CONTINUE +* +* Update the rectangular subdiagonal block +* + IF( J+JB.LE.N ) + $ CALL CGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, + $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ), + $ LDW, CONE, A( J+JB, J ), LDA ) + 110 CONTINUE +* +* Set KB to the number of columns factorized +* + KB = K - 1 +* + END IF +* + RETURN +* +* End of CLASYF_RK +* + END diff --git a/SRC/csycon_3.f b/SRC/csycon_3.f new file mode 100644 index 00000000..91aae29e --- /dev/null +++ b/SRC/csycon_3.f @@ -0,0 +1,287 @@ +*> \brief \b CSYCON_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYCON_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csycon_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csycon_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csycon_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, +* WORK, IWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* REAL ANORM, RCOND +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ), IWORK( * ) +* COMPLEX A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYCON_3 estimates the reciprocal of the condition number (in the +*> 1-norm) of a complex symmetric matrix A using the factorization +*> computed by CSYTRF_RK or CSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> An estimate is obtained for norm(inv(A)), and the reciprocal of the +*> condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). +*> This routine uses BLAS3 solver CSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by CSYTRF_RK and CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CSYTRF_RK or CSYTRF_BK. +*> \endverbatim +*> +*> \param[in] ANORM +*> \verbatim +*> ANORM is REAL +*> The 1-norm of the original matrix A. +*> \endverbatim +*> +*> \param[out] RCOND +*> \verbatim +*> RCOND is REAL +*> The reciprocal of the condition number of the matrix A, +*> computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an +*> estimate of the 1-norm of inv(A) computed in this routine. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension (2*N) +*> \endverbatim +*> +*> \param[out] IWORK +*> \verbatim +*> IWORK is INTEGER array, dimension (N) +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 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 CSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, + $ WORK, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N + REAL ANORM, RCOND +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE, ZERO + PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) + COMPLEX CZERO + PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, KASE + REAL AINVNM +* .. +* .. Local Arrays .. + INTEGER ISAVE( 3 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL CLACN2, CSYTRS_3, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( ANORM.LT.ZERO ) THEN + INFO = -7 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYCON_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + RCOND = ZERO + IF( N.EQ.0 ) THEN + RCOND = ONE + RETURN + ELSE IF( ANORM.LE.ZERO ) THEN + RETURN + END IF +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO I = N, 1, -1 + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.CZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO I = 1, N + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.CZERO ) + $ RETURN + END DO + END IF +* +* Estimate the 1-norm of the inverse. +* + KASE = 0 + 30 CONTINUE + CALL CLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE ) + IF( KASE.NE.0 ) THEN +* +* Multiply by inv(L*D*L**T) or inv(U*D*U**T). +* + CALL CSYTRS_3( UPLO, N, 1, A, LDA, E, IPIV, WORK, N, INFO ) + GO TO 30 + END IF +* +* Compute the estimate of the reciprocal condition number. +* + IF( AINVNM.NE.ZERO ) + $ RCOND = ( ONE / AINVNM ) / ANORM +* + RETURN +* +* End of CSYCON_3 +* + END diff --git a/SRC/csyconvf.f b/SRC/csyconvf.f new file mode 100644 index 00000000..df36055b --- /dev/null +++ b/SRC/csyconvf.f @@ -0,0 +1,562 @@ +*> \brief \b CSYCONVF +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYCONVF + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csyconvf.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csyconvf.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csyconvf.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYCONVF( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> CSYCONVF converts the factorization output format used in +*> CSYTRF provided on entry in parameter A into the factorization +*> output format used in CSYTRF_RK (or CSYTRF_BK) that is stored +*> on exit in parameters A and E. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in CSYTRF into +*> the format used in CSYTRF_RK (or CSYTRF_BK). +*> +*> If parameter WAY = 'R': +*> CSYCONVF performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in CSYTRF_RK +*> (or CSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in CSYTRF that is stored +*> on exit in parameter A. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in CSYTRF_RK +*> (or CSYTRF_BK) into the format used in CSYTRF. +*> +*> CSYCONVF can also convert in Hermitian matrix case, i.e. between +*> formats used in CHETRF and CHETRF_RK (or CHETRF_BK). +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> CSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> CSYTRF_RK or CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> CSYTRF_RK or CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> CSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in,out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> +*> 1) If WAY ='C': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in CSYTRF. +*> On exit, details of the interchanges and the block +*> structure of D in the format used in CSYTRF_RK +*> ( or CSYTRF_BK). +*> +*> 1) If WAY ='R': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in CSYTRF_RK +*> ( or CSYTRF_BK). +*> On exit, details of the interchanges and the block +*> structure of D in the format used in CSYTRF. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE CSYCONVF( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX ZERO + PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL CSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYCONVF', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL CSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL CSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i-1 and IPIV(i-1), +* so this should be recorded in two consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I-1 ) +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where k increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL CSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL CSWAP( I-1, A( IP, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i+1 and IPIV(i+1), +* so this should be recorded in consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I+1 ) +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of CSYCONVF +* + END diff --git a/SRC/csyconvf_rook.f b/SRC/csyconvf_rook.f new file mode 100644 index 00000000..a99678d5 --- /dev/null +++ b/SRC/csyconvf_rook.f @@ -0,0 +1,547 @@ +*> \brief \b CSYCONVF_ROOK +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYCONVF_ROOK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csyconvf_rook.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csyconvf_rook.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csyconvf_rook.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYCONVF_ROOK( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> CSYCONVF_ROOK converts the factorization output format used in +*> CSYTRF_ROOK provided on entry in parameter A into the factorization +*> output format used in CSYTRF_RK (or CSYTRF_BK) that is stored +*> on exit in parameters A and E. IPIV format for CSYTRF_ROOK and +*> CSYTRF_RK (or CSYTRF_BK) is the same and is not converted. +*> +*> If parameter WAY = 'R': +*> CSYCONVF_ROOK performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in CSYTRF_RK +*> (or CSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in CSYTRF_ROOK that is stored +*> on exit in parameter A. IPIV format for CSYTRF_ROOK and +*> CSYTRF_RK (or CSYTRF_BK) is the same and is not converted. +*> +*> CSYCONVF_ROOK can also convert in Hermitian matrix case, i.e. between +*> formats used in CHETRF_ROOK and CHETRF_RK (or CHETRF_BK). +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> CSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> CSYTRF_RK or CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> CSYTRF_RK or CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> CSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> On entry, details of the interchanges and the block +*> structure of D as determined: +*> 1) by CSYTRF_ROOK, if WAY ='C'; +*> 2) by CSYTRF_RK (or CSYTRF_BK), if WAY ='R'. +*> The IPIV format is the same for all these routines. +*> +*> On exit, is not changed. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE CSYCONVF_ROOK( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX ZERO + PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL CSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP, IP2 +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYCONVF_ROOK', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i-1 and IPIV(i-1) +* in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + IF( IP2.NE.(I-1) ) THEN + CALL CSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP2, I+1 ), LDA ) + END IF + END IF + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i-1) and i and IPIV(i) +* in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP2.NE.(I-1) ) THEN + CALL CSWAP( N-I, A( IP2, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL CSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i+1 and IPIV(i+1) +* in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + IF( IP2.NE.(I+1) ) THEN + CALL CSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP2, 1 ), LDA ) + END IF + END IF + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL CSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i+1) and i and IPIV(i) +* in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP2.NE.(I+1) ) THEN + CALL CSWAP( I-1, A( IP2, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL CSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of CSYCONVF_ROOK +* + END diff --git a/SRC/csysv_rk.f b/SRC/csysv_rk.f new file mode 100644 index 00000000..5cfd358b --- /dev/null +++ b/SRC/csysv_rk.f @@ -0,0 +1,316 @@ +*> \brief <b> CSYSV_RK computes the solution to system of linear equations A * X = B for SY matrices</b> +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYSV_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csysv_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csysv_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csysv_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* WORK, LWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYSV_RK computes the solution to a complex system of linear +*> equations A * X = B, where A is an N-by-N symmetric matrix +*> and X and B are N-by-NRHS matrices. +*> +*> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used +*> to factor A as +*> A = P*U*D*(U**T)*(P**T), if UPLO = 'U', or +*> A = P*L*D*(L**T)*(P**T), if UPLO = 'L', +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> CSYTRF_RK is called to compute the factorization of a complex +*> symmetric matrix. The factored form of A is then used to solve +*> the system of equations A * X = B by calling BLAS3 routine CSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric matrix A is stored: +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The number of linear equations, i.e., the order of the +*> matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, the symmetric 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, if INFO = 0, diagonal of the block diagonal +*> matrix D and factors U or L as computed by CSYTRF_RK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> For more info see the description of CSYTRF_RK routine. +*> \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 output computed by the factorization +*> routine CSYTRF_RK, i.e. the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> For more info see the description of CSYTRF_RK routine. +*> \endverbatim +*> +*> \param[out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D, +*> as determined by CSYTRF_RK. +*> +*> For more info see the description of CSYTRF_RK routine. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX array, dimension (LDB,NRHS) +*> On entry, the N-by-NRHS right hand side matrix B. +*> On exit, if INFO = 0, the N-by-NRHS solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension ( MAX(1,LWORK) ). +*> Work array used in the factorization stage. +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= 1. For best performance +*> of factorization stage LWORK >= max(1,N*NB), where NB is +*> the optimal blocksize for CSYTRF_RK. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array for factorization stage, returns this value as +*> the first entry of the WORK array, and no error message +*> related to LWORK is issued by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexSYsolve +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, WORK, + $ LWORK, INFO ) +* +* -- LAPACK driver routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY + INTEGER LWKOPT +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, CSYTRF_RK, CSYTRS_3 +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -11 + END IF +* + IF( INFO.EQ.0 ) THEN + IF( N.EQ.0 ) THEN + LWKOPT = 1 + ELSE + CALL CSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO ) + LWKOPT = WORK(1) + END IF + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYSV_RK ', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* +* Compute the factorization A = U*D*U**T or A = L*D*L**T. +* + CALL CSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO ) +* + IF( INFO.EQ.0 ) THEN +* +* Solve the system A*X = B with BLAS3 solver, overwriting B with X. +* + CALL CSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO ) +* + END IF +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of CSYSV_RK +* + END diff --git a/SRC/csytf2_rk.f b/SRC/csytf2_rk.f new file mode 100644 index 00000000..5715de90 --- /dev/null +++ b/SRC/csytf2_rk.f @@ -0,0 +1,952 @@ +*> \brief \b CSYTF2_RK computes the factorization of a complex symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYTF2_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csytf2_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csytf2_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csytf2_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E ( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYTF2_RK computes the factorization of a complex symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the unblocked version of the algorithm, calling Level 2 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put further details +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 +*> +*> 01-01-96 - Based on modifications by +*> J. Lewis, Boeing Computer Services Company +*> A. Petitet, Computer Science Dept., +*> Univ. of Tenn., Knoxville abd , USA +*> \endverbatim +* +* ===================================================================== + SUBROUTINE CSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), 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 UPPER, DONE + INTEGER I, IMAX, J, JMAX, ITEMP, K, KK, KP, KSTEP, + $ P, II + REAL ABSAKK, ALPHA, COLMAX, ROWMAX, STEMP, SFMIN + COMPLEX D11, D12, D21, D22, T, WK, WKM1, WKP1, Z +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ICAMAX + REAL SLAMCH + EXTERNAL LSAME, ICAMAX, SLAMCH +* .. +* .. External Subroutines .. + EXTERNAL CSCAL, CSWAP, CSYR, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, SQRT, AIMAG, REAL +* .. +* .. Statement Functions .. + REAL CABS1 +* .. +* .. Statement Function definitions .. + CABS1( Z ) = ABS( REAL( Z ) ) + ABS( AIMAG( Z ) ) +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYTF2_RK', -INFO ) + RETURN + END IF +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = SLAMCH( 'S' ) +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* Initilize 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 to 1 in steps of +* 1 or 2 +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 34 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( A( 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.GT.1 ) THEN + IMAX = ICAMAX( K-1, A( 1, K ), 1 ) + COLMAX = CABS1( A( 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 +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = CZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, +* use 1-by-1 pivot block +* + KP = K + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* 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, A( IMAX, IMAX+1 ), + $ LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = ICAMAX( IMAX-1, A( 1, IMAX ), 1 ) + STEMP = CABS1( A( ITEMP, IMAX ) ) + IF( STEMP.GT.ROWMAX ) THEN + ROWMAX = STEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( CABS1( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX )) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the leading +* submatrix A(1:k,1:k) if we have a 2-by-2 pivot +* + IF( P.GT.1 ) + $ CALL CSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 ) + IF( P.LT.(K-1) ) + $ CALL CSWAP( K-P-1, A( P+1, K ), 1, A( P, P+1 ), + $ LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL CSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K - KSTEP + 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the leading +* submatrix A(1:k,1:k) +* + IF( KP.GT.1 ) + $ CALL CSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) + IF( ( KK.GT.1 ) .AND. ( KP.LT.(KK-1) ) ) + $ CALL CSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K-1, K ) + A( K-1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL CSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) +* + END IF +* +* Update the leading submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* + IF( K.GT.1 ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) and +* store U(k) in column k +* + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*1/D(k)*W(k)**T +* + D11 = CONE / A( K, K ) + CALL CSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) +* +* Store U(k) in column k +* + CALL CSCAL( K-1, D11, A( 1, K ), 1 ) + ELSE +* +* Store L(k) in column K +* + D11 = A( K, K ) + DO 16 II = 1, K - 1 + A( II, K ) = A( II, K ) / D11 + 16 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL CSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = CZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k-1 now hold +* +* ( W(k-1) W(k) ) = ( 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 +* +* Perform a rank-2 update of A(1:k-2,1:k-2) as +* +* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T +* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.GT.2 ) THEN +* + D12 = A( K-1, K ) + D22 = A( K-1, K-1 ) / D12 + D11 = A( K, K ) / D12 + T = CONE / ( D11*D22-CONE ) +* + DO 30 J = K - 2, 1, -1 +* + WKM1 = T*( D11*A( J, K-1 )-A( J, K ) ) + WK = T*( D22*A( J, K )-A( J, K-1 ) ) +* + DO 20 I = J, 1, -1 + A( I, J ) = A( I, J ) - (A( I, K ) / D12 )*WK - + $ ( A( I, K-1 ) / D12 )*WKM1 + 20 CONTINUE +* +* Store U(k) and U(k-1) in cols k and k-1 for row J +* + A( J, K ) = WK / D12 + A( J, K-1 ) = WKM1 / D12 +* + 30 CONTINUE +* + END IF +* +* Copy superdiagonal elements of D(K) to E(K) and +* ZERO out superdiagonal entry of A +* + E( K ) = A( K-1, K ) + E( K-1 ) = CZERO + A( K-1, K ) = CZERO +* + 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 +* + 34 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = CZERO +* +* K is the main loop index, increasing from 1 to N in steps of +* 1 or 2 +* + K = 1 + 40 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 64 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( A( 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, A( K+1, K ), 1 ) + COLMAX = CABS1( A( 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 +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = CZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, use 1-by-1 pivot block +* + KP = K +* + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 42 CONTINUE +* +* Begin pivot search loop body +* +* 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, A( IMAX, K ), LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + ICAMAX( N-IMAX, A( IMAX+1, IMAX ), + $ 1 ) + STEMP = CABS1( A( ITEMP, IMAX ) ) + IF( STEMP.GT.ROWMAX ) THEN + ROWMAX = STEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( CABS1( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX )) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 42 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the trailing +* submatrix A(k:n,k:n) if we have a 2-by-2 pivot +* + IF( P.LT.N ) + $ CALL CSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) + IF( P.GT.(K+1) ) + $ CALL CSWAP( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL CSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K + KSTEP - 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the trailing +* submatrix A(k:n,k:n) +* + IF( KP.LT.N ) + $ CALL CSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) + IF( ( KK.LT.N ) .AND. ( KP.GT.(KK+1) ) ) + $ CALL CSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K+1, K ) + A( K+1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL CSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) +* + END IF +* +* Update the trailing submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = L(k)*D(k) +* +* where L(k) is the k-th column of L +* + IF( K.LT.N ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) and +* store L(k) in column k +* + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* + D11 = CONE / A( K, K ) + CALL CSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) +* +* Store L(k) in column k +* + CALL CSCAL( N-K, D11, A( K+1, K ), 1 ) + ELSE +* +* Store L(k) in column k +* + D11 = A( K, K ) + DO 46 II = K + 1, N + A( II, K ) = A( II, K ) / D11 + 46 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL CSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) + END IF +* +* 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 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 +* +* +* Perform a rank-2 update of A(k+2:n,k+2:n) as +* +* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T +* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.LT.N-1 ) THEN +* + D21 = A( K+1, K ) + D11 = A( K+1, K+1 ) / D21 + D22 = A( K, K ) / D21 + T = CONE / ( D11*D22-CONE ) +* + DO 60 J = K + 2, N +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WK = T*( D11*A( J, K )-A( J, K+1 ) ) + WKP1 = T*( D22*A( J, K+1 )-A( J, K ) ) +* +* Perform a rank-2 update of A(k+2:n,k+2:n) +* + DO 50 I = J, N + A( I, J ) = A( I, J ) - ( A( I, K ) / D21 )*WK - + $ ( A( I, K+1 ) / D21 )*WKP1 + 50 CONTINUE +* +* Store L(k) and L(k+1) in cols k and k+1 for row J +* + A( J, K ) = WK / D21 + A( J, K+1 ) = WKP1 / D21 +* + 60 CONTINUE +* + END IF +* +* Copy subdiagonal elements of D(K) to E(K) and +* ZERO out subdiagonal entry of A +* + E( K ) = A( K+1, K ) + E( K+1 ) = CZERO + A( K+1, K ) = CZERO +* + 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 40 +* + 64 CONTINUE +* + END IF +* + RETURN +* +* End of CSYTF2_RK +* + END diff --git a/SRC/csytrf_rk.f b/SRC/csytrf_rk.f new file mode 100644 index 00000000..953f6bee --- /dev/null +++ b/SRC/csytrf_rk.f @@ -0,0 +1,498 @@ +*> \brief \b CSYTRF_RK computes the factorization of a complex symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS3 blocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYTRF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csytrf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csytrf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csytrf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYTRF_RK computes the factorization of a complex symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension ( MAX(1,LWORK) ). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >=1. For best performance +*> LWORK >= N*NB, where NB is the block size returned +*> by ILAENV. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array, returns this value as the first entry of the WORK +*> array, and no error message related to LWORK is issued +*> by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put correct description +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY, UPPER + INTEGER I, IINFO, IP, IWS, K, KB, LDWORK, LWKOPT, + $ NB, NBMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL CLASYF_RK, CSYTF2_RK, CSWAP, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.EQ.0 ) THEN +* +* Determine the block size +* + NB = ILAENV( 1, 'CSYTRF_RK', UPLO, N, -1, -1, -1 ) + LWKOPT = N*NB + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYTRF_RK', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* + NBMIN = 2 + LDWORK = N + IF( NB.GT.1 .AND. NB.LT.N ) THEN + IWS = LDWORK*NB + IF( LWORK.LT.IWS ) THEN + NB = MAX( LWORK / LDWORK, 1 ) + NBMIN = MAX( 2, ILAENV( 2, 'CSYTRF_RK', + $ UPLO, N, -1, -1, -1 ) ) + END IF + ELSE + IWS = 1 + END IF + IF( NB.LT.NBMIN ) + $ NB = N +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* K is the main loop index, decreasing from N to 1 in steps of +* KB, where KB is the number of columns factorized by CLASYF_RK; +* KB is either NB or NB-1, or K for the last block +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 15 +* + IF( K.GT.NB ) THEN +* +* Factorize columns k-kb+1:k of A and use blocked code to +* update columns 1:k-kb +* + CALL CLASYF_RK( UPLO, K, NB, KB, A, LDA, E, + $ IPIV, WORK, LDWORK, IINFO ) + ELSE +* +* Use unblocked code to factorize columns 1:k of A +* + CALL CSYTF2_RK( UPLO, K, A, LDA, E, IPIV, IINFO ) + KB = K + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO +* +* No need to adjust IPIV +* +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k-kb+1:k and apply row permutations to the +* last k+1 colunms k+1:N after that block +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.LT.N ) THEN + DO I = K, ( K - KB + 1 ), -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL CSWAP( N-K, A( I, K+1 ), LDA, + $ A( IP, K+1 ), LDA ) + END IF + END DO + END IF +* +* Decrease K and return to the start of the main loop +* + K = K - KB + GO TO 10 +* +* This label is the exit from main loop over K decreasing +* from N to 1 in steps of KB +* + 15 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* K is the main loop index, increasing from 1 to N in steps of +* KB, where KB is the number of columns factorized by CLASYF_RK; +* KB is either NB or NB-1, or N-K+1 for the last block +* + K = 1 + 20 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 35 +* + IF( K.LE.N-NB ) THEN +* +* Factorize columns k:k+kb-1 of A and use blocked code to +* update columns k+kb:n +* + CALL CLASYF_RK( UPLO, N-K+1, NB, KB, A( K, K ), LDA, E( K ), + $ IPIV( K ), WORK, LDWORK, IINFO ) + + + ELSE +* +* Use unblocked code to factorize columns k:n of A +* + CALL CSYTF2_RK( UPLO, N-K+1, A( K, K ), LDA, E( K ), + $ IPIV( K ), IINFO ) + KB = N - K + 1 +* + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO + K - 1 +* +* Adjust IPIV +* + DO I = K, K + KB - 1 + IF( IPIV( I ).GT.0 ) THEN + IPIV( I ) = IPIV( I ) + K - 1 + ELSE + IPIV( I ) = IPIV( I ) - K + 1 + END IF + END DO +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k:k+kb-1 and apply row permutations to the +* first k-1 colunms 1:k-1 before that block +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.GT.1 ) THEN + DO I = K, ( K + KB - 1 ), 1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL CSWAP( K-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END DO + END IF +* +* Increase K and return to the start of the main loop +* + K = K + KB + GO TO 20 +* +* This label is the exit from main loop over K increasing +* from 1 to N in steps of KB +* + 35 CONTINUE +* +* End Lower +* + END IF +* + WORK( 1 ) = LWKOPT + RETURN +* +* End of CSYTRF_RK +* + END diff --git a/SRC/csytri_3.f b/SRC/csytri_3.f new file mode 100644 index 00000000..953c994a --- /dev/null +++ b/SRC/csytri_3.f @@ -0,0 +1,248 @@ +*> \brief \b CSYTRI_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYTRI_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csytri_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csytri_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csytri_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYTRI_3 computes the inverse of a complex symmetric indefinite +*> matrix A using the factorization computed by CSYTRF_RK or CSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> CSYTRI_3 sets the leading dimension of the workspace before calling +*> CSYTRI_3X that actually computes the inverse. This is the blocked +*> version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by CSYTRF_RK and CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CSYTRF_RK or CSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension (N+NB+1)*(NB+3). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= (N+NB+1)*(NB+3). +*> +*> If LDWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the optimal +*> size of the WORK array, returns this value as the first +*> entry of the WORK array, and no error message related to +*> LWORK is issued by XERBLA. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE CSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL UPPER, LQUERY + INTEGER LWKOPT, NB +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL CSYTRI_3X +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) +* +* Determine the block size +* + NB = MAX( 1, ILAENV( 1, 'CSYTRI_3', UPLO, N, -1, -1, -1 ) ) + LWKOPT = ( N+NB+1 ) * ( NB+3 ) +* + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF ( LWORK .LT. LWKOPT .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYTRI_3', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + WORK( 1 ) = LWKOPT + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + CALL CSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of CSYTRI_3 +* + END diff --git a/SRC/csytri_3x.f b/SRC/csytri_3x.f new file mode 100644 index 00000000..7e04d97c --- /dev/null +++ b/SRC/csytri_3x.f @@ -0,0 +1,647 @@ +*> \brief \b CSYTRI_3X +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYTRI_3X + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csytri_3x.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csytri_3x.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csytri_3x.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYTRI_3X computes the inverse of a complex symmetric indefinite +*> matrix A using the factorization computed by CSYTRF_RK or CSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by CSYTRF_RK and CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CSYTRF_RK or CSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX array, dimension (N+NB+1,NB+3). +*> \endverbatim +*> +*> \param[in] NB +*> \verbatim +*> NB is INTEGER +*> Block size. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE CSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX CONE, CZERO + PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ), + $ CZERO = ( 0.0E+0, 0.0E+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11 + COMPLEX AK, AKKP1, AKP1, D, T, U01_I_J, U01_IP1_J, + $ U11_I_J, U11_IP1_J +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL CGEMM, CSYSWAPR, CTRTRI, CTRMM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, MOD +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF +* +* Quick return if possible +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYTRI_3X', -INFO ) + RETURN + END IF + IF( N.EQ.0 ) + $ RETURN +* +* Workspace got Non-diag elements of D +* + DO K = 1, N + WORK( K, 1 ) = E( K ) + END DO +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO INFO = N, 1, -1 + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO INFO = 1, N + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + END IF +* + INFO = 0 +* +* Splitting Workspace +* U01 is a block ( N, NB+1 ) +* The first element of U01 is in WORK( 1, 1 ) +* U11 is a block ( NB+1, NB+1 ) +* The first element of U11 is in WORK( N+1, 1 ) +* + U11 = N +* +* INVD is a block ( N, 2 ) +* The first element of INVD is in WORK( 1, INVD ) +* + INVD = NB + 2 + + IF( UPPER ) THEN +* +* Begin Upper +* +* invA = P * inv(U**T) * inv(D) * inv(U) * P**T. +* + CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(U) +* + K = 1 + DO WHILE( K.LE.N ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = CONE / A( K, K ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K+1, 1 ) + AK = A( K, K ) / T + AKP1 = A( K+1, K+1 ) / T + AKKP1 = WORK( K+1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K, INVD ) = AKP1 / D + WORK( K+1, INVD+1 ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K+1, INVD ) = WORK( K, INVD+1 ) + K = K + 1 + END IF + K = K + 1 + END DO +* +* inv(U**T) = (inv(U))**T +* +* inv(U**T) * inv(D) * inv(U) +* + CUT = N + DO WHILE( CUT.GT.0 ) + NNB = NB + IF( CUT.LE.NNB ) THEN + NNB = CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT+1-NNB, CUT + IF( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF + + CUT = CUT - NNB +* +* U01 Block +* + DO I = 1, CUT + DO J = 1, NNB + WORK( I, J ) = A( I, CUT+J ) + END DO + END DO +* +* U11 Block +* + DO I = 1, NNB + WORK( U11+I, I ) = CONE + DO J = 1, I-1 + WORK( U11+I, J ) = CZERO + END DO + DO J = I+1, NNB + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD * U01 +* + I = 1 + DO WHILE( I.LE.CUT ) + IF( IPIV( I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( I, INVD ) * WORK( I, J ) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK( I, J ) + U01_IP1_J = WORK( I+1, J ) + WORK( I, J ) = WORK( I, INVD ) * U01_I_J + $ + WORK( I, INVD+1 ) * U01_IP1_J + WORK( I+1, J ) = WORK( I+1, INVD ) * U01_I_J + $ + WORK( I+1, INVD+1 ) * U01_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* invD1 * U11 +* + I = 1 + DO WHILE ( I.LE.NNB ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = I, NNB + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + END DO + ELSE + DO J = I, NNB + U11_I_J = WORK(U11+I,J) + U11_IP1_J = WORK(U11+I+1,J) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * WORK(U11+I+1,J) + WORK( U11+I+1, J ) = WORK(CUT+I+1,INVD) * U11_I_J + $ + WORK(CUT+I+1,INVD+1) * U11_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* U11**T * invD1 * U11 -> U11 +* + CALL CTRMM( 'L', 'U', 'T', 'U', NNB, NNB, + $ CONE, A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* +* U01**T * invD * U01 -> A( CUT+I, CUT+J ) +* + CALL CGEMM( 'T', 'N', NNB, NNB, CUT, CONE, A( 1, CUT+1 ), + $ LDA, WORK, N+NB+1, CZERO, WORK(U11+1,1), + $ N+NB+1 ) + +* +* U11 = U11**T * invD1 * U11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J ) + WORK(U11+I,J) + END DO + END DO +* +* U01 = U00**T * invD0 * U01 +* + CALL CTRMM( 'L', UPLO, 'T', 'U', CUT, NNB, + $ CONE, A, LDA, WORK, N+NB+1 ) + +* +* Update U01 +* + DO I = 1, CUT + DO J = 1, NNB + A( I, CUT+J ) = WORK( I, J ) + END DO + END DO +* +* Next Block +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(U**T) * inv(D) * inv(U) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Upper case. +* +* ( We can use a loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = 1, N + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL CSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL CSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* inv A = P * inv(L**T) * inv(D) * inv(L) * P**T. +* + CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(L) +* + K = N + DO WHILE ( K .GE. 1 ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = CONE / A( K, K ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K-1, 1 ) + AK = A( K-1, K-1 ) / T + AKP1 = A( K, K ) / T + AKKP1 = WORK( K-1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K-1, INVD ) = AKP1 / D + WORK( K, INVD ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K-1, INVD+1 ) = WORK( K, INVD+1 ) + K = K - 1 + END IF + K = K - 1 + END DO +* +* inv(L**T) = (inv(L))**T +* +* inv(L**T) * inv(D) * inv(L) +* + CUT = 0 + DO WHILE( CUT.LT.N ) + NNB = NB + IF( (CUT + NNB).GT.N ) THEN + NNB = N - CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT + 1, CUT+NNB + IF ( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF +* +* L21 Block +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + WORK( I, J ) = A( CUT+NNB+I, CUT+J ) + END DO + END DO +* +* L11 Block +* + DO I = 1, NNB + WORK( U11+I, I) = CONE + DO J = I+1, NNB + WORK( U11+I, J ) = CZERO + END DO + DO J = 1, I-1 + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD*L21 +* + I = N-CUT-NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+NNB+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( CUT+NNB+I, INVD) * WORK( I, J) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK(I,J) + U01_IP1_J = WORK(I-1,J) + WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ + $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J + WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ + $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* invD1*L11 +* + I = NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( U11+I, J ) = WORK( CUT+I, INVD)*WORK(U11+I,J) + END DO + + ELSE + DO J = 1, NNB + U11_I_J = WORK( U11+I, J ) + U11_IP1_J = WORK( U11+I-1, J ) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * U11_IP1_J + WORK( U11+I-1, J ) = WORK(CUT+I-1,INVD+1) * U11_I_J + $ + WORK(CUT+I-1,INVD) * U11_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* L11**T * invD1 * L11 -> L11 +* + CALL CTRMM( 'L', UPLO, 'T', 'U', NNB, NNB, CONE, + $ A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) + +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* + IF( (CUT+NNB).LT.N ) THEN +* +* L21**T * invD2*L21 -> A( CUT+I, CUT+J ) +* + CALL CGEMM( 'T', 'N', NNB, NNB, N-NNB-CUT, CONE, + $ A( CUT+NNB+1, CUT+1 ), LDA, WORK, N+NB+1, + $ CZERO, WORK( U11+1, 1 ), N+NB+1 ) + +* +* L11 = L11**T * invD1 * L11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J )+WORK(U11+I,J) + END DO + END DO +* +* L01 = L22**T * invD2 * L21 +* + CALL CTRMM( 'L', UPLO, 'T', 'U', N-NNB-CUT, NNB, CONE, + $ A( CUT+NNB+1, CUT+NNB+1 ), LDA, WORK, + $ N+NB+1 ) +* +* Update L21 +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + A( CUT+NNB+I, CUT+J ) = WORK( I, J ) + END DO + END DO +* + ELSE +* +* L11 = L11**T * invD1 * L11 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO + END IF +* +* Next Block +* + CUT = CUT + NNB +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(L**T) * inv(D) * inv(L) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Lower case. +* +* ( We can use a loop over IPIV with increment -1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = N, 1, -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL CSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL CSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + END IF +* + RETURN +* +* End of CSYTRI_3X +* + END + diff --git a/SRC/csytrs_3.f b/SRC/csytrs_3.f new file mode 100644 index 00000000..17e54aad --- /dev/null +++ b/SRC/csytrs_3.f @@ -0,0 +1,371 @@ +*> \brief \b CSYTRS_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download CSYTRS_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csytrs_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csytrs_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csytrs_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE CSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> CSYTRS_3 solves a system of linear equations A * X = B with a complex +*> symmetric matrix A using the factorization computed +*> by CSYTRF_RK or CSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This algorithm is using Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by CSYTRF_RK and CSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by CSYTRF_RK or CSYTRF_BK. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX array, dimension (LDB,NRHS) +*> On entry, the right hand side matrix B. +*> On exit, the solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complexSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 CSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX ONE + PARAMETER ( ONE = ( 1.0E+0,0.0E+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, J, K, KP + COMPLEX AK, AKM1, AKM1K, BK, BKM1, DENOM +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL CSCAL, CSWAP, CTRSM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'CSYTRS_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 .OR. NRHS.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin Upper +* +* Solve A*X = B, where A = U*D*U**T. +* +* P**T * B +* +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (U \P**T * B) -> B [ (U \P**T * B) ] +* + CALL CTRSM( 'L', 'U', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (U \P**T * B) ] +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN + CALL CSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF ( I.GT.1 ) THEN + AKM1K = E( I ) + AKM1 = A( I-1, I-1 ) / AKM1K + AK = A( I, I ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I-1, J ) / AKM1K + BK = B( I, J ) / AKM1K + B( I-1, J ) = ( AK*BKM1-BK ) / DENOM + B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* Compute (U**T \ B) -> B [ U**T \ (D \ (U \P**T * B) ) ] +* + CALL CTRSM( 'L', 'U', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (U**T \ (D \ (U \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* Solve A*X = B, where A = L*D*L**T. +* +* P**T * B +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (L \P**T * B) -> B [ (L \P**T * B) ] +* + CALL CTRSM( 'L', 'L', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (L \P**T * B) ] +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN + CALL CSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF( I.LT.N ) THEN + AKM1K = E( I ) + AKM1 = A( I, I ) / AKM1K + AK = A( I+1, I+1 ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I, J ) / AKM1K + BK = B( I+1, J ) / AKM1K + B( I, J ) = ( AK*BKM1-BK ) / DENOM + B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* Compute (L**T \ B) -> B [ L**T \ (D \ (L \P**T * B) ) ] +* + CALL CTRSM('L', 'L', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (L**T \ (D \ (L \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL CSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* END Lower +* + END IF +* + RETURN +* +* End of CSYTRS_3 +* + END diff --git a/SRC/dlasyf_rk.f b/SRC/dlasyf_rk.f new file mode 100644 index 00000000..cbc13deb --- /dev/null +++ b/SRC/dlasyf_rk.f @@ -0,0 +1,965 @@ +*> \brief \b DLASYF_RK computes a partial factorization of a real symmetric 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 DLASYF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasyf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasyf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasyf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DLASYF_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( * ) +* DOUBLE PRECISION A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DLASYF_RK computes a partial factorization of a real symmetric +*> 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**T U22**T ) +*> +*> A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) 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. +*> +*> DLASYF_RK is an auxiliary routine called by DSYTRF_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 +*> symmetric 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 DOUBLE PRECISION array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 DOUBLE PRECISION array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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 DOUBLE PRECISION 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. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 DLASYF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, KB, LDA, LDW, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO, ONE + PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) + DOUBLE PRECISION EIGHT, SEVTEN + PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) +* .. +* .. Local Scalars .. + LOGICAL DONE + INTEGER IMAX, ITEMP, J, JB, JJ, JMAX, K, KK, KW, KKW, + $ KP, KSTEP, P, II + DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, + $ DTEMP, R1, ROWMAX, T, SFMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER IDAMAX + DOUBLE PRECISION DLAMCH + EXTERNAL LSAME, IDAMAX, DLAMCH +* .. +* .. External Subroutines .. + EXTERNAL DCOPY, DGEMM, DGEMV, DSCAL, DSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, MIN, SQRT +* .. +* .. Executable Statements .. +* + INFO = 0 +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = DLAMCH( '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 +* +* Initilize the first entry of array E, where superdiagonal +* elements of D are stored +* + E( 1 ) = ZERO +* +* 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 +* + CALL DCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 ) + IF( K.LT.N ) + $ CALL DGEMV( 'No transpose', K, N-K, -ONE, A( 1, K+1 ), + $ LDA, W( K, KW+1 ), LDW, ONE, W( 1, KW ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( 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 = IDAMAX( K-1, W( 1, KW ), 1 ) + COLMAX = ABS( 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 + CALL DCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = ZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* +* Copy column IMAX to column KW-1 of W and update it +* + CALL DCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 ) + CALL DCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, + $ W( IMAX+1, KW-1 ), 1 ) +* + IF( K.LT.N ) + $ CALL DGEMV( 'No transpose', K, N-K, -ONE, + $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW, + $ ONE, W( 1, KW-1 ), 1 ) +* +* 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 + IDAMAX( K-IMAX, W( IMAX+1, KW-1 ), + $ 1 ) + ROWMAX = ABS( W( JMAX, KW-1 ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = IDAMAX( IMAX-1, W( 1, KW-1 ), 1 ) + DTEMP = ABS( W( ITEMP, KW-1 ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for +* ABS( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.(ABS( 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 DCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) +* + DONE = .TRUE. +* +* 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. + 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 DCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) +* + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* ============================================================ +* + KK = K - KSTEP + 1 +* +* KKW is the column of W which corresponds to column KK of A +* + KKW = NB + KK - N +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL DCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA ) + CALL DCOPY( P, A( 1, K ), 1, A( 1, P ), 1 ) +* +* Interchange rows K and P in last N-K+1 columns of A +* and last N-K+2 columns of W +* + CALL DSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA ) + CALL DSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW ) + END IF +* +* Updated column KP is already stored in column KKW of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL DCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + CALL DCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 ) +* +* Interchange rows KK and KP in last N-KK+1 columns +* of A and W +* + CALL DSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), LDA ) + CALL DSWAP( 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(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* +* Store U(k) in column k of A +* + CALL DCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) + IF( K.GT.1 ) THEN + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN + R1 = ONE / A( K, K ) + CALL DSCAL( K-1, R1, A( 1, K ), 1 ) + ELSE IF( A( K, K ).NE.ZERO ) THEN + DO 14 II = 1, K - 1 + A( II, K ) = A( II, K ) / A( K, K ) + 14 CONTINUE + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = ZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns KW and KW-1 of W now +* hold +* +* ( W(k-1) W(k) ) = ( 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 +* + IF( K.GT.2 ) THEN +* +* Store U(k) and U(k-1) in columns k and k-1 of A +* + D12 = W( K-1, KW ) + D11 = W( K, KW ) / D12 + D22 = W( K-1, KW-1 ) / D12 + T = ONE / ( D11*D22-ONE ) + DO 20 J = 1, K - 2 + A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) / + $ D12 ) + A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) / + $ D12 ) + 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 ) = ZERO + A( K, K ) = W( K, KW ) + E( K ) = W( K-1, KW ) + E( K-1 ) = ZERO +* + 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**T = A11 - U12*W**T +* +* computing blocks of NB columns at a time +* + DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB + JB = MIN( NB, K-J+1 ) +* +* Update the upper triangle of the diagonal block +* + DO 40 JJ = J, J + JB - 1 + CALL DGEMV( 'No transpose', JJ-J+1, N-K, -ONE, + $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, ONE, + $ A( J, JJ ), 1 ) + 40 CONTINUE +* +* Update the rectangular superdiagonal block +* + IF( J.GE.2 ) + $ CALL DGEMM( 'No transpose', 'Transpose', J-1, JB, + $ N-K, -ONE, A( 1, K+1 ), LDA, W( J, KW+1 ), + $ LDW, ONE, A( 1, J ), LDA ) + 50 CONTINUE +* +* 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 +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = ZERO +* +* 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 it +* + CALL DCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 ) + IF( K.GT.1 ) + $ CALL DGEMV( 'No transpose', N-K+1, K-1, -ONE, A( K, 1 ), + $ LDA, W( K, 1 ), LDW, ONE, W( K, K ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( 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 + IDAMAX( N-K, W( K+1, K ), 1 ) + COLMAX = ABS( 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 + CALL DCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = ZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 DCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1) + CALL DCOPY( N-IMAX+1, A( IMAX, IMAX ), 1, + $ W( IMAX, K+1 ), 1 ) + IF( K.GT.1 ) + $ CALL DGEMV( 'No transpose', N-K+1, K-1, -ONE, + $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW, + $ ONE, W( K, K+1 ), 1 ) +* +* 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 + IDAMAX( IMAX-K, W( K, K+1 ), 1 ) + ROWMAX = ABS( W( JMAX, K+1 ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + IDAMAX( N-IMAX, W( IMAX+1, K+1 ), 1) + DTEMP = ABS( W( ITEMP, K+1 ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for +* ABS( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.( ABS( 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 DCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 ) +* + DONE = .TRUE. +* +* 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. + 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 DCOPY( 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 +* +* ============================================================ +* + KK = K + KSTEP - 1 +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL DCOPY( P-K, A( K, K ), 1, A( P, K ), LDA ) + CALL DCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 ) +* +* Interchange rows K and P in first K columns of A +* and first K+1 columns of W +* + CALL DSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA ) + CALL DSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW ) + END IF +* +* Updated column KP is already stored in column KK of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL DCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA ) + CALL DCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 ) +* +* Interchange rows KK and KP in first KK columns of A and W +* + CALL DSWAP( KK, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) + CALL DSWAP( 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 +* +* Store L(k) in column k of A +* + CALL DCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) + IF( K.LT.N ) THEN + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN + R1 = ONE / A( K, K ) + CALL DSCAL( N-K, R1, A( K+1, K ), 1 ) + ELSE IF( A( K, K ).NE.ZERO ) THEN + DO 74 II = K + 1, N + A( II, K ) = A( II, K ) / A( K, K ) + 74 CONTINUE + END IF +* +* Store the subdiagonal element of D in array E +* + E( K ) = ZERO +* + 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 +* + IF( K.LT.N-1 ) THEN +* +* Store L(k) and L(k+1) in columns k and k+1 of A +* + D21 = W( K+1, K ) + D11 = W( K+1, K+1 ) / D21 + D22 = W( K, K ) / D21 + T = ONE / ( D11*D22-ONE ) + DO 80 J = K + 2, N + A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) / + $ 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 ) = ZERO + A( K+1, K+1 ) = W( K+1, K+1 ) + E( K ) = W( K+1, K ) + E( K+1 ) = ZERO +* + 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**T = A22 - L21*W**T +* +* computing blocks of NB columns at a time +* + DO 110 J = K, N, NB + JB = MIN( NB, N-J+1 ) +* +* Update the lower triangle of the diagonal block +* + DO 100 JJ = J, J + JB - 1 + CALL DGEMV( 'No transpose', J+JB-JJ, K-1, -ONE, + $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, ONE, + $ A( JJ, JJ ), 1 ) + 100 CONTINUE +* +* Update the rectangular subdiagonal block +* + IF( J+JB.LE.N ) + $ CALL DGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, + $ K-1, -ONE, A( J+JB, 1 ), LDA, W( J, 1 ), + $ LDW, ONE, A( J+JB, J ), LDA ) + 110 CONTINUE +* +* Set KB to the number of columns factorized +* + KB = K - 1 +* + END IF +* + RETURN +* +* End of DLASYF_RK +* + END diff --git a/SRC/dsycon_3.f b/SRC/dsycon_3.f new file mode 100644 index 00000000..b92e2a92 --- /dev/null +++ b/SRC/dsycon_3.f @@ -0,0 +1,285 @@ +*> \brief \b DSYCON_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYCON_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsycon_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsycon_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsycon_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, +* WORK, IWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* DOUBLE PRECISION ANORM, RCOND +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ), IWORK( * ) +* DOUBLE PRECISION A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYCON_3 estimates the reciprocal of the condition number (in the +*> 1-norm) of a real symmetric matrix A using the factorization +*> computed by DSYTRF_RK or DSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> An estimate is obtained for norm(inv(A)), and the reciprocal of the +*> condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). +*> This routine uses BLAS3 solver DSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by DSYTRF_RK and DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is DOUBLE PRECISION array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by DSYTRF_RK or DSYTRF_BK. +*> \endverbatim +*> +*> \param[in] ANORM +*> \verbatim +*> ANORM is DOUBLE PRECISION +*> The 1-norm of the original matrix A. +*> \endverbatim +*> +*> \param[out] RCOND +*> \verbatim +*> RCOND is DOUBLE PRECISION +*> The reciprocal of the condition number of the matrix A, +*> computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an +*> estimate of the 1-norm of inv(A) computed in this routine. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is DOUBLE PRECISION array, dimension (2*N) +*> \endverbatim +*> +*> \param[out] IWORK +*> \verbatim +*> IWORK is INTEGER array, dimension (N) +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 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 DSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, + $ WORK, IWORK, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N + DOUBLE PRECISION ANORM, RCOND +* .. +* .. Array Arguments .. + INTEGER IPIV( * ), IWORK( * ) + DOUBLE PRECISION A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ONE, ZERO + PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, KASE + DOUBLE PRECISION AINVNM +* .. +* .. Local Arrays .. + INTEGER ISAVE( 3 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL DLACN2, DSYTRS_3, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( ANORM.LT.ZERO ) THEN + INFO = -7 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYCON_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + RCOND = ZERO + IF( N.EQ.0 ) THEN + RCOND = ONE + RETURN + ELSE IF( ANORM.LE.ZERO ) THEN + RETURN + END IF +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO I = N, 1, -1 + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO I = 1, N + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + END IF +* +* Estimate the 1-norm of the inverse. +* + KASE = 0 + 30 CONTINUE + CALL DLACN2( N, WORK( N+1 ), WORK, IWORK, AINVNM, KASE, ISAVE ) + IF( KASE.NE.0 ) THEN +* +* Multiply by inv(L*D*L**T) or inv(U*D*U**T). +* + CALL DSYTRS_3( UPLO, N, 1, A, LDA, E, IPIV, WORK, N, INFO ) + GO TO 30 + END IF +* +* Compute the estimate of the reciprocal condition number. +* + IF( AINVNM.NE.ZERO ) + $ RCOND = ( ONE / AINVNM ) / ANORM +* + RETURN +* +* End of DSYCON_3 +* + END diff --git a/SRC/dsyconvf.f b/SRC/dsyconvf.f new file mode 100644 index 00000000..529c2327 --- /dev/null +++ b/SRC/dsyconvf.f @@ -0,0 +1,559 @@ +*> \brief \b DSYCONVF +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYCONVF + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsyconvf.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsyconvf.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsyconvf.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYCONVF( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> DSYCONVF converts the factorization output format used in +*> DSYTRF provided on entry in parameter A into the factorization +*> output format used in DSYTRF_RK (or DSYTRF_BK) that is stored +*> on exit in parameters A and E. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in DSYTRF into +*> the format used in DSYTRF_RK (or DSYTRF_BK). +*> +*> If parameter WAY = 'R': +*> DSYCONVF performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in DSYTRF_RK +*> (or DSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in DSYTRF that is stored +*> on exit in parameter A. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in DSYTRF_RK +*> (or DSYTRF_BK) into the format used in DSYTRF. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> DSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> DSYTRF_RK or DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> DSYTRF_RK or DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> DSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is DOUBLE PRECISION array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in,out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> +*> 1) If WAY ='C': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in DSYTRF. +*> On exit, details of the interchanges and the block +*> structure of D in the format used in DSYTRF_RK +*> ( or DSYTRF_BK). +*> +*> 1) If WAY ='R': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in DSYTRF_RK +*> ( or DSYTRF_BK). +*> On exit, details of the interchanges and the block +*> structure of D in the format used in DSYTRF. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE DSYCONVF( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO + PARAMETER ( ZERO = 0.0D+0 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL DSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYCONVF', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL DSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL DSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i-1 and IPIV(i-1), +* so this should be recorded in two consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I-1 ) +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where k increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL DSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL DSWAP( I-1, A( IP, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i+1 and IPIV(i+1), +* so this should be recorded in consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I+1 ) +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of DSYCONVF +* + END diff --git a/SRC/dsyconvf_rook.f b/SRC/dsyconvf_rook.f new file mode 100644 index 00000000..12b65167 --- /dev/null +++ b/SRC/dsyconvf_rook.f @@ -0,0 +1,544 @@ +*> \brief \b DSYCONVF_ROOK +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYCONVF_ROOK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsyconvf_rook.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsyconvf_rook.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsyconvf_rook.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYCONVF_ROOK( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> DSYCONVF_ROOK converts the factorization output format used in +*> DSYTRF_ROOK provided on entry in parameter A into the factorization +*> output format used in DSYTRF_RK (or DSYTRF_BK) that is stored +*> on exit in parameters A and E. IPIV format for DSYTRF_ROOK and +*> DSYTRF_RK (or DSYTRF_BK) is the same and is not converted. +*> +*> If parameter WAY = 'R': +*> DSYCONVF_ROOK performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in DSYTRF_RK +*> (or DSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in DSYTRF_ROOK that is stored +*> on exit in parameter A. IPIV format for DSYTRF_ROOK and +*> DSYTRF_RK (or DSYTRF_BK) is the same and is not converted. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> DSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> DSYTRF_RK or DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> DSYTRF_RK or DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> DSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is DOUBLE PRECISION array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> On entry, details of the interchanges and the block +*> structure of D as determined: +*> 1) by DSYTRF_ROOK, if WAY ='C'; +*> 2) by DSYTRF_RK (or DSYTRF_BK), if WAY ='R'. +*> The IPIV format is the same for all these routines. +*> +*> On exit, is not changed. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE DSYCONVF_ROOK( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO + PARAMETER ( ZERO = 0.0D+0 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL DSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP, IP2 +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYCONVF_ROOK', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i-1 and IPIV(i-1) +* in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + IF( IP2.NE.(I-1) ) THEN + CALL DSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP2, I+1 ), LDA ) + END IF + END IF + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i-1) and i and IPIV(i) +* in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP2.NE.(I-1) ) THEN + CALL DSWAP( N-I, A( IP2, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL DSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i+1 and IPIV(i+1) +* in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + IF( IP2.NE.(I+1) ) THEN + CALL DSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP2, 1 ), LDA ) + END IF + END IF + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL DSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i+1) and i and IPIV(i) +* in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP2.NE.(I+1) ) THEN + CALL DSWAP( I-1, A( IP2, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL DSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of DSYCONVF_ROOK +* + END diff --git a/SRC/dsysv_rk.f b/SRC/dsysv_rk.f new file mode 100644 index 00000000..cbedf052 --- /dev/null +++ b/SRC/dsysv_rk.f @@ -0,0 +1,317 @@ +*> \brief <b> DSYSV_RK computes the solution to system of linear equations A * X = B for SY matrices</b> +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYSV_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsysv_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsysv_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsysv_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* WORK, LWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYSV_RK computes the solution to a real system of linear +*> equations A * X = B, where A is an N-by-N symmetric matrix +*> and X and B are N-by-NRHS matrices. +*> +*> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used +*> to factor A as +*> A = P*U*D*(U**T)*(P**T), if UPLO = 'U', or +*> A = P*L*D*(L**T)*(P**T), if UPLO = 'L', +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> DSYTRF_RK is called to compute the factorization of a real +*> symmetric matrix. The factored form of A is then used to solve +*> the system of equations A * X = B by calling BLAS3 routine DSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric matrix A is stored: +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The number of linear equations, i.e., the order of the +*> matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> On entry, the symmetric 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, if INFO = 0, diagonal of the block diagonal +*> matrix D and factors U or L as computed by DSYTRF_RK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> For more info see the description of DSYTRF_RK routine. +*> \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 DOUBLE PRECISION array, dimension (N) +*> On exit, contains the output computed by the factorization +*> routine DSYTRF_RK, i.e. the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> For more info see the description of DSYTRF_RK routine. +*> \endverbatim +*> +*> \param[out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D, +*> as determined by DSYTRF_RK. +*> +*> For more info see the description of DSYTRF_RK routine. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is DOUBLE PRECISION array, dimension (LDB,NRHS) +*> On entry, the N-by-NRHS right hand side matrix B. +*> On exit, if INFO = 0, the N-by-NRHS solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is DOUBLE PRECISION array, dimension ( MAX(1,LWORK) ). +*> Work array used in the factorization stage. +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= 1. For best performance +*> of factorization stage LWORK >= max(1,N*NB), where NB is +*> the optimal blocksize for DSYTRF_RK. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array for factorization stage, returns this value as +*> the first entry of the WORK array, and no error message +*> related to LWORK is issued by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup doubleSYsolve +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 DSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ WORK, LWORK, INFO ) +* +* -- LAPACK driver routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY + INTEGER LWKOPT +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, DSYTRF_RK, DSYTRS_3 +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -11 + END IF +* + IF( INFO.EQ.0 ) THEN + IF( N.EQ.0 ) THEN + LWKOPT = 1 + ELSE + CALL DSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO ) + LWKOPT = WORK(1) + END IF + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYSV_RK ', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* +* Compute the factorization A = P*U*D*(U**T)*(P**T) or +* A = P*U*D*(U**T)*(P**T). +* + CALL DSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO ) +* + IF( INFO.EQ.0 ) THEN +* +* Solve the system A*X = B with BLAS3 solver, overwriting B with X. +* + CALL DSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO ) +* + END IF +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of DSYSV_RK +* + END diff --git a/SRC/dsytf2_rk.f b/SRC/dsytf2_rk.f new file mode 100644 index 00000000..78c61fce --- /dev/null +++ b/SRC/dsytf2_rk.f @@ -0,0 +1,943 @@ +*> \brief \b DSYTF2_RK computes the factorization of a real symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYTF2_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytf2_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytf2_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytf2_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), E ( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYTF2_RK computes the factorization of a real symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the unblocked version of the algorithm, calling Level 2 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 DOUBLE PRECISION array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \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. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put further details +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 +*> +*> 01-01-96 - Based on modifications by +*> J. Lewis, Boeing Computer Services Company +*> A. Petitet, Computer Science Dept., +*> Univ. of Tenn., Knoxville abd , USA +*> \endverbatim +* +* ===================================================================== + SUBROUTINE DSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO, ONE + PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) + DOUBLE PRECISION EIGHT, SEVTEN + PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER, DONE + INTEGER I, IMAX, J, JMAX, ITEMP, K, KK, KP, KSTEP, + $ P, II + DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, + $ ROWMAX, DTEMP, T, WK, WKM1, WKP1, SFMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER IDAMAX + DOUBLE PRECISION DLAMCH + EXTERNAL LSAME, IDAMAX, DLAMCH +* .. +* .. External Subroutines .. + EXTERNAL DSCAL, DSWAP, DSYR, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, SQRT +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYTF2_RK', -INFO ) + RETURN + END IF +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = DLAMCH( 'S' ) +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* Initilize the first entry of array E, where superdiagonal +* elements of D are stored +* + E( 1 ) = ZERO +* +* K is the main loop index, decreasing from N to 1 in steps of +* 1 or 2 +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 34 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( A( 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.GT.1 ) THEN + IMAX = IDAMAX( K-1, A( 1, K ), 1 ) + COLMAX = ABS( A( 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 +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = ZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, +* use 1-by-1 pivot block +* + KP = K + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* 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 + IDAMAX( K-IMAX, A( IMAX, IMAX+1 ), + $ LDA ) + ROWMAX = ABS( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = IDAMAX( IMAX-1, A( 1, IMAX ), 1 ) + DTEMP = ABS( A( ITEMP, IMAX ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( ABS( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX ) ) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the leading +* submatrix A(1:k,1:k) if we have a 2-by-2 pivot +* + IF( P.GT.1 ) + $ CALL DSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 ) + IF( P.LT.(K-1) ) + $ CALL DSWAP( K-P-1, A( P+1, K ), 1, A( P, P+1 ), + $ LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL DSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K - KSTEP + 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the leading +* submatrix A(1:k,1:k) +* + IF( KP.GT.1 ) + $ CALL DSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) + IF( ( KK.GT.1 ) .AND. ( KP.LT.(KK-1) ) ) + $ CALL DSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K-1, K ) + A( K-1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL DSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) +* + END IF +* +* Update the leading submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* + IF( K.GT.1 ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) and +* store U(k) in column k +* + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*1/D(k)*W(k)**T +* + D11 = ONE / A( K, K ) + CALL DSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) +* +* Store U(k) in column k +* + CALL DSCAL( K-1, D11, A( 1, K ), 1 ) + ELSE +* +* Store L(k) in column K +* + D11 = A( K, K ) + DO 16 II = 1, K - 1 + A( II, K ) = A( II, K ) / D11 + 16 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL DSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = ZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k-1 now hold +* +* ( W(k-1) W(k) ) = ( 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 +* +* Perform a rank-2 update of A(1:k-2,1:k-2) as +* +* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T +* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.GT.2 ) THEN +* + D12 = A( K-1, K ) + D22 = A( K-1, K-1 ) / D12 + D11 = A( K, K ) / D12 + T = ONE / ( D11*D22-ONE ) +* + DO 30 J = K - 2, 1, -1 +* + WKM1 = T*( D11*A( J, K-1 )-A( J, K ) ) + WK = T*( D22*A( J, K )-A( J, K-1 ) ) +* + DO 20 I = J, 1, -1 + A( I, J ) = A( I, J ) - (A( I, K ) / D12 )*WK - + $ ( A( I, K-1 ) / D12 )*WKM1 + 20 CONTINUE +* +* Store U(k) and U(k-1) in cols k and k-1 for row J +* + A( J, K ) = WK / D12 + A( J, K-1 ) = WKM1 / D12 +* + 30 CONTINUE +* + END IF +* +* Copy superdiagonal elements of D(K) to E(K) and +* ZERO out superdiagonal entry of A +* + E( K ) = A( K-1, K ) + E( K-1 ) = ZERO + A( K-1, K ) = ZERO +* + 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 +* + 34 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = ZERO +* +* K is the main loop index, increasing from 1 to N in steps of +* 1 or 2 +* + K = 1 + 40 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 64 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( A( 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 + IDAMAX( N-K, A( K+1, K ), 1 ) + COLMAX = ABS( A( 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 +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = ZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, use 1-by-1 pivot block +* + KP = K +* + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 42 CONTINUE +* +* Begin pivot search loop body +* +* 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 + IDAMAX( IMAX-K, A( IMAX, K ), LDA ) + ROWMAX = ABS( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + IDAMAX( N-IMAX, A( IMAX+1, IMAX ), + $ 1 ) + DTEMP = ABS( A( ITEMP, IMAX ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( ABS( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX ) ) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 42 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the trailing +* submatrix A(k:n,k:n) if we have a 2-by-2 pivot +* + IF( P.LT.N ) + $ CALL DSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) + IF( P.GT.(K+1) ) + $ CALL DSWAP( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL DSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K + KSTEP - 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the trailing +* submatrix A(k:n,k:n) +* + IF( KP.LT.N ) + $ CALL DSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) + IF( ( KK.LT.N ) .AND. ( KP.GT.(KK+1) ) ) + $ CALL DSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K+1, K ) + A( K+1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL DSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) +* + END IF +* +* Update the trailing submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = L(k)*D(k) +* +* where L(k) is the k-th column of L +* + IF( K.LT.N ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) and +* store L(k) in column k +* + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* + D11 = ONE / A( K, K ) + CALL DSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) +* +* Store L(k) in column k +* + CALL DSCAL( N-K, D11, A( K+1, K ), 1 ) + ELSE +* +* Store L(k) in column k +* + D11 = A( K, K ) + DO 46 II = K + 1, N + A( II, K ) = A( II, K ) / D11 + 46 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL DSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) + END IF +* +* Store the subdiagonal element of D in array E +* + E( K ) = ZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k+1 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 +* +* +* Perform a rank-2 update of A(k+2:n,k+2:n) as +* +* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T +* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.LT.N-1 ) THEN +* + D21 = A( K+1, K ) + D11 = A( K+1, K+1 ) / D21 + D22 = A( K, K ) / D21 + T = ONE / ( D11*D22-ONE ) +* + DO 60 J = K + 2, N +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WK = T*( D11*A( J, K )-A( J, K+1 ) ) + WKP1 = T*( D22*A( J, K+1 )-A( J, K ) ) +* +* Perform a rank-2 update of A(k+2:n,k+2:n) +* + DO 50 I = J, N + A( I, J ) = A( I, J ) - ( A( I, K ) / D21 )*WK - + $ ( A( I, K+1 ) / D21 )*WKP1 + 50 CONTINUE +* +* Store L(k) and L(k+1) in cols k and k+1 for row J +* + A( J, K ) = WK / D21 + A( J, K+1 ) = WKP1 / D21 +* + 60 CONTINUE +* + END IF +* +* Copy subdiagonal elements of D(K) to E(K) and +* ZERO out subdiagonal entry of A +* + E( K ) = A( K+1, K ) + E( K+1 ) = ZERO + A( K+1, K ) = ZERO +* + 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 40 +* + 64 CONTINUE +* + END IF +* + RETURN +* +* End of DSYTF2_RK +* + END diff --git a/SRC/dsytrf_rk.f b/SRC/dsytrf_rk.f new file mode 100644 index 00000000..0cca75ad --- /dev/null +++ b/SRC/dsytrf_rk.f @@ -0,0 +1,498 @@ +*> \brief \b DSYTRF_RK computes the factorization of a real symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS3 blocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYTRF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytrf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytrf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytrf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYTRF_RK computes the factorization of a real symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 DOUBLE PRECISION array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is DOUBLE PRECISION array, dimension ( MAX(1,LWORK) ). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >=1. For best performance +*> LWORK >= N*NB, where NB is the block size returned +*> by ILAENV. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array, returns this value as the first entry of the WORK +*> array, and no error message related to LWORK is issued +*> by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put correct description +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 DSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY, UPPER + INTEGER I, IINFO, IP, IWS, K, KB, LDWORK, LWKOPT, + $ NB, NBMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL DLASYF_RK, DSYTF2_RK, DSWAP, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.EQ.0 ) THEN +* +* Determine the block size +* + NB = ILAENV( 1, 'DSYTRF_RK', UPLO, N, -1, -1, -1 ) + LWKOPT = N*NB + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYTRF_RK', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* + NBMIN = 2 + LDWORK = N + IF( NB.GT.1 .AND. NB.LT.N ) THEN + IWS = LDWORK*NB + IF( LWORK.LT.IWS ) THEN + NB = MAX( LWORK / LDWORK, 1 ) + NBMIN = MAX( 2, ILAENV( 2, 'DSYTRF_RK', + $ UPLO, N, -1, -1, -1 ) ) + END IF + ELSE + IWS = 1 + END IF + IF( NB.LT.NBMIN ) + $ NB = N +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* K is the main loop index, decreasing from N to 1 in steps of +* KB, where KB is the number of columns factorized by DLASYF_RK; +* KB is either NB or NB-1, or K for the last block +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 15 +* + IF( K.GT.NB ) THEN +* +* Factorize columns k-kb+1:k of A and use blocked code to +* update columns 1:k-kb +* + CALL DLASYF_RK( UPLO, K, NB, KB, A, LDA, E, + $ IPIV, WORK, LDWORK, IINFO ) + ELSE +* +* Use unblocked code to factorize columns 1:k of A +* + CALL DSYTF2_RK( UPLO, K, A, LDA, E, IPIV, IINFO ) + KB = K + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO +* +* No need to adjust IPIV +* +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k-kb+1:k and apply row permutations to the +* last k+1 colunms k+1:N after that block +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.LT.N ) THEN + DO I = K, ( K - KB + 1 ), -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL DSWAP( N-K, A( I, K+1 ), LDA, + $ A( IP, K+1 ), LDA ) + END IF + END DO + END IF +* +* Decrease K and return to the start of the main loop +* + K = K - KB + GO TO 10 +* +* This label is the exit from main loop over K decreasing +* from N to 1 in steps of KB +* + 15 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* K is the main loop index, increasing from 1 to N in steps of +* KB, where KB is the number of columns factorized by DLASYF_RK; +* KB is either NB or NB-1, or N-K+1 for the last block +* + K = 1 + 20 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 35 +* + IF( K.LE.N-NB ) THEN +* +* Factorize columns k:k+kb-1 of A and use blocked code to +* update columns k+kb:n +* + CALL DLASYF_RK( UPLO, N-K+1, NB, KB, A( K, K ), LDA, E( K ), + $ IPIV( K ), WORK, LDWORK, IINFO ) + + + ELSE +* +* Use unblocked code to factorize columns k:n of A +* + CALL DSYTF2_RK( UPLO, N-K+1, A( K, K ), LDA, E( K ), + $ IPIV( K ), IINFO ) + KB = N - K + 1 +* + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO + K - 1 +* +* Adjust IPIV +* + DO I = K, K + KB - 1 + IF( IPIV( I ).GT.0 ) THEN + IPIV( I ) = IPIV( I ) + K - 1 + ELSE + IPIV( I ) = IPIV( I ) - K + 1 + END IF + END DO +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k:k+kb-1 and apply row permutations to the +* first k-1 colunms 1:k-1 before that block +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.GT.1 ) THEN + DO I = K, ( K + KB - 1 ), 1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL DSWAP( K-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END DO + END IF +* +* Increase K and return to the start of the main loop +* + K = K + KB + GO TO 20 +* +* This label is the exit from main loop over K increasing +* from 1 to N in steps of KB +* + 35 CONTINUE +* +* End Lower +* + END IF +* + WORK( 1 ) = LWKOPT + RETURN +* +* End of DSYTRF_RK +* + END diff --git a/SRC/dsytri_3.f b/SRC/dsytri_3.f new file mode 100644 index 00000000..51936167 --- /dev/null +++ b/SRC/dsytri_3.f @@ -0,0 +1,248 @@ +*> \brief \b DSYTRI_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYTRI_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytri_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytri_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytri_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYTRI_3 computes the inverse of a real symmetric indefinite +*> matrix A using the factorization computed by DSYTRF_RK or DSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> DSYTRI_3 sets the leading dimension of the workspace before calling +*> DSYTRI_3X that actually computes the inverse. This is the blocked +*> version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by DSYTRF_RK and DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is DOUBLE PRECISION array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by DSYTRF_RK or DSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is DOUBLE PRECISION array, dimension (N+NB+1)*(NB+3). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= (N+NB+1)*(NB+3). +*> +*> If LDWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the optimal +*> size of the WORK array, returns this value as the first +*> entry of the WORK array, and no error message related to +*> LWORK is issued by XERBLA. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE DSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL UPPER, LQUERY + INTEGER LWKOPT, NB +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL DSYTRI_3X +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) +* +* Determine the block size +* + NB = MAX( 1, ILAENV( 1, 'DSYTRI_3', UPLO, N, -1, -1, -1 ) ) + LWKOPT = ( N+NB+1 ) * ( NB+3 ) +* + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF ( LWORK .LT. LWKOPT .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYTRI_3', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + WORK( 1 ) = LWKOPT + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + CALL DSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of DSYTRI_3 +* + END diff --git a/SRC/dsytri_3x.f b/SRC/dsytri_3x.f new file mode 100644 index 00000000..7825f584 --- /dev/null +++ b/SRC/dsytri_3x.f @@ -0,0 +1,645 @@ +*> \brief \b DSYTRI_3X +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYTRI_3X + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytri_3x.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytri_3x.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytri_3x.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYTRI_3X computes the inverse of a real symmetric indefinite +*> matrix A using the factorization computed by DSYTRF_RK or DSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by DSYTRF_RK and DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is DOUBLE PRECISION array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by DSYTRF_RK or DSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is DOUBLE PRECISION array, dimension (N+NB+1,NB+3). +*> \endverbatim +*> +*> \param[in] NB +*> \verbatim +*> NB is INTEGER +*> Block size. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE DSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ONE, ZERO + PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11 + DOUBLE PRECISION AK, AKKP1, AKP1, D, T, U01_I_J, U01_IP1_J, + $ U11_I_J, U11_IP1_J +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL DGEMM, DSYSWAPR, DTRTRI, DTRMM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, MOD +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF +* +* Quick return if possible +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYTRI_3X', -INFO ) + RETURN + END IF + IF( N.EQ.0 ) + $ RETURN +* +* Workspace got Non-diag elements of D +* + DO K = 1, N + WORK( K, 1 ) = E( K ) + END DO +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO INFO = N, 1, -1 + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO INFO = 1, N + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO ) + $ RETURN + END DO + END IF +* + INFO = 0 +* +* Splitting Workspace +* U01 is a block ( N, NB+1 ) +* The first element of U01 is in WORK( 1, 1 ) +* U11 is a block ( NB+1, NB+1 ) +* The first element of U11 is in WORK( N+1, 1 ) +* + U11 = N +* +* INVD is a block ( N, 2 ) +* The first element of INVD is in WORK( 1, INVD ) +* + INVD = NB + 2 + + IF( UPPER ) THEN +* +* Begin Upper +* +* invA = P * inv(U**T) * inv(D) * inv(U) * P**T. +* + CALL DTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(U) +* + K = 1 + DO WHILE( K.LE.N ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / A( K, K ) + WORK( K, INVD+1 ) = ZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K+1, 1 ) + AK = A( K, K ) / T + AKP1 = A( K+1, K+1 ) / T + AKKP1 = WORK( K+1, 1 ) / T + D = T*( AK*AKP1-ONE ) + WORK( K, INVD ) = AKP1 / D + WORK( K+1, INVD+1 ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K+1, INVD ) = WORK( K, INVD+1 ) + K = K + 1 + END IF + K = K + 1 + END DO +* +* inv(U**T) = (inv(U))**T +* +* inv(U**T) * inv(D) * inv(U) +* + CUT = N + DO WHILE( CUT.GT.0 ) + NNB = NB + IF( CUT.LE.NNB ) THEN + NNB = CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT+1-NNB, CUT + IF( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF + + CUT = CUT - NNB +* +* U01 Block +* + DO I = 1, CUT + DO J = 1, NNB + WORK( I, J ) = A( I, CUT+J ) + END DO + END DO +* +* U11 Block +* + DO I = 1, NNB + WORK( U11+I, I ) = ONE + DO J = 1, I-1 + WORK( U11+I, J ) = ZERO + END DO + DO J = I+1, NNB + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD * U01 +* + I = 1 + DO WHILE( I.LE.CUT ) + IF( IPIV( I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( I, INVD ) * WORK( I, J ) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK( I, J ) + U01_IP1_J = WORK( I+1, J ) + WORK( I, J ) = WORK( I, INVD ) * U01_I_J + $ + WORK( I, INVD+1 ) * U01_IP1_J + WORK( I+1, J ) = WORK( I+1, INVD ) * U01_I_J + $ + WORK( I+1, INVD+1 ) * U01_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* invD1 * U11 +* + I = 1 + DO WHILE ( I.LE.NNB ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = I, NNB + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + END DO + ELSE + DO J = I, NNB + U11_I_J = WORK(U11+I,J) + U11_IP1_J = WORK(U11+I+1,J) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * WORK(U11+I+1,J) + WORK( U11+I+1, J ) = WORK(CUT+I+1,INVD) * U11_I_J + $ + WORK(CUT+I+1,INVD+1) * U11_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* U11**T * invD1 * U11 -> U11 +* + CALL DTRMM( 'L', 'U', 'T', 'U', NNB, NNB, + $ ONE, A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* +* U01**T * invD * U01 -> A( CUT+I, CUT+J ) +* + CALL DGEMM( 'T', 'N', NNB, NNB, CUT, ONE, A( 1, CUT+1 ), + $ LDA, WORK, N+NB+1, ZERO, WORK(U11+1,1), N+NB+1 ) + +* +* U11 = U11**T * invD1 * U11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J ) + WORK(U11+I,J) + END DO + END DO +* +* U01 = U00**T * invD0 * U01 +* + CALL DTRMM( 'L', UPLO, 'T', 'U', CUT, NNB, + $ ONE, A, LDA, WORK, N+NB+1 ) + +* +* Update U01 +* + DO I = 1, CUT + DO J = 1, NNB + A( I, CUT+J ) = WORK( I, J ) + END DO + END DO +* +* Next Block +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(U**T) * inv(D) * inv(U) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Upper case. +* +* ( We can use a loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = 1, N + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL DSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL DSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* inv A = P * inv(L**T) * inv(D) * inv(L) * P**T. +* + CALL DTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(L) +* + K = N + DO WHILE ( K .GE. 1 ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / A( K, K ) + WORK( K, INVD+1 ) = ZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K-1, 1 ) + AK = A( K-1, K-1 ) / T + AKP1 = A( K, K ) / T + AKKP1 = WORK( K-1, 1 ) / T + D = T*( AK*AKP1-ONE ) + WORK( K-1, INVD ) = AKP1 / D + WORK( K, INVD ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K-1, INVD+1 ) = WORK( K, INVD+1 ) + K = K - 1 + END IF + K = K - 1 + END DO +* +* inv(L**T) = (inv(L))**T +* +* inv(L**T) * inv(D) * inv(L) +* + CUT = 0 + DO WHILE( CUT.LT.N ) + NNB = NB + IF( (CUT + NNB).GT.N ) THEN + NNB = N - CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT + 1, CUT+NNB + IF ( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF +* +* L21 Block +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + WORK( I, J ) = A( CUT+NNB+I, CUT+J ) + END DO + END DO +* +* L11 Block +* + DO I = 1, NNB + WORK( U11+I, I) = ONE + DO J = I+1, NNB + WORK( U11+I, J ) = ZERO + END DO + DO J = 1, I-1 + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD*L21 +* + I = N-CUT-NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+NNB+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( CUT+NNB+I, INVD) * WORK( I, J) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK(I,J) + U01_IP1_J = WORK(I-1,J) + WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ + $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J + WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ + $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* invD1*L11 +* + I = NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( U11+I, J ) = WORK( CUT+I, INVD)*WORK(U11+I,J) + END DO + + ELSE + DO J = 1, NNB + U11_I_J = WORK( U11+I, J ) + U11_IP1_J = WORK( U11+I-1, J ) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * U11_IP1_J + WORK( U11+I-1, J ) = WORK(CUT+I-1,INVD+1) * U11_I_J + $ + WORK(CUT+I-1,INVD) * U11_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* L11**T * invD1 * L11 -> L11 +* + CALL DTRMM( 'L', UPLO, 'T', 'U', NNB, NNB, ONE, + $ A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) + +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* + IF( (CUT+NNB).LT.N ) THEN +* +* L21**T * invD2*L21 -> A( CUT+I, CUT+J ) +* + CALL DGEMM( 'T', 'N', NNB, NNB, N-NNB-CUT, ONE, + $ A( CUT+NNB+1, CUT+1 ), LDA, WORK, N+NB+1, + $ ZERO, WORK( U11+1, 1 ), N+NB+1 ) + +* +* L11 = L11**T * invD1 * L11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J )+WORK(U11+I,J) + END DO + END DO +* +* L01 = L22**T * invD2 * L21 +* + CALL DTRMM( 'L', UPLO, 'T', 'U', N-NNB-CUT, NNB, ONE, + $ A( CUT+NNB+1, CUT+NNB+1 ), LDA, WORK, + $ N+NB+1 ) +* +* Update L21 +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + A( CUT+NNB+I, CUT+J ) = WORK( I, J ) + END DO + END DO +* + ELSE +* +* L11 = L11**T * invD1 * L11 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO + END IF +* +* Next Block +* + CUT = CUT + NNB +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(L**T) * inv(D) * inv(L) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Lower case. +* +* ( We can use a loop over IPIV with increment -1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = N, 1, -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL DSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL DSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + END IF +* + RETURN +* +* End of DSYTRI_3X +* + END + diff --git a/SRC/dsytrs_3.f b/SRC/dsytrs_3.f new file mode 100644 index 00000000..ffef54c5 --- /dev/null +++ b/SRC/dsytrs_3.f @@ -0,0 +1,371 @@ +*> \brief \b DSYTRS_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download DSYTRS_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytrs_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytrs_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytrs_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE DSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> DSYTRS_3 solves a system of linear equations A * X = B with a real +*> symmetric matrix A using the factorization computed +*> by DSYTRF_RK or DSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This algorithm is using Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is DOUBLE PRECISION array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by DSYTRF_RK and DSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is DOUBLE PRECISION array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by DSYTRF_RK or DSYTRF_BK. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is DOUBLE PRECISION array, dimension (LDB,NRHS) +*> On entry, the right hand side matrix B. +*> On exit, the solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup doubleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 DSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + DOUBLE PRECISION A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ONE + PARAMETER ( ONE = 1.0D+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, J, K, KP + DOUBLE PRECISION AK, AKM1, AKM1K, BK, BKM1, DENOM +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL DSCAL, DSWAP, DTRSM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'DSYTRS_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 .OR. NRHS.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin Upper +* +* Solve A*X = B, where A = U*D*U**T. +* +* P**T * B +* +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (U \P**T * B) -> B [ (U \P**T * B) ] +* + CALL DTRSM( 'L', 'U', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (U \P**T * B) ] +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN + CALL DSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF ( I.GT.1 ) THEN + AKM1K = E( I ) + AKM1 = A( I-1, I-1 ) / AKM1K + AK = A( I, I ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I-1, J ) / AKM1K + BK = B( I, J ) / AKM1K + B( I-1, J ) = ( AK*BKM1-BK ) / DENOM + B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* Compute (U**T \ B) -> B [ U**T \ (D \ (U \P**T * B) ) ] +* + CALL DTRSM( 'L', 'U', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (U**T \ (D \ (U \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* Solve A*X = B, where A = L*D*L**T. +* +* P**T * B +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (L \P**T * B) -> B [ (L \P**T * B) ] +* + CALL DTRSM( 'L', 'L', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (L \P**T * B) ] +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN + CALL DSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF( I.LT.N ) THEN + AKM1K = E( I ) + AKM1 = A( I, I ) / AKM1K + AK = A( I+1, I+1 ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I, J ) / AKM1K + BK = B( I+1, J ) / AKM1K + B( I, J ) = ( AK*BKM1-BK ) / DENOM + B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* Compute (L**T \ B) -> B [ L**T \ (D \ (L \P**T * B) ) ] +* + CALL DTRSM('L', 'L', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (L**T \ (D \ (L \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* END Lower +* + END IF +* + RETURN +* +* End of DSYTRS_3 +* + END diff --git a/SRC/slasyf_rk.f b/SRC/slasyf_rk.f new file mode 100644 index 00000000..d3c73f98 --- /dev/null +++ b/SRC/slasyf_rk.f @@ -0,0 +1,965 @@ +*> \brief \b SLASYF_RK computes a partial factorization of a real symmetric 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 SLASYF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasyf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasyf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasyf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SLASYF_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( * ) +* REAL A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SLASYF_RK computes a partial factorization of a real symmetric +*> 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**T U22**T ) +*> +*> A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) 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. +*> +*> SLASYF_RK is an auxiliary routine called by SSYTRF_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 +*> symmetric 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 REAL array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 REAL array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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 REAL 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. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 SLASYF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, KB, LDA, LDW, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* ===================================================================== +* +* .. 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 ) +* .. +* .. Local Scalars .. + LOGICAL DONE + INTEGER IMAX, ITEMP, J, JB, JJ, JMAX, K, KK, KW, KKW, + $ KP, KSTEP, P, II + REAL ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, + $ STEMP, R1, ROWMAX, T, SFMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ISAMAX + REAL SLAMCH + EXTERNAL LSAME, ISAMAX, SLAMCH +* .. +* .. External Subroutines .. + EXTERNAL SCOPY, SGEMM, SGEMV, SSCAL, SSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, MIN, SQRT +* .. +* .. 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 +* +* Initilize the first entry of array E, where superdiagonal +* elements of D are stored +* + E( 1 ) = ZERO +* +* 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 +* + CALL SCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 ) + IF( K.LT.N ) + $ CALL SGEMV( 'No transpose', K, N-K, -ONE, A( 1, K+1 ), + $ LDA, W( K, KW+1 ), LDW, ONE, W( 1, KW ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( 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 = ISAMAX( K-1, W( 1, KW ), 1 ) + COLMAX = ABS( 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 + CALL SCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = ZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* +* Copy column IMAX to column KW-1 of W and update it +* + CALL SCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 ) + CALL SCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, + $ W( IMAX+1, KW-1 ), 1 ) +* + IF( K.LT.N ) + $ CALL SGEMV( 'No transpose', K, N-K, -ONE, + $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW, + $ ONE, W( 1, KW-1 ), 1 ) +* +* 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 + ISAMAX( K-IMAX, W( IMAX+1, KW-1 ), + $ 1 ) + ROWMAX = ABS( W( JMAX, KW-1 ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = ISAMAX( IMAX-1, W( 1, KW-1 ), 1 ) + STEMP = ABS( W( ITEMP, KW-1 ) ) + IF( STEMP.GT.ROWMAX ) THEN + ROWMAX = STEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for +* ABS( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.(ABS( 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 SCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) +* + DONE = .TRUE. +* +* 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. + 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 SCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) +* + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* ============================================================ +* + KK = K - KSTEP + 1 +* +* KKW is the column of W which corresponds to column KK of A +* + KKW = NB + KK - N +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL SCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA ) + CALL SCOPY( P, A( 1, K ), 1, A( 1, P ), 1 ) +* +* Interchange rows K and P in last N-K+1 columns of A +* and last N-K+2 columns of W +* + CALL SSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA ) + CALL SSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW ) + END IF +* +* Updated column KP is already stored in column KKW of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL SCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + CALL SCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 ) +* +* Interchange rows KK and KP in last N-KK+1 columns +* of A and W +* + CALL SSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), LDA ) + CALL SSWAP( 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(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* +* Store U(k) in column k of A +* + CALL SCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) + IF( K.GT.1 ) THEN + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN + R1 = ONE / A( K, K ) + CALL SSCAL( K-1, R1, A( 1, K ), 1 ) + ELSE IF( A( K, K ).NE.ZERO ) THEN + DO 14 II = 1, K - 1 + A( II, K ) = A( II, K ) / A( K, K ) + 14 CONTINUE + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = ZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns KW and KW-1 of W now +* hold +* +* ( W(k-1) W(k) ) = ( 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 +* + IF( K.GT.2 ) THEN +* +* Store U(k) and U(k-1) in columns k and k-1 of A +* + D12 = W( K-1, KW ) + D11 = W( K, KW ) / D12 + D22 = W( K-1, KW-1 ) / D12 + T = ONE / ( D11*D22-ONE ) + DO 20 J = 1, K - 2 + A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) / + $ D12 ) + A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) / + $ D12 ) + 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 ) = ZERO + A( K, K ) = W( K, KW ) + E( K ) = W( K-1, KW ) + E( K-1 ) = ZERO +* + 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**T = A11 - U12*W**T +* +* computing blocks of NB columns at a time +* + DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB + JB = MIN( NB, K-J+1 ) +* +* Update the upper triangle of the diagonal block +* + DO 40 JJ = J, J + JB - 1 + CALL SGEMV( 'No transpose', JJ-J+1, N-K, -ONE, + $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, ONE, + $ A( J, JJ ), 1 ) + 40 CONTINUE +* +* Update the rectangular superdiagonal block +* + IF( J.GE.2 ) + $ CALL SGEMM( 'No transpose', 'Transpose', J-1, JB, + $ N-K, -ONE, A( 1, K+1 ), LDA, W( J, KW+1 ), + $ LDW, ONE, A( 1, J ), LDA ) + 50 CONTINUE +* +* 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 +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = ZERO +* +* 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 it +* + CALL SCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 ) + IF( K.GT.1 ) + $ CALL SGEMV( 'No transpose', N-K+1, K-1, -ONE, A( K, 1 ), + $ LDA, W( K, 1 ), LDW, ONE, W( K, K ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( 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 + ISAMAX( N-K, W( K+1, K ), 1 ) + COLMAX = ABS( 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 + CALL SCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = ZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 SCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1) + CALL SCOPY( N-IMAX+1, A( IMAX, IMAX ), 1, + $ W( IMAX, K+1 ), 1 ) + IF( K.GT.1 ) + $ CALL SGEMV( 'No transpose', N-K+1, K-1, -ONE, + $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW, + $ ONE, W( K, K+1 ), 1 ) +* +* 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 + ISAMAX( IMAX-K, W( K, K+1 ), 1 ) + ROWMAX = ABS( W( JMAX, K+1 ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + ISAMAX( N-IMAX, W( IMAX+1, K+1 ), 1) + STEMP = ABS( W( ITEMP, K+1 ) ) + IF( STEMP.GT.ROWMAX ) THEN + ROWMAX = STEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for +* ABS( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.( ABS( 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 SCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 ) +* + DONE = .TRUE. +* +* 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. + 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 SCOPY( 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 +* +* ============================================================ +* + KK = K + KSTEP - 1 +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL SCOPY( P-K, A( K, K ), 1, A( P, K ), LDA ) + CALL SCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 ) +* +* Interchange rows K and P in first K columns of A +* and first K+1 columns of W +* + CALL SSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA ) + CALL SSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW ) + END IF +* +* Updated column KP is already stored in column KK of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL SCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA ) + CALL SCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 ) +* +* Interchange rows KK and KP in first KK columns of A and W +* + CALL SSWAP( KK, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) + CALL SSWAP( 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 +* +* Store L(k) in column k of A +* + CALL SCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) + IF( K.LT.N ) THEN + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN + R1 = ONE / A( K, K ) + CALL SSCAL( N-K, R1, A( K+1, K ), 1 ) + ELSE IF( A( K, K ).NE.ZERO ) THEN + DO 74 II = K + 1, N + A( II, K ) = A( II, K ) / A( K, K ) + 74 CONTINUE + END IF +* +* Store the subdiagonal element of D in array E +* + E( K ) = ZERO +* + 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 +* + IF( K.LT.N-1 ) THEN +* +* Store L(k) and L(k+1) in columns k and k+1 of A +* + D21 = W( K+1, K ) + D11 = W( K+1, K+1 ) / D21 + D22 = W( K, K ) / D21 + T = ONE / ( D11*D22-ONE ) + DO 80 J = K + 2, N + A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) / + $ 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 ) = ZERO + A( K+1, K+1 ) = W( K+1, K+1 ) + E( K ) = W( K+1, K ) + E( K+1 ) = ZERO +* + 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**T = A22 - L21*W**T +* +* computing blocks of NB columns at a time +* + DO 110 J = K, N, NB + JB = MIN( NB, N-J+1 ) +* +* Update the lower triangle of the diagonal block +* + DO 100 JJ = J, J + JB - 1 + CALL SGEMV( 'No transpose', J+JB-JJ, K-1, -ONE, + $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, ONE, + $ A( JJ, JJ ), 1 ) + 100 CONTINUE +* +* Update the rectangular subdiagonal block +* + IF( J+JB.LE.N ) + $ CALL SGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, + $ K-1, -ONE, A( J+JB, 1 ), LDA, W( J, 1 ), + $ LDW, ONE, A( J+JB, J ), LDA ) + 110 CONTINUE +* +* Set KB to the number of columns factorized +* + KB = K - 1 +* + END IF +* + RETURN +* +* End of SLASYF_RK +* + END diff --git a/SRC/ssycon_3.f b/SRC/ssycon_3.f new file mode 100644 index 00000000..b337add2 --- /dev/null +++ b/SRC/ssycon_3.f @@ -0,0 +1,285 @@ +*> \brief \b SSYCON_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYCON_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssycon_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssycon_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssycon_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, +* WORK, IWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* REAL ANORM, RCOND +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ), IWORK( * ) +* REAL A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYCON_3 estimates the reciprocal of the condition number (in the +*> 1-norm) of a real symmetric matrix A using the factorization +*> computed by DSYTRF_RK or DSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> An estimate is obtained for norm(inv(A)), and the reciprocal of the +*> condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). +*> This routine uses BLAS3 solver SSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by SSYTRF_RK and SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is REAL array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by SSYTRF_RK or SSYTRF_BK. +*> \endverbatim +*> +*> \param[in] ANORM +*> \verbatim +*> ANORM is REAL +*> The 1-norm of the original matrix A. +*> \endverbatim +*> +*> \param[out] RCOND +*> \verbatim +*> RCOND is REAL +*> The reciprocal of the condition number of the matrix A, +*> computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an +*> estimate of the 1-norm of inv(A) computed in this routine. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is REAL array, dimension (2*N) +*> \endverbatim +*> +*> \param[out] IWORK +*> \verbatim +*> IWORK is INTEGER array, dimension (N) +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 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 SSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, + $ WORK, IWORK, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N + REAL ANORM, RCOND +* .. +* .. Array Arguments .. + INTEGER IPIV( * ), IWORK( * ) + REAL A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE, ZERO + PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, KASE + REAL AINVNM +* .. +* .. Local Arrays .. + INTEGER ISAVE( 3 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL SLACN2, SSYTRS_3, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( ANORM.LT.ZERO ) THEN + INFO = -7 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYCON_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + RCOND = ZERO + IF( N.EQ.0 ) THEN + RCOND = ONE + RETURN + ELSE IF( ANORM.LE.ZERO ) THEN + RETURN + END IF +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO I = N, 1, -1 + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO I = 1, N + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + END IF +* +* Estimate the 1-norm of the inverse. +* + KASE = 0 + 30 CONTINUE + CALL SLACN2( N, WORK( N+1 ), WORK, IWORK, AINVNM, KASE, ISAVE ) + IF( KASE.NE.0 ) THEN +* +* Multiply by inv(L*D*L**T) or inv(U*D*U**T). +* + CALL SSYTRS_3( UPLO, N, 1, A, LDA, E, IPIV, WORK, N, INFO ) + GO TO 30 + END IF +* +* Compute the estimate of the reciprocal condition number. +* + IF( AINVNM.NE.ZERO ) + $ RCOND = ( ONE / AINVNM ) / ANORM +* + RETURN +* +* End of DSYCON_3 +* + END diff --git a/SRC/ssyconvf.f b/SRC/ssyconvf.f new file mode 100644 index 00000000..cf971824 --- /dev/null +++ b/SRC/ssyconvf.f @@ -0,0 +1,559 @@ +*> \brief \b SSYCONVF +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYCONVF + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssyconvf.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssyconvf.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssyconvf.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYCONVF( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> SSYCONVF converts the factorization output format used in +*> SSYTRF provided on entry in parameter A into the factorization +*> output format used in SSYTRF_RK (or SSYTRF_BK) that is stored +*> on exit in parameters A and E. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in SSYTRF into +*> the format used in SSYTRF_RK (or SSYTRF_BK). +*> +*> If parameter WAY = 'R': +*> SSYCONVF performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in SSYTRF_RK +*> (or SSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in SSYTRF that is stored +*> on exit in parameter A. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in SSYTRF_RK +*> (or SSYTRF_BK) into the format used in SSYTRF. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> SSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> SSYTRF_RK or SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> SSYTRF_RK or SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> SSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is REAL array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in,out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> +*> 1) If WAY ='C': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in SSYTRF. +*> On exit, details of the interchanges and the block +*> structure of D in the format used in SSYTRF_RK +*> ( or SSYTRF_BK). +*> +*> 1) If WAY ='R': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in SSYTRF_RK +*> ( or SSYTRF_BK). +*> On exit, details of the interchanges and the block +*> structure of D in the format used in SSYTRF. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE SSYCONVF( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ZERO + PARAMETER ( ZERO = 0.0E+0 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL SSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYCONVF', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL SSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL SSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i-1 and IPIV(i-1), +* so this should be recorded in two consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I-1 ) +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where k increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL SSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL SSWAP( I-1, A( IP, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i+1 and IPIV(i+1), +* so this should be recorded in consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I+1 ) +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of SSYCONVF +* + END diff --git a/SRC/ssyconvf_rook.f b/SRC/ssyconvf_rook.f new file mode 100644 index 00000000..69f04f6d --- /dev/null +++ b/SRC/ssyconvf_rook.f @@ -0,0 +1,544 @@ +*> \brief \b SSYCONVF_ROOK +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYCONVF_ROOK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssyconvf_rook.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssyconvf_rook.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssyconvf_rook.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYCONVF_ROOK( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> SSYCONVF_ROOK converts the factorization output format used in +*> SSYTRF_ROOK provided on entry in parameter A into the factorization +*> output format used in SSYTRF_RK (or SSYTRF_BK) that is stored +*> on exit in parameters A and E. IPIV format for SSYTRF_ROOK and +*> SSYTRF_RK (or SSYTRF_BK) is the same and is not converted. +*> +*> If parameter WAY = 'R': +*> SSYCONVF_ROOK performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in SSYTRF_RK +*> (or SSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in SSYTRF_ROOK that is stored +*> on exit in parameter A. IPIV format for SSYTRF_ROOK and +*> SSYTRF_RK (or SSYTRF_BK) is the same and is not converted. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> SSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> SSYTRF_RK or SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> SSYTRF_RK or SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> SSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is REAL array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> On entry, details of the interchanges and the block +*> structure of D as determined: +*> 1) by SSYTRF_ROOK, if WAY ='C'; +*> 2) by SSYTRF_RK (or SSYTRF_BK), if WAY ='R'. +*> The IPIV format is the same for all these routines. +*> +*> On exit, is not changed. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE SSYCONVF_ROOK( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ZERO + PARAMETER ( ZERO = 0.0E+0 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL SSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP, IP2 +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYCONVF_ROOK', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i-1 and IPIV(i-1) +* in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + IF( IP2.NE.(I-1) ) THEN + CALL SSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP2, I+1 ), LDA ) + END IF + END IF + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i-1) and i and IPIV(i) +* in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP2.NE.(I-1) ) THEN + CALL SSWAP( N-I, A( IP2, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL SSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i+1 and IPIV(i+1) +* in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + IF( IP2.NE.(I+1) ) THEN + CALL SSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP2, 1 ), LDA ) + END IF + END IF + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL SSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i+1) and i and IPIV(i) +* in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP2.NE.(I+1) ) THEN + CALL SSWAP( I-1, A( IP2, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL SSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of SSYCONVF_ROOK +* + END diff --git a/SRC/ssysv_rk.f b/SRC/ssysv_rk.f new file mode 100644 index 00000000..06641dbf --- /dev/null +++ b/SRC/ssysv_rk.f @@ -0,0 +1,317 @@ +*> \brief <b> SSYSV_RK computes the solution to system of linear equations A * X = B for SY matrices</b> +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYSV_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssysv_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssysv_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssysv_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* WORK, LWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYSV_RK computes the solution to a real system of linear +*> equations A * X = B, where A is an N-by-N symmetric matrix +*> and X and B are N-by-NRHS matrices. +*> +*> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used +*> to factor A as +*> A = P*U*D*(U**T)*(P**T), if UPLO = 'U', or +*> A = P*L*D*(L**T)*(P**T), if UPLO = 'L', +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> SSYTRF_RK is called to compute the factorization of a real +*> symmetric matrix. The factored form of A is then used to solve +*> the system of equations A * X = B by calling BLAS3 routine SSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric matrix A is stored: +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The number of linear equations, i.e., the order of the +*> matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> On entry, the symmetric 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, if INFO = 0, diagonal of the block diagonal +*> matrix D and factors U or L as computed by SSYTRF_RK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> For more info see the description of DSYTRF_RK routine. +*> \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 REAL array, dimension (N) +*> On exit, contains the output computed by the factorization +*> routine DSYTRF_RK, i.e. the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> For more info see the description of DSYTRF_RK routine. +*> \endverbatim +*> +*> \param[out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D, +*> as determined by SSYTRF_RK. +*> +*> For more info see the description of DSYTRF_RK routine. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is REAL array, dimension (LDB,NRHS) +*> On entry, the N-by-NRHS right hand side matrix B. +*> On exit, if INFO = 0, the N-by-NRHS solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is REAL array, dimension ( MAX(1,LWORK) ). +*> Work array used in the factorization stage. +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= 1. For best performance +*> of factorization stage LWORK >= max(1,N*NB), where NB is +*> the optimal blocksize for DSYTRF_RK. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array for factorization stage, returns this value as +*> the first entry of the WORK array, and no error message +*> related to LWORK is issued by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup singleSYsolve +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 SSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ WORK, LWORK, INFO ) +* +* -- LAPACK driver routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY + INTEGER LWKOPT +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, SSYTRF_RK, SSYTRS_3 +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -11 + END IF +* + IF( INFO.EQ.0 ) THEN + IF( N.EQ.0 ) THEN + LWKOPT = 1 + ELSE + CALL SSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO ) + LWKOPT = WORK(1) + END IF + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYSV_RK ', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* +* Compute the factorization A = P*U*D*(U**T)*(P**T) or +* A = P*U*D*(U**T)*(P**T). +* + CALL SSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO ) +* + IF( INFO.EQ.0 ) THEN +* +* Solve the system A*X = B with BLAS3 solver, overwriting B with X. +* + CALL SSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO ) +* + END IF +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of SSYSV_RK +* + END diff --git a/SRC/ssytf2_rk.f b/SRC/ssytf2_rk.f new file mode 100644 index 00000000..720a1503 --- /dev/null +++ b/SRC/ssytf2_rk.f @@ -0,0 +1,943 @@ +*> \brief \b SSYTF2_RK computes the factorization of a real symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYTF2_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytf2_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytf2_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytf2_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), E ( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYTF2_RK computes the factorization of a real symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the unblocked version of the algorithm, calling Level 2 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 REAL array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \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. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put further details +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 +*> +*> 01-01-96 - Based on modifications by +*> J. Lewis, Boeing Computer Services Company +*> A. Petitet, Computer Science Dept., +*> Univ. of Tenn., Knoxville abd , USA +*> \endverbatim +* +* ===================================================================== + SUBROUTINE SSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), 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 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER, DONE + INTEGER I, IMAX, J, JMAX, ITEMP, K, KK, KP, KSTEP, + $ P, II + REAL ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, + $ ROWMAX, STEMP, T, WK, WKM1, WKP1, SFMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ISAMAX + REAL SLAMCH + EXTERNAL LSAME, ISAMAX, SLAMCH +* .. +* .. External Subroutines .. + EXTERNAL SSCAL, SSWAP, SSYR, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, SQRT +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYTF2_RK', -INFO ) + RETURN + END IF +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = SLAMCH( 'S' ) +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* Initilize the first entry of array E, where superdiagonal +* elements of D are stored +* + E( 1 ) = ZERO +* +* K is the main loop index, decreasing from N to 1 in steps of +* 1 or 2 +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 34 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( A( 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.GT.1 ) THEN + IMAX = ISAMAX( K-1, A( 1, K ), 1 ) + COLMAX = ABS( A( 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 +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = ZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, +* use 1-by-1 pivot block +* + KP = K + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* 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 + ISAMAX( K-IMAX, A( IMAX, IMAX+1 ), + $ LDA ) + ROWMAX = ABS( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = ISAMAX( IMAX-1, A( 1, IMAX ), 1 ) + STEMP = ABS( A( ITEMP, IMAX ) ) + IF( STEMP.GT.ROWMAX ) THEN + ROWMAX = STEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( ABS( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX ) ) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the leading +* submatrix A(1:k,1:k) if we have a 2-by-2 pivot +* + IF( P.GT.1 ) + $ CALL SSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 ) + IF( P.LT.(K-1) ) + $ CALL SSWAP( K-P-1, A( P+1, K ), 1, A( P, P+1 ), + $ LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL SSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K - KSTEP + 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the leading +* submatrix A(1:k,1:k) +* + IF( KP.GT.1 ) + $ CALL SSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) + IF( ( KK.GT.1 ) .AND. ( KP.LT.(KK-1) ) ) + $ CALL SSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K-1, K ) + A( K-1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL SSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) +* + END IF +* +* Update the leading submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* + IF( K.GT.1 ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) and +* store U(k) in column k +* + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*1/D(k)*W(k)**T +* + D11 = ONE / A( K, K ) + CALL SSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) +* +* Store U(k) in column k +* + CALL SSCAL( K-1, D11, A( 1, K ), 1 ) + ELSE +* +* Store L(k) in column K +* + D11 = A( K, K ) + DO 16 II = 1, K - 1 + A( II, K ) = A( II, K ) / D11 + 16 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL SSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = ZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k-1 now hold +* +* ( W(k-1) W(k) ) = ( 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 +* +* Perform a rank-2 update of A(1:k-2,1:k-2) as +* +* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T +* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.GT.2 ) THEN +* + D12 = A( K-1, K ) + D22 = A( K-1, K-1 ) / D12 + D11 = A( K, K ) / D12 + T = ONE / ( D11*D22-ONE ) +* + DO 30 J = K - 2, 1, -1 +* + WKM1 = T*( D11*A( J, K-1 )-A( J, K ) ) + WK = T*( D22*A( J, K )-A( J, K-1 ) ) +* + DO 20 I = J, 1, -1 + A( I, J ) = A( I, J ) - (A( I, K ) / D12 )*WK - + $ ( A( I, K-1 ) / D12 )*WKM1 + 20 CONTINUE +* +* Store U(k) and U(k-1) in cols k and k-1 for row J +* + A( J, K ) = WK / D12 + A( J, K-1 ) = WKM1 / D12 +* + 30 CONTINUE +* + END IF +* +* Copy superdiagonal elements of D(K) to E(K) and +* ZERO out superdiagonal entry of A +* + E( K ) = A( K-1, K ) + E( K-1 ) = ZERO + A( K-1, K ) = ZERO +* + 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 +* + 34 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = ZERO +* +* K is the main loop index, increasing from 1 to N in steps of +* 1 or 2 +* + K = 1 + 40 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 64 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( A( 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 + ISAMAX( N-K, A( K+1, K ), 1 ) + COLMAX = ABS( A( 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 +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = ZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, use 1-by-1 pivot block +* + KP = K +* + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 42 CONTINUE +* +* Begin pivot search loop body +* +* 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 + ISAMAX( IMAX-K, A( IMAX, K ), LDA ) + ROWMAX = ABS( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + ISAMAX( N-IMAX, A( IMAX+1, IMAX ), + $ 1 ) + STEMP = ABS( A( ITEMP, IMAX ) ) + IF( STEMP.GT.ROWMAX ) THEN + ROWMAX = STEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( ABS( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX ) ) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 42 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the trailing +* submatrix A(k:n,k:n) if we have a 2-by-2 pivot +* + IF( P.LT.N ) + $ CALL SSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) + IF( P.GT.(K+1) ) + $ CALL SSWAP( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL SSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K + KSTEP - 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the trailing +* submatrix A(k:n,k:n) +* + IF( KP.LT.N ) + $ CALL SSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) + IF( ( KK.LT.N ) .AND. ( KP.GT.(KK+1) ) ) + $ CALL SSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K+1, K ) + A( K+1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL SSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) +* + END IF +* +* Update the trailing submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = L(k)*D(k) +* +* where L(k) is the k-th column of L +* + IF( K.LT.N ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) and +* store L(k) in column k +* + IF( ABS( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* + D11 = ONE / A( K, K ) + CALL SSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) +* +* Store L(k) in column k +* + CALL SSCAL( N-K, D11, A( K+1, K ), 1 ) + ELSE +* +* Store L(k) in column k +* + D11 = A( K, K ) + DO 46 II = K + 1, N + A( II, K ) = A( II, K ) / D11 + 46 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL SSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) + END IF +* +* Store the subdiagonal element of D in array E +* + E( K ) = ZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k+1 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 +* +* +* Perform a rank-2 update of A(k+2:n,k+2:n) as +* +* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T +* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.LT.N-1 ) THEN +* + D21 = A( K+1, K ) + D11 = A( K+1, K+1 ) / D21 + D22 = A( K, K ) / D21 + T = ONE / ( D11*D22-ONE ) +* + DO 60 J = K + 2, N +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WK = T*( D11*A( J, K )-A( J, K+1 ) ) + WKP1 = T*( D22*A( J, K+1 )-A( J, K ) ) +* +* Perform a rank-2 update of A(k+2:n,k+2:n) +* + DO 50 I = J, N + A( I, J ) = A( I, J ) - ( A( I, K ) / D21 )*WK - + $ ( A( I, K+1 ) / D21 )*WKP1 + 50 CONTINUE +* +* Store L(k) and L(k+1) in cols k and k+1 for row J +* + A( J, K ) = WK / D21 + A( J, K+1 ) = WKP1 / D21 +* + 60 CONTINUE +* + END IF +* +* Copy subdiagonal elements of D(K) to E(K) and +* ZERO out subdiagonal entry of A +* + E( K ) = A( K+1, K ) + E( K+1 ) = ZERO + A( K+1, K ) = ZERO +* + 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 40 +* + 64 CONTINUE +* + END IF +* + RETURN +* +* End of SSYTF2_RK +* + END diff --git a/SRC/ssytrf_rk.f b/SRC/ssytrf_rk.f new file mode 100644 index 00000000..df608fc6 --- /dev/null +++ b/SRC/ssytrf_rk.f @@ -0,0 +1,498 @@ +*> \brief \b SSYTRF_RK computes the factorization of a real symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS3 blocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYTRF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytrf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytrf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytrf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYTRF_RK computes the factorization of a real symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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 REAL array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is REAL array, dimension ( MAX(1,LWORK) ). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >=1. For best performance +*> LWORK >= N*NB, where NB is the block size returned +*> by ILAENV. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array, returns this value as the first entry of the WORK +*> array, and no error message related to LWORK is issued +*> by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put correct description +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 SSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY, UPPER + INTEGER I, IINFO, IP, IWS, K, KB, LDWORK, LWKOPT, + $ NB, NBMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL SLASYF_RK, SSYTF2_RK, SSWAP, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.EQ.0 ) THEN +* +* Determine the block size +* + NB = ILAENV( 1, 'SSYTRF_RK', UPLO, N, -1, -1, -1 ) + LWKOPT = N*NB + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYTRF_RK', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* + NBMIN = 2 + LDWORK = N + IF( NB.GT.1 .AND. NB.LT.N ) THEN + IWS = LDWORK*NB + IF( LWORK.LT.IWS ) THEN + NB = MAX( LWORK / LDWORK, 1 ) + NBMIN = MAX( 2, ILAENV( 2, 'SSYTRF_RK', + $ UPLO, N, -1, -1, -1 ) ) + END IF + ELSE + IWS = 1 + END IF + IF( NB.LT.NBMIN ) + $ NB = N +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* K is the main loop index, decreasing from N to 1 in steps of +* KB, where KB is the number of columns factorized by SLASYF_RK; +* KB is either NB or NB-1, or K for the last block +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 15 +* + IF( K.GT.NB ) THEN +* +* Factorize columns k-kb+1:k of A and use blocked code to +* update columns 1:k-kb +* + CALL SLASYF_RK( UPLO, K, NB, KB, A, LDA, E, + $ IPIV, WORK, LDWORK, IINFO ) + ELSE +* +* Use unblocked code to factorize columns 1:k of A +* + CALL SSYTF2_RK( UPLO, K, A, LDA, E, IPIV, IINFO ) + KB = K + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO +* +* No need to adjust IPIV +* +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k-kb+1:k and apply row permutations to the +* last k+1 colunms k+1:N after that block +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.LT.N ) THEN + DO I = K, ( K - KB + 1 ), -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL SSWAP( N-K, A( I, K+1 ), LDA, + $ A( IP, K+1 ), LDA ) + END IF + END DO + END IF +* +* Decrease K and return to the start of the main loop +* + K = K - KB + GO TO 10 +* +* This label is the exit from main loop over K decreasing +* from N to 1 in steps of KB +* + 15 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* K is the main loop index, increasing from 1 to N in steps of +* KB, where KB is the number of columns factorized by SLASYF_RK; +* KB is either NB or NB-1, or N-K+1 for the last block +* + K = 1 + 20 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 35 +* + IF( K.LE.N-NB ) THEN +* +* Factorize columns k:k+kb-1 of A and use blocked code to +* update columns k+kb:n +* + CALL SLASYF_RK( UPLO, N-K+1, NB, KB, A( K, K ), LDA, E( K ), + $ IPIV( K ), WORK, LDWORK, IINFO ) + + + ELSE +* +* Use unblocked code to factorize columns k:n of A +* + CALL SSYTF2_RK( UPLO, N-K+1, A( K, K ), LDA, E( K ), + $ IPIV( K ), IINFO ) + KB = N - K + 1 +* + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO + K - 1 +* +* Adjust IPIV +* + DO I = K, K + KB - 1 + IF( IPIV( I ).GT.0 ) THEN + IPIV( I ) = IPIV( I ) + K - 1 + ELSE + IPIV( I ) = IPIV( I ) - K + 1 + END IF + END DO +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k:k+kb-1 and apply row permutations to the +* first k-1 colunms 1:k-1 before that block +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.GT.1 ) THEN + DO I = K, ( K + KB - 1 ), 1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL SSWAP( K-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END DO + END IF +* +* Increase K and return to the start of the main loop +* + K = K + KB + GO TO 20 +* +* This label is the exit from main loop over K increasing +* from 1 to N in steps of KB +* + 35 CONTINUE +* +* End Lower +* + END IF +* + WORK( 1 ) = LWKOPT + RETURN +* +* End of SSYTRF_RK +* + END diff --git a/SRC/ssytri_3.f b/SRC/ssytri_3.f new file mode 100644 index 00000000..4acad458 --- /dev/null +++ b/SRC/ssytri_3.f @@ -0,0 +1,248 @@ +*> \brief \b SSYTRI_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYTRI_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytri_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytri_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytri_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYTRI_3 computes the inverse of a real symmetric indefinite +*> matrix A using the factorization computed by SSYTRF_RK or SSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> SSYTRI_3 sets the leading dimension of the workspace before calling +*> SSYTRI_3X that actually computes the inverse. This is the blocked +*> version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by SSYTRF_RK and SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is REAL array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by SSYTRF_RK or SSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is REAL array, dimension (N+NB+1)*(NB+3). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= (N+NB+1)*(NB+3). +*> +*> If LDWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the optimal +*> size of the WORK array, returns this value as the first +*> entry of the WORK array, and no error message related to +*> LWORK is issued by XERBLA. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE SSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL UPPER, LQUERY + INTEGER LWKOPT, NB +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL SSYTRI_3X +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) +* +* Determine the block size +* + NB = MAX( 1, ILAENV( 1, 'SSYTRI_3', UPLO, N, -1, -1, -1 ) ) + LWKOPT = ( N+NB+1 ) * ( NB+3 ) +* + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF ( LWORK .LT. LWKOPT .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYTRI_3', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + WORK( 1 ) = LWKOPT + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + CALL SSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of SSYTRI_3 +* + END diff --git a/SRC/ssytri_3x.f b/SRC/ssytri_3x.f new file mode 100644 index 00000000..d4a1bcea --- /dev/null +++ b/SRC/ssytri_3x.f @@ -0,0 +1,645 @@ +*> \brief \b SSYTRI_3X +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYTRI_3X + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytri_3x.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytri_3x.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytri_3x.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYTRI_3X computes the inverse of a real symmetric indefinite +*> matrix A using the factorization computed by SSYTRF_RK or SSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by SYTRF_RK and SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is REAL array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by SSYTRF_RK or SSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is REAL array, dimension (N+NB+1,NB+3). +*> \endverbatim +*> +*> \param[in] NB +*> \verbatim +*> NB is INTEGER +*> Block size. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE SSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE, ZERO + PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11 + REAL AK, AKKP1, AKP1, D, T, U01_I_J, U01_IP1_J, + $ U11_I_J, U11_IP1_J +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL SGEMM, SSYSWAPR, STRTRI, STRMM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, MOD +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF +* +* Quick return if possible +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYTRI_3X', -INFO ) + RETURN + END IF + IF( N.EQ.0 ) + $ RETURN +* +* Workspace got Non-diag elements of D +* + DO K = 1, N + WORK( K, 1 ) = E( K ) + END DO +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO INFO = N, 1, -1 + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO INFO = 1, N + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO ) + $ RETURN + END DO + END IF +* + INFO = 0 +* +* Splitting Workspace +* U01 is a block ( N, NB+1 ) +* The first element of U01 is in WORK( 1, 1 ) +* U11 is a block ( NB+1, NB+1 ) +* The first element of U11 is in WORK( N+1, 1 ) +* + U11 = N +* +* INVD is a block ( N, 2 ) +* The first element of INVD is in WORK( 1, INVD ) +* + INVD = NB + 2 + + IF( UPPER ) THEN +* +* Begin Upper +* +* invA = P * inv(U**T) * inv(D) * inv(U) * P**T. +* + CALL STRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(U) +* + K = 1 + DO WHILE( K.LE.N ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / A( K, K ) + WORK( K, INVD+1 ) = ZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K+1, 1 ) + AK = A( K, K ) / T + AKP1 = A( K+1, K+1 ) / T + AKKP1 = WORK( K+1, 1 ) / T + D = T*( AK*AKP1-ONE ) + WORK( K, INVD ) = AKP1 / D + WORK( K+1, INVD+1 ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K+1, INVD ) = WORK( K, INVD+1 ) + K = K + 1 + END IF + K = K + 1 + END DO +* +* inv(U**T) = (inv(U))**T +* +* inv(U**T) * inv(D) * inv(U) +* + CUT = N + DO WHILE( CUT.GT.0 ) + NNB = NB + IF( CUT.LE.NNB ) THEN + NNB = CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT+1-NNB, CUT + IF( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF + + CUT = CUT - NNB +* +* U01 Block +* + DO I = 1, CUT + DO J = 1, NNB + WORK( I, J ) = A( I, CUT+J ) + END DO + END DO +* +* U11 Block +* + DO I = 1, NNB + WORK( U11+I, I ) = ONE + DO J = 1, I-1 + WORK( U11+I, J ) = ZERO + END DO + DO J = I+1, NNB + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD * U01 +* + I = 1 + DO WHILE( I.LE.CUT ) + IF( IPIV( I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( I, INVD ) * WORK( I, J ) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK( I, J ) + U01_IP1_J = WORK( I+1, J ) + WORK( I, J ) = WORK( I, INVD ) * U01_I_J + $ + WORK( I, INVD+1 ) * U01_IP1_J + WORK( I+1, J ) = WORK( I+1, INVD ) * U01_I_J + $ + WORK( I+1, INVD+1 ) * U01_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* invD1 * U11 +* + I = 1 + DO WHILE ( I.LE.NNB ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = I, NNB + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + END DO + ELSE + DO J = I, NNB + U11_I_J = WORK(U11+I,J) + U11_IP1_J = WORK(U11+I+1,J) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * WORK(U11+I+1,J) + WORK( U11+I+1, J ) = WORK(CUT+I+1,INVD) * U11_I_J + $ + WORK(CUT+I+1,INVD+1) * U11_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* U11**T * invD1 * U11 -> U11 +* + CALL STRMM( 'L', 'U', 'T', 'U', NNB, NNB, + $ ONE, A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* +* U01**T * invD * U01 -> A( CUT+I, CUT+J ) +* + CALL SGEMM( 'T', 'N', NNB, NNB, CUT, ONE, A( 1, CUT+1 ), + $ LDA, WORK, N+NB+1, ZERO, WORK(U11+1,1), N+NB+1 ) + +* +* U11 = U11**T * invD1 * U11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J ) + WORK(U11+I,J) + END DO + END DO +* +* U01 = U00**T * invD0 * U01 +* + CALL STRMM( 'L', UPLO, 'T', 'U', CUT, NNB, + $ ONE, A, LDA, WORK, N+NB+1 ) + +* +* Update U01 +* + DO I = 1, CUT + DO J = 1, NNB + A( I, CUT+J ) = WORK( I, J ) + END DO + END DO +* +* Next Block +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(U**T) * inv(D) * inv(U) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Upper case. +* +* ( We can use a loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = 1, N + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* inv A = P * inv(L**T) * inv(D) * inv(L) * P**T. +* + CALL STRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(L) +* + K = N + DO WHILE ( K .GE. 1 ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / A( K, K ) + WORK( K, INVD+1 ) = ZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K-1, 1 ) + AK = A( K-1, K-1 ) / T + AKP1 = A( K, K ) / T + AKKP1 = WORK( K-1, 1 ) / T + D = T*( AK*AKP1-ONE ) + WORK( K-1, INVD ) = AKP1 / D + WORK( K, INVD ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K-1, INVD+1 ) = WORK( K, INVD+1 ) + K = K - 1 + END IF + K = K - 1 + END DO +* +* inv(L**T) = (inv(L))**T +* +* inv(L**T) * inv(D) * inv(L) +* + CUT = 0 + DO WHILE( CUT.LT.N ) + NNB = NB + IF( (CUT + NNB).GT.N ) THEN + NNB = N - CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT + 1, CUT+NNB + IF ( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF +* +* L21 Block +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + WORK( I, J ) = A( CUT+NNB+I, CUT+J ) + END DO + END DO +* +* L11 Block +* + DO I = 1, NNB + WORK( U11+I, I) = ONE + DO J = I+1, NNB + WORK( U11+I, J ) = ZERO + END DO + DO J = 1, I-1 + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD*L21 +* + I = N-CUT-NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+NNB+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( CUT+NNB+I, INVD) * WORK( I, J) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK(I,J) + U01_IP1_J = WORK(I-1,J) + WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ + $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J + WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ + $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* invD1*L11 +* + I = NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( U11+I, J ) = WORK( CUT+I, INVD)*WORK(U11+I,J) + END DO + + ELSE + DO J = 1, NNB + U11_I_J = WORK( U11+I, J ) + U11_IP1_J = WORK( U11+I-1, J ) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * U11_IP1_J + WORK( U11+I-1, J ) = WORK(CUT+I-1,INVD+1) * U11_I_J + $ + WORK(CUT+I-1,INVD) * U11_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* L11**T * invD1 * L11 -> L11 +* + CALL STRMM( 'L', UPLO, 'T', 'U', NNB, NNB, ONE, + $ A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) + +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* + IF( (CUT+NNB).LT.N ) THEN +* +* L21**T * invD2*L21 -> A( CUT+I, CUT+J ) +* + CALL SGEMM( 'T', 'N', NNB, NNB, N-NNB-CUT, ONE, + $ A( CUT+NNB+1, CUT+1 ), LDA, WORK, N+NB+1, + $ ZERO, WORK( U11+1, 1 ), N+NB+1 ) + +* +* L11 = L11**T * invD1 * L11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J )+WORK(U11+I,J) + END DO + END DO +* +* L01 = L22**T * invD2 * L21 +* + CALL STRMM( 'L', UPLO, 'T', 'U', N-NNB-CUT, NNB, ONE, + $ A( CUT+NNB+1, CUT+NNB+1 ), LDA, WORK, + $ N+NB+1 ) +* +* Update L21 +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + A( CUT+NNB+I, CUT+J ) = WORK( I, J ) + END DO + END DO +* + ELSE +* +* L11 = L11**T * invD1 * L11 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO + END IF +* +* Next Block +* + CUT = CUT + NNB +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(L**T) * inv(D) * inv(L) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Lower case. +* +* ( We can use a loop over IPIV with increment -1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = N, 1, -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + END IF +* + RETURN +* +* End of SSYTRI_3X +* + END + diff --git a/SRC/ssytrs_3.f b/SRC/ssytrs_3.f new file mode 100644 index 00000000..453d8380 --- /dev/null +++ b/SRC/ssytrs_3.f @@ -0,0 +1,371 @@ +*> \brief \b SSYTRS_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download SSYTRS_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytrs_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytrs_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytrs_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE SSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* REAL A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> SSYTRS_3 solves a system of linear equations A * X = B with a real +*> symmetric matrix A using the factorization computed +*> by SSYTRF_RK or SSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This algorithm is using Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is REAL array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by SSYTRF_RK and SSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is REAL array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by SSYTRF_RK or SSYTRF_BK. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is REAL array, dimension (LDB,NRHS) +*> On entry, the right hand side matrix B. +*> On exit, the solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup singleSYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 SSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + REAL A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE + PARAMETER ( ONE = 1.0E+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, J, K, KP + REAL AK, AKM1, AKM1K, BK, BKM1, DENOM +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL SSCAL, SSWAP, STRSM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'SSYTRS_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 .OR. NRHS.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin Upper +* +* Solve A*X = B, where A = U*D*U**T. +* +* P**T * B +* +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (U \P**T * B) -> B [ (U \P**T * B) ] +* + CALL STRSM( 'L', 'U', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (U \P**T * B) ] +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN + CALL SSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF ( I.GT.1 ) THEN + AKM1K = E( I ) + AKM1 = A( I-1, I-1 ) / AKM1K + AK = A( I, I ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I-1, J ) / AKM1K + BK = B( I, J ) / AKM1K + B( I-1, J ) = ( AK*BKM1-BK ) / DENOM + B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* Compute (U**T \ B) -> B [ U**T \ (D \ (U \P**T * B) ) ] +* + CALL STRSM( 'L', 'U', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (U**T \ (D \ (U \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* Solve A*X = B, where A = L*D*L**T. +* +* P**T * B +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (L \P**T * B) -> B [ (L \P**T * B) ] +* + CALL STRSM( 'L', 'L', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (L \P**T * B) ] +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN + CALL SSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF( I.LT.N ) THEN + AKM1K = E( I ) + AKM1 = A( I, I ) / AKM1K + AK = A( I+1, I+1 ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I, J ) / AKM1K + BK = B( I+1, J ) / AKM1K + B( I, J ) = ( AK*BKM1-BK ) / DENOM + B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* Compute (L**T \ B) -> B [ L**T \ (D \ (L \P**T * B) ) ] +* + CALL STRSM('L', 'L', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (L**T \ (D \ (L \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL SSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* END Lower +* + END IF +* + RETURN +* +* End of SSYTRS_3 +* + END diff --git a/SRC/zhecon_3.f b/SRC/zhecon_3.f new file mode 100644 index 00000000..8ade0bf4 --- /dev/null +++ b/SRC/zhecon_3.f @@ -0,0 +1,285 @@ +*> \brief \b ZHECON_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHECON_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhecon_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhecon_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhecon_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHECON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, +* WORK, IWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* DOUBLE PRECISION ANORM, RCOND +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ), IWORK( * ) +* COMPLEX*16 A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHECON_3 estimates the reciprocal of the condition number (in the +*> 1-norm) of a complex Hermitian matrix A using the factorization +*> computed by ZHETRF_RK or ZHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> An estimate is obtained for norm(inv(A)), and the reciprocal of the +*> condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). +*> This routine uses BLAS3 solver ZHETRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**H)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**H)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by ZHETRF_RK and ZHETRF_BK: +*> 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 +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZHETRF_RK or ZHETRF_BK. +*> \endverbatim +*> +*> \param[in] ANORM +*> \verbatim +*> ANORM is DOUBLE PRECISION +*> The 1-norm of the original matrix A. +*> \endverbatim +*> +*> \param[out] RCOND +*> \verbatim +*> RCOND is DOUBLE PRECISION +*> The reciprocal of the condition number of the matrix A, +*> computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an +*> estimate of the 1-norm of inv(A) computed in this routine. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension (2*N) +*> \endverbatim +*> +*> \param[out] IWORK +*> \verbatim +*> IWORK is INTEGER array, dimension (N) +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 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 ZHECON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, + $ WORK, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N + DOUBLE PRECISION ANORM, RCOND +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + REAL ONE, ZERO + PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, KASE + DOUBLE PRECISION AINVNM +* .. +* .. Local Arrays .. + INTEGER ISAVE( 3 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL ZHETRS_3, ZLACN2, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( ANORM.LT.ZERO ) THEN + INFO = -7 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHECON_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + RCOND = ZERO + IF( N.EQ.0 ) THEN + RCOND = ONE + RETURN + ELSE IF( ANORM.LE.ZERO ) THEN + RETURN + END IF +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO I = N, 1, -1 + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO I = 1, N + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.ZERO ) + $ RETURN + END DO + END IF +* +* Estimate the 1-norm of the inverse. +* + KASE = 0 + 30 CONTINUE + CALL ZLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE ) + IF( KASE.NE.0 ) THEN +* +* Multiply by inv(L*D*L**H) or inv(U*D*U**H). +* + CALL ZHETRS_3( UPLO, N, 1, A, LDA, E, IPIV, WORK, N, INFO ) + GO TO 30 + END IF +* +* Compute the estimate of the reciprocal condition number. +* + IF( AINVNM.NE.ZERO ) + $ RCOND = ( ONE / AINVNM ) / ANORM +* + RETURN +* +* End of ZHECON_3 +* + END diff --git a/SRC/zhesv_rk.f b/SRC/zhesv_rk.f new file mode 100644 index 00000000..8a649b27 --- /dev/null +++ b/SRC/zhesv_rk.f @@ -0,0 +1,317 @@ +*> \brief <b> ZHESV_RK computes the solution to system of linear equations A * X = B for SY matrices</b> +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHESV_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhesv_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhesv_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhesv_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHESV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* WORK, LWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHESV_RK computes the solution to a complex system of linear +*> equations A * X = B, where A is an N-by-N Hermitian matrix +*> and X and B are N-by-NRHS matrices. +*> +*> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used +*> to factor A as +*> A = P*U*D*(U**H)*(P**T), if UPLO = 'U', or +*> A = P*L*D*(L**H)*(P**T), if UPLO = 'L', +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> ZHETRF_RK is called to compute the factorization of a complex +*> Hermitian matrix. The factored form of A is then used to solve +*> the system of equations A * X = B by calling BLAS3 routine ZHETRS_3. +*> \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 triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The number of linear equations, i.e., the order of the +*> matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 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, if INFO = 0, diagonal of the block diagonal +*> matrix D and factors U or L as computed by ZHETRF_RK: +*> 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. +*> +*> For more info see the description of ZHETRF_RK routine. +*> \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*16 array, dimension (N) +*> On exit, contains the output computed by the factorization +*> routine ZHETRF_RK, i.e. 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. +*> +*> For more info see the description of ZHETRF_RK routine. +*> \endverbatim +*> +*> \param[out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D, +*> as determined by ZHETRF_RK. +*> +*> For more info see the description of ZHETRF_RK routine. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX*16 array, dimension (LDB,NRHS) +*> On entry, the N-by-NRHS right hand side matrix B. +*> On exit, if INFO = 0, the N-by-NRHS solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension ( MAX(1,LWORK) ). +*> Work array used in the factorization stage. +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= 1. For best performance +*> of factorization stage LWORK >= max(1,N*NB), where NB is +*> the optimal blocksize for ZHETRF_RK. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array for factorization stage, returns this value as +*> the first entry of the WORK array, and no error message +*> related to LWORK is issued by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complex16HEsolve +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZHESV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, WORK, + $ LWORK, INFO ) +* +* -- LAPACK driver routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY + INTEGER LWKOPT +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, ZHETRF_RK, ZHETRS_3 +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -11 + END IF +* + IF( INFO.EQ.0 ) THEN + IF( N.EQ.0 ) THEN + LWKOPT = 1 + ELSE + CALL ZHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO ) + LWKOPT = WORK(1) + END IF + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHESV_RK ', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* +* Compute the factorization A = P*U*D*(U**H)*(P**T) or +* A = P*U*D*(U**H)*(P**T). +* + CALL ZHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO ) +* + IF( INFO.EQ.0 ) THEN +* +* Solve the system A*X = B with BLAS3 solver, overwriting B with X. +* + CALL ZHETRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO ) +* + END IF +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of ZHESV_RK +* + END diff --git a/SRC/zhetf2_rk.f b/SRC/zhetf2_rk.f new file mode 100644 index 00000000..857f1c67 --- /dev/null +++ b/SRC/zhetf2_rk.f @@ -0,0 +1,1039 @@ +*> \brief \b ZHETF2_RK computes the factorization of a complex Hermitian indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHETF2_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetf2_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetf2_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetf2_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHETF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E ( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHETF2_RK computes the factorization of a complex Hermitian matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the unblocked version of the algorithm, calling Level 2 BLAS. +*> For more information see Further Details section. +*> \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,out] A +*> \verbatim +*> A is COMPLEX*16 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*16 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put further details +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 +*> +*> 01-01-96 - Based on modifications by +*> J. Lewis, Boeing Computer Services Company +*> A. Petitet, Computer Science Dept., +*> Univ. of Tenn., Knoxville abd , USA +*> \endverbatim +* +* ===================================================================== + SUBROUTINE ZHETF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ) +* .. +* +* ====================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO, ONE + PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) + DOUBLE PRECISION EIGHT, SEVTEN + PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) + COMPLEX*16 CZERO + PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL DONE, UPPER + INTEGER I, II, IMAX, ITEMP, J, JMAX, K, KK, KP, KSTEP, + $ P + DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, DTEMP, + $ ROWMAX, TT, SFMIN + COMPLEX*16 D12, D21, T, WK, WKM1, WKP1, Z +* .. +* .. External Functions .. +* + LOGICAL LSAME + INTEGER IZAMAX + DOUBLE PRECISION DLAMCH, DLAPY2 + EXTERNAL LSAME, IZAMAX, DLAMCH, DLAPY2 +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, ZDSCAL, ZHER, ZSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX, SQRT +* .. +* .. Statement Functions .. + DOUBLE PRECISION CABS1 +* .. +* .. Statement Function definitions .. + CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) ) +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHETF2_RK', -INFO ) + RETURN + END IF +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = DLAMCH( 'S' ) +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**H using the upper triangle of A +* +* Initilize 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 to 1 in steps of +* 1 or 2 +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 34 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( DBLE( A( 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.GT.1 ) THEN + IMAX = IZAMAX( K-1, A( 1, K ), 1 ) + COLMAX = CABS1( A( 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 ) = DBLE( A( K, K ) ) +* +* 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 +* + DONE = .FALSE. +* +* Loop until pivot found +* + 12 CONTINUE +* +* BEGIN pivot search loop body +* +* +* 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 + IZAMAX( K-IMAX, A( IMAX, IMAX+1 ), + $ LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = IZAMAX( IMAX-1, A( 1, IMAX ), 1 ) + DTEMP = CABS1( A( ITEMP, IMAX ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + 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( DBLE( A( IMAX, IMAX ) ) ) + $ .LT.ALPHA*ROWMAX ) ) THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + 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 + 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 +* +* For only a 2x2 pivot, interchange rows and columns K and P +* in the leading submatrix A(1:k,1:k) +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* (1) Swap columnar parts + IF( P.GT.1 ) + $ CALL ZSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 ) +* (2) Swap and conjugate middle parts + DO 14 J = P + 1, K - 1 + T = DCONJG( A( J, K ) ) + A( J, K ) = DCONJG( A( P, J ) ) + A( P, J ) = T + 14 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( P, K ) = DCONJG( A( P, K ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = DBLE( A( K, K ) ) + A( K, K ) = DBLE( A( P, P ) ) + A( P, P ) = R1 +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL ZSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), LDA ) +* + END IF +* +* For both 1x1 and 2x2 pivots, interchange rows and +* columns KK and KP in the leading submatrix A(1:k,1:k) +* + IF( KP.NE.KK ) THEN +* (1) Swap columnar parts + IF( KP.GT.1 ) + $ CALL ZSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) +* (2) Swap and conjugate middle parts + DO 15 J = KP + 1, KK - 1 + T = DCONJG( A( J, KK ) ) + A( J, KK ) = DCONJG( A( KP, J ) ) + A( KP, J ) = T + 15 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( KP, KK ) = DCONJG( A( KP, KK ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = DBLE( A( KK, KK ) ) + A( KK, KK ) = DBLE( A( KP, KP ) ) + A( KP, KP ) = R1 +* + IF( KSTEP.EQ.2 ) THEN +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = DBLE( A( K, K ) ) +* (5) Swap row elements + T = A( K-1, K ) + A( K-1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) +* + ELSE +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = DBLE( A( K, K ) ) + IF( KSTEP.EQ.2 ) + $ A( K-1, K-1 ) = DBLE( A( K-1, K-1 ) ) + END IF +* +* Update the leading submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* + IF( K.GT.1 ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) and +* store U(k) in column k +* + IF( ABS( DBLE( A( K, K ) ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*1/D(k)*W(k)**T +* + D11 = ONE / DBLE( A( K, K ) ) + CALL ZHER( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) +* +* Store U(k) in column k +* + CALL ZDSCAL( K-1, D11, A( 1, K ), 1 ) + ELSE +* +* Store L(k) in column K +* + D11 = DBLE( A( K, K ) ) + DO 16 II = 1, K - 1 + A( II, K ) = A( II, K ) / D11 + 16 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL ZHER( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = CZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k-1 now hold +* +* ( W(k-1) W(k) ) = ( 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 +* +* Perform a rank-2 update of A(1:k-2,1:k-2) as +* +* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T +* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.GT.2 ) THEN +* D = |A12| + D = DLAPY2( DBLE( A( K-1, K ) ), + $ DIMAG( A( K-1, K ) ) ) + D11 = A( K, K ) / D + D22 = A( K-1, K-1 ) / D + D12 = A( K-1, K ) / D + TT = ONE / ( D11*D22-ONE ) +* + DO 30 J = K - 2, 1, -1 +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WKM1 = TT*( D11*A( J, K-1 )-DCONJG( D12 )* + $ A( J, K ) ) + WK = TT*( D22*A( J, K )-D12*A( J, K-1 ) ) +* +* Perform a rank-2 update of A(1:k-2,1:k-2) +* + DO 20 I = J, 1, -1 + A( I, J ) = A( I, J ) - + $ ( A( I, K ) / D )*DCONJG( WK ) - + $ ( A( I, K-1 ) / D )*DCONJG( WKM1 ) + 20 CONTINUE +* +* Store U(k) and U(k-1) in cols k and k-1 for row J +* + A( J, K ) = WK / D + A( J, K-1 ) = WKM1 / D +* (*) Make sure that diagonal element of pivot is real + A( J, J ) = DCMPLX( DBLE( A( J, J ) ), ZERO ) +* + 30 CONTINUE +* + END IF +* +* Copy superdiagonal elements of D(K) to E(K) and +* ZERO out superdiagonal entry of A +* + E( K ) = A( K-1, K ) + E( K-1 ) = CZERO + A( K-1, K ) = CZERO +* + 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 +* + 34 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**H using the lower triangle of A +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = CZERO +* +* K is the main loop index, increasing from 1 to N in steps of +* 1 or 2 +* + K = 1 + 40 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 64 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = ABS( DBLE( A( 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 + IZAMAX( N-K, A( K+1, K ), 1 ) + COLMAX = CABS1( A( 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 ) = DBLE( A( K, K ) ) +* +* 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 +* + 42 CONTINUE +* +* BEGIN pivot search loop body +* +* +* 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 + IZAMAX( IMAX-K, A( IMAX, K ), LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + IZAMAX( N-IMAX, A( IMAX+1, IMAX ), + $ 1 ) + DTEMP = CABS1( A( ITEMP, IMAX ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + 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( DBLE( A( IMAX, IMAX ) ) ) + $ .LT.ALPHA*ROWMAX ) ) THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + 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 + END IF +* +* +* END pivot search loop body +* + IF( .NOT.DONE ) GOTO 42 +* + END IF +* +* END pivot search +* +* ============================================================ +* +* KK is the column of A where pivoting step stopped +* + KK = K + KSTEP - 1 +* +* For only a 2x2 pivot, interchange rows and columns K and P +* in the trailing submatrix A(k:n,k:n) +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* (1) Swap columnar parts + IF( P.LT.N ) + $ CALL ZSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) +* (2) Swap and conjugate middle parts + DO 44 J = K + 1, P - 1 + T = DCONJG( A( J, K ) ) + A( J, K ) = DCONJG( A( P, J ) ) + A( P, J ) = T + 44 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( P, K ) = DCONJG( A( P, K ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = DBLE( A( K, K ) ) + A( K, K ) = DBLE( A( P, P ) ) + A( P, P ) = R1 +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL ZSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) +* + END IF +* +* For both 1x1 and 2x2 pivots, interchange rows and +* columns KK and KP in the trailing submatrix A(k:n,k:n) +* + IF( KP.NE.KK ) THEN +* (1) Swap columnar parts + IF( KP.LT.N ) + $ CALL ZSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) +* (2) Swap and conjugate middle parts + DO 45 J = KK + 1, KP - 1 + T = DCONJG( A( J, KK ) ) + A( J, KK ) = DCONJG( A( KP, J ) ) + A( KP, J ) = T + 45 CONTINUE +* (3) Swap and conjugate corner elements at row-col interserction + A( KP, KK ) = DCONJG( A( KP, KK ) ) +* (4) Swap diagonal elements at row-col intersection + R1 = DBLE( A( KK, KK ) ) + A( KK, KK ) = DBLE( A( KP, KP ) ) + A( KP, KP ) = R1 +* + IF( KSTEP.EQ.2 ) THEN +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = DBLE( A( K, K ) ) +* (5) Swap row elements + T = A( K+1, K ) + A( K+1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) +* + ELSE +* (*) Make sure that diagonal element of pivot is real + A( K, K ) = DBLE( A( K, K ) ) + IF( KSTEP.EQ.2 ) + $ A( K+1, K+1 ) = DBLE( A( K+1, K+1 ) ) + END IF +* +* Update the trailing submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k of A now holds +* +* W(k) = L(k)*D(k), +* +* where L(k) is the k-th column of L +* + IF( K.LT.N ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) and +* store L(k) in column k +* +* Handle division by a small number +* + IF( ABS( DBLE( A( K, K ) ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* + D11 = ONE / DBLE( A( K, K ) ) + CALL ZHER( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) +* +* Store L(k) in column k +* + CALL ZDSCAL( N-K, D11, A( K+1, K ), 1 ) + ELSE +* +* Store L(k) in column k +* + D11 = DBLE( A( K, K ) ) + DO 46 II = K + 1, N + A( II, K ) = A( II, K ) / D11 + 46 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL ZHER( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) + END IF +* +* 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 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 +* +* +* Perform a rank-2 update of A(k+2:n,k+2:n) as +* +* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T +* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.LT.N-1 ) THEN +* D = |A21| + D = DLAPY2( DBLE( A( K+1, K ) ), + $ DIMAG( A( K+1, K ) ) ) + D11 = DBLE( A( K+1, K+1 ) ) / D + D22 = DBLE( A( K, K ) ) / D + D21 = A( K+1, K ) / D + TT = ONE / ( D11*D22-ONE ) +* + DO 60 J = K + 2, N +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WK = TT*( D11*A( J, K )-D21*A( J, K+1 ) ) + WKP1 = TT*( D22*A( J, K+1 )-DCONJG( D21 )* + $ A( J, K ) ) +* +* Perform a rank-2 update of A(k+2:n,k+2:n) +* + DO 50 I = J, N + A( I, J ) = A( I, J ) - + $ ( A( I, K ) / D )*DCONJG( WK ) - + $ ( A( I, K+1 ) / D )*DCONJG( WKP1 ) + 50 CONTINUE +* +* Store L(k) and L(k+1) in cols k and k+1 for row J +* + A( J, K ) = WK / D + A( J, K+1 ) = WKP1 / D +* (*) Make sure that diagonal element of pivot is real + A( J, J ) = DCMPLX( DBLE( A( J, J ) ), ZERO ) +* + 60 CONTINUE +* + END IF +* +* Copy subdiagonal elements of D(K) to E(K) and +* ZERO out subdiagonal entry of A +* + E( K ) = A( K+1, K ) + E( K+1 ) = CZERO + A( K+1, K ) = CZERO +* + 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 40 +* + 64 CONTINUE +* + END IF +* + RETURN +* +* End of ZHETF2_RK +* + END diff --git a/SRC/zhetrf_rk.f b/SRC/zhetrf_rk.f new file mode 100644 index 00000000..dbf4f9a4 --- /dev/null +++ b/SRC/zhetrf_rk.f @@ -0,0 +1,498 @@ +*> \brief \b ZHETRF_RK computes the factorization of a complex Hermitian indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS3 blocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHETRF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHETRF_RK computes the factorization of a complex Hermitian matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> For more information see Further Details section. +*> \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,out] A +*> \verbatim +*> A is COMPLEX*16 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*16 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension ( MAX(1,LWORK) ). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >=1. For best performance +*> LWORK >= N*NB, where NB is the block size returned +*> by ILAENV. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array, returns this value as the first entry of the WORK +*> array, and no error message related to LWORK is issued +*> by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put correct description +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZHETRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY, UPPER + INTEGER I, IINFO, IP, IWS, K, KB, LDWORK, LWKOPT, + $ NB, NBMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL ZLAHEF_RK, ZHETF2_RK, ZSWAP, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.EQ.0 ) THEN +* +* Determine the block size +* + NB = ILAENV( 1, 'ZHETRF_RK', UPLO, N, -1, -1, -1 ) + LWKOPT = N*NB + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHETRF_RK', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* + NBMIN = 2 + LDWORK = N + IF( NB.GT.1 .AND. NB.LT.N ) THEN + IWS = LDWORK*NB + IF( LWORK.LT.IWS ) THEN + NB = MAX( LWORK / LDWORK, 1 ) + NBMIN = MAX( 2, ILAENV( 2, 'ZHETRF_RK', + $ UPLO, N, -1, -1, -1 ) ) + END IF + ELSE + IWS = 1 + END IF + IF( NB.LT.NBMIN ) + $ NB = N +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* K is the main loop index, decreasing from N to 1 in steps of +* KB, where KB is the number of columns factorized by ZLAHEF_RK; +* KB is either NB or NB-1, or K for the last block +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 15 +* + IF( K.GT.NB ) THEN +* +* Factorize columns k-kb+1:k of A and use blocked code to +* update columns 1:k-kb +* + CALL ZLAHEF_RK( UPLO, K, NB, KB, A, LDA, E, + $ IPIV, WORK, LDWORK, IINFO ) + ELSE +* +* Use unblocked code to factorize columns 1:k of A +* + CALL ZHETF2_RK( UPLO, K, A, LDA, E, IPIV, IINFO ) + KB = K + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO +* +* No need to adjust IPIV +* +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k-kb+1:k and apply row permutations to the +* last k+1 colunms k+1:N after that block +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.LT.N ) THEN + DO I = K, ( K - KB + 1 ), -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL ZSWAP( N-K, A( I, K+1 ), LDA, + $ A( IP, K+1 ), LDA ) + END IF + END DO + END IF +* +* Decrease K and return to the start of the main loop +* + K = K - KB + GO TO 10 +* +* This label is the exit from main loop over K decreasing +* from N to 1 in steps of KB +* + 15 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* K is the main loop index, increasing from 1 to N in steps of +* KB, where KB is the number of columns factorized by ZLAHEF_RK; +* KB is either NB or NB-1, or N-K+1 for the last block +* + K = 1 + 20 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 35 +* + IF( K.LE.N-NB ) THEN +* +* Factorize columns k:k+kb-1 of A and use blocked code to +* update columns k+kb:n +* + CALL ZLAHEF_RK( UPLO, N-K+1, NB, KB, A( K, K ), LDA, E( K ), + $ IPIV( K ), WORK, LDWORK, IINFO ) + + + ELSE +* +* Use unblocked code to factorize columns k:n of A +* + CALL ZHETF2_RK( UPLO, N-K+1, A( K, K ), LDA, E( K ), + $ IPIV( K ), IINFO ) + KB = N - K + 1 +* + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO + K - 1 +* +* Adjust IPIV +* + DO I = K, K + KB - 1 + IF( IPIV( I ).GT.0 ) THEN + IPIV( I ) = IPIV( I ) + K - 1 + ELSE + IPIV( I ) = IPIV( I ) - K + 1 + END IF + END DO +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k:k+kb-1 and apply row permutations to the +* first k-1 colunms 1:k-1 before that block +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.GT.1 ) THEN + DO I = K, ( K + KB - 1 ), 1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL ZSWAP( K-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END DO + END IF +* +* Increase K and return to the start of the main loop +* + K = K + KB + GO TO 20 +* +* This label is the exit from main loop over K increasing +* from 1 to N in steps of KB +* + 35 CONTINUE +* +* End Lower +* + END IF +* + WORK( 1 ) = LWKOPT + RETURN +* +* End of ZHETRF_RK +* + END diff --git a/SRC/zhetri_3.f b/SRC/zhetri_3.f new file mode 100644 index 00000000..4d9b4cb1 --- /dev/null +++ b/SRC/zhetri_3.f @@ -0,0 +1,248 @@ +*> \brief \b ZHETRI_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHETRI_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetri_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetri_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetri_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHETRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHETRI_3 computes the inverse of a complex Hermitian indefinite +*> matrix A using the factorization computed by ZHETRF_RK or ZHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> ZHETRI_3 sets the leading dimension of the workspace before calling +*> ZHETRI_3X that actually computes the inverse. This is the blocked +*> version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by ZHETRF_RK and ZHETRF_BK: +*> 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 +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the Hermitian inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZHETRF_RK or ZHETRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension (N+NB+1)*(NB+3). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= (N+NB+1)*(NB+3). +*> +*> If LDWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the optimal +*> size of the WORK array, returns this value as the first +*> entry of the WORK array, and no error message related to +*> LWORK is issued by XERBLA. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE ZHETRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL UPPER, LQUERY + INTEGER LWKOPT, NB +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL ZHETRI_3X +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) +* +* Determine the block size +* + NB = MAX( 1, ILAENV( 1, 'ZHETRI_3', UPLO, N, -1, -1, -1 ) ) + LWKOPT = ( N+NB+1 ) * ( NB+3 ) +* + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF ( LWORK .LT. LWKOPT .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHETRI_3', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + WORK( 1 ) = LWKOPT + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + CALL ZHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of ZHETRI_3 +* + END diff --git a/SRC/zhetri_3x.f b/SRC/zhetri_3x.f new file mode 100644 index 00000000..9e736dac --- /dev/null +++ b/SRC/zhetri_3x.f @@ -0,0 +1,649 @@ +*> \brief \b ZHETRI_3X +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHETRI_3X + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetri_3x.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetri_3x.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetri_3x.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHETRI_3X computes the inverse of a complex Hermitian indefinite +*> matrix A using the factorization computed by ZHETRF_RK or ZHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by ZHETRF_RK and ZHETRF_BK: +*> 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 +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the Hermitian inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZHETRF_RK or ZHETRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension (N+NB+1,NB+3). +*> \endverbatim +*> +*> \param[in] NB +*> \verbatim +*> NB is INTEGER +*> Block size. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE ZHETRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ONE + PARAMETER ( ONE = 1.0D+0 ) + COMPLEX*16 CONE, CZERO + PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ), + $ CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11 + DOUBLE PRECISION AK, AKP1, T + COMPLEX*16 AKKP1, D, U01_I_J, U01_IP1_J, U11_I_J, + $ U11_IP1_J +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL ZGEMM, ZHESWAPR, ZTRTRI, ZTRMM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, DCONJG, DBLE, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF +* +* Quick return if possible +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHETRI_3X', -INFO ) + RETURN + END IF + IF( N.EQ.0 ) + $ RETURN +* +* Workspace got Non-diag elements of D +* + DO K = 1, N + WORK( K, 1 ) = E( K ) + END DO +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO INFO = N, 1, -1 + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO INFO = 1, N + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + END IF +* + INFO = 0 +* +* Splitting Workspace +* U01 is a block ( N, NB+1 ) +* The first element of U01 is in WORK( 1, 1 ) +* U11 is a block ( NB+1, NB+1 ) +* The first element of U11 is in WORK( N+1, 1 ) +* + U11 = N +* +* INVD is a block ( N, 2 ) +* The first element of INVD is in WORK( 1, INVD ) +* + INVD = NB + 2 + + IF( UPPER ) THEN +* +* Begin Upper +* +* invA = P * inv(U**H) * inv(D) * inv(U) * P**T. +* + CALL ZTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(U) +* + K = 1 + DO WHILE( K.LE.N ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / DBLE( A( K, K ) ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = ABS( WORK( K+1, 1 ) ) + AK = DBLE( A( K, K ) ) / T + AKP1 = DBLE( A( K+1, K+1 ) ) / T + AKKP1 = WORK( K+1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K, INVD ) = AKP1 / D + WORK( K+1, INVD+1 ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K+1, INVD ) = DCONJG( WORK( K, INVD+1 ) ) + K = K + 1 + END IF + K = K + 1 + END DO +* +* inv(U**H) = (inv(U))**H +* +* inv(U**H) * inv(D) * inv(U) +* + CUT = N + DO WHILE( CUT.GT.0 ) + NNB = NB + IF( CUT.LE.NNB ) THEN + NNB = CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT+1-NNB, CUT + IF( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF + + CUT = CUT - NNB +* +* U01 Block +* + DO I = 1, CUT + DO J = 1, NNB + WORK( I, J ) = A( I, CUT+J ) + END DO + END DO +* +* U11 Block +* + DO I = 1, NNB + WORK( U11+I, I ) = CONE + DO J = 1, I-1 + WORK( U11+I, J ) = CZERO + END DO + DO J = I+1, NNB + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD * U01 +* + I = 1 + DO WHILE( I.LE.CUT ) + IF( IPIV( I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( I, INVD ) * WORK( I, J ) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK( I, J ) + U01_IP1_J = WORK( I+1, J ) + WORK( I, J ) = WORK( I, INVD ) * U01_I_J + $ + WORK( I, INVD+1 ) * U01_IP1_J + WORK( I+1, J ) = WORK( I+1, INVD ) * U01_I_J + $ + WORK( I+1, INVD+1 ) * U01_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* invD1 * U11 +* + I = 1 + DO WHILE ( I.LE.NNB ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = I, NNB + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + END DO + ELSE + DO J = I, NNB + U11_I_J = WORK(U11+I,J) + U11_IP1_J = WORK(U11+I+1,J) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * WORK(U11+I+1,J) + WORK( U11+I+1, J ) = WORK(CUT+I+1,INVD) * U11_I_J + $ + WORK(CUT+I+1,INVD+1) * U11_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* U11**H * invD1 * U11 -> U11 +* + CALL ZTRMM( 'L', 'U', 'C', 'U', NNB, NNB, + $ CONE, A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* +* U01**H * invD * U01 -> A( CUT+I, CUT+J ) +* + CALL ZGEMM( 'C', 'N', NNB, NNB, CUT, CONE, A( 1, CUT+1 ), + $ LDA, WORK, N+NB+1, CZERO, WORK(U11+1,1), + $ N+NB+1 ) + +* +* U11 = U11**H * invD1 * U11 + U01**H * invD * U01 +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J ) + WORK(U11+I,J) + END DO + END DO +* +* U01 = U00**H * invD0 * U01 +* + CALL ZTRMM( 'L', UPLO, 'C', 'U', CUT, NNB, + $ CONE, A, LDA, WORK, N+NB+1 ) + +* +* Update U01 +* + DO I = 1, CUT + DO J = 1, NNB + A( I, CUT+J ) = WORK( I, J ) + END DO + END DO +* +* Next Block +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(U**H) * inv(D) * inv(U) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Upper case. +* +* ( We can use a loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = 1, N + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL ZHESWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL ZHESWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* inv A = P * inv(L**H) * inv(D) * inv(L) * P**T. +* + CALL ZTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(L) +* + K = N + DO WHILE ( K .GE. 1 ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = ONE / DBLE( A( K, K ) ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = ABS( WORK( K-1, 1 ) ) + AK = DBLE( A( K-1, K-1 ) ) / T + AKP1 = DBLE( A( K, K ) ) / T + AKKP1 = WORK( K-1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K-1, INVD ) = AKP1 / D + WORK( K, INVD ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K-1, INVD+1 ) = DCONJG( WORK( K, INVD+1 ) ) + K = K - 1 + END IF + K = K - 1 + END DO +* +* inv(L**H) = (inv(L))**H +* +* inv(L**H) * inv(D) * inv(L) +* + CUT = 0 + DO WHILE( CUT.LT.N ) + NNB = NB + IF( (CUT + NNB).GT.N ) THEN + NNB = N - CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT + 1, CUT+NNB + IF ( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF +* +* L21 Block +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + WORK( I, J ) = A( CUT+NNB+I, CUT+J ) + END DO + END DO +* +* L11 Block +* + DO I = 1, NNB + WORK( U11+I, I) = CONE + DO J = I+1, NNB + WORK( U11+I, J ) = CZERO + END DO + DO J = 1, I-1 + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD*L21 +* + I = N-CUT-NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+NNB+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( CUT+NNB+I, INVD) * WORK( I, J) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK(I,J) + U01_IP1_J = WORK(I-1,J) + WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ + $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J + WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ + $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* invD1*L11 +* + I = NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( U11+I, J ) = WORK( CUT+I, INVD)*WORK(U11+I,J) + END DO + + ELSE + DO J = 1, NNB + U11_I_J = WORK( U11+I, J ) + U11_IP1_J = WORK( U11+I-1, J ) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * U11_IP1_J + WORK( U11+I-1, J ) = WORK(CUT+I-1,INVD+1) * U11_I_J + $ + WORK(CUT+I-1,INVD) * U11_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* L11**H * invD1 * L11 -> L11 +* + CALL ZTRMM( 'L', UPLO, 'C', 'U', NNB, NNB, CONE, + $ A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) + +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* + IF( (CUT+NNB).LT.N ) THEN +* +* L21**H * invD2*L21 -> A( CUT+I, CUT+J ) +* + CALL ZGEMM( 'C', 'N', NNB, NNB, N-NNB-CUT, CONE, + $ A( CUT+NNB+1, CUT+1 ), LDA, WORK, N+NB+1, + $ CZERO, WORK( U11+1, 1 ), N+NB+1 ) + +* +* L11 = L11**H * invD1 * L11 + U01**H * invD * U01 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J )+WORK(U11+I,J) + END DO + END DO +* +* L01 = L22**H * invD2 * L21 +* + CALL ZTRMM( 'L', UPLO, 'C', 'U', N-NNB-CUT, NNB, CONE, + $ A( CUT+NNB+1, CUT+NNB+1 ), LDA, WORK, + $ N+NB+1 ) +* +* Update L21 +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + A( CUT+NNB+I, CUT+J ) = WORK( I, J ) + END DO + END DO +* + ELSE +* +* L11 = L11**H * invD1 * L11 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO + END IF +* +* Next Block +* + CUT = CUT + NNB +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(L**H) * inv(D) * inv(L) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Lower case. +* +* ( We can use a loop over IPIV with increment -1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = N, 1, -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL ZHESWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL ZHESWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + END IF +* + RETURN +* +* End of ZHETRI_3X +* + END diff --git a/SRC/zhetrs_3.f b/SRC/zhetrs_3.f new file mode 100644 index 00000000..2239941c --- /dev/null +++ b/SRC/zhetrs_3.f @@ -0,0 +1,374 @@ +*> \brief \b ZHETRS_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZHETRS_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrs_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrs_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrs_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZHETRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZHETRS_3 solves a system of linear equations A * X = B with a complex +*> Hermitian matrix A using the factorization computed +*> by ZHETRF_RK or ZHETRF_BK: +*> +*> A = P*U*D*(U**H)*(P**T) or A = P*L*D*(L**H)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**H (or L**H) is the conjugate of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is Hermitian and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This algorithm is using Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**H)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**H)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by ZHETRF_RK and ZHETRF_BK: +*> 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 +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZHETRF_RK or ZHETRF_BK. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX*16 array, dimension (LDB,NRHS) +*> On entry, the right hand side matrix B. +*> On exit, the solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZHETRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX*16 ONE + PARAMETER ( ONE = ( 1.0D+0,0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, J, K, KP + DOUBLE PRECISION S + COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL ZDSCAL, ZSWAP, ZTRSM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, DBLE, DCONJG, MAX +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZHETRS_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 .OR. NRHS.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin Upper +* +* Solve A*X = B, where A = U*D*U**H. +* +* P**T * B +* +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (U \P**T * B) -> B [ (U \P**T * B) ] +* + CALL ZTRSM( 'L', 'U', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (U \P**T * B) ] +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN + S = DBLE( ONE ) / DBLE( A( I, I ) ) + CALL ZDSCAL( NRHS, S, B( I, 1 ), LDB ) + ELSE IF ( I.GT.1 ) THEN + AKM1K = E( I ) + AKM1 = A( I-1, I-1 ) / AKM1K + AK = A( I, I ) / DCONJG( AKM1K ) + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I-1, J ) / AKM1K + BK = B( I, J ) / DCONJG( AKM1K ) + B( I-1, J ) = ( AK*BKM1-BK ) / DENOM + B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* Compute (U**H \ B) -> B [ U**H \ (D \ (U \P**T * B) ) ] +* + CALL ZTRSM( 'L', 'U', 'C', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (U**H \ (D \ (U \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* Solve A*X = B, where A = L*D*L**H. +* +* P**T * B +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (L \P**T * B) -> B [ (L \P**T * B) ] +* + CALL ZTRSM( 'L', 'L', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (L \P**T * B) ] +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN + S = DBLE( ONE ) / DBLE( A( I, I ) ) + CALL ZDSCAL( NRHS, S, B( I, 1 ), LDB ) + ELSE IF( I.LT.N ) THEN + AKM1K = E( I ) + AKM1 = A( I, I ) / DCONJG( AKM1K ) + AK = A( I+1, I+1 ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I, J ) / DCONJG( AKM1K ) + BK = B( I+1, J ) / AKM1K + B( I, J ) = ( AK*BKM1-BK ) / DENOM + B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* Compute (L**H \ B) -> B [ L**H \ (D \ (L \P**T * B) ) ] +* + CALL ZTRSM('L', 'L', 'C', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (L**H \ (D \ (L \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* END Lower +* + END IF +* + RETURN +* +* End of ZHETRS_3 +* + END diff --git a/SRC/zhetrs_aa_REMOTE_88959.f b/SRC/zhetrs_aa_REMOTE_88959.f deleted file mode 100644 index 6d2c73cc..00000000 --- a/SRC/zhetrs_aa_REMOTE_88959.f +++ /dev/null @@ -1,284 +0,0 @@ -*> \brief \b ZHETRS_AASEN -* -* =========== DOCUMENTATION =========== -* -* Online html documentation available at -* http://www.netlib.org/lapack/explore-html/ -* -*> \htmlonly -*> Download ZHETRS_AASEN + dependencies -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrs_aasen.f"> -*> [TGZ]</a> -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrs_aasen.f"> -*> [ZIP]</a> -*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrs_aasen.f"> -*> [TXT]</a> -*> \endhtmlonly -* -* Definition: -* =========== -* -* SUBROUTINE ZHETRS_AASEN( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, -* WORK, LWORK, INFO ) -* -* .. Scalar Arguments .. -* CHARACTER UPLO -* INTEGER N, NRHS, LDA, LDB, LWORK, INFO -* .. -* .. Array Arguments .. -* INTEGER IPIV( * ) -* COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ) -* .. -* -* -*> \par Purpose: -* ============= -*> -*> \verbatim -*> -*> ZHETRS_AASEN solves a system of linear equations A*X = B with a real -*> hermitian matrix A using the factorization A = U*T*U**T or -*> A = L*T*L**T computed by ZHETRF_AASEN. -*> \endverbatim -* -* Arguments: -* ========== -* -*> \param[in] UPLO -*> \verbatim -*> UPLO is CHARACTER*1 -*> Specifies whether the details of the factorization are stored -*> as an upper or lower triangular matrix. -*> = 'U': Upper triangular, form is A = U*T*U**T; -*> = 'L': Lower triangular, form is A = L*T*L**T. -*> \endverbatim -*> -*> \param[in] N -*> \verbatim -*> N is INTEGER -*> The order of the matrix A. N >= 0. -*> \endverbatim -*> -*> \param[in] NRHS -*> \verbatim -*> NRHS is INTEGER -*> The number of right hand sides, i.e., the number of columns -*> of the matrix B. NRHS >= 0. -*> \endverbatim -*> -*> \param[in,out] A -*> \verbatim -*> A is COMPLEX*16 array, dimension (LDA,N) -*> Details of factors computed by ZHETRF_AASEN. -*> \endverbatim -*> -*> \param[in] LDA -*> \verbatim -*> LDA is INTEGER -*> The leading dimension of the array A. LDA >= max(1,N). -*> \endverbatim -*> -*> \param[in] IPIV -*> \verbatim -*> IPIV is INTEGER array, dimension (N) -*> Details of the interchanges as computed by ZHETRF_AASEN. -*> \endverbatim -*> -*> \param[in,out] B -*> \verbatim -*> B is COMPLEX*16 array, dimension (LDB,NRHS) -*> On entry, the right hand side matrix B. -*> On exit, the solution matrix X. -*> \endverbatim -*> -*> \param[in] LDB -*> \verbatim -*> LDB is INTEGER -*> The leading dimension of the array B. LDB >= max(1,N). -*> \endverbatim -*> -*> \param[in] WORK -*> \verbatim -*> WORK is DOUBLE array, dimension (MAX(1,LWORK)) -*> \endverbatim -*> -*> \param[in] LWORK -*> \verbatim -*> LWORK is INTEGER, LWORK >= 3*N-2. -*> -*> \param[out] INFO -*> \verbatim -*> INFO is INTEGER -*> = 0: successful exit -*> < 0: if INFO = -i, the i-th argument had an illegal value -*> \endverbatim -* -* Authors: -* ======== -* -*> \author Univ. of Tennessee -*> \author Univ. of California Berkeley -*> \author Univ. of Colorado Denver -*> \author NAG Ltd. -* -*> \date November 2016 -* -*> \ingroup complex16SYcomputational -* -* @precisions fortran z -> c -* -* ===================================================================== - SUBROUTINE ZHETRS_AASEN( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, - $ WORK, LWORK, INFO ) -* -* -- LAPACK computational routine (version 3.4.0) -- -* -- LAPACK is a software package provided by Univ. of Tennessee, -- -* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- -* November 2016 -* - IMPLICIT NONE -* -* .. Scalar Arguments .. - CHARACTER UPLO - INTEGER N, NRHS, LDA, LDB, LWORK, INFO -* .. -* .. Array Arguments .. - INTEGER IPIV( * ) - COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * ) -* .. -* -* ===================================================================== -* - COMPLEX*16 ONE - PARAMETER ( ONE = 1.0D+0 ) -* .. -* .. Local Scalars .. - LOGICAL UPPER - INTEGER K, KP -* .. -* .. External Functions .. - LOGICAL LSAME - EXTERNAL LSAME -* .. -* .. External Subroutines .. - EXTERNAL ZGTSV, ZSWAP, ZTRSM, XERBLA -* .. -* .. Intrinsic Functions .. - INTRINSIC MAX -* .. -* .. Executable Statements .. -* - INFO = 0 - UPPER = LSAME( UPLO, 'U' ) - IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN - INFO = -1 - ELSE IF( N.LT.0 ) THEN - INFO = -2 - ELSE IF( NRHS.LT.0 ) THEN - INFO = -3 - ELSE IF( LDA.LT.MAX( 1, N ) ) THEN - INFO = -5 - ELSE IF( LDB.LT.MAX( 1, N ) ) THEN - INFO = -8 - ELSE IF( LWORK.LT.(3*N-2) ) THEN - INFO = -10 - END IF - IF( INFO.NE.0 ) THEN - CALL XERBLA( 'ZHETRS_AASEN', -INFO ) - RETURN - END IF -* -* Quick return if possible -* - IF( N.EQ.0 .OR. NRHS.EQ.0 ) - $ RETURN -* - IF( UPPER ) THEN -* -* Solve A*X = B, where A = U*T*U**T. -* -* Pivot, P**T * B -* - DO K = 1, N - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - END DO -* -* Compute (U \P**T * B) -> B [ (U \P**T * B) ] -* - CALL ZTRSM('L', 'U', 'C', 'U', N-1, NRHS, ONE, A( 1, 2 ), LDA, - $ B( 2, 1 ), LDB) -* -* Compute T \ B -> B [ T \ (U \P**T * B) ] -* - CALL ZLACPY( 'F', 1, N, A(1, 1), LDA+1, WORK(N), 1) - IF( N.GT.1 ) THEN - CALL ZLACPY( 'F', 1, N-1, A( 1, 2 ), LDA+1, WORK( 2*N ), 1) - CALL ZLACPY( 'F', 1, N-1, A( 1, 2 ), LDA+1, WORK( 1 ), 1) - CALL ZLACGV( N-1, WORK( 1 ), 1 ) - END IF - CALL ZGTSV(N, NRHS, WORK(1), WORK(N), WORK(2*N), B, LDB, - $ INFO) -* -* Compute (U**T \ B) -> B [ U**T \ (T \ (U \P**T * B) ) ] -* - CALL ZTRSM( 'L', 'U', 'N', 'U', N-1, NRHS, ONE, A( 1, 2 ), LDA, - $ B(2, 1), LDB) -* -* Pivot, P * B [ P * (U**T \ (T \ (U \P**T * B) )) ] -* - DO K = N, 1, -1 - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - END DO -* - ELSE -* -* Solve A*X = B, where A = L*T*L**T. -* -* Pivot, P**T * B -* - DO K = 1, N - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - END DO -* -* Compute (L \P**T * B) -> B [ (L \P**T * B) ] -* - CALL ZTRSM( 'L', 'L', 'N', 'U', N-1, NRHS, ONE, A( 2, 1 ), LDA, - $ B(2, 1), LDB) -* -* Compute T \ B -> B [ T \ (L \P**T * B) ] -* - CALL ZLACPY( 'F', 1, N, A(1, 1), LDA+1, WORK(N), 1) - IF( N.GT.1 ) THEN - CALL ZLACPY( 'F', 1, N-1, A( 2, 1 ), LDA+1, WORK( 1 ), 1) - CALL ZLACPY( 'F', 1, N-1, A( 2, 1 ), LDA+1, WORK( 2*N ), 1) - CALL ZLACGV( N-1, WORK( 2*N ), 1 ) - END IF - CALL ZGTSV(N, NRHS, WORK(1), WORK(N), WORK(2*N), B, LDB, - $ INFO) -* -* Compute (L**T \ B) -> B [ L**T \ (T \ (L \P**T * B) ) ] -* - CALL ZTRSM( 'L', 'L', 'C', 'U', N-1, NRHS, ONE, A( 2, 1 ), LDA, - $ B( 2, 1 ), LDB) -* -* Pivot, P * B [ P * (L**T \ (T \ (L \P**T * B) )) ] -* - DO K = N, 1, -1 - KP = IPIV( K ) - IF( KP.NE.K ) - $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) - END DO -* - END IF -* - RETURN -* -* End of ZHETRS_AASEN -* - END diff --git a/SRC/zlahef_rk.f b/SRC/zlahef_rk.f new file mode 100644 index 00000000..cf8c8586 --- /dev/null +++ b/SRC/zlahef_rk.f @@ -0,0 +1,1234 @@ +*> \brief \b ZLAHEF_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 ZLAHEF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahef_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahef_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahef_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZLAHEF_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*16 A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZLAHEF_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. +*> +*> ZLAHEF_RK is an auxiliary routine called by ZHETRF_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*16 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*16 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*16 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. +* +*> \date November 2016 +* +*> \ingroup complex16HEcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, KB, LDA, LDW, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), W( LDW, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO, ONE + PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) + COMPLEX*16 CONE + PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) ) + DOUBLE PRECISION EIGHT, SEVTEN + PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) + COMPLEX*16 CZERO + PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL DONE + INTEGER IMAX, ITEMP, II, J, JB, JJ, JMAX, K, KK, KKW, + $ KP, KSTEP, KW, P + DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, DTEMP, R1, ROWMAX, T, + $ SFMIN + COMPLEX*16 D11, D21, D22, Z +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER IZAMAX + DOUBLE PRECISION DLAMCH + EXTERNAL LSAME, IZAMAX, DLAMCH +* .. +* .. External Subroutines .. + EXTERNAL ZCOPY, ZDSCAL, ZGEMM, ZGEMV, ZLACGV, ZSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, DBLE, DCONJG, DIMAG, MAX, MIN, SQRT +* .. +* .. Statement Functions .. + DOUBLE PRECISION CABS1 +* .. +* .. Statement Function definitions .. + CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) ) +* .. +* .. Executable Statements .. +* + INFO = 0 +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = DLAMCH( '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) +* Initilize 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 ZCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 ) + W( K, KW ) = DBLE( A( K, K ) ) + IF( K.LT.N ) THEN + CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA, + $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 ) + W( K, KW ) = DBLE( 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( DBLE( 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 = IZAMAX( 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 ) = DBLE( W( K, KW ) ) + IF( K.GT.1 ) + $ CALL ZCOPY( 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 ZCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ), + $ 1 ) + W( IMAX, KW-1 ) = DBLE( A( IMAX, IMAX ) ) +* + CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, + $ W( IMAX+1, KW-1 ), 1 ) + CALL ZLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 ) +* + IF( K.LT.N ) THEN + CALL ZGEMV( '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 ) = DBLE( 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 + IZAMAX( 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 = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 ) + DTEMP = CABS1( W( ITEMP, KW-1 ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + 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( DBLE( 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 ZCOPY( 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 ZCOPY( 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 ) = DBLE( A( K, K ) ) + CALL ZCOPY( K-1-P, A( P+1, K ), 1, A( P, P+1 ), + $ LDA ) + CALL ZLACGV( K-1-P, A( P, P+1 ), LDA ) + IF( P.GT.1 ) + $ CALL ZCOPY( 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 ZSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), + $ LDA ) + CALL ZSWAP( 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 ) = DBLE( A( KK, KK ) ) + CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + CALL ZLACGV( KK-1-KP, A( KP, KP+1 ), LDA ) + IF( KP.GT.1 ) + $ CALL ZCOPY( 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 ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) + CALL ZSWAP( 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 ZCOPY( 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 = DBLE( A( K, K ) ) + IF( ABS( T ).GE.SFMIN ) THEN + R1 = ONE / T + CALL ZDSCAL( 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 ZLACGV( 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 ) / DCONJG( D21 ) + D22 = W( K-1, KW-1 ) / D21 + T = ONE / ( DBLE( 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 ) ) / + $ DCONJG( 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 ZLACGV( K-1, W( 1, KW ), 1 ) + CALL ZLACGV( 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 +* +* computing blocks of NB columns at a time (note that conjg(W) is +* actually stored) +* + DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB + JB = MIN( NB, K-J+1 ) +* +* Update the upper triangle of the diagonal block +* + DO 40 JJ = J, J + JB - 1 + A( JJ, JJ ) = DBLE( A( JJ, JJ ) ) + CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE, + $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE, + $ A( J, JJ ), 1 ) + A( JJ, JJ ) = DBLE( A( JJ, JJ ) ) + 40 CONTINUE +* +* Update the rectangular superdiagonal block +* + IF( J.GE.2 ) + $ CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, N-K, + $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW, + $ CONE, A( 1, J ), LDA ) + 50 CONTINUE +* +* 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) +* +* Initilize 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 ) = DBLE( A( K, K ) ) + IF( K.LT.N ) + $ CALL ZCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 ) + IF( K.GT.1 ) THEN + CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), + $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 ) + W( K, K ) = DBLE( 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( DBLE( 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 + IZAMAX( 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 ) = DBLE( W( K, K ) ) + IF( K.LT.N ) + $ CALL ZCOPY( 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 ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1) + CALL ZLACGV( IMAX-K, W( K, K+1 ), 1 ) + W( IMAX, K+1 ) = DBLE( A( IMAX, IMAX ) ) +* + IF( IMAX.LT.N ) + $ CALL ZCOPY( N-IMAX, A( IMAX+1, IMAX ), 1, + $ W( IMAX+1, K+1 ), 1 ) +* + IF( K.GT.1 ) THEN + CALL ZGEMV( '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 ) = DBLE( 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 + IZAMAX( 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 + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1) + DTEMP = CABS1( W( ITEMP, K+1 ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + 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( DBLE( 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 ZCOPY( 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 ZCOPY( 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 ) = DBLE( A( K, K ) ) + CALL ZCOPY( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) + CALL ZLACGV( P-K-1, A( P, K+1 ), LDA ) + IF( P.LT.N ) + $ CALL ZCOPY( 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 ZSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) + CALL ZSWAP( 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 ) = DBLE( A( KK, KK ) ) + CALL ZCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), + $ LDA ) + CALL ZLACGV( KP-KK-1, A( KP, KK+1 ), LDA ) + IF( KP.LT.N ) + $ CALL ZCOPY( 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 ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) + CALL ZSWAP( 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 ZCOPY( 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 = DBLE( A( K, K ) ) + IF( ABS( T ).GE.SFMIN ) THEN + R1 = ONE / T + CALL ZDSCAL( 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 ZLACGV( 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 ) / DCONJG( D21 ) + T = ONE / ( DBLE( 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 ) ) / + $ DCONJG( 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 ZLACGV( N-K, W( K+1, K ), 1 ) + CALL ZLACGV( 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 +* +* computing blocks of NB columns at a time (note that conjg(W) is +* actually stored) +* + DO 110 J = K, N, NB + JB = MIN( NB, N-J+1 ) +* +* Update the lower triangle of the diagonal block +* + DO 100 JJ = J, J + JB - 1 + A( JJ, JJ ) = DBLE( A( JJ, JJ ) ) + CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE, + $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE, + $ A( JJ, JJ ), 1 ) + A( JJ, JJ ) = DBLE( A( JJ, JJ ) ) + 100 CONTINUE +* +* Update the rectangular subdiagonal block +* + IF( J+JB.LE.N ) + $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, + $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ), + $ LDW, CONE, A( J+JB, J ), LDA ) + 110 CONTINUE +* +* Set KB to the number of columns factorized +* + KB = K - 1 +* + END IF + RETURN +* +* End of ZLAHEF_RK +* + END diff --git a/SRC/zlasyf_rk.f b/SRC/zlasyf_rk.f new file mode 100644 index 00000000..391eeff6 --- /dev/null +++ b/SRC/zlasyf_rk.f @@ -0,0 +1,974 @@ +*> \brief \b ZLASYF_RK computes a partial factorization of a complex symmetric 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 ZLASYF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlasyf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlasyf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlasyf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZLASYF_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*16 A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZLASYF_RK computes a partial factorization of a complex symmetric +*> 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**T U22**T ) +*> +*> A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) 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. +*> +*> ZLASYF_RK is an auxiliary routine called by ZSYTRF_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 +*> symmetric 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*16 array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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*16 array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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*16 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. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZLASYF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, KB, LDA, LDW, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), W( LDW, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO, ONE + PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) + DOUBLE PRECISION EIGHT, SEVTEN + PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) + COMPLEX*16 CONE, CZERO + PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ), + $ CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL DONE + INTEGER IMAX, ITEMP, J, JB, JJ, JMAX, K, KK, KW, KKW, + $ KP, KSTEP, P, II + DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, ROWMAX, SFMIN, DTEMP + COMPLEX*16 D11, D12, D21, D22, R1, T, Z +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER IZAMAX + DOUBLE PRECISION DLAMCH + EXTERNAL LSAME, IZAMAX, DLAMCH +* .. +* .. External Subroutines .. + EXTERNAL ZCOPY, ZGEMM, ZGEMV, ZSCAL, ZSWAP +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, DBLE, DIMAG, MAX, MIN, SQRT +* .. +* .. Statement Functions .. + DOUBLE PRECISION CABS1 +* .. +* .. Statement Function definitions .. + CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) ) +* .. +* .. Executable Statements .. +* + INFO = 0 +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = DLAMCH( '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 +* +* Initilize 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 +* + CALL ZCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 ) + IF( K.LT.N ) + $ CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), + $ LDA, W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( 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 = IZAMAX( 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 + CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = CZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* +* Copy column IMAX to column KW-1 of W and update it +* + CALL ZCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 ) + CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA, + $ W( IMAX+1, KW-1 ), 1 ) +* + IF( K.LT.N ) + $ CALL ZGEMV( 'No transpose', K, N-K, -CONE, + $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW, + $ CONE, W( 1, KW-1 ), 1 ) +* +* 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 + IZAMAX( 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 = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 ) + DTEMP = CABS1( W( ITEMP, KW-1 ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for +* CABS1( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.(CABS1( 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 ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) +* + DONE = .TRUE. +* +* 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. + 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 ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 ) +* + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* ============================================================ +* + KK = K - KSTEP + 1 +* +* KKW is the column of W which corresponds to column KK of A +* + KKW = NB + KK - N +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL ZCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA ) + CALL ZCOPY( P, A( 1, K ), 1, A( 1, P ), 1 ) +* +* Interchange rows K and P in last N-K+1 columns of A +* and last N-K+2 columns of W +* + CALL ZSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA ) + CALL ZSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW ) + END IF +* +* Updated column KP is already stored in column KKW of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL ZCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + CALL ZCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 ) +* +* Interchange rows KK and KP in last N-KK+1 columns +* of A and W +* + CALL ZSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), LDA ) + CALL ZSWAP( 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(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* +* Store U(k) in column k of A +* + CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 ) + IF( K.GT.1 ) THEN + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN + R1 = CONE / A( K, K ) + CALL ZSCAL( K-1, R1, A( 1, K ), 1 ) + ELSE IF( A( K, K ).NE.CZERO ) THEN + DO 14 II = 1, K - 1 + A( II, K ) = A( II, K ) / A( K, K ) + 14 CONTINUE + END IF +* +* 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(k-1) W(k) ) = ( 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 +* + IF( K.GT.2 ) THEN +* +* Store U(k) and U(k-1) in columns k and k-1 of A +* + D12 = W( K-1, KW ) + D11 = W( K, KW ) / D12 + D22 = W( K-1, KW-1 ) / D12 + T = CONE / ( D11*D22-CONE ) + DO 20 J = 1, K - 2 + A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) / + $ D12 ) + A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) / + $ D12 ) + 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 +* + 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**T = A11 - U12*W**T +* +* computing blocks of NB columns at a time +* + DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB + JB = MIN( NB, K-J+1 ) +* +* Update the upper triangle of the diagonal block +* + DO 40 JJ = J, J + JB - 1 + CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE, + $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE, + $ A( J, JJ ), 1 ) + 40 CONTINUE +* +* Update the rectangular superdiagonal block +* + IF( J.GE.2 ) + $ CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, + $ N-K, -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), + $ LDW, CONE, A( 1, J ), LDA ) + 50 CONTINUE +* +* 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 +* +* Initilize 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 it +* + CALL ZCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 ) + IF( K.GT.1 ) + $ CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), + $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 ) +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( 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 + IZAMAX( 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 + CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = CZERO +* + ELSE +* +* ============================================================ +* +* Test for interchange +* +* 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 ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1) + CALL ZCOPY( N-IMAX+1, A( IMAX, IMAX ), 1, + $ W( IMAX, K+1 ), 1 ) + IF( K.GT.1 ) + $ CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, + $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW, + $ CONE, W( K, K+1 ), 1 ) +* +* 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 + IZAMAX( 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 + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1) + DTEMP = CABS1( W( ITEMP, K+1 ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for +* CABS1( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX +* (used to handle NaN and Inf) +* + IF( .NOT.( CABS1( 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 ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 ) +* + DONE = .TRUE. +* +* 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. + 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 ZCOPY( 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 +* +* ============================================================ +* + KK = K + KSTEP - 1 +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Copy non-updated column K to column P +* + CALL ZCOPY( P-K, A( K, K ), 1, A( P, K ), LDA ) + CALL ZCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 ) +* +* Interchange rows K and P in first K columns of A +* and first K+1 columns of W +* + CALL ZSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA ) + CALL ZSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW ) + END IF +* +* Updated column KP is already stored in column KK of W +* + IF( KP.NE.KK ) THEN +* +* Copy non-updated column KK to column KP +* + A( KP, K ) = A( KK, K ) + CALL ZCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA ) + CALL ZCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 ) +* +* Interchange rows KK and KP in first KK columns of A and W +* + CALL ZSWAP( KK, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) + CALL ZSWAP( 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 +* +* Store L(k) in column k of A +* + CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 ) + IF( K.LT.N ) THEN + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN + R1 = CONE / A( K, K ) + CALL ZSCAL( N-K, R1, A( K+1, K ), 1 ) + ELSE IF( A( K, K ).NE.CZERO ) THEN + DO 74 II = K + 1, N + A( II, K ) = A( II, K ) / A( K, K ) + 74 CONTINUE + END IF +* +* 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 +* + IF( K.LT.N-1 ) THEN +* +* Store L(k) and L(k+1) in columns k and k+1 of A +* + D21 = W( K+1, K ) + D11 = W( K+1, K+1 ) / D21 + D22 = W( K, K ) / D21 + T = CONE / ( D11*D22-CONE ) + DO 80 J = K + 2, N + A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) / + $ 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 +* + 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**T = A22 - L21*W**T +* +* computing blocks of NB columns at a time +* + DO 110 J = K, N, NB + JB = MIN( NB, N-J+1 ) +* +* Update the lower triangle of the diagonal block +* + DO 100 JJ = J, J + JB - 1 + CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE, + $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE, + $ A( JJ, JJ ), 1 ) + 100 CONTINUE +* +* Update the rectangular subdiagonal block +* + IF( J+JB.LE.N ) + $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB, + $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ), + $ LDW, CONE, A( J+JB, J ), LDA ) + 110 CONTINUE +* +* Set KB to the number of columns factorized +* + KB = K - 1 +* + END IF +* + RETURN +* +* End of ZLASYF_RK +* + END diff --git a/SRC/zsycon_3.f b/SRC/zsycon_3.f new file mode 100644 index 00000000..e2157659 --- /dev/null +++ b/SRC/zsycon_3.f @@ -0,0 +1,287 @@ +*> \brief \b ZSYCON_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYCON_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsycon_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsycon_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsycon_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, +* WORK, IWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* DOUBLE PRECISION ANORM, RCOND +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ), IWORK( * ) +* COMPLEX*16 A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYCON_3 estimates the reciprocal of the condition number (in the +*> 1-norm) of a complex symmetric matrix A using the factorization +*> computed by ZSYTRF_RK or ZSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> An estimate is obtained for norm(inv(A)), and the reciprocal of the +*> condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). +*> This routine uses BLAS3 solver ZSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by ZSYTRF_RK and ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZSYTRF_RK or ZSYTRF_BK. +*> \endverbatim +*> +*> \param[in] ANORM +*> \verbatim +*> ANORM is DOUBLE PRECISION +*> The 1-norm of the original matrix A. +*> \endverbatim +*> +*> \param[out] RCOND +*> \verbatim +*> RCOND is DOUBLE PRECISION +*> The reciprocal of the condition number of the matrix A, +*> computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an +*> estimate of the 1-norm of inv(A) computed in this routine. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension (2*N) +*> \endverbatim +*> +*> \param[out] IWORK +*> \verbatim +*> IWORK is INTEGER array, dimension (N) +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 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 ZSYCON_3( UPLO, N, A, LDA, E, IPIV, ANORM, RCOND, + $ WORK, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N + DOUBLE PRECISION ANORM, RCOND +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ONE, ZERO + PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) + COMPLEX*16 CZERO + PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, KASE + DOUBLE PRECISION AINVNM +* .. +* .. Local Arrays .. + INTEGER ISAVE( 3 ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL ZLACN2, ZSYTRS_3, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( ANORM.LT.ZERO ) THEN + INFO = -7 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYCON_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + RCOND = ZERO + IF( N.EQ.0 ) THEN + RCOND = ONE + RETURN + ELSE IF( ANORM.LE.ZERO ) THEN + RETURN + END IF +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO I = N, 1, -1 + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.CZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO I = 1, N + IF( IPIV( I ).GT.0 .AND. A( I, I ).EQ.CZERO ) + $ RETURN + END DO + END IF +* +* Estimate the 1-norm of the inverse. +* + KASE = 0 + 30 CONTINUE + CALL ZLACN2( N, WORK( N+1 ), WORK, AINVNM, KASE, ISAVE ) + IF( KASE.NE.0 ) THEN +* +* Multiply by inv(L*D*L**T) or inv(U*D*U**T). +* + CALL ZSYTRS_3( UPLO, N, 1, A, LDA, E, IPIV, WORK, N, INFO ) + GO TO 30 + END IF +* +* Compute the estimate of the reciprocal condition number. +* + IF( AINVNM.NE.ZERO ) + $ RCOND = ( ONE / AINVNM ) / ANORM +* + RETURN +* +* End of ZSYCON_3 +* + END diff --git a/SRC/zsyconvf.f b/SRC/zsyconvf.f new file mode 100644 index 00000000..4c65c0ac --- /dev/null +++ b/SRC/zsyconvf.f @@ -0,0 +1,562 @@ +*> \brief \b ZSYCONVF +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYCONVF + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsyconvf.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsyconvf.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsyconvf.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYCONVF( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> ZSYCONVF converts the factorization output format used in +*> ZSYTRF provided on entry in parameter A into the factorization +*> output format used in ZSYTRF_RK (or ZSYTRF_BK) that is stored +*> on exit in parameters A and E. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in ZSYTRF into +*> the format used in ZSYTRF_RK (or ZSYTRF_BK). +*> +*> If parameter WAY = 'R': +*> ZSYCONVF performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in ZSYTRF_RK +*> (or ZSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in ZSYTRF that is stored +*> on exit in parameter A. It also coverts in place details of +*> the intechanges stored in IPIV from the format used in ZSYTRF_RK +*> (or ZSYTRF_BK) into the format used in ZSYTRF. +*> +*> ZSYCONVF can also convert in Hermitian matrix case, i.e. between +*> formats used in ZHETRF and ZHETRF_RK (or ZHETRF_BK). +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> ZSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> ZSYTRF_RK or ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> ZSYTRF_RK or ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> ZSYTRF: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in,out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> +*> 1) If WAY ='C': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in ZSYTRF. +*> On exit, details of the interchanges and the block +*> structure of D in the format used in ZSYTRF_RK +*> ( or ZSYTRF_BK). +*> +*> 1) If WAY ='R': +*> On entry, details of the interchanges and the block +*> structure of D in the format used in ZSYTRF_RK +*> ( or ZSYTRF_BK). +*> On exit, details of the interchanges and the block +*> structure of D in the format used in ZSYTRF. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE ZSYCONVF( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX*16 ZERO + PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL ZSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYCONVF', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL ZSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i) in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.(I-1) ) THEN + CALL ZSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i-1 and IPIV(i-1), +* so this should be recorded in two consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I-1 ) +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where k increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL ZSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is no interchnge of rows i and and IPIV(i), +* so this should be reflected in IPIV format for +* *SYTRF_RK ( or *SYTRF_BK) +* + IPIV( I ) = I +* + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS and IPIV +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i) in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.(I+1) ) THEN + CALL ZSWAP( I-1, A( IP, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + END IF +* +* Convert IPIV +* There is one interchange of rows i+1 and IPIV(i+1), +* so this should be recorded in consecutive entries +* in IPIV format for *SYTRF +* + IPIV( I ) = IPIV( I+1 ) +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of ZSYCONVF +* + END diff --git a/SRC/zsyconvf_rook.f b/SRC/zsyconvf_rook.f new file mode 100644 index 00000000..36e765ef --- /dev/null +++ b/SRC/zsyconvf_rook.f @@ -0,0 +1,547 @@ +*> \brief \b ZSYCONVF_ROOK +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYCONVF_ROOK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsyconvf_rook.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsyconvf_rook.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsyconvf_rook.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYCONVF_ROOK( UPLO, WAY, N, A, LDA, IPIV, E, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO, WAY +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> If parameter WAY = 'C': +*> ZSYCONVF_ROOK converts the factorization output format used in +*> ZSYTRF_ROOK provided on entry in parameter A into the factorization +*> output format used in ZSYTRF_RK (or ZSYTRF_BK) that is stored +*> on exit in parameters A and E. IPIV format for ZSYTRF_ROOK and +*> ZSYTRF_RK (or ZSYTRF_BK) is the same and is not converted. +*> +*> If parameter WAY = 'R': +*> ZSYCONVF_ROOK performs the conversion in reverse direction, i.e. +*> converts the factorization output format used in ZSYTRF_RK +*> (or ZSYTRF_BK) provided on entry in parametes A and E into +*> the factorization output format used in ZSYTRF_ROOK that is stored +*> on exit in parameter A. IPIV format for ZSYTRF_ROOK and +*> ZSYTRF_RK (or ZSYTRF_BK) is the same and is not converted. +*> +*> ZSYCONVF_ROOK can also convert in Hermitian matrix case, i.e. between +*> formats used in ZHETRF_ROOK and ZHETRF_RK (or ZHETRF_BK). +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix A. +*> = 'U': Upper triangular +*> = 'L': Lower triangular +*> \endverbatim +*> +*> \param[in] WAY +*> \verbatim +*> WAY is CHARACTER*1 +*> = 'C': Convert +*> = 'R': Revert +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> +*> 1) If WAY ='C': +*> +*> On entry, contains factorization details in format used in +*> ZSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> +*> On exit, contains factorization details in format used in +*> ZSYTRF_RK or ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains factorization details in format used in +*> ZSYTRF_RK or ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> On exit, contains factorization details in format used in +*> ZSYTRF_ROOK: +*> a) all elements of the symmetric block diagonal +*> matrix D on the diagonal of A and on superdiagonal +*> (or subdiagonal) of A, and +*> b) If UPLO = 'U': multipliers used to obtain factor U +*> in the superdiagonal part of A. +*> If UPLO = 'L': multipliers used to obtain factor L +*> in the superdiagonal part of A. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in,out] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> +*> 1) If WAY ='C': +*> +*> On entry, just a workspace. +*> +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> 2) If WAY = 'R': +*> +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not referenced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> On exit, is not changed +*> \endverbatim +*. +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> On entry, details of the interchanges and the block +*> structure of D as determined: +*> 1) by ZSYTRF_ROOK, if WAY ='C'; +*> 2) by ZSYTRF_RK (or ZSYTRF_BK), if WAY ='R'. +*> The IPIV format is the same for all these routines. +*> +*> On exit, is not changed. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* ===================================================================== + SUBROUTINE ZSYCONVF_ROOK( UPLO, WAY, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO, WAY + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX*16 ZERO + PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* +* .. External Subroutines .. + EXTERNAL ZSWAP, XERBLA +* .. Local Scalars .. + LOGICAL UPPER, CONVERT + INTEGER I, IP, IP2 +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + CONVERT = LSAME( WAY, 'C' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( .NOT.CONVERT .AND. .NOT.LSAME( WAY, 'R' ) ) THEN + INFO = -2 + ELSE IF( N.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYCONVF_ROOK', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin A is UPPER +* + IF ( CONVERT ) THEN +* +* Convert A (A is upper) +* +* +* Convert VALUE +* +* Assign superdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = N + E( 1 ) = ZERO + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + E( I ) = A( I-1, I ) + E( I-1 ) = ZERO + A( I-1, I ) = ZERO + I = I - 1 + ELSE + E( I ) = ZERO + END IF + I = I - 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i-1 and IPIV(i-1) +* in A(1:i,N-i:N) +* + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( N-I, A( I, I+1 ), LDA, + $ A( IP, I+1 ), LDA ) + END IF + IF( IP2.NE.(I-1) ) THEN + CALL ZSWAP( N-I, A( I-1, I+1 ), LDA, + $ A( IP2, I+1 ), LDA ) + END IF + END IF + I = I - 1 +* + END IF + I = I - 1 + END DO +* + ELSE +* +* Revert A (A is upper) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of upper part of A +* in reverse factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(1:i,N-i:N) +* + IP = IPIV( I ) + IF( I.LT.N ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i-1 and IPIV(i-1) and i and IPIV(i) +* in A(1:i,N-i:N) +* + I = I + 1 + IP = -IPIV( I ) + IP2 = -IPIV( I-1 ) + IF( I.LT.N ) THEN + IF( IP2.NE.(I-1) ) THEN + CALL ZSWAP( N-I, A( IP2, I+1 ), LDA, + $ A( I-1, I+1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL ZSWAP( N-I, A( IP, I+1 ), LDA, + $ A( I, I+1 ), LDA ) + END IF + END IF +* + END IF + I = I + 1 + END DO +* +* Revert VALUE +* Assign superdiagonal entries of D from array E to +* superdiagonal entries of A. +* + I = N + DO WHILE ( I.GT.1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I-1, I ) = E( I ) + I = I - 1 + END IF + I = I - 1 + END DO +* +* End A is UPPER +* + END IF +* + ELSE +* +* Begin A is LOWER +* + IF ( CONVERT ) THEN +* +* Convert A (A is lower) +* +* +* Convert VALUE +* Assign subdiagonal entries of D to array E and zero out +* corresponding entries in input storage A +* + I = 1 + E( N ) = ZERO + DO WHILE ( I.LE.N ) + IF( I.LT.N .AND. IPIV(I).LT.0 ) THEN + E( I ) = A( I+1, I ) + E( I+1 ) = ZERO + A( I+1, I ) = ZERO + I = I + 1 + ELSE + E( I ) = ZERO + END IF + I = I + 1 + END DO +* +* Convert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in factorization order where i increases from 1 to N +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i and IPIV(i) and i+1 and IPIV(i+1) +* in A(i:N,1:i-1) +* + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( I-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + IF( IP2.NE.(I+1) ) THEN + CALL ZSWAP( I-1, A( I+1, 1 ), LDA, + $ A( IP2, 1 ), LDA ) + END IF + END IF + I = I + 1 +* + END IF + I = I + 1 + END DO +* + ELSE +* +* Revert A (A is lower) +* +* +* Revert PERMUTATIONS +* +* Apply permutaions to submatrices of lower part of A +* in reverse factorization order where i decreases from N to 1 +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN +* +* 1-by-1 pivot interchange +* +* Swap rows i and IPIV(i) in A(i:N,1:i-1) +* + IP = IPIV( I ) + IF ( I.GT.1 ) THEN + IF( IP.NE.I ) THEN + CALL ZSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + ELSE +* +* 2-by-2 pivot interchange +* +* Swap rows i+1 and IPIV(i+1) and i and IPIV(i) +* in A(i:N,1:i-1) +* + I = I - 1 + IP = -IPIV( I ) + IP2 = -IPIV( I+1 ) + IF ( I.GT.1 ) THEN + IF( IP2.NE.(I+1) ) THEN + CALL ZSWAP( I-1, A( IP2, 1 ), LDA, + $ A( I+1, 1 ), LDA ) + END IF + IF( IP.NE.I ) THEN + CALL ZSWAP( I-1, A( IP, 1 ), LDA, + $ A( I, 1 ), LDA ) + END IF + END IF +* + END IF + I = I - 1 + END DO +* +* Revert VALUE +* Assign subdiagonal entries of D from array E to +* subgiagonal entries of A. +* + I = 1 + DO WHILE ( I.LE.N-1 ) + IF( IPIV( I ).LT.0 ) THEN + A( I + 1, I ) = E( I ) + I = I + 1 + END IF + I = I + 1 + END DO +* + END IF +* +* End A is LOWER +* + END IF + + RETURN +* +* End of ZSYCONVF_ROOK +* + END diff --git a/SRC/zsysv_rk.f b/SRC/zsysv_rk.f new file mode 100644 index 00000000..3445512f --- /dev/null +++ b/SRC/zsysv_rk.f @@ -0,0 +1,317 @@ +*> \brief <b> ZSYSV_RK computes the solution to system of linear equations A * X = B for SY matrices</b> +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYSV_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsysv_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsysv_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsysv_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* WORK, LWORK, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYSV_RK computes the solution to a complex system of linear +*> equations A * X = B, where A is an N-by-N symmetric matrix +*> and X and B are N-by-NRHS matrices. +*> +*> The bounded Bunch-Kaufman (rook) diagonal pivoting method is used +*> to factor A as +*> A = P*U*D*(U**T)*(P**T), if UPLO = 'U', or +*> A = P*L*D*(L**T)*(P**T), if UPLO = 'L', +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> ZSYTRF_RK is called to compute the factorization of a complex +*> symmetric matrix. The factored form of A is then used to solve +*> the system of equations A * X = B by calling BLAS3 routine ZSYTRS_3. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric matrix A is stored: +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The number of linear equations, i.e., the order of the +*> matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, the symmetric 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, if INFO = 0, diagonal of the block diagonal +*> matrix D and factors U or L as computed by ZSYTRF_RK: +*> a) ONLY diagonal elements of the symmetric 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. +*> +*> For more info see the description of ZSYTRF_RK routine. +*> \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*16 array, dimension (N) +*> On exit, contains the output computed by the factorization +*> routine ZSYTRF_RK, i.e. the superdiagonal (or subdiagonal) +*> elements of the symmetric 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. +*> +*> For more info see the description of ZSYTRF_RK routine. +*> \endverbatim +*> +*> \param[out] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D, +*> as determined by ZSYTRF_RK. +*> +*> For more info see the description of ZSYTRF_RK routine. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX*16 array, dimension (LDB,NRHS) +*> On entry, the N-by-NRHS right hand side matrix B. +*> On exit, if INFO = 0, the N-by-NRHS solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension ( MAX(1,LWORK) ). +*> Work array used in the factorization stage. +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= 1. For best performance +*> of factorization stage LWORK >= max(1,N*NB), where NB is +*> the optimal blocksize for ZSYTRF_RK. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array for factorization stage, returns this value as +*> the first entry of the WORK array, and no error message +*> related to LWORK is issued by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complex16SYsolve +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZSYSV_RK( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, WORK, + $ LWORK, INFO ) +* +* -- LAPACK driver routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, LWORK, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY + INTEGER LWKOPT +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL XERBLA, ZSYTRF_RK, ZSYTRS_3 +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -11 + END IF +* + IF( INFO.EQ.0 ) THEN + IF( N.EQ.0 ) THEN + LWKOPT = 1 + ELSE + CALL ZSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, -1, INFO ) + LWKOPT = WORK(1) + END IF + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYSV_RK ', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* +* Compute the factorization A = P*U*D*(U**T)*(P**T) or +* A = P*U*D*(U**T)*(P**T). +* + CALL ZSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, INFO ) +* + IF( INFO.EQ.0 ) THEN +* +* Solve the system A*X = B with BLAS3 solver, overwriting B with X. +* + CALL ZSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, INFO ) +* + END IF +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of ZSYSV_RK +* + END diff --git a/SRC/zsytf2_rk.f b/SRC/zsytf2_rk.f new file mode 100644 index 00000000..6f2649df --- /dev/null +++ b/SRC/zsytf2_rk.f @@ -0,0 +1,952 @@ +*> \brief \b ZSYTF2_RK computes the factorization of a complex symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS2 unblocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYTF2_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytf2_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytf2_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytf2_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E ( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYTF2_RK computes the factorization of a complex symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the unblocked version of the algorithm, calling Level 2 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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*16 array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put further details +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 +*> +*> 01-01-96 - Based on modifications by +*> J. Lewis, Boeing Computer Services Company +*> A. Petitet, Computer Science Dept., +*> Univ. of Tenn., Knoxville abd , USA +*> \endverbatim +* +* ===================================================================== + SUBROUTINE ZSYTF2_RK( UPLO, N, A, LDA, E, IPIV, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + DOUBLE PRECISION ZERO, ONE + PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) + DOUBLE PRECISION EIGHT, SEVTEN + PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) + COMPLEX*16 CONE, CZERO + PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ), + $ CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER, DONE + INTEGER I, IMAX, J, JMAX, ITEMP, K, KK, KP, KSTEP, + $ P, II + DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, ROWMAX, DTEMP, SFMIN + COMPLEX*16 D11, D12, D21, D22, T, WK, WKM1, WKP1, Z +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER IZAMAX + DOUBLE PRECISION DLAMCH + EXTERNAL LSAME, IZAMAX, DLAMCH +* .. +* .. External Subroutines .. + EXTERNAL ZSCAL, ZSWAP, ZSYR, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, SQRT, DIMAG, DBLE +* .. +* .. Statement Functions .. + DOUBLE PRECISION CABS1 +* .. +* .. Statement Function definitions .. + CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) ) +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYTF2_RK', -INFO ) + RETURN + END IF +* +* Initialize ALPHA for use in choosing pivot block size. +* + ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT +* +* Compute machine safe minimum +* + SFMIN = DLAMCH( 'S' ) +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* Initilize 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 to 1 in steps of +* 1 or 2 +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 34 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( A( 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.GT.1 ) THEN + IMAX = IZAMAX( K-1, A( 1, K ), 1 ) + COLMAX = CABS1( A( 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 +* +* Set E( K ) to zero +* + IF( K.GT.1 ) + $ E( K ) = CZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, +* use 1-by-1 pivot block +* + KP = K + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 12 CONTINUE +* +* Begin pivot search loop body +* +* 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 + IZAMAX( K-IMAX, A( IMAX, IMAX+1 ), + $ LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.GT.1 ) THEN + ITEMP = IZAMAX( IMAX-1, A( 1, IMAX ), 1 ) + DTEMP = CABS1( A( ITEMP, IMAX ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( CABS1( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX )) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 12 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the leading +* submatrix A(1:k,1:k) if we have a 2-by-2 pivot +* + IF( P.GT.1 ) + $ CALL ZSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 ) + IF( P.LT.(K-1) ) + $ CALL ZSWAP( K-P-1, A( P+1, K ), 1, A( P, P+1 ), + $ LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL ZSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K - KSTEP + 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the leading +* submatrix A(1:k,1:k) +* + IF( KP.GT.1 ) + $ CALL ZSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) + IF( ( KK.GT.1 ) .AND. ( KP.LT.(KK-1) ) ) + $ CALL ZSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K-1, K ) + A( K-1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert upper triangle of A into U form by applying +* the interchanges in columns k+1:N. +* + IF( K.LT.N ) + $ CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ), + $ LDA ) +* + END IF +* +* Update the leading submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = U(k)*D(k) +* +* where U(k) is the k-th column of U +* + IF( K.GT.1 ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) and +* store U(k) in column k +* + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(1:k-1,1:k-1) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*1/D(k)*W(k)**T +* + D11 = CONE / A( K, K ) + CALL ZSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) +* +* Store U(k) in column k +* + CALL ZSCAL( K-1, D11, A( 1, K ), 1 ) + ELSE +* +* Store L(k) in column K +* + D11 = A( K, K ) + DO 16 II = 1, K - 1 + A( II, K ) = A( II, K ) / D11 + 16 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - U(k)*D(k)*U(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL ZSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA ) + END IF +* +* Store the superdiagonal element of D in array E +* + E( K ) = CZERO +* + END IF +* + ELSE +* +* 2-by-2 pivot block D(k): columns k and k-1 now hold +* +* ( W(k-1) W(k) ) = ( 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 +* +* Perform a rank-2 update of A(1:k-2,1:k-2) as +* +* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T +* = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.GT.2 ) THEN +* + D12 = A( K-1, K ) + D22 = A( K-1, K-1 ) / D12 + D11 = A( K, K ) / D12 + T = CONE / ( D11*D22-CONE ) +* + DO 30 J = K - 2, 1, -1 +* + WKM1 = T*( D11*A( J, K-1 )-A( J, K ) ) + WK = T*( D22*A( J, K )-A( J, K-1 ) ) +* + DO 20 I = J, 1, -1 + A( I, J ) = A( I, J ) - (A( I, K ) / D12 )*WK - + $ ( A( I, K-1 ) / D12 )*WKM1 + 20 CONTINUE +* +* Store U(k) and U(k-1) in cols k and k-1 for row J +* + A( J, K ) = WK / D12 + A( J, K-1 ) = WKM1 / D12 +* + 30 CONTINUE +* + END IF +* +* Copy superdiagonal elements of D(K) to E(K) and +* ZERO out superdiagonal entry of A +* + E( K ) = A( K-1, K ) + E( K-1 ) = CZERO + A( K-1, K ) = CZERO +* + 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 +* + 34 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* Initilize the unused last entry of the subdiagonal array E. +* + E( N ) = CZERO +* +* K is the main loop index, increasing from 1 to N in steps of +* 1 or 2 +* + K = 1 + 40 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 64 + KSTEP = 1 + P = K +* +* Determine rows and columns to be interchanged and whether +* a 1-by-1 or 2-by-2 pivot block will be used +* + ABSAKK = CABS1( A( 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 + IZAMAX( N-K, A( K+1, K ), 1 ) + COLMAX = CABS1( A( 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 +* +* Set E( K ) to zero +* + IF( K.LT.N ) + $ E( K ) = CZERO +* + ELSE +* +* Test for interchange +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABSAKK.GE.ALPHA*COLMAX +* + IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN +* +* no interchange, use 1-by-1 pivot block +* + KP = K +* + ELSE +* + DONE = .FALSE. +* +* Loop until pivot found +* + 42 CONTINUE +* +* Begin pivot search loop body +* +* 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 + IZAMAX( IMAX-K, A( IMAX, K ), LDA ) + ROWMAX = CABS1( A( IMAX, JMAX ) ) + ELSE + ROWMAX = ZERO + END IF +* + IF( IMAX.LT.N ) THEN + ITEMP = IMAX + IZAMAX( N-IMAX, A( IMAX+1, IMAX ), + $ 1 ) + DTEMP = CABS1( A( ITEMP, IMAX ) ) + IF( DTEMP.GT.ROWMAX ) THEN + ROWMAX = DTEMP + JMAX = ITEMP + END IF + END IF +* +* Equivalent to testing for (used to handle NaN and Inf) +* ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX +* + IF( .NOT.( CABS1( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX )) + $ THEN +* +* interchange rows and columns K and IMAX, +* use 1-by-1 pivot block +* + KP = IMAX + DONE = .TRUE. +* +* 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. + ELSE +* +* Pivot NOT found, set variables and repeat +* + P = IMAX + COLMAX = ROWMAX + IMAX = JMAX + END IF +* +* End pivot search loop body +* + IF( .NOT. DONE ) GOTO 42 +* + END IF +* +* Swap TWO rows and TWO columns +* +* First swap +* + IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN +* +* Interchange rows and column K and P in the trailing +* submatrix A(k:n,k:n) if we have a 2-by-2 pivot +* + IF( P.LT.N ) + $ CALL ZSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 ) + IF( P.GT.(K+1) ) + $ CALL ZSWAP( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA ) + T = A( K, K ) + A( K, K ) = A( P, P ) + A( P, P ) = T +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL ZSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA ) +* + END IF +* +* Second swap +* + KK = K + KSTEP - 1 + IF( KP.NE.KK ) THEN +* +* Interchange rows and columns KK and KP in the trailing +* submatrix A(k:n,k:n) +* + IF( KP.LT.N ) + $ CALL ZSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) + IF( ( KK.LT.N ) .AND. ( KP.GT.(KK+1) ) ) + $ CALL ZSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), + $ LDA ) + T = A( KK, KK ) + A( KK, KK ) = A( KP, KP ) + A( KP, KP ) = T + IF( KSTEP.EQ.2 ) THEN + T = A( K+1, K ) + A( K+1, K ) = A( KP, K ) + A( KP, K ) = T + END IF +* +* Convert lower triangle of A into L form by applying +* the interchanges in columns 1:k-1. +* + IF ( K.GT.1 ) + $ CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA ) +* + END IF +* +* Update the trailing submatrix +* + IF( KSTEP.EQ.1 ) THEN +* +* 1-by-1 pivot block D(k): column k now holds +* +* W(k) = L(k)*D(k) +* +* where L(k) is the k-th column of L +* + IF( K.LT.N ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) and +* store L(k) in column k +* + IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* + D11 = CONE / A( K, K ) + CALL ZSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) +* +* Store L(k) in column k +* + CALL ZSCAL( N-K, D11, A( K+1, K ), 1 ) + ELSE +* +* Store L(k) in column k +* + D11 = A( K, K ) + DO 46 II = K + 1, N + A( II, K ) = A( II, K ) / D11 + 46 CONTINUE +* +* Perform a rank-1 update of A(k+1:n,k+1:n) as +* A := A - L(k)*D(k)*L(k)**T +* = A - W(k)*(1/D(k))*W(k)**T +* = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T +* + CALL ZSYR( UPLO, N-K, -D11, A( K+1, K ), 1, + $ A( K+1, K+1 ), LDA ) + END IF +* +* 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 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 +* +* +* Perform a rank-2 update of A(k+2:n,k+2:n) as +* +* A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T +* = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T +* +* and store L(k) and L(k+1) in columns k and k+1 +* + IF( K.LT.N-1 ) THEN +* + D21 = A( K+1, K ) + D11 = A( K+1, K+1 ) / D21 + D22 = A( K, K ) / D21 + T = CONE / ( D11*D22-CONE ) +* + DO 60 J = K + 2, N +* +* Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J +* + WK = T*( D11*A( J, K )-A( J, K+1 ) ) + WKP1 = T*( D22*A( J, K+1 )-A( J, K ) ) +* +* Perform a rank-2 update of A(k+2:n,k+2:n) +* + DO 50 I = J, N + A( I, J ) = A( I, J ) - ( A( I, K ) / D21 )*WK - + $ ( A( I, K+1 ) / D21 )*WKP1 + 50 CONTINUE +* +* Store L(k) and L(k+1) in cols k and k+1 for row J +* + A( J, K ) = WK / D21 + A( J, K+1 ) = WKP1 / D21 +* + 60 CONTINUE +* + END IF +* +* Copy subdiagonal elements of D(K) to E(K) and +* ZERO out subdiagonal entry of A +* + E( K ) = A( K+1, K ) + E( K+1 ) = CZERO + A( K+1, K ) = CZERO +* + 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 40 +* + 64 CONTINUE +* + END IF +* + RETURN +* +* End of ZSYTF2_RK +* + END diff --git a/SRC/zsytrf_rk.f b/SRC/zsytrf_rk.f new file mode 100644 index 00000000..b584be58 --- /dev/null +++ b/SRC/zsytrf_rk.f @@ -0,0 +1,498 @@ +*> \brief \b ZSYTRF_RK computes the factorization of a complex symmetric indefinite matrix using the bounded Bunch-Kaufman (rook) diagonal pivoting method (BLAS3 blocked algorithm). +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYTRF_RK + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytrf_rk.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytrf_rk.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytrf_rk.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E ( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYTRF_RK computes the factorization of a complex symmetric matrix A +*> using the bounded Bunch-Kaufman (rook) diagonal pivoting method: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> For more information see Further Details section. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the upper or lower triangular part of the +*> symmetric 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,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, the symmetric 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 symmetric 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*16 array, dimension (N) +*> On exit, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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 symmetric 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. For more info see Further +*> Details section. +*> +*> 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 matrix A(1:N,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,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 matrix A(1:N,1:N). +*> If -IPIV(k-1) = k-1, no interchange occurred. +*> +*> c) In both cases a) and b), 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 matrix A(1:N,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: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 matrix A(1:N,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 matrix A(1:N,1:N). +*> If -IPIV(k+1) = k+1, no interchange occurred. +*> +*> c) In both cases a) and b), always ABS( IPIV(k) ) >= k. +*> +*> d) NOTE: Any entry IPIV(k) is always NONZERO on output. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension ( MAX(1,LWORK) ). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >=1. For best performance +*> LWORK >= N*NB, where NB is the block size returned +*> by ILAENV. +*> +*> If LWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the WORK +*> array, returns this value as the first entry of the WORK +*> array, and no error message related to LWORK is issued +*> by XERBLA. +*> \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. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Further Details: +* ===================== +*> +*> \verbatim +*> TODO: put correct description +*> \endverbatim +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZSYTRF_RK( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL LQUERY, UPPER + INTEGER I, IINFO, IP, IWS, K, KB, LDWORK, LWKOPT, + $ NB, NBMIN +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL ZLASYF_RK, ZSYTF2_RK, ZSWAP, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.EQ.0 ) THEN +* +* Determine the block size +* + NB = ILAENV( 1, 'ZSYTRF_RK', UPLO, N, -1, -1, -1 ) + LWKOPT = N*NB + WORK( 1 ) = LWKOPT + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYTRF_RK', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + RETURN + END IF +* + NBMIN = 2 + LDWORK = N + IF( NB.GT.1 .AND. NB.LT.N ) THEN + IWS = LDWORK*NB + IF( LWORK.LT.IWS ) THEN + NB = MAX( LWORK / LDWORK, 1 ) + NBMIN = MAX( 2, ILAENV( 2, 'ZSYTRF_RK', + $ UPLO, N, -1, -1, -1 ) ) + END IF + ELSE + IWS = 1 + END IF + IF( NB.LT.NBMIN ) + $ NB = N +* + IF( UPPER ) THEN +* +* Factorize A as U*D*U**T using the upper triangle of A +* +* K is the main loop index, decreasing from N to 1 in steps of +* KB, where KB is the number of columns factorized by ZLASYF_RK; +* KB is either NB or NB-1, or K for the last block +* + K = N + 10 CONTINUE +* +* If K < 1, exit from loop +* + IF( K.LT.1 ) + $ GO TO 15 +* + IF( K.GT.NB ) THEN +* +* Factorize columns k-kb+1:k of A and use blocked code to +* update columns 1:k-kb +* + CALL ZLASYF_RK( UPLO, K, NB, KB, A, LDA, E, + $ IPIV, WORK, LDWORK, IINFO ) + ELSE +* +* Use unblocked code to factorize columns 1:k of A +* + CALL ZSYTF2_RK( UPLO, K, A, LDA, E, IPIV, IINFO ) + KB = K + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO +* +* No need to adjust IPIV +* +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k-kb+1:k and apply row permutations to the +* last k+1 colunms k+1:N after that block +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.LT.N ) THEN + DO I = K, ( K - KB + 1 ), -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL ZSWAP( N-K, A( I, K+1 ), LDA, + $ A( IP, K+1 ), LDA ) + END IF + END DO + END IF +* +* Decrease K and return to the start of the main loop +* + K = K - KB + GO TO 10 +* +* This label is the exit from main loop over K decreasing +* from N to 1 in steps of KB +* + 15 CONTINUE +* + ELSE +* +* Factorize A as L*D*L**T using the lower triangle of A +* +* K is the main loop index, increasing from 1 to N in steps of +* KB, where KB is the number of columns factorized by ZLASYF_RK; +* KB is either NB or NB-1, or N-K+1 for the last block +* + K = 1 + 20 CONTINUE +* +* If K > N, exit from loop +* + IF( K.GT.N ) + $ GO TO 35 +* + IF( K.LE.N-NB ) THEN +* +* Factorize columns k:k+kb-1 of A and use blocked code to +* update columns k+kb:n +* + CALL ZLASYF_RK( UPLO, N-K+1, NB, KB, A( K, K ), LDA, E( K ), + $ IPIV( K ), WORK, LDWORK, IINFO ) + + + ELSE +* +* Use unblocked code to factorize columns k:n of A +* + CALL ZSYTF2_RK( UPLO, N-K+1, A( K, K ), LDA, E( K ), + $ IPIV( K ), IINFO ) + KB = N - K + 1 +* + END IF +* +* Set INFO on the first occurrence of a zero pivot +* + IF( INFO.EQ.0 .AND. IINFO.GT.0 ) + $ INFO = IINFO + K - 1 +* +* Adjust IPIV +* + DO I = K, K + KB - 1 + IF( IPIV( I ).GT.0 ) THEN + IPIV( I ) = IPIV( I ) + K - 1 + ELSE + IPIV( I ) = IPIV( I ) - K + 1 + END IF + END DO +* +* Apply permutations to the leading panel 1:k-1 +* +* Read IPIV from the last block factored, i.e. +* indices k:k+kb-1 and apply row permutations to the +* first k-1 colunms 1:k-1 before that block +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV( I ) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + IF( K.GT.1 ) THEN + DO I = K, ( K + KB - 1 ), 1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + CALL ZSWAP( K-1, A( I, 1 ), LDA, + $ A( IP, 1 ), LDA ) + END IF + END DO + END IF +* +* Increase K and return to the start of the main loop +* + K = K + KB + GO TO 20 +* +* This label is the exit from main loop over K increasing +* from 1 to N in steps of KB +* + 35 CONTINUE +* +* End Lower +* + END IF +* + WORK( 1 ) = LWKOPT + RETURN +* +* End of ZSYTRF_RK +* + END diff --git a/SRC/zsytri_3.f b/SRC/zsytri_3.f new file mode 100644 index 00000000..81a66ed7 --- /dev/null +++ b/SRC/zsytri_3.f @@ -0,0 +1,248 @@ +*> \brief \b ZSYTRI_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYTRI_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytri_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytri_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytri_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYTRI_3 computes the inverse of a complex symmetric indefinite +*> matrix A using the factorization computed by ZSYTRF_RK or ZSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> ZSYTRI_3 sets the leading dimension of the workspace before calling +*> ZSYTRI_3X that actually computes the inverse. This is the blocked +*> version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by ZSYTRF_RK and ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZSYTRF_RK or ZSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension (N+NB+1)*(NB+3). +*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. +*> \endverbatim +*> +*> \param[in] LWORK +*> \verbatim +*> LWORK is INTEGER +*> The length of WORK. LWORK >= (N+NB+1)*(NB+3). +*> +*> If LDWORK = -1, then a workspace query is assumed; +*> the routine only calculates the optimal size of the optimal +*> size of the WORK array, returns this value as the first +*> entry of the WORK array, and no error message related to +*> LWORK is issued by XERBLA. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE ZSYTRI_3( UPLO, N, A, LDA, E, IPIV, WORK, LWORK, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LWORK, N +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( * ) +* .. +* +* ===================================================================== +* +* .. Local Scalars .. + LOGICAL UPPER, LQUERY + INTEGER LWKOPT, NB +* .. +* .. External Functions .. + LOGICAL LSAME + INTEGER ILAENV + EXTERNAL LSAME, ILAENV +* .. +* .. External Subroutines .. + EXTERNAL ZSYTRI_3X +* .. +* .. Intrinsic Functions .. + INTRINSIC MAX +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + LQUERY = ( LWORK.EQ.-1 ) +* +* Determine the block size +* + NB = MAX( 1, ILAENV( 1, 'ZSYTRI_3', UPLO, N, -1, -1, -1 ) ) + LWKOPT = ( N+NB+1 ) * ( NB+3 ) +* + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + ELSE IF ( LWORK .LT. LWKOPT .AND. .NOT.LQUERY ) THEN + INFO = -8 + END IF +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYTRI_3', -INFO ) + RETURN + ELSE IF( LQUERY ) THEN + WORK( 1 ) = LWKOPT + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 ) + $ RETURN +* + CALL ZSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* + WORK( 1 ) = LWKOPT +* + RETURN +* +* End of ZSYTRI_3 +* + END diff --git a/SRC/zsytri_3x.f b/SRC/zsytri_3x.f new file mode 100644 index 00000000..f1cb1f31 --- /dev/null +++ b/SRC/zsytri_3x.f @@ -0,0 +1,647 @@ +*> \brief \b ZSYTRI_3X +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYTRI_3X + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytri_3x.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytri_3x.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytri_3x.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYTRI_3X computes the inverse of a complex symmetric indefinite +*> matrix A using the factorization computed by ZSYTRF_RK or ZSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This is the blocked version of the algorithm, calling Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix. +*> = 'U': Upper triangle of A is stored; +*> = 'L': Lower triangle of A is stored. +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in,out] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> On entry, diagonal of the block diagonal matrix D and +*> factors U or L as computed by ZSYTRF_RK and ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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. +*> +*> On exit, if INFO = 0, the symmetric inverse of the original +*> matrix. +*> If UPLO = 'U': the upper triangular part of the inverse +*> is formed and the part of A below the diagonal is not +*> referenced; +*> If UPLO = 'L': the lower triangular part of the inverse +*> is formed and the part of A above the diagonal is not +*> referenced. +*> \endverbatim +*> +*> \param[in] LDA +*> \verbatim +*> LDA is INTEGER +*> The leading dimension of the array A. LDA >= max(1,N). +*> \endverbatim +*> +*> \param[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZSYTRF_RK or ZSYTRF_BK. +*> \endverbatim +*> +*> \param[out] WORK +*> \verbatim +*> WORK is COMPLEX*16 array, dimension (N+NB+1,NB+3). +*> \endverbatim +*> +*> \param[in] NB +*> \verbatim +*> NB is INTEGER +*> Block size. +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its +*> inverse could not be computed. +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> \verbatim +*> +*> November 2016, Igor Kozachenko, +*> Computer Science Division, +*> University of California, Berkeley +*> +*> \endverbatim +* +* ===================================================================== + SUBROUTINE ZSYTRI_3X( UPLO, N, A, LDA, E, IPIV, WORK, NB, INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, N, NB +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), E( * ), WORK( N+NB+1, * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX*16 CONE, CZERO + PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ), + $ CZERO = ( 0.0D+0, 0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER CUT, I, ICOUNT, INVD, IP, K, NNB, J, U11 + COMPLEX*16 AK, AKKP1, AKP1, D, T, U01_I_J, U01_IP1_J, + $ U11_I_J, U11_IP1_J +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL ZGEMM, ZSYSWAPR, ZTRTRI, ZTRMM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX, MOD +* .. +* .. Executable Statements .. +* +* Test the input parameters. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -4 + END IF +* +* Quick return if possible +* + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYTRI_3X', -INFO ) + RETURN + END IF + IF( N.EQ.0 ) + $ RETURN +* +* Workspace got Non-diag elements of D +* + DO K = 1, N + WORK( K, 1 ) = E( K ) + END DO +* +* Check that the diagonal matrix D is nonsingular. +* + IF( UPPER ) THEN +* +* Upper triangular storage: examine D from bottom to top +* + DO INFO = N, 1, -1 + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + ELSE +* +* Lower triangular storage: examine D from top to bottom. +* + DO INFO = 1, N + IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.CZERO ) + $ RETURN + END DO + END IF +* + INFO = 0 +* +* Splitting Workspace +* U01 is a block ( N, NB+1 ) +* The first element of U01 is in WORK( 1, 1 ) +* U11 is a block ( NB+1, NB+1 ) +* The first element of U11 is in WORK( N+1, 1 ) +* + U11 = N +* +* INVD is a block ( N, 2 ) +* The first element of INVD is in WORK( 1, INVD ) +* + INVD = NB + 2 + + IF( UPPER ) THEN +* +* Begin Upper +* +* invA = P * inv(U**T) * inv(D) * inv(U) * P**T. +* + CALL ZTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(U) +* + K = 1 + DO WHILE( K.LE.N ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = CONE / A( K, K ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K+1, 1 ) + AK = A( K, K ) / T + AKP1 = A( K+1, K+1 ) / T + AKKP1 = WORK( K+1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K, INVD ) = AKP1 / D + WORK( K+1, INVD+1 ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K+1, INVD ) = WORK( K, INVD+1 ) + K = K + 1 + END IF + K = K + 1 + END DO +* +* inv(U**T) = (inv(U))**T +* +* inv(U**T) * inv(D) * inv(U) +* + CUT = N + DO WHILE( CUT.GT.0 ) + NNB = NB + IF( CUT.LE.NNB ) THEN + NNB = CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT+1-NNB, CUT + IF( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF + + CUT = CUT - NNB +* +* U01 Block +* + DO I = 1, CUT + DO J = 1, NNB + WORK( I, J ) = A( I, CUT+J ) + END DO + END DO +* +* U11 Block +* + DO I = 1, NNB + WORK( U11+I, I ) = CONE + DO J = 1, I-1 + WORK( U11+I, J ) = CZERO + END DO + DO J = I+1, NNB + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD * U01 +* + I = 1 + DO WHILE( I.LE.CUT ) + IF( IPIV( I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( I, INVD ) * WORK( I, J ) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK( I, J ) + U01_IP1_J = WORK( I+1, J ) + WORK( I, J ) = WORK( I, INVD ) * U01_I_J + $ + WORK( I, INVD+1 ) * U01_IP1_J + WORK( I+1, J ) = WORK( I+1, INVD ) * U01_I_J + $ + WORK( I+1, INVD+1 ) * U01_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* invD1 * U11 +* + I = 1 + DO WHILE ( I.LE.NNB ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = I, NNB + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + END DO + ELSE + DO J = I, NNB + U11_I_J = WORK(U11+I,J) + U11_IP1_J = WORK(U11+I+1,J) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * WORK(U11+I+1,J) + WORK( U11+I+1, J ) = WORK(CUT+I+1,INVD) * U11_I_J + $ + WORK(CUT+I+1,INVD+1) * U11_IP1_J + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* U11**T * invD1 * U11 -> U11 +* + CALL ZTRMM( 'L', 'U', 'T', 'U', NNB, NNB, + $ CONE, A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* +* U01**T * invD * U01 -> A( CUT+I, CUT+J ) +* + CALL ZGEMM( 'T', 'N', NNB, NNB, CUT, CONE, A( 1, CUT+1 ), + $ LDA, WORK, N+NB+1, CZERO, WORK(U11+1,1), + $ N+NB+1 ) + +* +* U11 = U11**T * invD1 * U11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = I, NNB + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J ) + WORK(U11+I,J) + END DO + END DO +* +* U01 = U00**T * invD0 * U01 +* + CALL ZTRMM( 'L', UPLO, 'T', 'U', CUT, NNB, + $ CONE, A, LDA, WORK, N+NB+1 ) + +* +* Update U01 +* + DO I = 1, CUT + DO J = 1, NNB + A( I, CUT+J ) = WORK( I, J ) + END DO + END DO +* +* Next Block +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(U**T) * inv(D) * inv(U) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Upper case. +* +* ( We can use a loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = 1, N + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL ZSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL ZSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* inv A = P * inv(L**T) * inv(D) * inv(L) * P**T. +* + CALL ZTRTRI( UPLO, 'U', N, A, LDA, INFO ) +* +* inv(D) and inv(D) * inv(L) +* + K = N + DO WHILE ( K .GE. 1 ) + IF( IPIV( K ).GT.0 ) THEN +* 1 x 1 diagonal NNB + WORK( K, INVD ) = CONE / A( K, K ) + WORK( K, INVD+1 ) = CZERO + ELSE +* 2 x 2 diagonal NNB + T = WORK( K-1, 1 ) + AK = A( K-1, K-1 ) / T + AKP1 = A( K, K ) / T + AKKP1 = WORK( K-1, 1 ) / T + D = T*( AK*AKP1-CONE ) + WORK( K-1, INVD ) = AKP1 / D + WORK( K, INVD ) = AK / D + WORK( K, INVD+1 ) = -AKKP1 / D + WORK( K-1, INVD+1 ) = WORK( K, INVD+1 ) + K = K - 1 + END IF + K = K - 1 + END DO +* +* inv(L**T) = (inv(L))**T +* +* inv(L**T) * inv(D) * inv(L) +* + CUT = 0 + DO WHILE( CUT.LT.N ) + NNB = NB + IF( (CUT + NNB).GT.N ) THEN + NNB = N - CUT + ELSE + ICOUNT = 0 +* count negative elements, + DO I = CUT + 1, CUT+NNB + IF ( IPIV( I ).LT.0 ) ICOUNT = ICOUNT + 1 + END DO +* need a even number for a clear cut + IF( MOD( ICOUNT, 2 ).EQ.1 ) NNB = NNB + 1 + END IF +* +* L21 Block +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + WORK( I, J ) = A( CUT+NNB+I, CUT+J ) + END DO + END DO +* +* L11 Block +* + DO I = 1, NNB + WORK( U11+I, I) = CONE + DO J = I+1, NNB + WORK( U11+I, J ) = CZERO + END DO + DO J = 1, I-1 + WORK( U11+I, J ) = A( CUT+I, CUT+J ) + END DO + END DO +* +* invD*L21 +* + I = N-CUT-NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+NNB+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( I, J ) = WORK( CUT+NNB+I, INVD) * WORK( I, J) + END DO + ELSE + DO J = 1, NNB + U01_I_J = WORK(I,J) + U01_IP1_J = WORK(I-1,J) + WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+ + $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J + WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+ + $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* invD1*L11 +* + I = NNB + DO WHILE( I.GE.1 ) + IF( IPIV( CUT+I ).GT.0 ) THEN + DO J = 1, NNB + WORK( U11+I, J ) = WORK( CUT+I, INVD)*WORK(U11+I,J) + END DO + + ELSE + DO J = 1, NNB + U11_I_J = WORK( U11+I, J ) + U11_IP1_J = WORK( U11+I-1, J ) + WORK( U11+I, J ) = WORK(CUT+I,INVD) * WORK(U11+I,J) + $ + WORK(CUT+I,INVD+1) * U11_IP1_J + WORK( U11+I-1, J ) = WORK(CUT+I-1,INVD+1) * U11_I_J + $ + WORK(CUT+I-1,INVD) * U11_IP1_J + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* L11**T * invD1 * L11 -> L11 +* + CALL ZTRMM( 'L', UPLO, 'T', 'U', NNB, NNB, CONE, + $ A( CUT+1, CUT+1 ), LDA, WORK( U11+1, 1 ), + $ N+NB+1 ) + +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO +* + IF( (CUT+NNB).LT.N ) THEN +* +* L21**T * invD2*L21 -> A( CUT+I, CUT+J ) +* + CALL ZGEMM( 'T', 'N', NNB, NNB, N-NNB-CUT, CONE, + $ A( CUT+NNB+1, CUT+1 ), LDA, WORK, N+NB+1, + $ CZERO, WORK( U11+1, 1 ), N+NB+1 ) + +* +* L11 = L11**T * invD1 * L11 + U01**T * invD * U01 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = A( CUT+I, CUT+J )+WORK(U11+I,J) + END DO + END DO +* +* L01 = L22**T * invD2 * L21 +* + CALL ZTRMM( 'L', UPLO, 'T', 'U', N-NNB-CUT, NNB, CONE, + $ A( CUT+NNB+1, CUT+NNB+1 ), LDA, WORK, + $ N+NB+1 ) +* +* Update L21 +* + DO I = 1, N-CUT-NNB + DO J = 1, NNB + A( CUT+NNB+I, CUT+J ) = WORK( I, J ) + END DO + END DO +* + ELSE +* +* L11 = L11**T * invD1 * L11 +* + DO I = 1, NNB + DO J = 1, I + A( CUT+I, CUT+J ) = WORK( U11+I, J ) + END DO + END DO + END IF +* +* Next Block +* + CUT = CUT + NNB +* + END DO +* +* Apply PERMUTATIONS P and P**T: +* P * inv(L**T) * inv(D) * inv(L) * P**T. +* Interchange rows and columns I and IPIV(I) in reverse order +* from the formation order of IPIV vector for Lower case. +* +* ( We can use a loop over IPIV with increment -1, +* since the ABS value of IPIV(I) represents the row (column) +* index of the interchange with row (column) i in both 1x1 +* and 2x2 pivot cases, i.e. we don't need separate code branches +* for 1x1 and 2x2 pivot cases ) +* + DO I = N, 1, -1 + IP = ABS( IPIV( I ) ) + IF( IP.NE.I ) THEN + IF (I .LT. IP) CALL ZSYSWAPR( UPLO, N, A, LDA, I ,IP ) + IF (I .GT. IP) CALL ZSYSWAPR( UPLO, N, A, LDA, IP ,I ) + END IF + END DO +* + END IF +* + RETURN +* +* End of ZSYTRI_3X +* + END + diff --git a/SRC/zsytrs_3.f b/SRC/zsytrs_3.f new file mode 100644 index 00000000..45e6fbc1 --- /dev/null +++ b/SRC/zsytrs_3.f @@ -0,0 +1,371 @@ +*> \brief \b ZSYTRS_3 +* +* =========== DOCUMENTATION =========== +* +* Online html documentation available at +* http://www.netlib.org/lapack/explore-html/ +* +*> \htmlonly +*> Download ZSYTRS_3 + dependencies +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytrs_3.f"> +*> [TGZ]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytrs_3.f"> +*> [ZIP]</a> +*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytrs_3.f"> +*> [TXT]</a> +*> \endhtmlonly +* +* Definition: +* =========== +* +* SUBROUTINE ZSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, +* INFO ) +* +* .. Scalar Arguments .. +* CHARACTER UPLO +* INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. +* INTEGER IPIV( * ) +* COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* +*> \par Purpose: +* ============= +*> +*> \verbatim +*> ZSYTRS_3 solves a system of linear equations A * X = B with a complex +*> symmetric matrix A using the factorization computed +*> by ZSYTRF_RK or ZSYTRF_BK: +*> +*> A = P*U*D*(U**T)*(P**T) or A = P*L*D*(L**T)*(P**T), +*> +*> where U (or L) is unit upper (or lower) triangular matrix, +*> U**T (or L**T) is the transpose of U (or L), P is a permutation +*> matrix, P**T is the transpose of P, and D is symmetric and block +*> diagonal with 1-by-1 and 2-by-2 diagonal blocks. +*> +*> This algorithm is using Level 3 BLAS. +*> \endverbatim +* +* Arguments: +* ========== +* +*> \param[in] UPLO +*> \verbatim +*> UPLO is CHARACTER*1 +*> Specifies whether the details of the factorization are +*> stored as an upper or lower triangular matrix: +*> = 'U': Upper triangular, form is A = P*U*D*(U**T)*(P**T); +*> = 'L': Lower triangular, form is A = P*L*D*(L**T)*(P**T). +*> \endverbatim +*> +*> \param[in] N +*> \verbatim +*> N is INTEGER +*> The order of the matrix A. N >= 0. +*> \endverbatim +*> +*> \param[in] NRHS +*> \verbatim +*> NRHS is INTEGER +*> The number of right hand sides, i.e., the number of columns +*> of the matrix B. NRHS >= 0. +*> \endverbatim +*> +*> \param[in] A +*> \verbatim +*> A is COMPLEX*16 array, dimension (LDA,N) +*> Diagonal of the block diagonal matrix D and factors U or L +*> as computed by ZSYTRF_RK and ZSYTRF_BK: +*> a) ONLY diagonal elements of the symmetric block diagonal +*> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); +*> (superdiagonal (or subdiagonal) elements of D +*> should be provided on entry 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[in] E +*> \verbatim +*> E is COMPLEX*16 array, dimension (N) +*> On entry, contains the superdiagonal (or subdiagonal) +*> elements of the symmetric 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) not refernced; +*> If UPLO = 'L': E(i) = D(i+1,i),i=1:N-1, E(N) not referenced. +*> +*> NOTE: For 1-by-1 diagonal block D(k), where +*> 1 <= k <= N, the element E(k) is not referenced in both +*> UPLO = 'U' or UPLO = 'L' cases. +*> \endverbatim +*> +*> \param[in] IPIV +*> \verbatim +*> IPIV is INTEGER array, dimension (N) +*> Details of the interchanges and the block structure of D +*> as determined by ZSYTRF_RK or ZSYTRF_BK. +*> \endverbatim +*> +*> \param[in,out] B +*> \verbatim +*> B is COMPLEX*16 array, dimension (LDB,NRHS) +*> On entry, the right hand side matrix B. +*> On exit, the solution matrix X. +*> \endverbatim +*> +*> \param[in] LDB +*> \verbatim +*> LDB is INTEGER +*> The leading dimension of the array B. LDB >= max(1,N). +*> \endverbatim +*> +*> \param[out] INFO +*> \verbatim +*> INFO is INTEGER +*> = 0: successful exit +*> < 0: if INFO = -i, the i-th argument had an illegal value +*> \endverbatim +* +* Authors: +* ======== +* +*> \author Univ. of Tennessee +*> \author Univ. of California Berkeley +*> \author Univ. of Colorado Denver +*> \author NAG Ltd. +* +*> \date November 2016 +* +*> \ingroup complex16SYcomputational +* +*> \par Contributors: +* ================== +*> +*> \verbatim +*> +*> November 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 ZSYTRS_3( UPLO, N, NRHS, A, LDA, E, IPIV, B, LDB, + $ INFO ) +* +* -- LAPACK computational routine (version 3.7.0) -- +* -- LAPACK is a software package provided by Univ. of Tennessee, -- +* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- +* November 2016 +* +* .. Scalar Arguments .. + CHARACTER UPLO + INTEGER INFO, LDA, LDB, N, NRHS +* .. +* .. Array Arguments .. + INTEGER IPIV( * ) + COMPLEX*16 A( LDA, * ), B( LDB, * ), E( * ) +* .. +* +* ===================================================================== +* +* .. Parameters .. + COMPLEX*16 ONE + PARAMETER ( ONE = ( 1.0D+0,0.0D+0 ) ) +* .. +* .. Local Scalars .. + LOGICAL UPPER + INTEGER I, J, K, KP + COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM +* .. +* .. External Functions .. + LOGICAL LSAME + EXTERNAL LSAME +* .. +* .. External Subroutines .. + EXTERNAL ZSCAL, ZSWAP, ZTRSM, XERBLA +* .. +* .. Intrinsic Functions .. + INTRINSIC ABS, MAX +* .. +* .. Executable Statements .. +* + INFO = 0 + UPPER = LSAME( UPLO, 'U' ) + IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN + INFO = -1 + ELSE IF( N.LT.0 ) THEN + INFO = -2 + ELSE IF( NRHS.LT.0 ) THEN + INFO = -3 + ELSE IF( LDA.LT.MAX( 1, N ) ) THEN + INFO = -5 + ELSE IF( LDB.LT.MAX( 1, N ) ) THEN + INFO = -9 + END IF + IF( INFO.NE.0 ) THEN + CALL XERBLA( 'ZSYTRS_3', -INFO ) + RETURN + END IF +* +* Quick return if possible +* + IF( N.EQ.0 .OR. NRHS.EQ.0 ) + $ RETURN +* + IF( UPPER ) THEN +* +* Begin Upper +* +* Solve A*X = B, where A = U*D*U**T. +* +* P**T * B +* +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (U \P**T * B) -> B [ (U \P**T * B) ] +* + CALL ZTRSM( 'L', 'U', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (U \P**T * B) ] +* + I = N + DO WHILE ( I.GE.1 ) + IF( IPIV( I ).GT.0 ) THEN + CALL ZSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF ( I.GT.1 ) THEN + AKM1K = E( I ) + AKM1 = A( I-1, I-1 ) / AKM1K + AK = A( I, I ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I-1, J ) / AKM1K + BK = B( I, J ) / AKM1K + B( I-1, J ) = ( AK*BKM1-BK ) / DENOM + B( I, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I - 1 + END IF + I = I - 1 + END DO +* +* Compute (U**T \ B) -> B [ U**T \ (D \ (U \P**T * B) ) ] +* + CALL ZTRSM( 'L', 'U', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (U**T \ (D \ (U \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Upper case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* + ELSE +* +* Begin Lower +* +* Solve A*X = B, where A = L*D*L**T. +* +* P**T * B +* Interchange rows K and IPIV(K) of matrix B in the same order +* that the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with increment 1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = 1, N, 1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* Compute (L \P**T * B) -> B [ (L \P**T * B) ] +* + CALL ZTRSM( 'L', 'L', 'N', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* Compute D \ B -> B [ D \ (L \P**T * B) ] +* + I = 1 + DO WHILE ( I.LE.N ) + IF( IPIV( I ).GT.0 ) THEN + CALL ZSCAL( NRHS, ONE / A( I, I ), B( I, 1 ), LDB ) + ELSE IF( I.LT.N ) THEN + AKM1K = E( I ) + AKM1 = A( I, I ) / AKM1K + AK = A( I+1, I+1 ) / AKM1K + DENOM = AKM1*AK - ONE + DO J = 1, NRHS + BKM1 = B( I, J ) / AKM1K + BK = B( I+1, J ) / AKM1K + B( I, J ) = ( AK*BKM1-BK ) / DENOM + B( I+1, J ) = ( AKM1*BK-BKM1 ) / DENOM + END DO + I = I + 1 + END IF + I = I + 1 + END DO +* +* Compute (L**T \ B) -> B [ L**T \ (D \ (L \P**T * B) ) ] +* + CALL ZTRSM('L', 'L', 'T', 'U', N, NRHS, ONE, A, LDA, B, LDB ) +* +* P * B [ P * (L**T \ (D \ (L \P**T * B) )) ] +* +* Interchange rows K and IPIV(K) of matrix B in reverse order +* from the formation order of IPIV(I) vector for Lower case. +* +* (We can do the simple loop over IPIV with decrement -1, +* since the ABS value of IPIV(I) represents the row index +* of the interchange with row i in both 1x1 and 2x2 pivot cases) +* + DO K = N, 1, -1 + KP = ABS( IPIV( K ) ) + IF( KP.NE.K ) THEN + CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB ) + END IF + END DO +* +* END Lower +* + END IF +* + RETURN +* +* End of ZSYTRS_3 +* + END |