1
SUBROUTINE SGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,
4
* $Id: sgemm.f 19695 2010-10-29 16:51:02Z d3y133 $
3
* =========== DOCUMENTATION ===========
5
* Online html documentation available at
6
* http://www.netlib.org/lapack/explore-html/
11
* SUBROUTINE SGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
13
* .. Scalar Arguments ..
15
* INTEGER K,LDA,LDB,LDC,M,N
16
* CHARACTER TRANSA,TRANSB
18
* .. Array Arguments ..
19
* REAL A(LDA,*),B(LDB,*),C(LDC,*)
28
*> SGEMM performs one of the matrix-matrix operations
30
*> C := alpha*op( A )*op( B ) + beta*C,
32
*> where op( X ) is one of
34
*> op( X ) = X or op( X ) = X**T,
36
*> alpha and beta are scalars, and A, B and C are matrices, with op( A )
37
*> an m by k matrix, op( B ) a k by n matrix and C an m by n matrix.
45
*> TRANSA is CHARACTER*1
46
*> On entry, TRANSA specifies the form of op( A ) to be used in
47
*> the matrix multiplication as follows:
49
*> TRANSA = 'N' or 'n', op( A ) = A.
51
*> TRANSA = 'T' or 't', op( A ) = A**T.
53
*> TRANSA = 'C' or 'c', op( A ) = A**T.
58
*> TRANSB is CHARACTER*1
59
*> On entry, TRANSB specifies the form of op( B ) to be used in
60
*> the matrix multiplication as follows:
62
*> TRANSB = 'N' or 'n', op( B ) = B.
64
*> TRANSB = 'T' or 't', op( B ) = B**T.
66
*> TRANSB = 'C' or 'c', op( B ) = B**T.
72
*> On entry, M specifies the number of rows of the matrix
73
*> op( A ) and of the matrix C. M must be at least zero.
79
*> On entry, N specifies the number of columns of the matrix
80
*> op( B ) and the number of columns of the matrix C. N must be
87
*> On entry, K specifies the number of columns of the matrix
88
*> op( A ) and the number of rows of the matrix op( B ). K must
95
*> On entry, ALPHA specifies the scalar alpha.
100
*> A is REAL array of DIMENSION ( LDA, ka ), where ka is
101
*> k when TRANSA = 'N' or 'n', and is m otherwise.
102
*> Before entry with TRANSA = 'N' or 'n', the leading m by k
103
*> part of the array A must contain the matrix A, otherwise
104
*> the leading k by m part of the array A must contain the
111
*> On entry, LDA specifies the first dimension of A as declared
112
*> in the calling (sub) program. When TRANSA = 'N' or 'n' then
113
*> LDA must be at least max( 1, m ), otherwise LDA must be at
114
*> least max( 1, k ).
119
*> B is REAL array of DIMENSION ( LDB, kb ), where kb is
120
*> n when TRANSB = 'N' or 'n', and is k otherwise.
121
*> Before entry with TRANSB = 'N' or 'n', the leading k by n
122
*> part of the array B must contain the matrix B, otherwise
123
*> the leading n by k part of the array B must contain the
130
*> On entry, LDB specifies the first dimension of B as declared
131
*> in the calling (sub) program. When TRANSB = 'N' or 'n' then
132
*> LDB must be at least max( 1, k ), otherwise LDB must be at
133
*> least max( 1, n ).
139
*> On entry, BETA specifies the scalar beta. When BETA is
140
*> supplied as zero then C need not be set on input.
145
*> C is REAL array of DIMENSION ( LDC, n ).
146
*> Before entry, the leading m by n part of the array C must
147
*> contain the matrix C, except when beta is zero, in which
148
*> case C need not be set on entry.
149
*> On exit, the array C is overwritten by the m by n matrix
150
*> ( alpha*op( A )*op( B ) + beta*C ).
156
*> On entry, LDC specifies the first dimension of C as declared
157
*> in the calling (sub) program. LDC must be at least
164
*> \author Univ. of Tennessee
165
*> \author Univ. of California Berkeley
166
*> \author Univ. of Colorado Denver
169
*> \date November 2011
171
*> \ingroup single_blas_level3
173
*> \par Further Details:
174
* =====================
178
*> Level 3 Blas routine.
180
*> -- Written on 8-February-1989.
181
*> Jack Dongarra, Argonne National Laboratory.
182
*> Iain Duff, AERE Harwell.
183
*> Jeremy Du Croz, Numerical Algorithms Group Ltd.
184
*> Sven Hammarling, Numerical Algorithms Group Ltd.
187
* =====================================================================
188
SUBROUTINE SGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
190
* -- Reference BLAS level3 routine (version 3.4.0) --
191
* -- Reference BLAS is a software package provided by Univ. of Tennessee, --
192
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6
195
* .. Scalar Arguments ..
7
CHARACTER*1 TRANSA, TRANSB
8
INTEGER M, N, K, LDA, LDB, LDC
197
INTEGER K,LDA,LDB,LDC,M,N
198
CHARACTER TRANSA,TRANSB
10
200
* .. Array Arguments ..
11
REAL A( LDA, * ), B( LDB, * ), C( LDC, * )
201
REAL A(LDA,*),B(LDB,*),C(LDC,*)
17
* SGEMM performs one of the matrix-matrix operations
19
* C := alpha*op( A )*op( B ) + beta*C,
21
* where op( X ) is one of
23
* op( X ) = X or op( X ) = X',
25
* alpha and beta are scalars, and A, B and C are matrices, with op( A )
26
* an m by k matrix, op( B ) a k by n matrix and C an m by n matrix.
31
* TRANSA - CHARACTER*1.
32
* On entry, TRANSA specifies the form of op( A ) to be used in
33
* the matrix multiplication as follows:
35
* TRANSA = 'N' or 'n', op( A ) = A.
37
* TRANSA = 'T' or 't', op( A ) = A'.
39
* TRANSA = 'C' or 'c', op( A ) = A'.
43
* TRANSB - CHARACTER*1.
44
* On entry, TRANSB specifies the form of op( B ) to be used in
45
* the matrix multiplication as follows:
47
* TRANSB = 'N' or 'n', op( B ) = B.
49
* TRANSB = 'T' or 't', op( B ) = B'.
51
* TRANSB = 'C' or 'c', op( B ) = B'.
56
* On entry, M specifies the number of rows of the matrix
57
* op( A ) and of the matrix C. M must be at least zero.
61
* On entry, N specifies the number of columns of the matrix
62
* op( B ) and the number of columns of the matrix C. N must be
67
* On entry, K specifies the number of columns of the matrix
68
* op( A ) and the number of rows of the matrix op( B ). K must
73
* On entry, ALPHA specifies the scalar alpha.
76
* A - REAL array of DIMENSION ( LDA, ka ), where ka is
77
* k when TRANSA = 'N' or 'n', and is m otherwise.
78
* Before entry with TRANSA = 'N' or 'n', the leading m by k
79
* part of the array A must contain the matrix A, otherwise
80
* the leading k by m part of the array A must contain the
85
* On entry, LDA specifies the first dimension of A as declared
86
* in the calling (sub) program. When TRANSA = 'N' or 'n' then
87
* LDA must be at least max( 1, m ), otherwise LDA must be at
91
* B - REAL array of DIMENSION ( LDB, kb ), where kb is
92
* n when TRANSB = 'N' or 'n', and is k otherwise.
93
* Before entry with TRANSB = 'N' or 'n', the leading k by n
94
* part of the array B must contain the matrix B, otherwise
95
* the leading n by k part of the array B must contain the
100
* On entry, LDB specifies the first dimension of B as declared
101
* in the calling (sub) program. When TRANSB = 'N' or 'n' then
102
* LDB must be at least max( 1, k ), otherwise LDB must be at
107
* On entry, BETA specifies the scalar beta. When BETA is
108
* supplied as zero then C need not be set on input.
111
* C - REAL array of DIMENSION ( LDC, n ).
112
* Before entry, the leading m by n part of the array C must
113
* contain the matrix C, except when beta is zero, in which
114
* case C need not be set on entry.
115
* On exit, the array C is overwritten by the m by n matrix
116
* ( alpha*op( A )*op( B ) + beta*C ).
119
* On entry, LDC specifies the first dimension of C as declared
120
* in the calling (sub) program. LDC must be at least
125
* Level 3 Blas routine.
127
* -- Written on 8-February-1989.
128
* Jack Dongarra, Argonne National Laboratory.
129
* Iain Duff, AERE Harwell.
130
* Jeremy Du Croz, Numerical Algorithms Group Ltd.
131
* Sven Hammarling, Numerical Algorithms Group Ltd.
204
* =====================================================================
134
206
* .. External Functions ..
137
210
* .. External Subroutines ..
139
213
* .. Intrinsic Functions ..
141
216
* .. Local Scalars ..
143
INTEGER I, INFO, J, L, NCOLA, NROWA, NROWB
218
INTEGER I,INFO,J,L,NCOLA,NROWA,NROWB
145
221
* .. Parameters ..
147
PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
223
PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)
149
* .. Executable Statements ..
151
226
* Set NOTA and NOTB as true if A and B respectively are not
152
227
* transposed and set NROWA, NCOLA and NROWB as the number of rows
153
228
* and columns of A and the number of rows of B respectively.
155
NOTA = LSAME( TRANSA, 'N' )
156
NOTB = LSAME( TRANSB, 'N' )
230
NOTA = LSAME(TRANSA,'N')
231
NOTB = LSAME(TRANSB,'N')
170
245
* Test the input parameters.
173
IF( ( .NOT.NOTA ).AND.
174
$ ( .NOT.LSAME( TRANSA, 'C' ) ).AND.
175
$ ( .NOT.LSAME( TRANSA, 'T' ) ) )THEN
177
ELSE IF( ( .NOT.NOTB ).AND.
178
$ ( .NOT.LSAME( TRANSB, 'C' ) ).AND.
179
$ ( .NOT.LSAME( TRANSB, 'T' ) ) )THEN
181
ELSE IF( M .LT.0 )THEN
183
ELSE IF( N .LT.0 )THEN
185
ELSE IF( K .LT.0 )THEN
187
ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN
189
ELSE IF( LDB.LT.MAX( 1, NROWB ) )THEN
191
ELSE IF( LDC.LT.MAX( 1, M ) )THEN
248
IF ((.NOT.NOTA) .AND. (.NOT.LSAME(TRANSA,'C')) .AND.
249
+ (.NOT.LSAME(TRANSA,'T'))) THEN
251
ELSE IF ((.NOT.NOTB) .AND. (.NOT.LSAME(TRANSB,'C')) .AND.
252
+ (.NOT.LSAME(TRANSB,'T'))) THEN
254
ELSE IF (M.LT.0) THEN
256
ELSE IF (N.LT.0) THEN
258
ELSE IF (K.LT.0) THEN
260
ELSE IF (LDA.LT.MAX(1,NROWA)) THEN
262
ELSE IF (LDB.LT.MAX(1,NROWB)) THEN
264
ELSE IF (LDC.LT.MAX(1,M)) THEN
195
CALL XERBLA( 'SGEMM ', INFO )
268
CALL XERBLA('SGEMM ',INFO)
199
272
* Quick return if possible.
201
IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.
202
$ ( ( ( ALPHA.EQ.ZERO ).OR.( K.EQ.0 ) ).AND.( BETA.EQ.ONE ) ) )
274
IF ((M.EQ.0) .OR. (N.EQ.0) .OR.
275
+ (((ALPHA.EQ.ZERO).OR. (K.EQ.0)).AND. (BETA.EQ.ONE))) RETURN
205
277
* And if alpha.eq.zero.
207
IF( ALPHA.EQ.ZERO )THEN
208
IF( BETA.EQ.ZERO )THEN
217
C( I, J ) = BETA*C( I, J )
279
IF (ALPHA.EQ.ZERO) THEN
280
IF (BETA.EQ.ZERO) THEN
224
296
* Start the operations.
229
301
* Form C := alpha*A*B + beta*C.
232
IF( BETA.EQ.ZERO )THEN
236
ELSE IF( BETA.NE.ONE )THEN
238
C( I, J ) = BETA*C( I, J )
242
IF( B( L, J ).NE.ZERO )THEN
243
TEMP = ALPHA*B( L, J )
245
C( I, J ) = C( I, J ) + TEMP*A( I, L )
252
* Form C := alpha*A'*B + beta*C
258
TEMP = TEMP + A( L, I )*B( L, J )
260
IF( BETA.EQ.ZERO )THEN
261
C( I, J ) = ALPHA*TEMP
263
C( I, J ) = ALPHA*TEMP + BETA*C( I, J )
304
IF (BETA.EQ.ZERO) THEN
308
ELSE IF (BETA.NE.ONE) THEN
314
IF (B(L,J).NE.ZERO) THEN
317
C(I,J) = C(I,J) + TEMP*A(I,L)
324
* Form C := alpha*A**T*B + beta*C
330
TEMP = TEMP + A(L,I)*B(L,J)
332
IF (BETA.EQ.ZERO) THEN
335
C(I,J) = ALPHA*TEMP + BETA*C(I,J)
271
* Form C := alpha*A*B' + beta*C
274
IF( BETA.EQ.ZERO )THEN
278
ELSE IF( BETA.NE.ONE )THEN
280
C( I, J ) = BETA*C( I, J )
284
IF( B( J, L ).NE.ZERO )THEN
285
TEMP = ALPHA*B( J, L )
287
C( I, J ) = C( I, J ) + TEMP*A( I, L )
294
* Form C := alpha*A'*B' + beta*C
300
TEMP = TEMP + A( L, I )*B( J, L )
302
IF( BETA.EQ.ZERO )THEN
303
C( I, J ) = ALPHA*TEMP
305
C( I, J ) = ALPHA*TEMP + BETA*C( I, J )
343
* Form C := alpha*A*B**T + beta*C
346
IF (BETA.EQ.ZERO) THEN
350
ELSE IF (BETA.NE.ONE) THEN
356
IF (B(J,L).NE.ZERO) THEN
359
C(I,J) = C(I,J) + TEMP*A(I,L)
366
* Form C := alpha*A**T*B**T + beta*C
372
TEMP = TEMP + A(L,I)*B(J,L)
374
IF (BETA.EQ.ZERO) THEN
377
C(I,J) = ALPHA*TEMP + BETA*C(I,J)