KTH framework for Nek5000 toolboxes; testing version  0.0.1
zgemm.f
Go to the documentation of this file.
1  SUBROUTINE zgemm ( 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  COMPLEX*16 ALPHA, BETA
7 * .. Array Arguments ..
8  COMPLEX*16 A( LDA, * ), B( LDB, * ), C( LDC, * )
9 * ..
10 *
11 * Purpose
12 * =======
13 *
14 * ZGEMM 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' or op( X ) = conjg( 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 ) = conjg( 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 ) = conjg( 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 - COMPLEX*16 .
70 * On entry, ALPHA specifies the scalar alpha.
71 * Unchanged on exit.
72 *
73 * A - COMPLEX*16 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 - COMPLEX*16 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 - COMPLEX*16 .
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 - COMPLEX*16 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 dconjg, max
138 * .. Local Scalars ..
139  LOGICAL CONJA, CONJB, NOTA, NOTB
140  INTEGER I, INFO, J, L, NCOLA, NROWA, NROWB
141  COMPLEX*16 TEMP
142 * .. Parameters ..
143  COMPLEX*16 ONE
144  parameter( one = ( 1.0d+0, 0.0d+0 ) )
145  COMPLEX*16 ZERO
146  parameter( zero = ( 0.0d+0, 0.0d+0 ) )
147 * ..
148 * .. Executable Statements ..
149 *
150 * Set NOTA and NOTB as true if A and B respectively are not
151 * conjugated or transposed, set CONJA and CONJB as true if A and
152 * B respectively are to be transposed but not conjugated and set
153 * NROWA, NCOLA and NROWB as the number of rows and columns of A
154 * and the number of rows of B respectively.
155 *
156  nota = lsame( transa, 'N' )
157  notb = lsame( transb, 'N' )
158  conja = lsame( transa, 'C' )
159  conjb = lsame( transb, 'C' )
160  IF( nota )THEN
161  nrowa = m
162  ncola = k
163  ELSE
164  nrowa = k
165  ncola = m
166  END IF
167  IF( notb )THEN
168  nrowb = k
169  ELSE
170  nrowb = n
171  END IF
172 *
173 * Test the input parameters.
174 *
175  info = 0
176  IF( ( .NOT.nota ).AND.
177  $ ( .NOT.conja ).AND.
178  $ ( .NOT.lsame( transa, 'T' ) ) )THEN
179  info = 1
180  ELSE IF( ( .NOT.notb ).AND.
181  $ ( .NOT.conjb ).AND.
182  $ ( .NOT.lsame( transb, 'T' ) ) )THEN
183  info = 2
184  ELSE IF( m .LT.0 )THEN
185  info = 3
186  ELSE IF( n .LT.0 )THEN
187  info = 4
188  ELSE IF( k .LT.0 )THEN
189  info = 5
190  ELSE IF( lda.LT.max( 1, nrowa ) )THEN
191  info = 8
192  ELSE IF( ldb.LT.max( 1, nrowb ) )THEN
193  info = 10
194  ELSE IF( ldc.LT.max( 1, m ) )THEN
195  info = 13
196  END IF
197  IF( info.NE.0 )THEN
198  CALL xerbla( 'ZGEMM ', info )
199  RETURN
200  END IF
201 *
202 * Quick return if possible.
203 *
204  IF( ( m.EQ.0 ).OR.( n.EQ.0 ).OR.
205  $ ( ( ( alpha.EQ.zero ).OR.( k.EQ.0 ) ).AND.( beta.EQ.one ) ) )
206  $ RETURN
207 *
208 * And when alpha.eq.zero.
209 *
210  IF( alpha.EQ.zero )THEN
211  IF( beta.EQ.zero )THEN
212  DO 20, j = 1, n
213  DO 10, i = 1, m
214  c( i, j ) = zero
215  10 CONTINUE
216  20 CONTINUE
217  ELSE
218  DO 40, j = 1, n
219  DO 30, i = 1, m
220  c( i, j ) = beta*c( i, j )
221  30 CONTINUE
222  40 CONTINUE
223  END IF
224  RETURN
225  END IF
226 *
227 * Start the operations.
228 *
229  IF( notb )THEN
230  IF( nota )THEN
231 *
232 * Form C := alpha*A*B + beta*C.
233 *
234  DO 90, j = 1, n
235  IF( beta.EQ.zero )THEN
236  DO 50, i = 1, m
237  c( i, j ) = zero
238  50 CONTINUE
239  ELSE IF( beta.NE.one )THEN
240  DO 60, i = 1, m
241  c( i, j ) = beta*c( i, j )
242  60 CONTINUE
243  END IF
244  DO 80, l = 1, k
245  IF( b( l, j ).NE.zero )THEN
246  temp = alpha*b( l, j )
247  DO 70, i = 1, m
248  c( i, j ) = c( i, j ) + temp*a( i, l )
249  70 CONTINUE
250  END IF
251  80 CONTINUE
252  90 CONTINUE
253  ELSE IF( conja )THEN
254 *
255 * Form C := alpha*conjg( A' )*B + beta*C.
256 *
257  DO 120, j = 1, n
258  DO 110, i = 1, m
259  temp = zero
260  DO 100, l = 1, k
261  temp = temp + dconjg( a( l, i ) )*b( l, j )
262  100 CONTINUE
263  IF( beta.EQ.zero )THEN
264  c( i, j ) = alpha*temp
265  ELSE
266  c( i, j ) = alpha*temp + beta*c( i, j )
267  END IF
268  110 CONTINUE
269  120 CONTINUE
270  ELSE
271 *
272 * Form C := alpha*A'*B + beta*C
273 *
274  DO 150, j = 1, n
275  DO 140, i = 1, m
276  temp = zero
277  DO 130, l = 1, k
278  temp = temp + a( l, i )*b( l, j )
279  130 CONTINUE
280  IF( beta.EQ.zero )THEN
281  c( i, j ) = alpha*temp
282  ELSE
283  c( i, j ) = alpha*temp + beta*c( i, j )
284  END IF
285  140 CONTINUE
286  150 CONTINUE
287  END IF
288  ELSE IF( nota )THEN
289  IF( conjb )THEN
290 *
291 * Form C := alpha*A*conjg( B' ) + beta*C.
292 *
293  DO 200, j = 1, n
294  IF( beta.EQ.zero )THEN
295  DO 160, i = 1, m
296  c( i, j ) = zero
297  160 CONTINUE
298  ELSE IF( beta.NE.one )THEN
299  DO 170, i = 1, m
300  c( i, j ) = beta*c( i, j )
301  170 CONTINUE
302  END IF
303  DO 190, l = 1, k
304  IF( b( j, l ).NE.zero )THEN
305  temp = alpha*dconjg( b( j, l ) )
306  DO 180, i = 1, m
307  c( i, j ) = c( i, j ) + temp*a( i, l )
308  180 CONTINUE
309  END IF
310  190 CONTINUE
311  200 CONTINUE
312  ELSE
313 *
314 * Form C := alpha*A*B' + beta*C
315 *
316  DO 250, j = 1, n
317  IF( beta.EQ.zero )THEN
318  DO 210, i = 1, m
319  c( i, j ) = zero
320  210 CONTINUE
321  ELSE IF( beta.NE.one )THEN
322  DO 220, i = 1, m
323  c( i, j ) = beta*c( i, j )
324  220 CONTINUE
325  END IF
326  DO 240, l = 1, k
327  IF( b( j, l ).NE.zero )THEN
328  temp = alpha*b( j, l )
329  DO 230, i = 1, m
330  c( i, j ) = c( i, j ) + temp*a( i, l )
331  230 CONTINUE
332  END IF
333  240 CONTINUE
334  250 CONTINUE
335  END IF
336  ELSE IF( conja )THEN
337  IF( conjb )THEN
338 *
339 * Form C := alpha*conjg( A' )*conjg( B' ) + beta*C.
340 *
341  DO 280, j = 1, n
342  DO 270, i = 1, m
343  temp = zero
344  DO 260, l = 1, k
345  temp = temp +
346  $ dconjg( a( l, i ) )*dconjg( b( j, l ) )
347  260 CONTINUE
348  IF( beta.EQ.zero )THEN
349  c( i, j ) = alpha*temp
350  ELSE
351  c( i, j ) = alpha*temp + beta*c( i, j )
352  END IF
353  270 CONTINUE
354  280 CONTINUE
355  ELSE
356 *
357 * Form C := alpha*conjg( A' )*B' + beta*C
358 *
359  DO 310, j = 1, n
360  DO 300, i = 1, m
361  temp = zero
362  DO 290, l = 1, k
363  temp = temp + dconjg( a( l, i ) )*b( j, l )
364  290 CONTINUE
365  IF( beta.EQ.zero )THEN
366  c( i, j ) = alpha*temp
367  ELSE
368  c( i, j ) = alpha*temp + beta*c( i, j )
369  END IF
370  300 CONTINUE
371  310 CONTINUE
372  END IF
373  ELSE
374  IF( conjb )THEN
375 *
376 * Form C := alpha*A'*conjg( B' ) + beta*C
377 *
378  DO 340, j = 1, n
379  DO 330, i = 1, m
380  temp = zero
381  DO 320, l = 1, k
382  temp = temp + a( l, i )*dconjg( b( j, l ) )
383  320 CONTINUE
384  IF( beta.EQ.zero )THEN
385  c( i, j ) = alpha*temp
386  ELSE
387  c( i, j ) = alpha*temp + beta*c( i, j )
388  END IF
389  330 CONTINUE
390  340 CONTINUE
391  ELSE
392 *
393 * Form C := alpha*A'*B' + beta*C
394 *
395  DO 370, j = 1, n
396  DO 360, i = 1, m
397  temp = zero
398  DO 350, l = 1, k
399  temp = temp + a( l, i )*b( j, l )
400  350 CONTINUE
401  IF( beta.EQ.zero )THEN
402  c( i, j ) = alpha*temp
403  ELSE
404  c( i, j ) = alpha*temp + beta*c( i, j )
405  END IF
406  360 CONTINUE
407  370 CONTINUE
408  END IF
409  END IF
410 *
411  RETURN
412 *
413 * End of ZGEMM .
414 *
415  END
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2
subroutine zgemm(TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
Definition: zgemm.f:3