176
177
178
179
180
181
182 CHARACTER UPLO
183 INTEGER INFO, KB, LDA, LDW, N, NB
184
185
186 INTEGER IPIV( * )
187 COMPLEX*16 A( LDA, * ), W( LDW, * )
188
189
190
191
192
193 DOUBLE PRECISION ZERO, ONE
194 parameter( zero = 0.0d+0, one = 1.0d+0 )
195 COMPLEX*16 CONE
196 parameter( cone = ( 1.0d+0, 0.0d+0 ) )
197 DOUBLE PRECISION EIGHT, SEVTEN
198 parameter( eight = 8.0d+0, sevten = 17.0d+0 )
199
200
201 INTEGER IMAX, J, JJ, JMAX, JP, K, KK, KKW, KP,
202 $ KSTEP, KW
203 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, R1, ROWMAX, T
204 COMPLEX*16 D11, D21, D22, Z
205
206
207 LOGICAL LSAME
208 INTEGER IZAMAX
210
211
214
215
216 INTRINSIC abs, dble, dconjg, dimag, max, min, sqrt
217
218
219 DOUBLE PRECISION CABS1
220
221
222 cabs1( z ) = abs( dble( z ) ) + abs( dimag( z ) )
223
224
225
226 info = 0
227
228
229
230 alpha = ( one+sqrt( sevten ) ) / eight
231
232 IF(
lsame( uplo,
'U' ) )
THEN
233
234
235
236
237
238
239
240
241
242 k = n
243 10 CONTINUE
244 kw = nb + k - n
245
246
247
248 IF( ( k.LE.n-nb+1 .AND. nb.LT.n ) .OR. k.LT.1 )
249 $ GO TO 30
250
251 kstep = 1
252
253
254
255 CALL zcopy( k-1, a( 1, k ), 1, w( 1, kw ), 1 )
256 w( k, kw ) = dble( a( k, k ) )
257 IF( k.LT.n ) THEN
258 CALL zgemv(
'No transpose', k, n-k, -cone, a( 1, k+1 ),
259 $ lda,
260 $ w( k, kw+1 ), ldw, cone, w( 1, kw ), 1 )
261 w( k, kw ) = dble( w( k, kw ) )
262 END IF
263
264
265
266
267 absakk = abs( dble( w( k, kw ) ) )
268
269
270
271
272
273 IF( k.GT.1 ) THEN
274 imax =
izamax( k-1, w( 1, kw ), 1 )
275 colmax = cabs1( w( imax, kw ) )
276 ELSE
277 colmax = zero
278 END IF
279
280 IF( max( absakk, colmax ).EQ.zero ) THEN
281
282
283
284 IF( info.EQ.0 )
285 $ info = k
286 kp = k
287 a( k, k ) = dble( a( k, k ) )
288 ELSE
289
290
291
292
293
294
295 IF( absakk.GE.alpha*colmax ) THEN
296
297
298
299 kp = k
300 ELSE
301
302
303
304
305
306
307 CALL zcopy( imax-1, a( 1, imax ), 1, w( 1, kw-1 ), 1 )
308 w( imax, kw-1 ) = dble( a( imax, imax ) )
309 CALL zcopy( k-imax, a( imax, imax+1 ), lda,
310 $ w( imax+1, kw-1 ), 1 )
311 CALL zlacgv( k-imax, w( imax+1, kw-1 ), 1 )
312 IF( k.LT.n ) THEN
313 CALL zgemv(
'No transpose', k, n-k, -cone,
314 $ a( 1, k+1 ), lda, w( imax, kw+1 ), ldw,
315 $ cone, w( 1, kw-1 ), 1 )
316 w( imax, kw-1 ) = dble( w( imax, kw-1 ) )
317 END IF
318
319
320
321
322
323 jmax = imax +
izamax( k-imax, w( imax+1, kw-1 ), 1 )
324 rowmax = cabs1( w( jmax, kw-1 ) )
325 IF( imax.GT.1 ) THEN
326 jmax =
izamax( imax-1, w( 1, kw-1 ), 1 )
327 rowmax = max( rowmax, cabs1( w( jmax, kw-1 ) ) )
328 END IF
329
330
331 IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
332
333
334
335 kp = k
336
337
338 ELSE IF( abs( dble( w( imax, kw-1 ) ) ).GE.alpha*rowmax )
339 $ THEN
340
341
342
343
344 kp = imax
345
346
347
348 CALL zcopy( k, w( 1, kw-1 ), 1, w( 1, kw ), 1 )
349
350
351 ELSE
352
353
354
355
356 kp = imax
357 kstep = 2
358 END IF
359
360
361
362
363 END IF
364
365
366
367
368
369
370
371 kk = k - kstep + 1
372
373
374
375 kkw = nb + kk - n
376
377
378
379
380 IF( kp.NE.kk ) THEN
381
382
383
384
385
386
387 a( kp, kp ) = dble( a( kk, kk ) )
388 CALL zcopy( kk-1-kp, a( kp+1, kk ), 1, a( kp, kp+1 ),
389 $ lda )
390 CALL zlacgv( kk-1-kp, a( kp, kp+1 ), lda )
391 IF( kp.GT.1 )
392 $
CALL zcopy( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
393
394
395
396
397
398
399 IF( k.LT.n )
400 $
CALL zswap( n-k, a( kk, k+1 ), lda, a( kp, k+1 ),
401 $ lda )
402 CALL zswap( n-kk+1, w( kk, kkw ), ldw, w( kp, kkw ),
403 $ ldw )
404 END IF
405
406 IF( kstep.EQ.1 ) THEN
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424 CALL zcopy( k, w( 1, kw ), 1, a( 1, k ), 1 )
425 IF( k.GT.1 ) THEN
426
427
428
429
430
431 r1 = one / dble( a( k, k ) )
432 CALL zdscal( k-1, r1, a( 1, k ), 1 )
433
434
435
436 CALL zlacgv( k-1, w( 1, kw ), 1 )
437 END IF
438
439 ELSE
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456 IF( k.GT.2 ) THEN
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500 d21 = w( k-1, kw )
501 d11 = w( k, kw ) / dconjg( d21 )
502 d22 = w( k-1, kw-1 ) / d21
503 t = one / ( dble( d11*d22 )-one )
504 d21 = t / d21
505
506
507
508
509
510 DO 20 j = 1, k - 2
511 a( j, k-1 ) = d21*( d11*w( j, kw-1 )-w( j, kw ) )
512 a( j, k ) = dconjg( d21 )*
513 $ ( d22*w( j, kw )-w( j, kw-1 ) )
514 20 CONTINUE
515 END IF
516
517
518
519 a( k-1, k-1 ) = w( k-1, kw-1 )
520 a( k-1, k ) = w( k-1, kw )
521 a( k, k ) = w( k, kw )
522
523
524
525 CALL zlacgv( k-1, w( 1, kw ), 1 )
526 CALL zlacgv( k-2, w( 1, kw-1 ), 1 )
527
528 END IF
529
530 END IF
531
532
533
534 IF( kstep.EQ.1 ) THEN
535 ipiv( k ) = kp
536 ELSE
537 ipiv( k ) = -kp
538 ipiv( k-1 ) = -kp
539 END IF
540
541
542
543 k = k - kstep
544 GO TO 10
545
546 30 CONTINUE
547
548
549
550
551
552
553
554 CALL zgemmtr(
'Upper',
'No transpose',
'Transpose', k, n-k,
555 $ -cone, a( 1, k+1 ), lda, w( 1, kw+1 ), ldw,
556 $ cone, a( 1, 1 ), lda )
557
558
559
560
561 j = k + 1
562 60 CONTINUE
563
564
565
566
567
568 jj = j
569 jp = ipiv( j )
570 IF( jp.LT.0 ) THEN
571 jp = -jp
572
573 j = j + 1
574 END IF
575
576
577 j = j + 1
578 IF( jp.NE.jj .AND. j.LE.n )
579 $
CALL zswap( n-j+1, a( jp, j ), lda, a( jj, j ), lda )
580 IF( j.LT.n )
581 $ GO TO 60
582
583
584
585 kb = n - k
586
587 ELSE
588
589
590
591
592
593
594
595 k = 1
596 70 CONTINUE
597
598
599
600 IF( ( k.GE.nb .AND. nb.LT.n ) .OR. k.GT.n )
601 $ GO TO 90
602
603 kstep = 1
604
605
606
607 w( k, k ) = dble( a( k, k ) )
608 IF( k.LT.n )
609 $
CALL zcopy( n-k, a( k+1, k ), 1, w( k+1, k ), 1 )
610 CALL zgemv(
'No transpose', n-k+1, k-1, -cone, a( k, 1 ),
611 $ lda,
612 $ w( k, 1 ), ldw, cone, w( k, k ), 1 )
613 w( k, k ) = dble( w( k, k ) )
614
615
616
617
618 absakk = abs( dble( w( k, k ) ) )
619
620
621
622
623
624 IF( k.LT.n ) THEN
625 imax = k +
izamax( n-k, w( k+1, k ), 1 )
626 colmax = cabs1( w( imax, k ) )
627 ELSE
628 colmax = zero
629 END IF
630
631 IF( max( absakk, colmax ).EQ.zero ) THEN
632
633
634
635 IF( info.EQ.0 )
636 $ info = k
637 kp = k
638 a( k, k ) = dble( a( k, k ) )
639 ELSE
640
641
642
643
644
645
646 IF( absakk.GE.alpha*colmax ) THEN
647
648
649
650 kp = k
651 ELSE
652
653
654
655
656
657
658 CALL zcopy( imax-k, a( imax, k ), lda, w( k, k+1 ),
659 $ 1 )
660 CALL zlacgv( imax-k, w( k, k+1 ), 1 )
661 w( imax, k+1 ) = dble( a( imax, imax ) )
662 IF( imax.LT.n )
663 $
CALL zcopy( n-imax, a( imax+1, imax ), 1,
664 $ w( imax+1, k+1 ), 1 )
665 CALL zgemv(
'No transpose', n-k+1, k-1, -cone, a( k,
666 $ 1 ),
667 $ lda, w( imax, 1 ), ldw, cone, w( k, k+1 ),
668 $ 1 )
669 w( imax, k+1 ) = dble( w( imax, k+1 ) )
670
671
672
673
674
675 jmax = k - 1 +
izamax( imax-k, w( k, k+1 ), 1 )
676 rowmax = cabs1( w( jmax, k+1 ) )
677 IF( imax.LT.n ) THEN
678 jmax = imax +
izamax( n-imax, w( imax+1, k+1 ), 1 )
679 rowmax = max( rowmax, cabs1( w( jmax, k+1 ) ) )
680 END IF
681
682
683 IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
684
685
686
687 kp = k
688
689
690 ELSE IF( abs( dble( w( imax, k+1 ) ) ).GE.alpha*rowmax )
691 $ THEN
692
693
694
695
696 kp = imax
697
698
699
700 CALL zcopy( n-k+1, w( k, k+1 ), 1, w( k, k ), 1 )
701
702
703 ELSE
704
705
706
707
708 kp = imax
709 kstep = 2
710 END IF
711
712
713
714
715 END IF
716
717
718
719
720
721
722
723 kk = k + kstep - 1
724
725
726
727
728 IF( kp.NE.kk ) THEN
729
730
731
732
733
734
735 a( kp, kp ) = dble( a( kk, kk ) )
736 CALL zcopy( kp-kk-1, a( kk+1, kk ), 1, a( kp, kk+1 ),
737 $ lda )
738 CALL zlacgv( kp-kk-1, a( kp, kk+1 ), lda )
739 IF( kp.LT.n )
740 $
CALL zcopy( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ),
741 $ 1 )
742
743
744
745
746
747
748 IF( k.GT.1 )
749 $
CALL zswap( k-1, a( kk, 1 ), lda, a( kp, 1 ), lda )
750 CALL zswap( kk, w( kk, 1 ), ldw, w( kp, 1 ), ldw )
751 END IF
752
753 IF( kstep.EQ.1 ) THEN
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771 CALL zcopy( n-k+1, w( k, k ), 1, a( k, k ), 1 )
772 IF( k.LT.n ) THEN
773
774
775
776
777
778 r1 = one / dble( a( k, k ) )
779 CALL zdscal( n-k, r1, a( k+1, k ), 1 )
780
781
782
783 CALL zlacgv( n-k, w( k+1, k ), 1 )
784 END IF
785
786 ELSE
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803 IF( k.LT.n-1 ) THEN
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847 d21 = w( k+1, k )
848 d11 = w( k+1, k+1 ) / d21
849 d22 = w( k, k ) / dconjg( d21 )
850 t = one / ( dble( d11*d22 )-one )
851 d21 = t / d21
852
853
854
855
856
857 DO 80 j = k + 2, n
858 a( j, k ) = dconjg( d21 )*
859 $ ( d11*w( j, k )-w( j, k+1 ) )
860 a( j, k+1 ) = d21*( d22*w( j, k+1 )-w( j, k ) )
861 80 CONTINUE
862 END IF
863
864
865
866 a( k, k ) = w( k, k )
867 a( k+1, k ) = w( k+1, k )
868 a( k+1, k+1 ) = w( k+1, k+1 )
869
870
871
872 CALL zlacgv( n-k, w( k+1, k ), 1 )
873 CALL zlacgv( n-k-1, w( k+2, k+1 ), 1 )
874
875 END IF
876
877 END IF
878
879
880
881 IF( kstep.EQ.1 ) THEN
882 ipiv( k ) = kp
883 ELSE
884 ipiv( k ) = -kp
885 ipiv( k+1 ) = -kp
886 END IF
887
888
889
890 k = k + kstep
891 GO TO 70
892
893 90 CONTINUE
894
895
896
897
898
899
900
901 CALL zgemmtr(
'Lower',
'No transpose',
'Transpose', n-k+1,
902 $ k-1, -cone, a( k, 1 ), lda, w( k, 1 ), ldw,
903 $ cone, a( k, k ), lda )
904
905
906
907
908 j = k - 1
909 120 CONTINUE
910
911
912
913
914
915 jj = j
916 jp = ipiv( j )
917 IF( jp.LT.0 ) THEN
918 jp = -jp
919
920 j = j - 1
921 END IF
922
923
924 j = j - 1
925 IF( jp.NE.jj .AND. j.GE.1 )
926 $
CALL zswap( j, a( jp, 1 ), lda, a( jj, 1 ), lda )
927 IF( j.GT.1 )
928 $ GO TO 120
929
930
931
932 kb = k - 1
933
934 END IF
935 RETURN
936
937
938
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
subroutine zgemmtr(uplo, transa, transb, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMMTR
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.
logical function lsame(ca, cb)
LSAME
subroutine zdscal(n, da, zx, incx)
ZDSCAL
subroutine zswap(n, zx, incx, zy, incy)
ZSWAP