298
299
300
301
302
303
304 CHARACTER TRANSR, DIAG, SIDE, TRANS, UPLO
305 INTEGER LDB, M, N
306 COMPLEX*16 ALPHA
307
308
309 COMPLEX*16 A( 0: * ), B( 0: LDB-1, 0: * )
310
311
312
313
314
315 COMPLEX*16 CONE, CZERO
316 parameter( cone = ( 1.0d+0, 0.0d+0 ),
317 $ czero = ( 0.0d+0, 0.0d+0 ) )
318
319
320 LOGICAL LOWER, LSIDE, MISODD, NISODD, NORMALTRANSR,
321 $ NOTRANS
322 INTEGER M1, M2, N1, N2, K, INFO, I, J
323
324
325 LOGICAL LSAME
327
328
330
331
332 INTRINSIC max, mod
333
334
335
336
337
338 info = 0
339 normaltransr =
lsame( transr,
'N' )
340 lside =
lsame( side,
'L' )
341 lower =
lsame( uplo,
'L' )
342 notrans =
lsame( trans,
'N' )
343 IF( .NOT.normaltransr .AND. .NOT.
lsame( transr,
'C' ) )
THEN
344 info = -1
345 ELSE IF( .NOT.lside .AND. .NOT.
lsame( side,
'R' ) )
THEN
346 info = -2
347 ELSE IF( .NOT.lower .AND. .NOT.
lsame( uplo,
'U' ) )
THEN
348 info = -3
349 ELSE IF( .NOT.notrans .AND. .NOT.
lsame( trans,
'C' ) )
THEN
350 info = -4
351 ELSE IF( .NOT.
lsame( diag,
'N' ) .AND.
352 $ .NOT.
lsame( diag,
'U' ) )
353 $ THEN
354 info = -5
355 ELSE IF( m.LT.0 ) THEN
356 info = -6
357 ELSE IF( n.LT.0 ) THEN
358 info = -7
359 ELSE IF( ldb.LT.max( 1, m ) ) THEN
360 info = -11
361 END IF
362 IF( info.NE.0 ) THEN
363 CALL xerbla(
'ZTFSM ', -info )
364 RETURN
365 END IF
366
367
368
369 IF( ( m.EQ.0 ) .OR. ( n.EQ.0 ) )
370 $ RETURN
371
372
373
374 IF( alpha.EQ.czero ) THEN
375 DO 20 j = 0, n - 1
376 DO 10 i = 0, m - 1
377 b( i, j ) = czero
378 10 CONTINUE
379 20 CONTINUE
380 RETURN
381 END IF
382
383 IF( lside ) THEN
384
385
386
387
388
389
390
391 IF( mod( m, 2 ).EQ.0 ) THEN
392 misodd = .false.
393 k = m / 2
394 ELSE
395 misodd = .true.
396 IF( lower ) THEN
397 m2 = m / 2
398 m1 = m - m2
399 ELSE
400 m1 = m / 2
401 m2 = m - m1
402 END IF
403 END IF
404
405 IF( misodd ) THEN
406
407
408
409 IF( normaltransr ) THEN
410
411
412
413 IF( lower ) THEN
414
415
416
417 IF( notrans ) THEN
418
419
420
421
422 IF( m.EQ.1 ) THEN
423 CALL ztrsm(
'L',
'L',
'N', diag, m1, n,
424 $ alpha,
425 $ a, m, b, ldb )
426 ELSE
427 CALL ztrsm(
'L',
'L',
'N', diag, m1, n,
428 $ alpha,
429 $ a( 0 ), m, b, ldb )
430 CALL zgemm(
'N',
'N', m2, n, m1, -cone,
431 $ a( m1 ),
432 $ m, b, ldb, alpha, b( m1, 0 ), ldb )
433 CALL ztrsm(
'L',
'U',
'C', diag, m2, n, cone,
434 $ a( m ), m, b( m1, 0 ), ldb )
435 END IF
436
437 ELSE
438
439
440
441
442 IF( m.EQ.1 ) THEN
443 CALL ztrsm(
'L',
'L',
'C', diag, m1, n,
444 $ alpha,
445 $ a( 0 ), m, b, ldb )
446 ELSE
447 CALL ztrsm(
'L',
'U',
'N', diag, m2, n,
448 $ alpha,
449 $ a( m ), m, b( m1, 0 ), ldb )
450 CALL zgemm(
'C',
'N', m1, n, m2, -cone,
451 $ a( m1 ),
452 $ m, b( m1, 0 ), ldb, alpha, b, ldb )
453 CALL ztrsm(
'L',
'L',
'C', diag, m1, n, cone,
454 $ a( 0 ), m, b, ldb )
455 END IF
456
457 END IF
458
459 ELSE
460
461
462
463 IF( .NOT.notrans ) THEN
464
465
466
467
468 CALL ztrsm(
'L',
'L',
'N', diag, m1, n, alpha,
469 $ a( m2 ), m, b, ldb )
470 CALL zgemm(
'C',
'N', m2, n, m1, -cone, a( 0 ),
471 $ m,
472 $ b, ldb, alpha, b( m1, 0 ), ldb )
473 CALL ztrsm(
'L',
'U',
'C', diag, m2, n, cone,
474 $ a( m1 ), m, b( m1, 0 ), ldb )
475
476 ELSE
477
478
479
480
481 CALL ztrsm(
'L',
'U',
'N', diag, m2, n, alpha,
482 $ a( m1 ), m, b( m1, 0 ), ldb )
483 CALL zgemm(
'N',
'N', m1, n, m2, -cone, a( 0 ),
484 $ m,
485 $ b( m1, 0 ), ldb, alpha, b, ldb )
486 CALL ztrsm(
'L',
'L',
'C', diag, m1, n, cone,
487 $ a( m2 ), m, b, ldb )
488
489 END IF
490
491 END IF
492
493 ELSE
494
495
496
497 IF( lower ) THEN
498
499
500
501 IF( notrans ) THEN
502
503
504
505
506 IF( m.EQ.1 ) THEN
507 CALL ztrsm(
'L',
'U',
'C', diag, m1, n,
508 $ alpha,
509 $ a( 0 ), m1, b, ldb )
510 ELSE
511 CALL ztrsm(
'L',
'U',
'C', diag, m1, n,
512 $ alpha,
513 $ a( 0 ), m1, b, ldb )
514 CALL zgemm(
'C',
'N', m2, n, m1, -cone,
515 $ a( m1*m1 ), m1, b, ldb, alpha,
516 $ b( m1, 0 ), ldb )
517 CALL ztrsm(
'L',
'L',
'N', diag, m2, n, cone,
518 $ a( 1 ), m1, b( m1, 0 ), ldb )
519 END IF
520
521 ELSE
522
523
524
525
526 IF( m.EQ.1 ) THEN
527 CALL ztrsm(
'L',
'U',
'N', diag, m1, n,
528 $ alpha,
529 $ a( 0 ), m1, b, ldb )
530 ELSE
531 CALL ztrsm(
'L',
'L',
'C', diag, m2, n,
532 $ alpha,
533 $ a( 1 ), m1, b( m1, 0 ), ldb )
534 CALL zgemm(
'N',
'N', m1, n, m2, -cone,
535 $ a( m1*m1 ), m1, b( m1, 0 ), ldb,
536 $ alpha, b, ldb )
537 CALL ztrsm(
'L',
'U',
'N', diag, m1, n, cone,
538 $ a( 0 ), m1, b, ldb )
539 END IF
540
541 END IF
542
543 ELSE
544
545
546
547 IF( .NOT.notrans ) THEN
548
549
550
551
552 CALL ztrsm(
'L',
'U',
'C', diag, m1, n, alpha,
553 $ a( m2*m2 ), m2, b, ldb )
554 CALL zgemm(
'N',
'N', m2, n, m1, -cone, a( 0 ),
555 $ m2,
556 $ b, ldb, alpha, b( m1, 0 ), ldb )
557 CALL ztrsm(
'L',
'L',
'N', diag, m2, n, cone,
558 $ a( m1*m2 ), m2, b( m1, 0 ), ldb )
559
560 ELSE
561
562
563
564
565 CALL ztrsm(
'L',
'L',
'C', diag, m2, n, alpha,
566 $ a( m1*m2 ), m2, b( m1, 0 ), ldb )
567 CALL zgemm(
'C',
'N', m1, n, m2, -cone, a( 0 ),
568 $ m2,
569 $ b( m1, 0 ), ldb, alpha, b, ldb )
570 CALL ztrsm(
'L',
'U',
'N', diag, m1, n, cone,
571 $ a( m2*m2 ), m2, b, ldb )
572
573 END IF
574
575 END IF
576
577 END IF
578
579 ELSE
580
581
582
583 IF( normaltransr ) THEN
584
585
586
587 IF( lower ) THEN
588
589
590
591 IF( notrans ) THEN
592
593
594
595
596 CALL ztrsm(
'L',
'L',
'N', diag, k, n, alpha,
597 $ a( 1 ), m+1, b, ldb )
598 CALL zgemm(
'N',
'N', k, n, k, -cone, a( k+1 ),
599 $ m+1, b, ldb, alpha, b( k, 0 ), ldb )
600 CALL ztrsm(
'L',
'U',
'C', diag, k, n, cone,
601 $ a( 0 ), m+1, b( k, 0 ), ldb )
602
603 ELSE
604
605
606
607
608 CALL ztrsm(
'L',
'U',
'N', diag, k, n, alpha,
609 $ a( 0 ), m+1, b( k, 0 ), ldb )
610 CALL zgemm(
'C',
'N', k, n, k, -cone, a( k+1 ),
611 $ m+1, b( k, 0 ), ldb, alpha, b, ldb )
612 CALL ztrsm(
'L',
'L',
'C', diag, k, n, cone,
613 $ a( 1 ), m+1, b, ldb )
614
615 END IF
616
617 ELSE
618
619
620
621 IF( .NOT.notrans ) THEN
622
623
624
625
626 CALL ztrsm(
'L',
'L',
'N', diag, k, n, alpha,
627 $ a( k+1 ), m+1, b, ldb )
628 CALL zgemm(
'C',
'N', k, n, k, -cone, a( 0 ),
629 $ m+1,
630 $ b, ldb, alpha, b( k, 0 ), ldb )
631 CALL ztrsm(
'L',
'U',
'C', diag, k, n, cone,
632 $ a( k ), m+1, b( k, 0 ), ldb )
633
634 ELSE
635
636
637
638 CALL ztrsm(
'L',
'U',
'N', diag, k, n, alpha,
639 $ a( k ), m+1, b( k, 0 ), ldb )
640 CALL zgemm(
'N',
'N', k, n, k, -cone, a( 0 ),
641 $ m+1,
642 $ b( k, 0 ), ldb, alpha, b, ldb )
643 CALL ztrsm(
'L',
'L',
'C', diag, k, n, cone,
644 $ a( k+1 ), m+1, b, ldb )
645
646 END IF
647
648 END IF
649
650 ELSE
651
652
653
654 IF( lower ) THEN
655
656
657
658 IF( notrans ) THEN
659
660
661
662
663 CALL ztrsm(
'L',
'U',
'C', diag, k, n, alpha,
664 $ a( k ), k, b, ldb )
665 CALL zgemm(
'C',
'N', k, n, k, -cone,
666 $ a( k*( k+1 ) ), k, b, ldb, alpha,
667 $ b( k, 0 ), ldb )
668 CALL ztrsm(
'L',
'L',
'N', diag, k, n, cone,
669 $ a( 0 ), k, b( k, 0 ), ldb )
670
671 ELSE
672
673
674
675
676 CALL ztrsm(
'L',
'L',
'C', diag, k, n, alpha,
677 $ a( 0 ), k, b( k, 0 ), ldb )
678 CALL zgemm(
'N',
'N', k, n, k, -cone,
679 $ a( k*( k+1 ) ), k, b( k, 0 ), ldb,
680 $ alpha, b, ldb )
681 CALL ztrsm(
'L',
'U',
'N', diag, k, n, cone,
682 $ a( k ), k, b, ldb )
683
684 END IF
685
686 ELSE
687
688
689
690 IF( .NOT.notrans ) THEN
691
692
693
694
695 CALL ztrsm(
'L',
'U',
'C', diag, k, n, alpha,
696 $ a( k*( k+1 ) ), k, b, ldb )
697 CALL zgemm(
'N',
'N', k, n, k, -cone, a( 0 ), k,
698 $ b,
699 $ ldb, alpha, b( k, 0 ), ldb )
700 CALL ztrsm(
'L',
'L',
'N', diag, k, n, cone,
701 $ a( k*k ), k, b( k, 0 ), ldb )
702
703 ELSE
704
705
706
707
708 CALL ztrsm(
'L',
'L',
'C', diag, k, n, alpha,
709 $ a( k*k ), k, b( k, 0 ), ldb )
710 CALL zgemm(
'C',
'N', k, n, k, -cone, a( 0 ), k,
711 $ b( k, 0 ), ldb, alpha, b, ldb )
712 CALL ztrsm(
'L',
'U',
'N', diag, k, n, cone,
713 $ a( k*( k+1 ) ), k, b, ldb )
714
715 END IF
716
717 END IF
718
719 END IF
720
721 END IF
722
723 ELSE
724
725
726
727
728
729
730
731 IF( mod( n, 2 ).EQ.0 ) THEN
732 nisodd = .false.
733 k = n / 2
734 ELSE
735 nisodd = .true.
736 IF( lower ) THEN
737 n2 = n / 2
738 n1 = n - n2
739 ELSE
740 n1 = n / 2
741 n2 = n - n1
742 END IF
743 END IF
744
745 IF( nisodd ) THEN
746
747
748
749 IF( normaltransr ) THEN
750
751
752
753 IF( lower ) THEN
754
755
756
757 IF( notrans ) THEN
758
759
760
761
762 CALL ztrsm(
'R',
'U',
'C', diag, m, n2, alpha,
763 $ a( n ), n, b( 0, n1 ), ldb )
764 CALL zgemm(
'N',
'N', m, n1, n2, -cone, b( 0,
765 $ n1 ),
766 $ ldb, a( n1 ), n, alpha, b( 0, 0 ),
767 $ ldb )
768 CALL ztrsm(
'R',
'L',
'N', diag, m, n1, cone,
769 $ a( 0 ), n, b( 0, 0 ), ldb )
770
771 ELSE
772
773
774
775
776 CALL ztrsm(
'R',
'L',
'C', diag, m, n1, alpha,
777 $ a( 0 ), n, b( 0, 0 ), ldb )
778 CALL zgemm(
'N',
'C', m, n2, n1, -cone, b( 0,
779 $ 0 ),
780 $ ldb, a( n1 ), n, alpha, b( 0, n1 ),
781 $ ldb )
782 CALL ztrsm(
'R',
'U',
'N', diag, m, n2, cone,
783 $ a( n ), n, b( 0, n1 ), ldb )
784
785 END IF
786
787 ELSE
788
789
790
791 IF( notrans ) THEN
792
793
794
795
796 CALL ztrsm(
'R',
'L',
'C', diag, m, n1, alpha,
797 $ a( n2 ), n, b( 0, 0 ), ldb )
798 CALL zgemm(
'N',
'N', m, n2, n1, -cone, b( 0,
799 $ 0 ),
800 $ ldb, a( 0 ), n, alpha, b( 0, n1 ),
801 $ ldb )
802 CALL ztrsm(
'R',
'U',
'N', diag, m, n2, cone,
803 $ a( n1 ), n, b( 0, n1 ), ldb )
804
805 ELSE
806
807
808
809
810 CALL ztrsm(
'R',
'U',
'C', diag, m, n2, alpha,
811 $ a( n1 ), n, b( 0, n1 ), ldb )
812 CALL zgemm(
'N',
'C', m, n1, n2, -cone, b( 0,
813 $ n1 ),
814 $ ldb, a( 0 ), n, alpha, b( 0, 0 ), ldb )
815 CALL ztrsm(
'R',
'L',
'N', diag, m, n1, cone,
816 $ a( n2 ), n, b( 0, 0 ), ldb )
817
818 END IF
819
820 END IF
821
822 ELSE
823
824
825
826 IF( lower ) THEN
827
828
829
830 IF( notrans ) THEN
831
832
833
834
835 CALL ztrsm(
'R',
'L',
'N', diag, m, n2, alpha,
836 $ a( 1 ), n1, b( 0, n1 ), ldb )
837 CALL zgemm(
'N',
'C', m, n1, n2, -cone, b( 0,
838 $ n1 ),
839 $ ldb, a( n1*n1 ), n1, alpha, b( 0, 0 ),
840 $ ldb )
841 CALL ztrsm(
'R',
'U',
'C', diag, m, n1, cone,
842 $ a( 0 ), n1, b( 0, 0 ), ldb )
843
844 ELSE
845
846
847
848
849 CALL ztrsm(
'R',
'U',
'N', diag, m, n1, alpha,
850 $ a( 0 ), n1, b( 0, 0 ), ldb )
851 CALL zgemm(
'N',
'N', m, n2, n1, -cone, b( 0,
852 $ 0 ),
853 $ ldb, a( n1*n1 ), n1, alpha, b( 0, n1 ),
854 $ ldb )
855 CALL ztrsm(
'R',
'L',
'C', diag, m, n2, cone,
856 $ a( 1 ), n1, b( 0, n1 ), ldb )
857
858 END IF
859
860 ELSE
861
862
863
864 IF( notrans ) THEN
865
866
867
868
869 CALL ztrsm(
'R',
'U',
'N', diag, m, n1, alpha,
870 $ a( n2*n2 ), n2, b( 0, 0 ), ldb )
871 CALL zgemm(
'N',
'C', m, n2, n1, -cone, b( 0,
872 $ 0 ),
873 $ ldb, a( 0 ), n2, alpha, b( 0, n1 ),
874 $ ldb )
875 CALL ztrsm(
'R',
'L',
'C', diag, m, n2, cone,
876 $ a( n1*n2 ), n2, b( 0, n1 ), ldb )
877
878 ELSE
879
880
881
882
883 CALL ztrsm(
'R',
'L',
'N', diag, m, n2, alpha,
884 $ a( n1*n2 ), n2, b( 0, n1 ), ldb )
885 CALL zgemm(
'N',
'N', m, n1, n2, -cone, b( 0,
886 $ n1 ),
887 $ ldb, a( 0 ), n2, alpha, b( 0, 0 ),
888 $ ldb )
889 CALL ztrsm(
'R',
'U',
'C', diag, m, n1, cone,
890 $ a( n2*n2 ), n2, b( 0, 0 ), ldb )
891
892 END IF
893
894 END IF
895
896 END IF
897
898 ELSE
899
900
901
902 IF( normaltransr ) THEN
903
904
905
906 IF( lower ) THEN
907
908
909
910 IF( notrans ) THEN
911
912
913
914
915 CALL ztrsm(
'R',
'U',
'C', diag, m, k, alpha,
916 $ a( 0 ), n+1, b( 0, k ), ldb )
917 CALL zgemm(
'N',
'N', m, k, k, -cone, b( 0, k ),
918 $ ldb, a( k+1 ), n+1, alpha, b( 0, 0 ),
919 $ ldb )
920 CALL ztrsm(
'R',
'L',
'N', diag, m, k, cone,
921 $ a( 1 ), n+1, b( 0, 0 ), ldb )
922
923 ELSE
924
925
926
927
928 CALL ztrsm(
'R',
'L',
'C', diag, m, k, alpha,
929 $ a( 1 ), n+1, b( 0, 0 ), ldb )
930 CALL zgemm(
'N',
'C', m, k, k, -cone, b( 0, 0 ),
931 $ ldb, a( k+1 ), n+1, alpha, b( 0, k ),
932 $ ldb )
933 CALL ztrsm(
'R',
'U',
'N', diag, m, k, cone,
934 $ a( 0 ), n+1, b( 0, k ), ldb )
935
936 END IF
937
938 ELSE
939
940
941
942 IF( notrans ) THEN
943
944
945
946
947 CALL ztrsm(
'R',
'L',
'C', diag, m, k, alpha,
948 $ a( k+1 ), n+1, b( 0, 0 ), ldb )
949 CALL zgemm(
'N',
'N', m, k, k, -cone, b( 0, 0 ),
950 $ ldb, a( 0 ), n+1, alpha, b( 0, k ),
951 $ ldb )
952 CALL ztrsm(
'R',
'U',
'N', diag, m, k, cone,
953 $ a( k ), n+1, b( 0, k ), ldb )
954
955 ELSE
956
957
958
959
960 CALL ztrsm(
'R',
'U',
'C', diag, m, k, alpha,
961 $ a( k ), n+1, b( 0, k ), ldb )
962 CALL zgemm(
'N',
'C', m, k, k, -cone, b( 0, k ),
963 $ ldb, a( 0 ), n+1, alpha, b( 0, 0 ),
964 $ ldb )
965 CALL ztrsm(
'R',
'L',
'N', diag, m, k, cone,
966 $ a( k+1 ), n+1, b( 0, 0 ), ldb )
967
968 END IF
969
970 END IF
971
972 ELSE
973
974
975
976 IF( lower ) THEN
977
978
979
980 IF( notrans ) THEN
981
982
983
984
985 CALL ztrsm(
'R',
'L',
'N', diag, m, k, alpha,
986 $ a( 0 ), k, b( 0, k ), ldb )
987 CALL zgemm(
'N',
'C', m, k, k, -cone, b( 0, k ),
988 $ ldb, a( ( k+1 )*k ), k, alpha,
989 $ b( 0, 0 ), ldb )
990 CALL ztrsm(
'R',
'U',
'C', diag, m, k, cone,
991 $ a( k ), k, b( 0, 0 ), ldb )
992
993 ELSE
994
995
996
997
998 CALL ztrsm(
'R',
'U',
'N', diag, m, k, alpha,
999 $ a( k ), k, b( 0, 0 ), ldb )
1000 CALL zgemm(
'N',
'N', m, k, k, -cone, b( 0, 0 ),
1001 $ ldb, a( ( k+1 )*k ), k, alpha,
1002 $ b( 0, k ), ldb )
1003 CALL ztrsm(
'R',
'L',
'C', diag, m, k, cone,
1004 $ a( 0 ), k, b( 0, k ), ldb )
1005
1006 END IF
1007
1008 ELSE
1009
1010
1011
1012 IF( notrans ) THEN
1013
1014
1015
1016
1017 CALL ztrsm(
'R',
'U',
'N', diag, m, k, alpha,
1018 $ a( ( k+1 )*k ), k, b( 0, 0 ), ldb )
1019 CALL zgemm(
'N',
'C', m, k, k, -cone, b( 0, 0 ),
1020 $ ldb, a( 0 ), k, alpha, b( 0, k ), ldb )
1021 CALL ztrsm(
'R',
'L',
'C', diag, m, k, cone,
1022 $ a( k*k ), k, b( 0, k ), ldb )
1023
1024 ELSE
1025
1026
1027
1028
1029 CALL ztrsm(
'R',
'L',
'N', diag, m, k, alpha,
1030 $ a( k*k ), k, b( 0, k ), ldb )
1031 CALL zgemm(
'N',
'N', m, k, k, -cone, b( 0, k ),
1032 $ ldb, a( 0 ), k, alpha, b( 0, 0 ), ldb )
1033 CALL ztrsm(
'R',
'U',
'C', diag, m, k, cone,
1034 $ a( ( k+1 )*k ), k, b( 0, 0 ), ldb )
1035
1036 END IF
1037
1038 END IF
1039
1040 END IF
1041
1042 END IF
1043 END IF
1044
1045 RETURN
1046
1047
1048
subroutine xerbla(srname, info)
subroutine zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMM
logical function lsame(ca, cb)
LSAME
subroutine ztrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
ZTRSM