-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathblas.f90
More file actions
2016 lines (1653 loc) · 52.2 KB
/
blas.f90
File metadata and controls
2016 lines (1653 loc) · 52.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
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
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SUBROUTINE CAXPY(N,CA,CX,INCX,CY,INCY)
USE DDPRECISION,ONLY : WP
! constant times a vector plus a vector:
! given:
! vectors CX,CY
! scalar CA
! computes
! CY = CY + CA*CX
!
! jack dongarra, linpack, 3/11/78.
! modified 12/3/93, array(1) declarations changed to array(*)
COMPLEX (WP) :: CX(*),CY(*),CA
INTEGER :: I,INCX,INCY,IX,IY,N
IF (N<=0) RETURN
IF (ABS(REAL(CA))+ABS(AIMAG(CA))==0.0_WP) RETURN
IF (INCX==1 .AND. INCY==1) GO TO 20
! code for unequal increments or equal increments
! not equal to 1
IX = 1
IY = 1
IF (INCX<0) IX = (-N+1)*INCX+1
IF (INCY<0) IY = (-N+1)*INCY+1
DO I = 1,N
CY(IY) = CY(IY)+CA*CX(IX)
IX = IX+INCX
IY = IY+INCY
END DO
RETURN
! code for both increments equal to 1
20 DO I = 1,N
CY(I) = CY(I)+CA*CX(I)
END DO
RETURN
END SUBROUTINE CAXPY
SUBROUTINE CSCAL(N,CA,CX,INCX)
USE DDPRECISION,ONLY : WP
! scales a vector by a constant.
! jack dongarra, 3/11/78.
! modified to correct problem with negative increment, 8/21/90.
COMPLEX (WP) :: CA,CX(1)
INTEGER :: I,INCX,IX,N
IF (N<=0) RETURN
IF (INCX==1) GO TO 20
! code for increment not equal to 1
IX = 1
IF (INCX<0) IX = (-N+1)*INCX+1
DO I = 1,N
CX(IX) = CA*CX(IX)
IX = IX+INCX
END DO
RETURN
! code for increment equal to 1
20 DO I = 1,N
CX(I) = CA*CX(I)
END DO
RETURN
END SUBROUTINE CSCAL
SUBROUTINE CSWAP(N,CX,INCX,CY,INCY)
USE DDPRECISION,ONLY : WP
! interchanges two vectors.
! jack dongarra, 3/11/78.
COMPLEX (WP) :: CX(1),CY(1),CTEMP
INTEGER :: I,IX,IY,N,INCX,INCY
IF (N<=0) RETURN
IF (INCX==1 .AND. INCY==1) GO TO 20
! code for unequal increments or equal increments not equal
! to 1
IX = 1
IY = 1
IF (INCX<0) IX = (-N+1)*INCX+1
IF (INCY<0) IY = (-N+1)*INCY+1
DO I = 1,N
CTEMP = CX(IX)
CX(IX) = CY(IY)
CY(IY) = CTEMP
IX = IX+INCX
IY = IY+INCY
END DO
RETURN
! code for both increments equal to 1
20 DO I = 1,N
CTEMP = CX(I)
CX(I) = CY(I)
CY(I) = CTEMP
END DO
RETURN
END SUBROUTINE CSWAP
INTEGER FUNCTION ICAMAX(N,CX,INCX)
USE DDPRECISION,ONLY : WP
! finds the index of element having max. absolute value.
! jack dongarra, linpack, 3/11/78.
! modified 3/93 to return if incx .le. 0.
! modified 12/3/93, array(1) declarations changed to array(*)
COMPLEX (WP) :: CX(*)
REAL (WP) :: SMAX
INTEGER :: I,INCX,IX,N
COMPLEX (WP) :: ZDUM
REAL (WP) :: CABS1
CABS1(ZDUM) = ABS(REAL(ZDUM))+ABS(AIMAG(ZDUM))
ICAMAX = 0
IF (N<1 .OR. INCX<=0) RETURN
ICAMAX = 1
IF (N==1) RETURN
IF (INCX==1) GO TO 20
! code for increment not equal to 1
IX = 1
SMAX = CABS1(CX(1))
IX = IX+INCX
DO I = 2,N
IF (CABS1(CX(IX))<=SMAX) GO TO 5
ICAMAX = I
SMAX = CABS1(CX(IX))
5 IX = IX+INCX
END DO
RETURN
! code for increment equal to 1
20 SMAX = CABS1(CX(1))
DO I = 2,N
IF (CABS1(CX(I))<=SMAX) GO TO 30
ICAMAX = I
SMAX = CABS1(CX(I))
30 END DO
RETURN
END FUNCTION ICAMAX
!---------------------------------------------------------------------------
INTEGER FUNCTION ISAMAX(N,SX,INCX)
USE DDPRECISION,ONLY : WP
! finds the index of element having max. absolute value.
! jack dongarra, linpack, 3/11/78.
! modified 3/93 to return if incx .le. 0.
! modified 12/3/93, array(1) declarations changed to array(*)
REAL (WP) :: SX(*),SMAX
INTEGER :: I,INCX,IX,N
ISAMAX = 0
IF (N<1 .OR. INCX<=0) RETURN
ISAMAX = 1
IF (N==1) RETURN
IF (INCX==1) GO TO 20
! code for increment not equal to 1
IX = 1
SMAX = ABS(SX(1))
IX = IX+INCX
DO I = 2,N
IF (ABS(SX(IX))<=SMAX) GO TO 5
ISAMAX = I
SMAX = ABS(SX(IX))
5 IX = IX+INCX
END DO
RETURN
! code for increment equal to 1
20 SMAX = ABS(SX(1))
DO I = 2,N
IF (ABS(SX(I))<=SMAX) GO TO 30
ISAMAX = I
SMAX = ABS(SX(I))
30 END DO
RETURN
END FUNCTION ISAMAX
LOGICAL FUNCTION LSAME(CA,CB)
! -- LAPACK auxiliary routine (version 3.0) --
! Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
! Courant Institute, Argonne National Lab, and Rice University
! September 30, 1994
! .. Scalar Arguments ..
CHARACTER :: CA,CB
! ..
! Purpose
! =======
! LSAME returns .TRUE. if CA is the same letter as CB regardless of
! case.
! Arguments
! =========
! CA (input) CHARACTER*1
! CB (input) CHARACTER*1
! CA and CB specify the single characters to be compared.
! =====================================================================
! .. Intrinsic Functions ..
INTRINSIC ICHAR
! ..
! .. Local Scalars ..
INTEGER :: INTA,INTB,ZCODE
! ..
! .. Executable Statements ..
! Test if the characters are equal
LSAME = CA == CB
IF (LSAME) RETURN
! Now test for equivalence if both characters are alphabetic.
ZCODE = ICHAR('Z')
! Use 'Z' rather than 'A' so that ASCII can be detected on Prime
! machines, on which ICHAR returns a value with bit 8 set.
! ICHAR('A') on Prime machines returns 193 which is the same as
! ICHAR('A') on an EBCDIC machine.
INTA = ICHAR(CA)
INTB = ICHAR(CB)
IF (ZCODE==90 .OR. ZCODE==122) THEN
! ASCII is assumed - ZCODE is the ASCII code of either lower or
! upper case 'Z'.
IF (INTA>=97 .AND. INTA<=122) INTA = INTA - 32
IF (INTB>=97 .AND. INTB<=122) INTB = INTB - 32
ELSE IF (ZCODE==233 .OR. ZCODE==169) THEN
! EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or
! upper case 'Z'.
IF (INTA>=129 .AND. INTA<=137 .OR. INTA>=145 .AND. INTA<=153 .OR. &
INTA>=162 .AND. INTA<=169) INTA = INTA+64
IF (INTB>=129 .AND. INTB<=137 .OR. INTB>=145 .AND. INTB<=153 .OR. &
INTB>=162 .AND. INTB<=169) INTB = INTB+64
ELSE IF (ZCODE==218 .OR. ZCODE==250) THEN
! ASCII is assumed, on Prime machines - ZCODE is the ASCII code
! plus 128 of either lower or upper case 'Z'.
IF (INTA>=225 .AND. INTA<=250) INTA = INTA - 32
IF (INTB>=225 .AND. INTB<=250) INTB = INTB - 32
END IF
LSAME = INTA == INTB
! RETURN
! End of LSAME
END FUNCTION LSAME
SUBROUTINE SAXPY(N,SA,SX,INCX,SY,INCY)
USE DDPRECISION,ONLY : WP
! constant times a vector plus a vector.
! uses unrolled loop for increments equal to one.
! jack dongarra, linpack, 3/11/78.
! modified 12/3/93, array(1) declarations changed to array(*)
REAL (WP) :: SX(*),SY(*),SA
INTEGER :: I,INCX,INCY,IX,IY,M,MP1,N
IF (N<=0) RETURN
IF (SA==0.0_WP) RETURN
IF (INCX==1 .AND. INCY==1) GO TO 20
! code for unequal increments or equal increments
! not equal to 1
IX = 1
IY = 1
IF (INCX<0) IX = (-N+1)*INCX+1
IF (INCY<0) IY = (-N+1)*INCY+1
DO I = 1,N
SY(IY) = SY(IY)+SA*SX(IX)
IX = IX+INCX
IY = IY+INCY
END DO
RETURN
! code for both increments equal to 1
! clean-up loop
20 M = MOD(N,4)
IF (M==0) GO TO 40
DO I = 1,M
SY(I) = SY(I)+SA*SX(I)
END DO
IF (N<4) RETURN
40 MP1 = M+1
DO I = MP1,N,4
SY(I) = SY(I)+SA*SX(I)
SY(I+1) = SY(I+1)+SA*SX(I+1)
SY(I+2) = SY(I+2)+SA*SX(I+2)
SY(I+3) = SY(I+3)+SA*SX(I+3)
END DO
RETURN
END SUBROUTINE SAXPY
SUBROUTINE SCOPY(N,SX,INCX,SY,INCY)
USE DDPRECISION,ONLY : WP
! copies a vector, x, to a vector, y.
! uses unrolled loops for increments equal to 1.
! jack dongarra, linpack, 3/11/78.
! modified 12/3/93, array(1) declarations changed to array(*)
REAL (WP) :: SX(*),SY(*)
INTEGER :: I,INCX,INCY,IX,IY,M,MP1,N
IF (N<=0) RETURN
IF (INCX==1 .AND. INCY==1) GO TO 20
! code for unequal increments or equal increments
! not equal to 1
IX = 1
IY = 1
IF (INCX<0) IX = (-N+1)*INCX+1
IF (INCY<0) IY = (-N+1)*INCY+1
DO I = 1,N
SY(IY) = SX(IX)
IX = IX+INCX
IY = IY+INCY
END DO
RETURN
! code for both increments equal to 1
! clean-up loop
20 M = MOD(N,7)
IF (M==0) GO TO 40
DO I = 1,M
SY(I) = SX(I)
END DO
IF (N<7) RETURN
40 MP1 = M+1
DO I = MP1,N,7
SY(I) = SX(I)
SY(I+1) = SX(I+1)
SY(I+2) = SX(I+2)
SY(I+3) = SX(I+3)
SY(I+4) = SX(I+4)
SY(I+5) = SX(I+5)
SY(I+6) = SX(I+6)
END DO
RETURN
END SUBROUTINE SCOPY
FUNCTION SDOT(N,SX,INCX,SY,INCY)
USE DDPRECISION,ONLY : WP
REAL (WP) :: SDOT
! forms the dot product of two vectors.
! uses unrolled loops for increments equal to one.
! jack dongarra, linpack, 3/11/78.
! modified 12/3/93, array(1) declarations changed to array(*)
REAL (WP) :: SX(*),SY(*),STEMP
INTEGER :: I,INCX,INCY,IX,IY,M,MP1,N
STEMP = 0.0E0_WP
SDOT = 0.0E0_WP
IF (N<=0) RETURN
IF (INCX==1 .AND. INCY==1) GO TO 20
! code for unequal increments or equal increments
! not equal to 1
IX = 1
IY = 1
IF (INCX<0) IX = (-N+1)*INCX+1
IF (INCY<0) IY = (-N+1)*INCY+1
DO I = 1,N
STEMP = STEMP+SX(IX)*SY(IY)
IX = IX+INCX
IY = IY+INCY
END DO
SDOT = STEMP
RETURN
! code for both increments equal to 1
! clean-up loop
20 M = MOD(N,5)
IF (M==0) GO TO 40
DO I = 1,M
STEMP = STEMP+SX(I)*SY(I)
END DO
IF (N<5) GO TO 60
40 MP1 = M+1
DO I = MP1,N,5
STEMP = STEMP+SX(I)*SY(I)+SX(I+1)*SY(I+1)+SX(I+2)*SY(I+2)+ &
SX(I+3)*SY(I+3)+SX(I+4)*SY(I+4)
END DO
60 SDOT = STEMP
RETURN
END FUNCTION SDOT
SUBROUTINE SGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
USE DDPRECISION,ONLY : WP
! .. Scalar Arguments ..
CHARACTER (1) :: TRANSA,TRANSB
INTEGER :: M,N,K,LDA,LDB,LDC
REAL (WP) :: ALPHA,BETA
! .. Array Arguments ..
REAL (WP) :: A(LDA,*),B(LDB,*),C(LDC,*)
! ..
! Purpose
! =======
! SGEMM performs one of the matrix-matrix operations
! C := alpha*op( A )*op( B ) + beta*C,
! where op( X ) is one of
! op( X ) = X or op( X ) = X',
! alpha and beta are scalars, and A, B and C are matrices, with op( A )
! an m by k matrix, op( B ) a k by n matrix and C an m by n matrix.
! Parameters
! ==========
! TRANSA - CHARACTER*1.
! On entry, TRANSA specifies the form of op( A ) to be used in
! the matrix multiplication as follows:
! TRANSA = 'N' or 'n', op( A ) = A.
! TRANSA = 'T' or 't', op( A ) = A'.
! TRANSA = 'C' or 'c', op( A ) = A'.
! Unchanged on exit.
! TRANSB - CHARACTER*1.
! On entry, TRANSB specifies the form of op( B ) to be used in
! the matrix multiplication as follows:
! TRANSB = 'N' or 'n', op( B ) = B.
! TRANSB = 'T' or 't', op( B ) = B'.
! TRANSB = 'C' or 'c', op( B ) = B'.
! Unchanged on exit.
! M - INTEGER.
! On entry, M specifies the number of rows of the matrix
! op( A ) and of the matrix C. M must be at least zero.
! Unchanged on exit.
! N - INTEGER.
! On entry, N specifies the number of columns of the matrix
! op( B ) and the number of columns of the matrix C. N must be
! at least zero.
! Unchanged on exit.
! K - INTEGER.
! On entry, K specifies the number of columns of the matrix
! op( A ) and the number of rows of the matrix op( B ). K must
! be at least zero.
! Unchanged on exit.
! ALPHA - REAL .
! On entry, ALPHA specifies the scalar alpha.
! Unchanged on exit.
! A - REAL array of DIMENSION ( LDA, ka ), where ka is
! k when TRANSA = 'N' or 'n', and is m otherwise.
! Before entry with TRANSA = 'N' or 'n', the leading m by k
! part of the array A must contain the matrix A, otherwise
! the leading k by m part of the array A must contain the
! matrix A.
! Unchanged on exit.
! LDA - INTEGER.
! On entry, LDA specifies the first dimension of A as declared
! in the calling (sub) program. When TRANSA = 'N' or 'n' then
! LDA must be at least max( 1, m ), otherwise LDA must be at
! least max( 1, k ).
! Unchanged on exit.
! B - REAL array of DIMENSION ( LDB, kb ), where kb is
! n when TRANSB = 'N' or 'n', and is k otherwise.
! Before entry with TRANSB = 'N' or 'n', the leading k by n
! part of the array B must contain the matrix B, otherwise
! the leading n by k part of the array B must contain the
! matrix B.
! Unchanged on exit.
! LDB - INTEGER.
! On entry, LDB specifies the first dimension of B as declared
! in the calling (sub) program. When TRANSB = 'N' or 'n' then
! LDB must be at least max( 1, k ), otherwise LDB must be at
! least max( 1, n ).
! Unchanged on exit.
! BETA - REAL .
! On entry, BETA specifies the scalar beta. When BETA is
! supplied as zero then C need not be set on input.
! Unchanged on exit.
! C - REAL array of DIMENSION ( LDC, n ).
! Before entry, the leading m by n part of the array C must
! contain the matrix C, except when beta is zero, in which
! case C need not be set on entry.
! On exit, the array C is overwritten by the m by n matrix
! ( alpha*op( A )*op( B ) + beta*C ).
! LDC - INTEGER.
! On entry, LDC specifies the first dimension of C as declared
! in the calling (sub) program. LDC must be at least
! max( 1, m ).
! Unchanged on exit.
! Level 3 Blas routine.
! -- Written on 8-February-1989.
! Jack Dongarra, Argonne National Laboratory.
! Iain Duff, AERE Harwell.
! Jeremy Du Croz, Numerical Algorithms Group Ltd.
! Sven Hammarling, Numerical Algorithms Group Ltd.
! .. External Functions ..
LOGICAL :: LSAME
EXTERNAL LSAME
! .. External Subroutines ..
EXTERNAL XERBLA
! .. Intrinsic Functions ..
INTRINSIC MAX
! .. Local Scalars ..
LOGICAL :: NOTA,NOTB
INTEGER :: I,INFO,J,L,NCOLA,NROWA,NROWB
REAL (WP) :: TEMP
! .. Parameters ..
REAL (WP) :: ONE,ZERO
PARAMETER (ONE=1.0E+0_WP,ZERO=0.0E+0_WP)
! ..
! .. Executable Statements ..
! Set NOTA and NOTB as true if A and B respectively are not
! transposed and set NROWA, NCOLA and NROWB as the number of rows
! and columns of A and the number of rows of B respectively.
NOTA = LSAME(TRANSA,'N')
NOTB = LSAME(TRANSB,'N')
IF (NOTA) THEN
NROWA = M
NCOLA = K
ELSE
NROWA = K
NCOLA = M
END IF
IF (NOTB) THEN
NROWB = K
ELSE
NROWB = N
END IF
! Test the input parameters.
INFO = 0
IF (( .NOT. NOTA) .AND. ( .NOT. LSAME(TRANSA,'C')) .AND. ( .NOT. LSAME( &
TRANSA,'T'))) THEN
INFO = 1
ELSE IF (( .NOT. NOTB) .AND. ( .NOT. LSAME(TRANSB, &
'C')) .AND. ( .NOT. LSAME(TRANSB,'T'))) THEN
INFO = 2
ELSE IF (M<0) THEN
INFO = 3
ELSE IF (N<0) THEN
INFO = 4
ELSE IF (K<0) THEN
INFO = 5
ELSE IF (LDA<MAX(1,NROWA)) THEN
INFO = 8
ELSE IF (LDB<MAX(1,NROWB)) THEN
INFO = 10
ELSE IF (LDC<MAX(1,M)) THEN
INFO = 13
END IF
IF (INFO/=0) THEN
CALL XERBLA('SGEMM ',INFO)
RETURN
END IF
! Quick return if possible.
IF ((M==0) .OR. (N==0) .OR. (((ALPHA==ZERO) .OR. (K==0)) .AND. (BETA== &
ONE))) RETURN
! And if alpha.eq.zero.
IF (ALPHA==ZERO) THEN
IF (BETA==ZERO) THEN
DO J = 1,N
DO I = 1,M
C(I,J) = ZERO
END DO
END DO
ELSE
DO J = 1,N
DO I = 1,M
C(I,J) = BETA*C(I,J)
END DO
END DO
END IF
RETURN
END IF
! Start the operations.
IF (NOTB) THEN
IF (NOTA) THEN
! Form C := alpha*A*B + beta*C.
DO J = 1,N
IF (BETA==ZERO) THEN
DO I = 1,M
C(I,J) = ZERO
END DO
ELSE IF (BETA/=ONE) THEN
DO I = 1,M
C(I,J) = BETA*C(I,J)
END DO
END IF
DO L = 1,K
IF (B(L,J)/=ZERO) THEN
TEMP = ALPHA*B(L,J)
DO I = 1,M
C(I,J) = C(I,J)+TEMP*A(I,L)
END DO
END IF
END DO
END DO
ELSE
! Form C := alpha*A'*B + beta*C
DO J = 1,N
DO I = 1,M
TEMP = ZERO
DO L = 1,K
TEMP = TEMP+A(L,I)*B(L,J)
END DO
IF (BETA==ZERO) THEN
C(I,J) = ALPHA*TEMP
ELSE
C(I,J) = ALPHA*TEMP+BETA*C(I,J)
END IF
END DO
END DO
END IF
ELSE
IF (NOTA) THEN
! Form C := alpha*A*B' + beta*C
DO J = 1,N
IF (BETA==ZERO) THEN
DO I = 1,M
C(I,J) = ZERO
END DO
ELSE IF (BETA/=ONE) THEN
DO I = 1,M
C(I,J) = BETA*C(I,J)
END DO
END IF
DO L = 1,K
IF (B(J,L)/=ZERO) THEN
TEMP = ALPHA*B(J,L)
DO I = 1,M
C(I,J) = C(I,J)+TEMP*A(I,L)
END DO
END IF
END DO
END DO
ELSE
! Form C := alpha*A'*B' + beta*C
DO J = 1,N
DO I = 1,M
TEMP = ZERO
DO L = 1,K
TEMP = TEMP+A(L,I)*B(J,L)
END DO
IF (BETA==ZERO) THEN
C(I,J) = ALPHA*TEMP
ELSE
C(I,J) = ALPHA*TEMP+BETA*C(I,J)
END IF
END DO
END DO
END IF
END IF
RETURN
! End of SGEMM .
END SUBROUTINE SGEMM
SUBROUTINE SGEMV(TRANS,M,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
USE DDPRECISION,ONLY : WP
! .. Scalar Arguments ..
REAL (WP) :: ALPHA,BETA
INTEGER :: INCX,INCY,LDA,M,N
CHARACTER (1) :: TRANS
! .. Array Arguments ..
REAL (WP) :: A(LDA,*),X(*),Y(*)
! ..
! Purpose
! =======
! SGEMV performs one of the matrix-vector operations
! y := alpha*A*x + beta*y, or y := alpha*A'*x + beta*y,
! where alpha and beta are scalars, x and y are vectors and A is an
! m by n matrix.
! Parameters
! ==========
! TRANS - CHARACTER*1.
! On entry, TRANS specifies the operation to be performed as
! follows:
! TRANS = 'N' or 'n' y := alpha*A*x + beta*y.
! TRANS = 'T' or 't' y := alpha*A'*x + beta*y.
! TRANS = 'C' or 'c' y := alpha*A'*x + beta*y.
! Unchanged on exit.
! M - INTEGER.
! On entry, M specifies the number of rows of the matrix A.
! M must be at least zero.
! Unchanged on exit.
! N - INTEGER.
! On entry, N specifies the number of columns of the matrix A.
! N must be at least zero.
! Unchanged on exit.
! ALPHA - REAL .
! On entry, ALPHA specifies the scalar alpha.
! Unchanged on exit.
! A - REAL array of DIMENSION ( LDA, n ).
! Before entry, the leading m by n part of the array A must
! contain the matrix of coefficients.
! Unchanged on exit.
! LDA - INTEGER.
! On entry, LDA specifies the first dimension of A as declared
! in the calling (sub) program. LDA must be at least
! max( 1, m ).
! Unchanged on exit.
! X - REAL array of DIMENSION at least
! ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'
! and at least
! ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.
! Before entry, the incremented array X must contain the
! vector x.
! Unchanged on exit.
! INCX - INTEGER.
! On entry, INCX specifies the increment for the elements of
! X. INCX must not be zero.
! Unchanged on exit.
! BETA - REAL .
! On entry, BETA specifies the scalar beta. When BETA is
! supplied as zero then Y need not be set on input.
! Unchanged on exit.
! Y - REAL array of DIMENSION at least
! ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'
! and at least
! ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.
! Before entry with BETA non-zero, the incremented array Y
! must contain the vector y. On exit, Y is overwritten by the
! updated vector y.
! INCY - INTEGER.
! On entry, INCY specifies the increment for the elements of
! Y. INCY must not be zero.
! Unchanged on exit.
! Level 2 Blas routine.
! -- Written on 22-October-1986.
! Jack Dongarra, Argonne National Lab.
! Jeremy Du Croz, Nag Central Office.
! Sven Hammarling, Nag Central Office.
! Richard Hanson, Sandia National Labs.
! .. Parameters ..
REAL (WP) :: ONE,ZERO
PARAMETER (ONE=1.0E+0_WP,ZERO=0.0E+0_WP)
! .. Local Scalars ..
REAL (WP) :: TEMP
INTEGER :: I,INFO,IX,IY,J,JX,JY,KX,KY,LENX,LENY
! .. External Functions ..
LOGICAL :: LSAME
EXTERNAL LSAME
! .. External Subroutines ..
EXTERNAL XERBLA
! .. Intrinsic Functions ..
INTRINSIC MAX
! ..
! .. Executable Statements ..
! Test the input parameters.
INFO = 0
IF ( .NOT. LSAME(TRANS,'N') .AND. .NOT. LSAME(TRANS,'T') .AND. &
.NOT. LSAME(TRANS,'C')) THEN
INFO = 1
ELSE IF (M<0) THEN
INFO = 2
ELSE IF (N<0) THEN
INFO = 3
ELSE IF (LDA<MAX(1,M)) THEN
INFO = 6
ELSE IF (INCX==0) THEN
INFO = 8
ELSE IF (INCY==0) THEN
INFO = 11
END IF
IF (INFO/=0) THEN
CALL XERBLA('SGEMV ',INFO)
RETURN
END IF
! Quick return if possible.
IF ((M==0) .OR. (N==0) .OR. ((ALPHA==ZERO) .AND. (BETA==ONE))) RETURN
! Set LENX and LENY, the lengths of the vectors x and y, and set
! up the start points in X and Y.
IF (LSAME(TRANS,'N')) THEN
LENX = N
LENY = M
ELSE
LENX = M
LENY = N
END IF
IF (INCX>0) THEN
KX = 1
ELSE
KX = 1 - (LENX-1)*INCX
END IF
IF (INCY>0) THEN
KY = 1
ELSE
KY = 1 - (LENY-1)*INCY
END IF
! Start the operations. In this version the elements of A are
! accessed sequentially with one pass through A.
! First form y := beta*y.
IF (BETA/=ONE) THEN
IF (INCY==1) THEN
IF (BETA==ZERO) THEN
DO I = 1,LENY
Y(I) = ZERO
END DO
ELSE
DO I = 1,LENY
Y(I) = BETA*Y(I)
END DO
END IF
ELSE
IY = KY
IF (BETA==ZERO) THEN
DO I = 1,LENY
Y(IY) = ZERO
IY = IY+INCY
END DO
ELSE
DO I = 1,LENY
Y(IY) = BETA*Y(IY)
IY = IY+INCY
END DO
END IF
END IF
END IF
IF (ALPHA==ZERO) RETURN
IF (LSAME(TRANS,'N')) THEN
! Form y := alpha*A*x + y.
JX = KX
IF (INCY==1) THEN
DO J = 1,N
IF (X(JX)/=ZERO) THEN
TEMP = ALPHA*X(JX)
DO I = 1,M
Y(I) = Y(I)+TEMP*A(I,J)
END DO
END IF
JX = JX+INCX
END DO
ELSE
DO J = 1,N
IF (X(JX)/=ZERO) THEN
TEMP = ALPHA*X(JX)
IY = KY
DO I = 1,M
Y(IY) = Y(IY)+TEMP*A(I,J)
IY = IY+INCY
END DO
END IF
JX = JX+INCX
END DO
END IF
ELSE
! Form y := alpha*A'*x + y.
JY = KY
IF (INCX==1) THEN
DO J = 1,N
TEMP = ZERO
DO I = 1,M
TEMP = TEMP+A(I,J)*X(I)
END DO
Y(JY) = Y(JY)+ALPHA*TEMP
JY = JY+INCY
END DO
ELSE
DO J = 1,N
TEMP = ZERO
IX = KX
DO I = 1,M
TEMP = TEMP+A(I,J)*X(IX)
IX = IX+INCX
END DO
Y(JY) = Y(JY)+ALPHA*TEMP
JY = JY+INCY
END DO
END IF
END IF
RETURN
! End of SGEMV .
END SUBROUTINE SGEMV
SUBROUTINE SGER(M,N,ALPHA,X,INCX,Y,INCY,A,LDA)
USE DDPRECISION,ONLY : WP