184
185
186
187
188
189
190 CHARACTER UPLO
191 INTEGER INFO, KB, LDA, LDW, N, NB
192
193
194 INTEGER IPIV( * )
195 COMPLEX*16 A( LDA, * ), W( LDW, * )
196
197
198
199
200
201 DOUBLE PRECISION ZERO, ONE
202 parameter( zero = 0.0d+0, one = 1.0d+0 )
203 COMPLEX*16 CONE
204 parameter( cone = ( 1.0d+0, 0.0d+0 ) )
205 DOUBLE PRECISION EIGHT, SEVTEN
206 parameter( eight = 8.0d+0, sevten = 17.0d+0 )
207
208
209 LOGICAL DONE
210 INTEGER IMAX, ITEMP, II, J, JB, JJ, JMAX, JP1, JP2, K,
211 $ KK, KKW, KP, KSTEP, KW, P
212 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, DTEMP, R1, ROWMAX, T,
213 $ SFMIN
214 COMPLEX*16 D11, D21, D22, Z
215
216
217 LOGICAL LSAME
218 INTEGER IZAMAX
219 DOUBLE PRECISION DLAMCH
221
222
224
225
226 INTRINSIC abs, dble, dconjg, dimag, max, min, sqrt
227
228
229 DOUBLE PRECISION CABS1
230
231
232 cabs1( z ) = abs( dble( z ) ) + abs( dimag( z ) )
233
234
235
236 info = 0
237
238
239
240 alpha = ( one+sqrt( sevten ) ) / eight
241
242
243
245
246 IF(
lsame( uplo,
'U' ) )
THEN
247
248
249
250
251
252
253
254 k = n
255 10 CONTINUE
256
257
258
259 kw = nb + k - n
260
261
262
263 IF( ( k.LE.n-nb+1 .AND. nb.LT.n ) .OR. k.LT.1 )
264 $ GO TO 30
265
266 kstep = 1
267 p = k
268
269
270
271 IF( k.GT.1 )
272 $
CALL zcopy( k-1, a( 1, k ), 1, w( 1, kw ), 1 )
273 w( k, kw ) = dble( a( k, k ) )
274 IF( k.LT.n ) THEN
275 CALL zgemv(
'No transpose', k, n-k, -cone, a( 1, k+1 ), lda,
276 $ w( k, kw+1 ), ldw, cone, w( 1, kw ), 1 )
277 w( k, kw ) = dble( w( k, kw ) )
278 END IF
279
280
281
282
283 absakk = abs( dble( w( k, kw ) ) )
284
285
286
287
288
289 IF( k.GT.1 ) THEN
290 imax =
izamax( k-1, w( 1, kw ), 1 )
291 colmax = cabs1( w( imax, kw ) )
292 ELSE
293 colmax = zero
294 END IF
295
296 IF( max( absakk, colmax ).EQ.zero ) THEN
297
298
299
300 IF( info.EQ.0 )
301 $ info = k
302 kp = k
303 a( k, k ) = dble( w( k, kw ) )
304 IF( k.GT.1 )
305 $
CALL zcopy( k-1, w( 1, kw ), 1, a( 1, k ), 1 )
306 ELSE
307
308
309
310
311
312
313
314
315 IF( .NOT.( absakk.LT.alpha*colmax ) ) THEN
316
317
318
319 kp = k
320
321 ELSE
322
323
324
325 done = .false.
326
327 12 CONTINUE
328
329
330
331
332
333
334 IF( imax.GT.1 )
335 $
CALL zcopy( imax-1, a( 1, imax ), 1, w( 1, kw-1 ),
336 $ 1 )
337 w( imax, kw-1 ) = dble( a( imax, imax ) )
338
339 CALL zcopy( k-imax, a( imax, imax+1 ), lda,
340 $ w( imax+1, kw-1 ), 1 )
341 CALL zlacgv( k-imax, w( imax+1, kw-1 ), 1 )
342
343 IF( k.LT.n ) THEN
344 CALL zgemv(
'No transpose', k, n-k, -cone,
345 $ a( 1, k+1 ), lda, w( imax, kw+1 ), ldw,
346 $ cone, w( 1, kw-1 ), 1 )
347 w( imax, kw-1 ) = dble( w( imax, kw-1 ) )
348 END IF
349
350
351
352
353
354 IF( imax.NE.k ) THEN
355 jmax = imax +
izamax( k-imax, w( imax+1, kw-1 ),
356 $ 1 )
357 rowmax = cabs1( w( jmax, kw-1 ) )
358 ELSE
359 rowmax = zero
360 END IF
361
362 IF( imax.GT.1 ) THEN
363 itemp =
izamax( imax-1, w( 1, kw-1 ), 1 )
364 dtemp = cabs1( w( itemp, kw-1 ) )
365 IF( dtemp.GT.rowmax ) THEN
366 rowmax = dtemp
367 jmax = itemp
368 END IF
369 END IF
370
371
372
373
374
375
376 IF( .NOT.( abs( dble( w( imax,kw-1 ) ) )
377 $ .LT.alpha*rowmax ) ) THEN
378
379
380
381
382 kp = imax
383
384
385
386 CALL zcopy( k, w( 1, kw-1 ), 1, w( 1, kw ), 1 )
387
388 done = .true.
389
390
391
392
393
394 ELSE IF( ( p.EQ.jmax ) .OR. ( rowmax.LE.colmax ) )
395 $ THEN
396
397
398
399
400 kp = imax
401 kstep = 2
402 done = .true.
403
404
405 ELSE
406
407
408
409 p = imax
410 colmax = rowmax
411 imax = jmax
412
413
414
415 CALL zcopy( k, w( 1, kw-1 ), 1, w( 1, kw ), 1 )
416
417 END IF
418
419
420
421
422 IF( .NOT.done ) GOTO 12
423
424 END IF
425
426
427
428
429
430
431
432 kk = k - kstep + 1
433
434
435
436 kkw = nb + kk - n
437
438
439
440
441 IF( ( kstep.EQ.2 ) .AND. ( p.NE.k ) ) THEN
442
443
444
445
446
447
448 a( p, p ) = dble( a( k, k ) )
449 CALL zcopy( k-1-p, a( p+1, k ), 1, a( p, p+1 ),
450 $ lda )
451 CALL zlacgv( k-1-p, a( p, p+1 ), lda )
452 IF( p.GT.1 )
453 $
CALL zcopy( p-1, a( 1, k ), 1, a( 1, p ), 1 )
454
455
456
457
458
459
460 IF( k.LT.n )
461 $
CALL zswap( n-k, a( k, k+1 ), lda, a( p, k+1 ),
462 $ lda )
463 CALL zswap( n-kk+1, w( k, kkw ), ldw, w( p, kkw ),
464 $ ldw )
465 END IF
466
467
468
469
470 IF( kp.NE.kk ) THEN
471
472
473
474
475
476
477 a( kp, kp ) = dble( a( kk, kk ) )
478 CALL zcopy( kk-1-kp, a( kp+1, kk ), 1, a( kp, kp+1 ),
479 $ lda )
480 CALL zlacgv( kk-1-kp, a( kp, kp+1 ), lda )
481 IF( kp.GT.1 )
482 $
CALL zcopy( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
483
484
485
486
487
488
489 IF( k.LT.n )
490 $
CALL zswap( n-k, a( kk, k+1 ), lda, a( kp, k+1 ),
491 $ lda )
492 CALL zswap( n-kk+1, w( kk, kkw ), ldw, w( kp, kkw ),
493 $ ldw )
494 END IF
495
496 IF( kstep.EQ.1 ) THEN
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514 CALL zcopy( k, w( 1, kw ), 1, a( 1, k ), 1 )
515 IF( k.GT.1 ) THEN
516
517
518
519
520
521
522
523 t = dble( a( k, k ) )
524 IF( abs( t ).GE.sfmin ) THEN
525 r1 = one / t
526 CALL zdscal( k-1, r1, a( 1, k ), 1 )
527 ELSE
528 DO 14 ii = 1, k-1
529 a( ii, k ) = a( ii, k ) / t
530 14 CONTINUE
531 END IF
532
533
534
535 CALL zlacgv( k-1, w( 1, kw ), 1 )
536 END IF
537
538 ELSE
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 IF( k.GT.2 ) THEN
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 d21 = w( k-1, kw )
603 d11 = w( k, kw ) / dconjg( d21 )
604 d22 = w( k-1, kw-1 ) / d21
605 t = one / ( dble( d11*d22 )-one )
606
607
608
609
610
611 DO 20 j = 1, k - 2
612 a( j, k-1 ) = t*( ( d11*w( j, kw-1 )-w( j, kw ) ) /
613 $ d21 )
614 a( j, k ) = t*( ( d22*w( j, kw )-w( j, kw-1 ) ) /
615 $ dconjg( d21 ) )
616 20 CONTINUE
617 END IF
618
619
620
621 a( k-1, k-1 ) = w( k-1, kw-1 )
622 a( k-1, k ) = w( k-1, kw )
623 a( k, k ) = w( k, kw )
624
625
626
627 CALL zlacgv( k-1, w( 1, kw ), 1 )
628 CALL zlacgv( k-2, w( 1, kw-1 ), 1 )
629
630 END IF
631
632 END IF
633
634
635
636 IF( kstep.EQ.1 ) THEN
637 ipiv( k ) = kp
638 ELSE
639 ipiv( k ) = -p
640 ipiv( k-1 ) = -kp
641 END IF
642
643
644
645 k = k - kstep
646 GO TO 10
647
648 30 CONTINUE
649
650
651
652
653
654
655
656
657 DO 50 j = ( ( k-1 ) / nb )*nb + 1, 1, -nb
658 jb = min( nb, k-j+1 )
659
660
661
662 DO 40 jj = j, j + jb - 1
663 a( jj, jj ) = dble( a( jj, jj ) )
664 CALL zgemv(
'No transpose', jj-j+1, n-k, -cone,
665 $ a( j, k+1 ), lda, w( jj, kw+1 ), ldw, cone,
666 $ a( j, jj ), 1 )
667 a( jj, jj ) = dble( a( jj, jj ) )
668 40 CONTINUE
669
670
671
672 IF( j.GE.2 )
673 $
CALL zgemm(
'No transpose',
'Transpose', j-1, jb, n-k,
674 $ -cone, a( 1, k+1 ), lda, w( j, kw+1 ), ldw,
675 $ cone, a( 1, j ), lda )
676 50 CONTINUE
677
678
679
680
681 j = k + 1
682 60 CONTINUE
683
684
685
686
687 kstep = 1
688 jp1 = 1
689
690 jj = j
691 jp2 = ipiv( j )
692 IF( jp2.LT.0 ) THEN
693 jp2 = -jp2
694
695 j = j + 1
696 jp1 = -ipiv( j )
697 kstep = 2
698 END IF
699
700
701 j = j + 1
702 IF( jp2.NE.jj .AND. j.LE.n )
703 $
CALL zswap( n-j+1, a( jp2, j ), lda, a( jj, j ), lda )
704 jj = jj + 1
705 IF( kstep.EQ.2 .AND. jp1.NE.jj .AND. j.LE.n )
706 $
CALL zswap( n-j+1, a( jp1, j ), lda, a( jj, j ), lda )
707 IF( j.LT.n )
708 $ GO TO 60
709
710
711
712 kb = n - k
713
714 ELSE
715
716
717
718
719
720
721
722 k = 1
723 70 CONTINUE
724
725
726
727 IF( ( k.GE.nb .AND. nb.LT.n ) .OR. k.GT.n )
728 $ GO TO 90
729
730 kstep = 1
731 p = k
732
733
734
735 w( k, k ) = dble( a( k, k ) )
736 IF( k.LT.n )
737 $
CALL zcopy( n-k, a( k+1, k ), 1, w( k+1, k ), 1 )
738 IF( k.GT.1 ) THEN
739 CALL zgemv(
'No transpose', n-k+1, k-1, -cone, a( k, 1 ),
740 $ lda, w( k, 1 ), ldw, cone, w( k, k ), 1 )
741 w( k, k ) = dble( w( k, k ) )
742 END IF
743
744
745
746
747 absakk = abs( dble( w( k, k ) ) )
748
749
750
751
752
753 IF( k.LT.n ) THEN
754 imax = k +
izamax( n-k, w( k+1, k ), 1 )
755 colmax = cabs1( w( imax, k ) )
756 ELSE
757 colmax = zero
758 END IF
759
760 IF( max( absakk, colmax ).EQ.zero ) THEN
761
762
763
764 IF( info.EQ.0 )
765 $ info = k
766 kp = k
767 a( k, k ) = dble( w( k, k ) )
768 IF( k.LT.n )
769 $
CALL zcopy( n-k, w( k+1, k ), 1, a( k+1, k ), 1 )
770 ELSE
771
772
773
774
775
776
777
778
779
780 IF( .NOT.( absakk.LT.alpha*colmax ) ) THEN
781
782
783
784 kp = k
785
786 ELSE
787
788 done = .false.
789
790
791
792 72 CONTINUE
793
794
795
796
797
798
799 CALL zcopy( imax-k, a( imax, k ), lda, w( k, k+1 ), 1)
800 CALL zlacgv( imax-k, w( k, k+1 ), 1 )
801 w( imax, k+1 ) = dble( a( imax, imax ) )
802
803 IF( imax.LT.n )
804 $
CALL zcopy( n-imax, a( imax+1, imax ), 1,
805 $ w( imax+1, k+1 ), 1 )
806
807 IF( k.GT.1 ) THEN
808 CALL zgemv(
'No transpose', n-k+1, k-1, -cone,
809 $ a( k, 1 ), lda, w( imax, 1 ), ldw,
810 $ cone, w( k, k+1 ), 1 )
811 w( imax, k+1 ) = dble( w( imax, k+1 ) )
812 END IF
813
814
815
816
817
818 IF( imax.NE.k ) THEN
819 jmax = k - 1 +
izamax( imax-k, w( k, k+1 ), 1 )
820 rowmax = cabs1( w( jmax, k+1 ) )
821 ELSE
822 rowmax = zero
823 END IF
824
825 IF( imax.LT.n ) THEN
826 itemp = imax +
izamax( n-imax, w( imax+1, k+1 ), 1)
827 dtemp = cabs1( w( itemp, k+1 ) )
828 IF( dtemp.GT.rowmax ) THEN
829 rowmax = dtemp
830 jmax = itemp
831 END IF
832 END IF
833
834
835
836
837
838
839 IF( .NOT.( abs( dble( w( imax,k+1 ) ) )
840 $ .LT.alpha*rowmax ) ) THEN
841
842
843
844
845 kp = imax
846
847
848
849 CALL zcopy( n-k+1, w( k, k+1 ), 1, w( k, k ), 1 )
850
851 done = .true.
852
853
854
855
856
857 ELSE IF( ( p.EQ.jmax ) .OR. ( rowmax.LE.colmax ) )
858 $ THEN
859
860
861
862
863 kp = imax
864 kstep = 2
865 done = .true.
866
867
868 ELSE
869
870
871
872 p = imax
873 colmax = rowmax
874 imax = jmax
875
876
877
878 CALL zcopy( n-k+1, w( k, k+1 ), 1, w( k, k ), 1 )
879
880 END IF
881
882
883
884
885 IF( .NOT.done ) GOTO 72
886
887 END IF
888
889
890
891
892
893
894
895 kk = k + kstep - 1
896
897
898
899
900 IF( ( kstep.EQ.2 ) .AND. ( p.NE.k ) ) THEN
901
902
903
904
905
906
907 a( p, p ) = dble( a( k, k ) )
908 CALL zcopy( p-k-1, a( k+1, k ), 1, a( p, k+1 ), lda )
909 CALL zlacgv( p-k-1, a( p, k+1 ), lda )
910 IF( p.LT.n )
911 $
CALL zcopy( n-p, a( p+1, k ), 1, a( p+1, p ), 1 )
912
913
914
915
916
917
918 IF( k.GT.1 )
919 $
CALL zswap( k-1, a( k, 1 ), lda, a( p, 1 ), lda )
920 CALL zswap( kk, w( k, 1 ), ldw, w( p, 1 ), ldw )
921 END IF
922
923
924
925
926 IF( kp.NE.kk ) THEN
927
928
929
930
931
932
933 a( kp, kp ) = dble( a( kk, kk ) )
934 CALL zcopy( kp-kk-1, a( kk+1, kk ), 1, a( kp, kk+1 ),
935 $ lda )
936 CALL zlacgv( kp-kk-1, a( kp, kk+1 ), lda )
937 IF( kp.LT.n )
938 $
CALL zcopy( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ), 1 )
939
940
941
942
943
944
945 IF( k.GT.1 )
946 $
CALL zswap( k-1, a( kk, 1 ), lda, a( kp, 1 ), lda )
947 CALL zswap( kk, w( kk, 1 ), ldw, w( kp, 1 ), ldw )
948 END IF
949
950 IF( kstep.EQ.1 ) THEN
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968 CALL zcopy( n-k+1, w( k, k ), 1, a( k, k ), 1 )
969 IF( k.LT.n ) THEN
970
971
972
973
974
975
976
977 t = dble( a( k, k ) )
978 IF( abs( t ).GE.sfmin ) THEN
979 r1 = one / t
980 CALL zdscal( n-k, r1, a( k+1, k ), 1 )
981 ELSE
982 DO 74 ii = k + 1, n
983 a( ii, k ) = a( ii, k ) / t
984 74 CONTINUE
985 END IF
986
987
988
989 CALL zlacgv( n-k, w( k+1, k ), 1 )
990 END IF
991
992 ELSE
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009 IF( k.LT.n-1 ) THEN
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056 d21 = w( k+1, k )
1057 d11 = w( k+1, k+1 ) / d21
1058 d22 = w( k, k ) / dconjg( d21 )
1059 t = one / ( dble( d11*d22 )-one )
1060
1061
1062
1063
1064
1065 DO 80 j = k + 2, n
1066 a( j, k ) = t*( ( d11*w( j, k )-w( j, k+1 ) ) /
1067 $ dconjg( d21 ) )
1068 a( j, k+1 ) = t*( ( d22*w( j, k+1 )-w( j, k ) ) /
1069 $ d21 )
1070 80 CONTINUE
1071 END IF
1072
1073
1074
1075 a( k, k ) = w( k, k )
1076 a( k+1, k ) = w( k+1, k )
1077 a( k+1, k+1 ) = w( k+1, k+1 )
1078
1079
1080
1081 CALL zlacgv( n-k, w( k+1, k ), 1 )
1082 CALL zlacgv( n-k-1, w( k+2, k+1 ), 1 )
1083
1084 END IF
1085
1086 END IF
1087
1088
1089
1090 IF( kstep.EQ.1 ) THEN
1091 ipiv( k ) = kp
1092 ELSE
1093 ipiv( k ) = -p
1094 ipiv( k+1 ) = -kp
1095 END IF
1096
1097
1098
1099 k = k + kstep
1100 GO TO 70
1101
1102 90 CONTINUE
1103
1104
1105
1106
1107
1108
1109
1110
1111 DO 110 j = k, n, nb
1112 jb = min( nb, n-j+1 )
1113
1114
1115
1116 DO 100 jj = j, j + jb - 1
1117 a( jj, jj ) = dble( a( jj, jj ) )
1118 CALL zgemv(
'No transpose', j+jb-jj, k-1, -cone,
1119 $ a( jj, 1 ), lda, w( jj, 1 ), ldw, cone,
1120 $ a( jj, jj ), 1 )
1121 a( jj, jj ) = dble( a( jj, jj ) )
1122 100 CONTINUE
1123
1124
1125
1126 IF( j+jb.LE.n )
1127 $
CALL zgemm(
'No transpose',
'Transpose', n-j-jb+1, jb,
1128 $ k-1, -cone, a( j+jb, 1 ), lda, w( j, 1 ),
1129 $ ldw, cone, a( j+jb, j ), lda )
1130 110 CONTINUE
1131
1132
1133
1134
1135 j = k - 1
1136 120 CONTINUE
1137
1138
1139
1140
1141 kstep = 1
1142 jp1 = 1
1143
1144 jj = j
1145 jp2 = ipiv( j )
1146 IF( jp2.LT.0 ) THEN
1147 jp2 = -jp2
1148
1149 j = j - 1
1150 jp1 = -ipiv( j )
1151 kstep = 2
1152 END IF
1153
1154
1155 j = j - 1
1156 IF( jp2.NE.jj .AND. j.GE.1 )
1157 $
CALL zswap( j, a( jp2, 1 ), lda, a( jj, 1 ), lda )
1158 jj = jj -1
1159 IF( kstep.EQ.2 .AND. jp1.NE.jj .AND. j.GE.1 )
1160 $
CALL zswap( j, a( jp1, 1 ), lda, a( jj, 1 ), lda )
1161 IF( j.GT.1 )
1162 $ GO TO 120
1163
1164
1165
1166 kb = k - 1
1167
1168 END IF
1169 RETURN
1170
1171
1172
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
subroutine zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMM
subroutine zgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
ZGEMV
integer function izamax(n, zx, incx)
IZAMAX
subroutine zlacgv(n, x, incx)
ZLACGV conjugates a complex vector.
double precision function dlamch(cmach)
DLAMCH
logical function lsame(ca, cb)
LSAME
subroutine zdscal(n, da, zx, incx)
ZDSCAL
subroutine zswap(n, zx, incx, zy, incy)
ZSWAP