LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zgemm.f
Go to the documentation of this file.
1*> \brief \b ZGEMM
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 ZGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
12*
13* .. Scalar Arguments ..
14* COMPLEX*16 ALPHA,BETA
15* INTEGER K,LDA,LDB,LDC,M,N
16* CHARACTER TRANSA,TRANSB
17* ..
18* .. Array Arguments ..
19* COMPLEX*16 A(LDA,*),B(LDB,*),C(LDC,*)
20* ..
21*
22*
23*> \par Purpose:
24* =============
25*>
26*> \verbatim
27*>
28*> ZGEMM 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*16
95*> On entry, ALPHA specifies the scalar alpha.
96*> \endverbatim
97*>
98*> \param[in] A
99*> \verbatim
100*> A is COMPLEX*16 array, 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*16 array, 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*16
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*16 array, 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*> \ingroup gemm
170*
171*> \par Further Details:
172* =====================
173*>
174*> \verbatim
175*>
176*> Level 3 Blas routine.
177*>
178*> -- Written on 8-February-1989.
179*> Jack Dongarra, Argonne National Laboratory.
180*> Iain Duff, AERE Harwell.
181*> Jeremy Du Croz, Numerical Algorithms Group Ltd.
182*> Sven Hammarling, Numerical Algorithms Group Ltd.
183*> \endverbatim
184*>
185* =====================================================================
186 SUBROUTINE zgemm(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,
187 + BETA,C,LDC)
188*
189* -- Reference BLAS level3 routine --
190* -- Reference BLAS is a software package provided by Univ. of Tennessee, --
191* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
192*
193* .. Scalar Arguments ..
194 COMPLEX*16 ALPHA,BETA
195 INTEGER K,LDA,LDB,LDC,M,N
196 CHARACTER TRANSA,TRANSB
197* ..
198* .. Array Arguments ..
199 COMPLEX*16 A(LDA,*),B(LDB,*),C(LDC,*)
200* ..
201*
202* =====================================================================
203*
204* .. External Functions ..
205 LOGICAL LSAME
206 EXTERNAL lsame
207* ..
208* .. External Subroutines ..
209 EXTERNAL xerbla
210* ..
211* .. Intrinsic Functions ..
212 INTRINSIC dconjg,max
213* ..
214* .. Local Scalars ..
215 COMPLEX*16 TEMP
216 INTEGER I,INFO,J,L,NROWA,NROWB
217 LOGICAL CONJA,CONJB,NOTA,NOTB
218* ..
219* .. Parameters ..
220 COMPLEX*16 ONE
221 parameter(one= (1.0d+0,0.0d+0))
222 COMPLEX*16 ZERO
223 parameter(zero= (0.0d+0,0.0d+0))
224* ..
225*
226* Set NOTA and NOTB as true if A and B respectively are not
227* conjugated or transposed, set CONJA and CONJB as true if A and
228* B respectively are to be transposed but not conjugated and set
229* NROWA and NROWB as the number of rows of A and B respectively.
230*
231 nota = lsame(transa,'N')
232 notb = lsame(transb,'N')
233 conja = lsame(transa,'C')
234 conjb = lsame(transb,'C')
235 IF (nota) THEN
236 nrowa = m
237 ELSE
238 nrowa = k
239 END IF
240 IF (notb) THEN
241 nrowb = k
242 ELSE
243 nrowb = n
244 END IF
245*
246* Test the input parameters.
247*
248 info = 0
249 IF ((.NOT.nota) .AND. (.NOT.conja) .AND.
250 + (.NOT.lsame(transa,'T'))) THEN
251 info = 1
252 ELSE IF ((.NOT.notb) .AND. (.NOT.conjb) .AND.
253 + (.NOT.lsame(transb,'T'))) THEN
254 info = 2
255 ELSE IF (m.LT.0) THEN
256 info = 3
257 ELSE IF (n.LT.0) THEN
258 info = 4
259 ELSE IF (k.LT.0) THEN
260 info = 5
261 ELSE IF (lda.LT.max(1,nrowa)) THEN
262 info = 8
263 ELSE IF (ldb.LT.max(1,nrowb)) THEN
264 info = 10
265 ELSE IF (ldc.LT.max(1,m)) THEN
266 info = 13
267 END IF
268 IF (info.NE.0) THEN
269 CALL xerbla('ZGEMM ',info)
270 RETURN
271 END IF
272*
273* Quick return if possible.
274*
275 IF ((m.EQ.0) .OR. (n.EQ.0) .OR.
276 + (((alpha.EQ.zero).OR. (k.EQ.0)).AND. (beta.EQ.one))) RETURN
277*
278* And when alpha.eq.zero.
279*
280 IF (alpha.EQ.zero) THEN
281 IF (beta.EQ.zero) THEN
282 DO 20 j = 1,n
283 DO 10 i = 1,m
284 c(i,j) = zero
285 10 CONTINUE
286 20 CONTINUE
287 ELSE
288 DO 40 j = 1,n
289 DO 30 i = 1,m
290 c(i,j) = beta*c(i,j)
291 30 CONTINUE
292 40 CONTINUE
293 END IF
294 RETURN
295 END IF
296*
297* Start the operations.
298*
299 IF (notb) THEN
300 IF (nota) THEN
301*
302* Form C := alpha*A*B + beta*C.
303*
304 DO 90 j = 1,n
305 IF (beta.EQ.zero) THEN
306 DO 50 i = 1,m
307 c(i,j) = zero
308 50 CONTINUE
309 ELSE IF (beta.NE.one) THEN
310 DO 60 i = 1,m
311 c(i,j) = beta*c(i,j)
312 60 CONTINUE
313 END IF
314 DO 80 l = 1,k
315 temp = alpha*b(l,j)
316 DO 70 i = 1,m
317 c(i,j) = c(i,j) + temp*a(i,l)
318 70 CONTINUE
319 80 CONTINUE
320 90 CONTINUE
321 ELSE IF (conja) THEN
322*
323* Form C := alpha*A**H*B + beta*C.
324*
325 DO 120 j = 1,n
326 DO 110 i = 1,m
327 temp = zero
328 DO 100 l = 1,k
329 temp = temp + dconjg(a(l,i))*b(l,j)
330 100 CONTINUE
331 IF (beta.EQ.zero) THEN
332 c(i,j) = alpha*temp
333 ELSE
334 c(i,j) = alpha*temp + beta*c(i,j)
335 END IF
336 110 CONTINUE
337 120 CONTINUE
338 ELSE
339*
340* Form C := alpha*A**T*B + beta*C
341*
342 DO 150 j = 1,n
343 DO 140 i = 1,m
344 temp = zero
345 DO 130 l = 1,k
346 temp = temp + a(l,i)*b(l,j)
347 130 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 140 CONTINUE
354 150 CONTINUE
355 END IF
356 ELSE IF (nota) THEN
357 IF (conjb) THEN
358*
359* Form C := alpha*A*B**H + beta*C.
360*
361 DO 200 j = 1,n
362 IF (beta.EQ.zero) THEN
363 DO 160 i = 1,m
364 c(i,j) = zero
365 160 CONTINUE
366 ELSE IF (beta.NE.one) THEN
367 DO 170 i = 1,m
368 c(i,j) = beta*c(i,j)
369 170 CONTINUE
370 END IF
371 DO 190 l = 1,k
372 temp = alpha*dconjg(b(j,l))
373 DO 180 i = 1,m
374 c(i,j) = c(i,j) + temp*a(i,l)
375 180 CONTINUE
376 190 CONTINUE
377 200 CONTINUE
378 ELSE
379*
380* Form C := alpha*A*B**T + beta*C
381*
382 DO 250 j = 1,n
383 IF (beta.EQ.zero) THEN
384 DO 210 i = 1,m
385 c(i,j) = zero
386 210 CONTINUE
387 ELSE IF (beta.NE.one) THEN
388 DO 220 i = 1,m
389 c(i,j) = beta*c(i,j)
390 220 CONTINUE
391 END IF
392 DO 240 l = 1,k
393 temp = alpha*b(j,l)
394 DO 230 i = 1,m
395 c(i,j) = c(i,j) + temp*a(i,l)
396 230 CONTINUE
397 240 CONTINUE
398 250 CONTINUE
399 END IF
400 ELSE IF (conja) THEN
401 IF (conjb) THEN
402*
403* Form C := alpha*A**H*B**H + beta*C.
404*
405 DO 280 j = 1,n
406 DO 270 i = 1,m
407 temp = zero
408 DO 260 l = 1,k
409 temp = temp + dconjg(a(l,i))*dconjg(b(j,l))
410 260 CONTINUE
411 IF (beta.EQ.zero) THEN
412 c(i,j) = alpha*temp
413 ELSE
414 c(i,j) = alpha*temp + beta*c(i,j)
415 END IF
416 270 CONTINUE
417 280 CONTINUE
418 ELSE
419*
420* Form C := alpha*A**H*B**T + beta*C
421*
422 DO 310 j = 1,n
423 DO 300 i = 1,m
424 temp = zero
425 DO 290 l = 1,k
426 temp = temp + dconjg(a(l,i))*b(j,l)
427 290 CONTINUE
428 IF (beta.EQ.zero) THEN
429 c(i,j) = alpha*temp
430 ELSE
431 c(i,j) = alpha*temp + beta*c(i,j)
432 END IF
433 300 CONTINUE
434 310 CONTINUE
435 END IF
436 ELSE
437 IF (conjb) THEN
438*
439* Form C := alpha*A**T*B**H + beta*C
440*
441 DO 340 j = 1,n
442 DO 330 i = 1,m
443 temp = zero
444 DO 320 l = 1,k
445 temp = temp + a(l,i)*dconjg(b(j,l))
446 320 CONTINUE
447 IF (beta.EQ.zero) THEN
448 c(i,j) = alpha*temp
449 ELSE
450 c(i,j) = alpha*temp + beta*c(i,j)
451 END IF
452 330 CONTINUE
453 340 CONTINUE
454 ELSE
455*
456* Form C := alpha*A**T*B**T + beta*C
457*
458 DO 370 j = 1,n
459 DO 360 i = 1,m
460 temp = zero
461 DO 350 l = 1,k
462 temp = temp + a(l,i)*b(j,l)
463 350 CONTINUE
464 IF (beta.EQ.zero) THEN
465 c(i,j) = alpha*temp
466 ELSE
467 c(i,j) = alpha*temp + beta*c(i,j)
468 END IF
469 360 CONTINUE
470 370 CONTINUE
471 END IF
472 END IF
473*
474 RETURN
475*
476* End of ZGEMM
477*
478 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMM
Definition zgemm.f:188