1 | SUBROUTINE CGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC) |
---|
2 | * .. Scalar Arguments .. |
---|
3 | COMPLEX ALPHA,BETA |
---|
4 | INTEGER K,LDA,LDB,LDC,M,N |
---|
5 | CHARACTER TRANSA,TRANSB |
---|
6 | * .. |
---|
7 | * .. Array Arguments .. |
---|
8 | COMPLEX A(LDA,*),B(LDB,*),C(LDC,*) |
---|
9 | * .. |
---|
10 | * |
---|
11 | * Purpose |
---|
12 | * ======= |
---|
13 | * |
---|
14 | * CGEMM 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 | * Arguments |
---|
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 . |
---|
70 | * On entry, ALPHA specifies the scalar alpha. |
---|
71 | * Unchanged on exit. |
---|
72 | * |
---|
73 | * A - COMPLEX 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 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 . |
---|
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 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 | * .. |
---|
135 | * .. External Subroutines .. |
---|
136 | EXTERNAL XERBLA |
---|
137 | * .. |
---|
138 | * .. Intrinsic Functions .. |
---|
139 | INTRINSIC CONJG,MAX |
---|
140 | * .. |
---|
141 | * .. Local Scalars .. |
---|
142 | COMPLEX TEMP |
---|
143 | INTEGER I,INFO,J,L,NCOLA,NROWA,NROWB |
---|
144 | LOGICAL CONJA,CONJB,NOTA,NOTB |
---|
145 | * .. |
---|
146 | * .. Parameters .. |
---|
147 | COMPLEX ONE |
---|
148 | PARAMETER (ONE= (1.0E+0,0.0E+0)) |
---|
149 | COMPLEX ZERO |
---|
150 | PARAMETER (ZERO= (0.0E+0,0.0E+0)) |
---|
151 | * .. |
---|
152 | * |
---|
153 | * Set NOTA and NOTB as true if A and B respectively are not |
---|
154 | * conjugated or transposed, set CONJA and CONJB as true if A and |
---|
155 | * B respectively are to be transposed but not conjugated and set |
---|
156 | * NROWA, NCOLA and NROWB as the number of rows and columns of A |
---|
157 | * and the number of rows of B respectively. |
---|
158 | * |
---|
159 | NOTA = LSAME(TRANSA,'N') |
---|
160 | NOTB = LSAME(TRANSB,'N') |
---|
161 | CONJA = LSAME(TRANSA,'C') |
---|
162 | CONJB = LSAME(TRANSB,'C') |
---|
163 | IF (NOTA) THEN |
---|
164 | NROWA = M |
---|
165 | NCOLA = K |
---|
166 | ELSE |
---|
167 | NROWA = K |
---|
168 | NCOLA = M |
---|
169 | END IF |
---|
170 | IF (NOTB) THEN |
---|
171 | NROWB = K |
---|
172 | ELSE |
---|
173 | NROWB = N |
---|
174 | END IF |
---|
175 | * |
---|
176 | * Test the input parameters. |
---|
177 | * |
---|
178 | INFO = 0 |
---|
179 | IF ((.NOT.NOTA) .AND. (.NOT.CONJA) .AND. |
---|
180 | + (.NOT.LSAME(TRANSA,'T'))) THEN |
---|
181 | INFO = 1 |
---|
182 | ELSE IF ((.NOT.NOTB) .AND. (.NOT.CONJB) .AND. |
---|
183 | + (.NOT.LSAME(TRANSB,'T'))) THEN |
---|
184 | INFO = 2 |
---|
185 | ELSE IF (M.LT.0) THEN |
---|
186 | INFO = 3 |
---|
187 | ELSE IF (N.LT.0) THEN |
---|
188 | INFO = 4 |
---|
189 | ELSE IF (K.LT.0) THEN |
---|
190 | INFO = 5 |
---|
191 | ELSE IF (LDA.LT.MAX(1,NROWA)) THEN |
---|
192 | INFO = 8 |
---|
193 | ELSE IF (LDB.LT.MAX(1,NROWB)) THEN |
---|
194 | INFO = 10 |
---|
195 | ELSE IF (LDC.LT.MAX(1,M)) THEN |
---|
196 | INFO = 13 |
---|
197 | END IF |
---|
198 | IF (INFO.NE.0) THEN |
---|
199 | CALL XERBLA('CGEMM ',INFO) |
---|
200 | RETURN |
---|
201 | END IF |
---|
202 | * |
---|
203 | * Quick return if possible. |
---|
204 | * |
---|
205 | IF ((M.EQ.0) .OR. (N.EQ.0) .OR. |
---|
206 | + (((ALPHA.EQ.ZERO).OR. (K.EQ.0)).AND. (BETA.EQ.ONE))) 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 + CONJG(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*CONJG(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 + CONJG(A(L,I))*CONJG(B(J,L)) |
---|
346 | 260 CONTINUE |
---|
347 | IF (BETA.EQ.ZERO) THEN |
---|
348 | C(I,J) = ALPHA*TEMP |
---|
349 | ELSE |
---|
350 | C(I,J) = ALPHA*TEMP + BETA*C(I,J) |
---|
351 | END IF |
---|
352 | 270 CONTINUE |
---|
353 | 280 CONTINUE |
---|
354 | ELSE |
---|
355 | * |
---|
356 | * Form C := alpha*conjg( A' )*B' + beta*C |
---|
357 | * |
---|
358 | DO 310 J = 1,N |
---|
359 | DO 300 I = 1,M |
---|
360 | TEMP = ZERO |
---|
361 | DO 290 L = 1,K |
---|
362 | TEMP = TEMP + CONJG(A(L,I))*B(J,L) |
---|
363 | 290 CONTINUE |
---|
364 | IF (BETA.EQ.ZERO) THEN |
---|
365 | C(I,J) = ALPHA*TEMP |
---|
366 | ELSE |
---|
367 | C(I,J) = ALPHA*TEMP + BETA*C(I,J) |
---|
368 | END IF |
---|
369 | 300 CONTINUE |
---|
370 | 310 CONTINUE |
---|
371 | END IF |
---|
372 | ELSE |
---|
373 | IF (CONJB) THEN |
---|
374 | * |
---|
375 | * Form C := alpha*A'*conjg( B' ) + beta*C |
---|
376 | * |
---|
377 | DO 340 J = 1,N |
---|
378 | DO 330 I = 1,M |
---|
379 | TEMP = ZERO |
---|
380 | DO 320 L = 1,K |
---|
381 | TEMP = TEMP + A(L,I)*CONJG(B(J,L)) |
---|
382 | 320 CONTINUE |
---|
383 | IF (BETA.EQ.ZERO) THEN |
---|
384 | C(I,J) = ALPHA*TEMP |
---|
385 | ELSE |
---|
386 | C(I,J) = ALPHA*TEMP + BETA*C(I,J) |
---|
387 | END IF |
---|
388 | 330 CONTINUE |
---|
389 | 340 CONTINUE |
---|
390 | ELSE |
---|
391 | * |
---|
392 | * Form C := alpha*A'*B' + beta*C |
---|
393 | * |
---|
394 | DO 370 J = 1,N |
---|
395 | DO 360 I = 1,M |
---|
396 | TEMP = ZERO |
---|
397 | DO 350 L = 1,K |
---|
398 | TEMP = TEMP + A(L,I)*B(J,L) |
---|
399 | 350 CONTINUE |
---|
400 | IF (BETA.EQ.ZERO) THEN |
---|
401 | C(I,J) = ALPHA*TEMP |
---|
402 | ELSE |
---|
403 | C(I,J) = ALPHA*TEMP + BETA*C(I,J) |
---|
404 | END IF |
---|
405 | 360 CONTINUE |
---|
406 | 370 CONTINUE |
---|
407 | END IF |
---|
408 | END IF |
---|
409 | * |
---|
410 | RETURN |
---|
411 | * |
---|
412 | * End of CGEMM . |
---|
413 | * |
---|
414 | END |
---|