1 SUBROUTINE DGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
2 ! .. Scalar Arguments ..
3 DOUBLE PRECISION ALPHA,BETA
4 INTEGER K,LDA,LDB,LDC,M,N
5 CHARACTER TRANSA,TRANSB
7 ! .. Array Arguments ..
8 DOUBLE PRECISION A(LDA,*),B(LDB,*),C(LDC,*)
14 ! DGEMM performs one of the matrix-matrix operations
16 ! C := alpha*op( A )*op( B ) + beta*C,
18 ! where op( X ) is one of
20 ! op( X ) = X or op( X ) = X',
22 ! alpha and beta are scalars, and A, B and C are matrices, with op( A )
23 ! an m by k matrix, op( B ) a k by n matrix and C an m by n matrix.
28 ! TRANSA - CHARACTER*1.
29 ! On entry, TRANSA specifies the form of op( A ) to be used in
30 ! the matrix multiplication as follows:
32 ! TRANSA = 'N' or 'n', op( A ) = A.
34 ! TRANSA = 'T' or 't', op( A ) = A'.
36 ! TRANSA = 'C' or 'c', op( A ) = A'.
40 ! TRANSB - CHARACTER*1.
41 ! On entry, TRANSB specifies the form of op( B ) to be used in
42 ! the matrix multiplication as follows:
44 ! TRANSB = 'N' or 'n', op( B ) = B.
46 ! TRANSB = 'T' or 't', op( B ) = B'.
48 ! TRANSB = 'C' or 'c', op( B ) = B'.
53 ! On entry, M specifies the number of rows of the matrix
54 ! op( A ) and of the matrix C. M must be at least zero.
58 ! On entry, N specifies the number of columns of the matrix
59 ! op( B ) and the number of columns of the matrix C. N must be
64 ! On entry, K specifies the number of columns of the matrix
65 ! op( A ) and the number of rows of the matrix op( B ). K must
69 ! ALPHA - DOUBLE PRECISION.
70 ! On entry, ALPHA specifies the scalar alpha.
73 ! A - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is
74 ! k when TRANSA = 'N' or 'n', and is m otherwise.
75 ! Before entry with TRANSA = 'N' or 'n', the leading m by k
76 ! part of the array A must contain the matrix A, otherwise
77 ! the leading k by m part of the array A must contain the
82 ! On entry, LDA specifies the first dimension of A as declared
83 ! in the calling (sub) program. When TRANSA = 'N' or 'n' then
84 ! LDA must be at least max( 1, m ), otherwise LDA must be at
88 ! B - DOUBLE PRECISION array of DIMENSION ( LDB, kb ), where kb is
89 ! n when TRANSB = 'N' or 'n', and is k otherwise.
90 ! Before entry with TRANSB = 'N' or 'n', the leading k by n
91 ! part of the array B must contain the matrix B, otherwise
92 ! the leading n by k part of the array B must contain the
97 ! On entry, LDB specifies the first dimension of B as declared
98 ! in the calling (sub) program. When TRANSB = 'N' or 'n' then
99 ! LDB must be at least max( 1, k ), otherwise LDB must be at
103 ! BETA - DOUBLE PRECISION.
104 ! On entry, BETA specifies the scalar beta. When BETA is
105 ! supplied as zero then C need not be set on input.
108 ! C - DOUBLE PRECISION array of DIMENSION ( LDC, n ).
109 ! Before entry, the leading m by n part of the array C must
110 ! contain the matrix C, except when beta is zero, in which
111 ! case C need not be set on entry.
112 ! On exit, the array C is overwritten by the m by n matrix
113 ! ( alpha*op( A )*op( B ) + beta*C ).
116 ! On entry, LDC specifies the first dimension of C as declared
117 ! in the calling (sub) program. LDC must be at least
122 ! Level 3 Blas routine.
124 ! -- Written on 8-February-1989.
125 ! Jack Dongarra, Argonne National Laboratory.
126 ! Iain Duff, AERE Harwell.
127 ! Jeremy Du Croz, Numerical Algorithms Group Ltd.
128 ! Sven Hammarling, Numerical Algorithms Group Ltd.
131 ! .. External Functions ..
135 ! .. External Subroutines ..
138 ! .. Intrinsic Functions ..
141 ! .. Local Scalars ..
142 DOUBLE PRECISION TEMP
143 INTEGER I,INFO,J,L,NCOLA,NROWA,NROWB
147 DOUBLE PRECISION ONE,ZERO
148 PARAMETER (ONE=1.0D+0,ZERO=0.0D+0)
151 ! Set NOTA and NOTB as true if A and B respectively are not
152 ! transposed and set NROWA, NCOLA and NROWB as the number of rows
153 ! and columns of A and the number of rows of B respectively.
155 NOTA = LSAME(TRANSA,'N')
156 NOTB = LSAME(TRANSB,'N')
170 ! Test the input parameters.
173 IF ((.NOT.NOTA) .AND. (.NOT.LSAME(TRANSA,'C')) .AND. &
174 (.NOT.LSAME(TRANSA,'T'))) THEN
176 ELSE IF ((.NOT.NOTB) .AND. (.NOT.LSAME(TRANSB,'C')) .AND. &
177 (.NOT.LSAME(TRANSB,'T'))) THEN
179 ELSE IF (M.LT.0) THEN
181 ELSE IF (N.LT.0) THEN
183 ELSE IF (K.LT.0) THEN
185 ELSE IF (LDA.LT.MAX(1,NROWA)) THEN
187 ELSE IF (LDB.LT.MAX(1,NROWB)) THEN
189 ELSE IF (LDC.LT.MAX(1,M)) THEN
193 CALL XERBLA('DGEMM ',INFO)
197 ! Quick return if possible.
199 IF ((M.EQ.0) .OR. (N.EQ.0) .OR. &
200 (((ALPHA.EQ.ZERO).OR. (K.EQ.0)).AND. (BETA.EQ.ONE))) RETURN
202 ! And if alpha.eq.zero.
204 IF (ALPHA.EQ.ZERO) THEN
205 IF (BETA.EQ.ZERO) THEN
221 ! Start the operations.
226 ! Form C := alpha*A*B + beta*C.
229 IF (BETA.EQ.ZERO) THEN
233 ELSE IF (BETA.NE.ONE) THEN
239 IF (B(L,J).NE.ZERO) THEN
242 C(I,J) = C(I,J) + TEMP*A(I,L)
249 ! Form C := alpha*A'*B + beta*C
255 TEMP = TEMP + A(L,I)*B(L,J)
257 IF (BETA.EQ.ZERO) THEN
260 C(I,J) = ALPHA*TEMP + BETA*C(I,J)
268 ! Form C := alpha*A*B' + beta*C
271 IF (BETA.EQ.ZERO) THEN
275 ELSE IF (BETA.NE.ONE) THEN
281 IF (B(J,L).NE.ZERO) THEN
284 C(I,J) = C(I,J) + TEMP*A(I,L)
291 ! Form C := alpha*A'*B' + beta*C
297 TEMP = TEMP + A(L,I)*B(J,L)
299 IF (BETA.EQ.ZERO) THEN
302 C(I,J) = ALPHA*TEMP + BETA*C(I,J)