KTH framework for Nek5000 toolboxes; testing version  0.0.1
dgemm.f
Go to the documentation of this file.
1  SUBROUTINE dgemm ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,
2  $ BETA, C, LDC )
3 * .. Scalar Arguments ..
4  CHARACTER*1 TRANSA, TRANSB
5  INTEGER M, N, K, LDA, LDB, LDC
6  DOUBLE PRECISION ALPHA, BETA
7 * .. Array Arguments ..
8  DOUBLE PRECISION A( LDA, * ), B( LDB, * ), C( LDC, * )
9 * ..
10 *
11 * Purpose
12 * =======
13 *
14 * DGEMM performs one of the matrix-matrix operations
15 *
16 * C := alpha*op( A )*op( B ) + beta*C,
17 *
18 * where op( X ) is one of
19 *
20 * op( X ) = X or op( X ) = X',
21 *
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.
24 *
25 * Parameters
26 * ==========
27 *
28 * TRANSA - CHARACTER*1.
29 * On entry, TRANSA specifies the form of op( A ) to be used in
30 * the matrix multiplication as follows:
31 *
32 * TRANSA = 'N' or 'n', op( A ) = A.
33 *
34 * TRANSA = 'T' or 't', op( A ) = A'.
35 *
36 * TRANSA = 'C' or 'c', op( A ) = A'.
37 *
38 * Unchanged on exit.
39 *
40 * TRANSB - CHARACTER*1.
41 * On entry, TRANSB specifies the form of op( B ) to be used in
42 * the matrix multiplication as follows:
43 *
44 * TRANSB = 'N' or 'n', op( B ) = B.
45 *
46 * TRANSB = 'T' or 't', op( B ) = B'.
47 *
48 * TRANSB = 'C' or 'c', op( B ) = B'.
49 *
50 * Unchanged on exit.
51 *
52 * M - INTEGER.
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.
55 * Unchanged on exit.
56 *
57 * N - INTEGER.
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
60 * at least zero.
61 * Unchanged on exit.
62 *
63 * K - INTEGER.
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
66 * be at least zero.
67 * Unchanged on exit.
68 *
69 * ALPHA - DOUBLE PRECISION.
70 * On entry, ALPHA specifies the scalar alpha.
71 * Unchanged on exit.
72 *
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
78 * matrix A.
79 * Unchanged on exit.
80 *
81 * LDA - INTEGER.
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
85 * least max( 1, k ).
86 * Unchanged on exit.
87 *
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
93 * matrix B.
94 * Unchanged on exit.
95 *
96 * LDB - INTEGER.
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
100 * least max( 1, n ).
101 * Unchanged on exit.
102 *
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.
106 * Unchanged on exit.
107 *
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 ).
114 *
115 * LDC - INTEGER.
116 * On entry, LDC specifies the first dimension of C as declared
117 * in the calling (sub) program. LDC must be at least
118 * max( 1, m ).
119 * Unchanged on exit.
120 *
121 *
122 * Level 3 Blas routine.
123 *
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.
129 *
130 *
131 * .. External Functions ..
132  LOGICAL LSAME
133  EXTERNAL lsame
134 * .. External Subroutines ..
135  EXTERNAL xerbla
136 * .. Intrinsic Functions ..
137  INTRINSIC max
138 * .. Local Scalars ..
139  LOGICAL NOTA, NOTB
140  INTEGER I, INFO, J, L, NCOLA, NROWA, NROWB
141  DOUBLE PRECISION TEMP
142 * .. Parameters ..
143  DOUBLE PRECISION ONE , ZERO
144  parameter( one = 1.0d+0, zero = 0.0d+0 )
145 * ..
146 * .. Executable Statements ..
147 *
148 * Set NOTA and NOTB as true if A and B respectively are not
149 * transposed and set NROWA, NCOLA and NROWB as the number of rows
150 * and columns of A and the number of rows of B respectively.
151 *
152  nota = lsame( transa, 'N' )
153  notb = lsame( transb, 'N' )
154  IF( nota )THEN
155  nrowa = m
156  ncola = k
157  ELSE
158  nrowa = k
159  ncola = m
160  END IF
161  IF( notb )THEN
162  nrowb = k
163  ELSE
164  nrowb = n
165  END IF
166 *
167 * Test the input parameters.
168 *
169  info = 0
170  IF( ( .NOT.nota ).AND.
171  $ ( .NOT.lsame( transa, 'C' ) ).AND.
172  $ ( .NOT.lsame( transa, 'T' ) ) )THEN
173  info = 1
174  ELSE IF( ( .NOT.notb ).AND.
175  $ ( .NOT.lsame( transb, 'C' ) ).AND.
176  $ ( .NOT.lsame( transb, 'T' ) ) )THEN
177  info = 2
178  ELSE IF( m .LT.0 )THEN
179  info = 3
180  ELSE IF( n .LT.0 )THEN
181  info = 4
182  ELSE IF( k .LT.0 )THEN
183  info = 5
184  ELSE IF( lda.LT.max( 1, nrowa ) )THEN
185  info = 8
186  ELSE IF( ldb.LT.max( 1, nrowb ) )THEN
187  info = 10
188  ELSE IF( ldc.LT.max( 1, m ) )THEN
189  info = 13
190  END IF
191  IF( info.NE.0 )THEN
192  CALL xerbla( 'DGEMM ', info )
193  RETURN
194  END IF
195 *
196 * Quick return if possible.
197 *
198  IF( ( m.EQ.0 ).OR.( n.EQ.0 ).OR.
199  $ ( ( ( alpha.EQ.zero ).OR.( k.EQ.0 ) ).AND.( beta.EQ.one ) ) )
200  $ RETURN
201 *
202 * And if alpha.eq.zero.
203 *
204  IF( alpha.EQ.zero )THEN
205  IF( beta.EQ.zero )THEN
206  DO 20, j = 1, n
207  DO 10, i = 1, m
208  c( i, j ) = zero
209  10 CONTINUE
210  20 CONTINUE
211  ELSE
212  DO 40, j = 1, n
213  DO 30, i = 1, m
214  c( i, j ) = beta*c( i, j )
215  30 CONTINUE
216  40 CONTINUE
217  END IF
218  RETURN
219  END IF
220 *
221 * Start the operations.
222 *
223  IF( notb )THEN
224  IF( nota )THEN
225 *
226 * Form C := alpha*A*B + beta*C.
227 *
228  DO 90, j = 1, n
229  IF( beta.EQ.zero )THEN
230  DO 50, i = 1, m
231  c( i, j ) = zero
232  50 CONTINUE
233  ELSE IF( beta.NE.one )THEN
234  DO 60, i = 1, m
235  c( i, j ) = beta*c( i, j )
236  60 CONTINUE
237  END IF
238  DO 80, l = 1, k
239  IF( b( l, j ).NE.zero )THEN
240  temp = alpha*b( l, j )
241  DO 70, i = 1, m
242  c( i, j ) = c( i, j ) + temp*a( i, l )
243  70 CONTINUE
244  END IF
245  80 CONTINUE
246  90 CONTINUE
247  ELSE
248 *
249 * Form C := alpha*A'*B + beta*C
250 *
251  DO 120, j = 1, n
252  DO 110, i = 1, m
253  temp = zero
254  DO 100, l = 1, k
255  temp = temp + a( l, i )*b( l, j )
256  100 CONTINUE
257  IF( beta.EQ.zero )THEN
258  c( i, j ) = alpha*temp
259  ELSE
260  c( i, j ) = alpha*temp + beta*c( i, j )
261  END IF
262  110 CONTINUE
263  120 CONTINUE
264  END IF
265  ELSE
266  IF( nota )THEN
267 *
268 * Form C := alpha*A*B' + beta*C
269 *
270  DO 170, j = 1, n
271  IF( beta.EQ.zero )THEN
272  DO 130, i = 1, m
273  c( i, j ) = zero
274  130 CONTINUE
275  ELSE IF( beta.NE.one )THEN
276  DO 140, i = 1, m
277  c( i, j ) = beta*c( i, j )
278  140 CONTINUE
279  END IF
280  DO 160, l = 1, k
281  IF( b( j, l ).NE.zero )THEN
282  temp = alpha*b( j, l )
283  DO 150, i = 1, m
284  c( i, j ) = c( i, j ) + temp*a( i, l )
285  150 CONTINUE
286  END IF
287  160 CONTINUE
288  170 CONTINUE
289  ELSE
290 *
291 * Form C := alpha*A'*B' + beta*C
292 *
293  DO 200, j = 1, n
294  DO 190, i = 1, m
295  temp = zero
296  DO 180, l = 1, k
297  temp = temp + a( l, i )*b( j, l )
298  180 CONTINUE
299  IF( beta.EQ.zero )THEN
300  c( i, j ) = alpha*temp
301  ELSE
302  c( i, j ) = alpha*temp + beta*c( i, j )
303  END IF
304  190 CONTINUE
305  200 CONTINUE
306  END IF
307  END IF
308 *
309  RETURN
310 *
311 * End of DGEMM .
312 *
313  END
subroutine dgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
Definition: dgemm.f:3
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2