LAPACK  3.4.2 LAPACK: Linear Algebra PACKage
cgemm.f
Go to the documentation of this file.
1 *> \brief \b CGEMM
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 * Definition:
9 * ===========
10 *
11 * SUBROUTINE CGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
12 *
13 * .. Scalar Arguments ..
14 * COMPLEX ALPHA,BETA
15 * INTEGER K,LDA,LDB,LDC,M,N
16 * CHARACTER TRANSA,TRANSB
17 * ..
18 * .. Array Arguments ..
19 * COMPLEX A(LDA,*),B(LDB,*),C(LDC,*)
20 * ..
21 *
22 *
23 *> \par Purpose:
24 * =============
25 *>
26 *> \verbatim
27 *>
28 *> CGEMM performs one of the matrix-matrix operations
29 *>
30 *> C := alpha*op( A )*op( B ) + beta*C,
31 *>
32 *> where op( X ) is one of
33 *>
34 *> op( X ) = X or op( X ) = X**T or op( X ) = X**H,
35 *>
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.
38 *> \endverbatim
39 *
40 * Arguments:
41 * ==========
42 *
43 *> \param[in] TRANSA
44 *> \verbatim
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:
48 *>
49 *> TRANSA = 'N' or 'n', op( A ) = A.
50 *>
51 *> TRANSA = 'T' or 't', op( A ) = A**T.
52 *>
53 *> TRANSA = 'C' or 'c', op( A ) = A**H.
54 *> \endverbatim
55 *>
56 *> \param[in] TRANSB
57 *> \verbatim
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:
61 *>
62 *> TRANSB = 'N' or 'n', op( B ) = B.
63 *>
64 *> TRANSB = 'T' or 't', op( B ) = B**T.
65 *>
66 *> TRANSB = 'C' or 'c', op( B ) = B**H.
67 *> \endverbatim
68 *>
69 *> \param[in] M
70 *> \verbatim
71 *> M is INTEGER
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.
74 *> \endverbatim
75 *>
76 *> \param[in] N
77 *> \verbatim
78 *> N is INTEGER
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
81 *> at least zero.
82 *> \endverbatim
83 *>
84 *> \param[in] K
85 *> \verbatim
86 *> K is INTEGER
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
89 *> be at least zero.
90 *> \endverbatim
91 *>
92 *> \param[in] ALPHA
93 *> \verbatim
94 *> ALPHA is COMPLEX
95 *> On entry, ALPHA specifies the scalar alpha.
96 *> \endverbatim
97 *>
98 *> \param[in] A
99 *> \verbatim
100 *> A is COMPLEX 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
105 *> matrix A.
106 *> \endverbatim
107 *>
108 *> \param[in] LDA
109 *> \verbatim
110 *> LDA is INTEGER
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 ).
115 *> \endverbatim
116 *>
117 *> \param[in] B
118 *> \verbatim
119 *> B is COMPLEX 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
124 *> matrix B.
125 *> \endverbatim
126 *>
127 *> \param[in] LDB
128 *> \verbatim
129 *> LDB is INTEGER
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 ).
134 *> \endverbatim
135 *>
136 *> \param[in] BETA
137 *> \verbatim
138 *> BETA is COMPLEX
139 *> On entry, BETA specifies the scalar beta. When BETA is
140 *> supplied as zero then C need not be set on input.
141 *> \endverbatim
142 *>
143 *> \param[in,out] C
144 *> \verbatim
145 *> C is COMPLEX 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 ).
151 *> \endverbatim
152 *>
153 *> \param[in] LDC
154 *> \verbatim
155 *> LDC is INTEGER
156 *> On entry, LDC specifies the first dimension of C as declared
157 *> in the calling (sub) program. LDC must be at least
158 *> max( 1, m ).
159 *> \endverbatim
160 *
161 * Authors:
162 * ========
163 *
164 *> \author Univ. of Tennessee
165 *> \author Univ. of California Berkeley
166 *> \author Univ. of Colorado Denver
167 *> \author NAG Ltd.
168 *
169 *> \date November 2011
170 *
171 *> \ingroup complex_blas_level3
172 *
173 *> \par Further Details:
174 * =====================
175 *>
176 *> \verbatim
177 *>
178 *> Level 3 Blas routine.
179 *>
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.
185 *> \endverbatim
186 *>
187 * =====================================================================
188  SUBROUTINE cgemm(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
189 *
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..--
193 * November 2011
194 *
195 * .. Scalar Arguments ..
196  COMPLEX alpha,beta
197  INTEGER k,lda,ldb,ldc,m,n
198  CHARACTER transa,transb
199 * ..
200 * .. Array Arguments ..
201  COMPLEX a(lda,*),b(ldb,*),c(ldc,*)
202 * ..
203 *
204 * =====================================================================
205 *
206 * .. External Functions ..
207  LOGICAL lsame
208  EXTERNAL lsame
209 * ..
210 * .. External Subroutines ..
211  EXTERNAL xerbla
212 * ..
213 * .. Intrinsic Functions ..
214  INTRINSIC conjg,max
215 * ..
216 * .. Local Scalars ..
217  COMPLEX temp
218  INTEGER i,info,j,l,ncola,nrowa,nrowb
219  LOGICAL conja,conjb,nota,notb
220 * ..
221 * .. Parameters ..
222  COMPLEX one
223  parameter(one= (1.0e+0,0.0e+0))
224  COMPLEX zero
225  parameter(zero= (0.0e+0,0.0e+0))
226 * ..
227 *
228 * Set NOTA and NOTB as true if A and B respectively are not
229 * conjugated or transposed, set CONJA and CONJB as true if A and
230 * B respectively are to be transposed but not conjugated and set
231 * NROWA, NCOLA and NROWB as the number of rows and columns of A
232 * and the number of rows of B respectively.
233 *
234  nota = lsame(transa,'N')
235  notb = lsame(transb,'N')
236  conja = lsame(transa,'C')
237  conjb = lsame(transb,'C')
238  IF (nota) THEN
239  nrowa = m
240  ncola = k
241  ELSE
242  nrowa = k
243  ncola = m
244  END IF
245  IF (notb) THEN
246  nrowb = k
247  ELSE
248  nrowb = n
249  END IF
250 *
251 * Test the input parameters.
252 *
253  info = 0
254  IF ((.NOT.nota) .AND. (.NOT.conja) .AND.
255  + (.NOT.lsame(transa,'T'))) THEN
256  info = 1
257  ELSE IF ((.NOT.notb) .AND. (.NOT.conjb) .AND.
258  + (.NOT.lsame(transb,'T'))) THEN
259  info = 2
260  ELSE IF (m.LT.0) THEN
261  info = 3
262  ELSE IF (n.LT.0) THEN
263  info = 4
264  ELSE IF (k.LT.0) THEN
265  info = 5
266  ELSE IF (lda.LT.max(1,nrowa)) THEN
267  info = 8
268  ELSE IF (ldb.LT.max(1,nrowb)) THEN
269  info = 10
270  ELSE IF (ldc.LT.max(1,m)) THEN
271  info = 13
272  END IF
273  IF (info.NE.0) THEN
274  CALL xerbla('CGEMM ',info)
275  return
276  END IF
277 *
278 * Quick return if possible.
279 *
280  IF ((m.EQ.0) .OR. (n.EQ.0) .OR.
281  + (((alpha.EQ.zero).OR. (k.EQ.0)).AND. (beta.EQ.one))) return
282 *
283 * And when alpha.eq.zero.
284 *
285  IF (alpha.EQ.zero) THEN
286  IF (beta.EQ.zero) THEN
287  DO 20 j = 1,n
288  DO 10 i = 1,m
289  c(i,j) = zero
290  10 continue
291  20 continue
292  ELSE
293  DO 40 j = 1,n
294  DO 30 i = 1,m
295  c(i,j) = beta*c(i,j)
296  30 continue
297  40 continue
298  END IF
299  return
300  END IF
301 *
302 * Start the operations.
303 *
304  IF (notb) THEN
305  IF (nota) THEN
306 *
307 * Form C := alpha*A*B + beta*C.
308 *
309  DO 90 j = 1,n
310  IF (beta.EQ.zero) THEN
311  DO 50 i = 1,m
312  c(i,j) = zero
313  50 continue
314  ELSE IF (beta.NE.one) THEN
315  DO 60 i = 1,m
316  c(i,j) = beta*c(i,j)
317  60 continue
318  END IF
319  DO 80 l = 1,k
320  IF (b(l,j).NE.zero) THEN
321  temp = alpha*b(l,j)
322  DO 70 i = 1,m
323  c(i,j) = c(i,j) + temp*a(i,l)
324  70 continue
325  END IF
326  80 continue
327  90 continue
328  ELSE IF (conja) THEN
329 *
330 * Form C := alpha*A**H*B + beta*C.
331 *
332  DO 120 j = 1,n
333  DO 110 i = 1,m
334  temp = zero
335  DO 100 l = 1,k
336  temp = temp + conjg(a(l,i))*b(l,j)
337  100 continue
338  IF (beta.EQ.zero) THEN
339  c(i,j) = alpha*temp
340  ELSE
341  c(i,j) = alpha*temp + beta*c(i,j)
342  END IF
343  110 continue
344  120 continue
345  ELSE
346 *
347 * Form C := alpha*A**T*B + beta*C
348 *
349  DO 150 j = 1,n
350  DO 140 i = 1,m
351  temp = zero
352  DO 130 l = 1,k
353  temp = temp + a(l,i)*b(l,j)
354  130 continue
355  IF (beta.EQ.zero) THEN
356  c(i,j) = alpha*temp
357  ELSE
358  c(i,j) = alpha*temp + beta*c(i,j)
359  END IF
360  140 continue
361  150 continue
362  END IF
363  ELSE IF (nota) THEN
364  IF (conjb) THEN
365 *
366 * Form C := alpha*A*B**H + beta*C.
367 *
368  DO 200 j = 1,n
369  IF (beta.EQ.zero) THEN
370  DO 160 i = 1,m
371  c(i,j) = zero
372  160 continue
373  ELSE IF (beta.NE.one) THEN
374  DO 170 i = 1,m
375  c(i,j) = beta*c(i,j)
376  170 continue
377  END IF
378  DO 190 l = 1,k
379  IF (b(j,l).NE.zero) THEN
380  temp = alpha*conjg(b(j,l))
381  DO 180 i = 1,m
382  c(i,j) = c(i,j) + temp*a(i,l)
383  180 continue
384  END IF
385  190 continue
386  200 continue
387  ELSE
388 *
389 * Form C := alpha*A*B**T + beta*C
390 *
391  DO 250 j = 1,n
392  IF (beta.EQ.zero) THEN
393  DO 210 i = 1,m
394  c(i,j) = zero
395  210 continue
396  ELSE IF (beta.NE.one) THEN
397  DO 220 i = 1,m
398  c(i,j) = beta*c(i,j)
399  220 continue
400  END IF
401  DO 240 l = 1,k
402  IF (b(j,l).NE.zero) THEN
403  temp = alpha*b(j,l)
404  DO 230 i = 1,m
405  c(i,j) = c(i,j) + temp*a(i,l)
406  230 continue
407  END IF
408  240 continue
409  250 continue
410  END IF
411  ELSE IF (conja) THEN
412  IF (conjb) THEN
413 *
414 * Form C := alpha*A**H*B**H + beta*C.
415 *
416  DO 280 j = 1,n
417  DO 270 i = 1,m
418  temp = zero
419  DO 260 l = 1,k
420  temp = temp + conjg(a(l,i))*conjg(b(j,l))
421  260 continue
422  IF (beta.EQ.zero) THEN
423  c(i,j) = alpha*temp
424  ELSE
425  c(i,j) = alpha*temp + beta*c(i,j)
426  END IF
427  270 continue
428  280 continue
429  ELSE
430 *
431 * Form C := alpha*A**H*B**T + beta*C
432 *
433  DO 310 j = 1,n
434  DO 300 i = 1,m
435  temp = zero
436  DO 290 l = 1,k
437  temp = temp + conjg(a(l,i))*b(j,l)
438  290 continue
439  IF (beta.EQ.zero) THEN
440  c(i,j) = alpha*temp
441  ELSE
442  c(i,j) = alpha*temp + beta*c(i,j)
443  END IF
444  300 continue
445  310 continue
446  END IF
447  ELSE
448  IF (conjb) THEN
449 *
450 * Form C := alpha*A**T*B**H + beta*C
451 *
452  DO 340 j = 1,n
453  DO 330 i = 1,m
454  temp = zero
455  DO 320 l = 1,k
456  temp = temp + a(l,i)*conjg(b(j,l))
457  320 continue
458  IF (beta.EQ.zero) THEN
459  c(i,j) = alpha*temp
460  ELSE
461  c(i,j) = alpha*temp + beta*c(i,j)
462  END IF
463  330 continue
464  340 continue
465  ELSE
466 *
467 * Form C := alpha*A**T*B**T + beta*C
468 *
469  DO 370 j = 1,n
470  DO 360 i = 1,m
471  temp = zero
472  DO 350 l = 1,k
473  temp = temp + a(l,i)*b(j,l)
474  350 continue
475  IF (beta.EQ.zero) THEN
476  c(i,j) = alpha*temp
477  ELSE
478  c(i,j) = alpha*temp + beta*c(i,j)
479  END IF
480  360 continue
481  370 continue
482  END IF
483  END IF
484 *
485  return
486 *
487 * End of CGEMM .
488 *
489  END