Statistiques
| Révision :

root / src / blas / zgemm.f @ 5

Historique | Voir | Annoter | Télécharger (12,79 ko)

1 1 pfleura2
      SUBROUTINE ZGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
2 1 pfleura2
*     .. Scalar Arguments ..
3 1 pfleura2
      DOUBLE COMPLEX ALPHA,BETA
4 1 pfleura2
      INTEGER K,LDA,LDB,LDC,M,N
5 1 pfleura2
      CHARACTER TRANSA,TRANSB
6 1 pfleura2
*     ..
7 1 pfleura2
*     .. Array Arguments ..
8 1 pfleura2
      DOUBLE COMPLEX A(LDA,*),B(LDB,*),C(LDC,*)
9 1 pfleura2
*     ..
10 1 pfleura2
*
11 1 pfleura2
*  Purpose
12 1 pfleura2
*  =======
13 1 pfleura2
*
14 1 pfleura2
*  ZGEMM  performs one of the matrix-matrix operations
15 1 pfleura2
*
16 1 pfleura2
*     C := alpha*op( A )*op( B ) + beta*C,
17 1 pfleura2
*
18 1 pfleura2
*  where  op( X ) is one of
19 1 pfleura2
*
20 1 pfleura2
*     op( X ) = X   or   op( X ) = X'   or   op( X ) = conjg( X' ),
21 1 pfleura2
*
22 1 pfleura2
*  alpha and beta are scalars, and A, B and C are matrices, with op( A )
23 1 pfleura2
*  an m by k matrix,  op( B )  a  k by n matrix and  C an m by n matrix.
24 1 pfleura2
*
25 1 pfleura2
*  Arguments
26 1 pfleura2
*  ==========
27 1 pfleura2
*
28 1 pfleura2
*  TRANSA - CHARACTER*1.
29 1 pfleura2
*           On entry, TRANSA specifies the form of op( A ) to be used in
30 1 pfleura2
*           the matrix multiplication as follows:
31 1 pfleura2
*
32 1 pfleura2
*              TRANSA = 'N' or 'n',  op( A ) = A.
33 1 pfleura2
*
34 1 pfleura2
*              TRANSA = 'T' or 't',  op( A ) = A'.
35 1 pfleura2
*
36 1 pfleura2
*              TRANSA = 'C' or 'c',  op( A ) = conjg( A' ).
37 1 pfleura2
*
38 1 pfleura2
*           Unchanged on exit.
39 1 pfleura2
*
40 1 pfleura2
*  TRANSB - CHARACTER*1.
41 1 pfleura2
*           On entry, TRANSB specifies the form of op( B ) to be used in
42 1 pfleura2
*           the matrix multiplication as follows:
43 1 pfleura2
*
44 1 pfleura2
*              TRANSB = 'N' or 'n',  op( B ) = B.
45 1 pfleura2
*
46 1 pfleura2
*              TRANSB = 'T' or 't',  op( B ) = B'.
47 1 pfleura2
*
48 1 pfleura2
*              TRANSB = 'C' or 'c',  op( B ) = conjg( B' ).
49 1 pfleura2
*
50 1 pfleura2
*           Unchanged on exit.
51 1 pfleura2
*
52 1 pfleura2
*  M      - INTEGER.
53 1 pfleura2
*           On entry,  M  specifies  the number  of rows  of the  matrix
54 1 pfleura2
*           op( A )  and of the  matrix  C.  M  must  be at least  zero.
55 1 pfleura2
*           Unchanged on exit.
56 1 pfleura2
*
57 1 pfleura2
*  N      - INTEGER.
58 1 pfleura2
*           On entry,  N  specifies the number  of columns of the matrix
59 1 pfleura2
*           op( B ) and the number of columns of the matrix C. N must be
60 1 pfleura2
*           at least zero.
61 1 pfleura2
*           Unchanged on exit.
62 1 pfleura2
*
63 1 pfleura2
*  K      - INTEGER.
64 1 pfleura2
*           On entry,  K  specifies  the number of columns of the matrix
65 1 pfleura2
*           op( A ) and the number of rows of the matrix op( B ). K must
66 1 pfleura2
*           be at least  zero.
67 1 pfleura2
*           Unchanged on exit.
68 1 pfleura2
*
69 1 pfleura2
*  ALPHA  - COMPLEX*16      .
70 1 pfleura2
*           On entry, ALPHA specifies the scalar alpha.
71 1 pfleura2
*           Unchanged on exit.
72 1 pfleura2
*
73 1 pfleura2
*  A      - COMPLEX*16       array of DIMENSION ( LDA, ka ), where ka is
74 1 pfleura2
*           k  when  TRANSA = 'N' or 'n',  and is  m  otherwise.
75 1 pfleura2
*           Before entry with  TRANSA = 'N' or 'n',  the leading  m by k
76 1 pfleura2
*           part of the array  A  must contain the matrix  A,  otherwise
77 1 pfleura2
*           the leading  k by m  part of the array  A  must contain  the
78 1 pfleura2
*           matrix A.
79 1 pfleura2
*           Unchanged on exit.
80 1 pfleura2
*
81 1 pfleura2
*  LDA    - INTEGER.
82 1 pfleura2
*           On entry, LDA specifies the first dimension of A as declared
83 1 pfleura2
*           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
84 1 pfleura2
*           LDA must be at least  max( 1, m ), otherwise  LDA must be at
85 1 pfleura2
*           least  max( 1, k ).
86 1 pfleura2
*           Unchanged on exit.
87 1 pfleura2
*
88 1 pfleura2
*  B      - COMPLEX*16       array of DIMENSION ( LDB, kb ), where kb is
89 1 pfleura2
*           n  when  TRANSB = 'N' or 'n',  and is  k  otherwise.
90 1 pfleura2
*           Before entry with  TRANSB = 'N' or 'n',  the leading  k by n
91 1 pfleura2
*           part of the array  B  must contain the matrix  B,  otherwise
92 1 pfleura2
*           the leading  n by k  part of the array  B  must contain  the
93 1 pfleura2
*           matrix B.
94 1 pfleura2
*           Unchanged on exit.
95 1 pfleura2
*
96 1 pfleura2
*  LDB    - INTEGER.
97 1 pfleura2
*           On entry, LDB specifies the first dimension of B as declared
98 1 pfleura2
*           in the calling (sub) program. When  TRANSB = 'N' or 'n' then
99 1 pfleura2
*           LDB must be at least  max( 1, k ), otherwise  LDB must be at
100 1 pfleura2
*           least  max( 1, n ).
101 1 pfleura2
*           Unchanged on exit.
102 1 pfleura2
*
103 1 pfleura2
*  BETA   - COMPLEX*16      .
104 1 pfleura2
*           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
105 1 pfleura2
*           supplied as zero then C need not be set on input.
106 1 pfleura2
*           Unchanged on exit.
107 1 pfleura2
*
108 1 pfleura2
*  C      - COMPLEX*16       array of DIMENSION ( LDC, n ).
109 1 pfleura2
*           Before entry, the leading  m by n  part of the array  C must
110 1 pfleura2
*           contain the matrix  C,  except when  beta  is zero, in which
111 1 pfleura2
*           case C need not be set on entry.
112 1 pfleura2
*           On exit, the array  C  is overwritten by the  m by n  matrix
113 1 pfleura2
*           ( alpha*op( A )*op( B ) + beta*C ).
114 1 pfleura2
*
115 1 pfleura2
*  LDC    - INTEGER.
116 1 pfleura2
*           On entry, LDC specifies the first dimension of C as declared
117 1 pfleura2
*           in  the  calling  (sub)  program.   LDC  must  be  at  least
118 1 pfleura2
*           max( 1, m ).
119 1 pfleura2
*           Unchanged on exit.
120 1 pfleura2
*
121 1 pfleura2
*
122 1 pfleura2
*  Level 3 Blas routine.
123 1 pfleura2
*
124 1 pfleura2
*  -- Written on 8-February-1989.
125 1 pfleura2
*     Jack Dongarra, Argonne National Laboratory.
126 1 pfleura2
*     Iain Duff, AERE Harwell.
127 1 pfleura2
*     Jeremy Du Croz, Numerical Algorithms Group Ltd.
128 1 pfleura2
*     Sven Hammarling, Numerical Algorithms Group Ltd.
129 1 pfleura2
*
130 1 pfleura2
*
131 1 pfleura2
*     .. External Functions ..
132 1 pfleura2
      LOGICAL LSAME
133 1 pfleura2
      EXTERNAL LSAME
134 1 pfleura2
*     ..
135 1 pfleura2
*     .. External Subroutines ..
136 1 pfleura2
      EXTERNAL XERBLA
137 1 pfleura2
*     ..
138 1 pfleura2
*     .. Intrinsic Functions ..
139 1 pfleura2
      INTRINSIC DCONJG,MAX
140 1 pfleura2
*     ..
141 1 pfleura2
*     .. Local Scalars ..
142 1 pfleura2
      DOUBLE COMPLEX TEMP
143 1 pfleura2
      INTEGER I,INFO,J,L,NCOLA,NROWA,NROWB
144 1 pfleura2
      LOGICAL CONJA,CONJB,NOTA,NOTB
145 1 pfleura2
*     ..
146 1 pfleura2
*     .. Parameters ..
147 1 pfleura2
      DOUBLE COMPLEX ONE
148 1 pfleura2
      PARAMETER (ONE= (1.0D+0,0.0D+0))
149 1 pfleura2
      DOUBLE COMPLEX ZERO
150 1 pfleura2
      PARAMETER (ZERO= (0.0D+0,0.0D+0))
151 1 pfleura2
*     ..
152 1 pfleura2
*
153 1 pfleura2
*     Set  NOTA  and  NOTB  as  true if  A  and  B  respectively are not
154 1 pfleura2
*     conjugated or transposed, set  CONJA and CONJB  as true if  A  and
155 1 pfleura2
*     B  respectively are to be  transposed but  not conjugated  and set
156 1 pfleura2
*     NROWA, NCOLA and  NROWB  as the number of rows and  columns  of  A
157 1 pfleura2
*     and the number of rows of  B  respectively.
158 1 pfleura2
*
159 1 pfleura2
      NOTA = LSAME(TRANSA,'N')
160 1 pfleura2
      NOTB = LSAME(TRANSB,'N')
161 1 pfleura2
      CONJA = LSAME(TRANSA,'C')
162 1 pfleura2
      CONJB = LSAME(TRANSB,'C')
163 1 pfleura2
      IF (NOTA) THEN
164 1 pfleura2
          NROWA = M
165 1 pfleura2
          NCOLA = K
166 1 pfleura2
      ELSE
167 1 pfleura2
          NROWA = K
168 1 pfleura2
          NCOLA = M
169 1 pfleura2
      END IF
170 1 pfleura2
      IF (NOTB) THEN
171 1 pfleura2
          NROWB = K
172 1 pfleura2
      ELSE
173 1 pfleura2
          NROWB = N
174 1 pfleura2
      END IF
175 1 pfleura2
*
176 1 pfleura2
*     Test the input parameters.
177 1 pfleura2
*
178 1 pfleura2
      INFO = 0
179 1 pfleura2
      IF ((.NOT.NOTA) .AND. (.NOT.CONJA) .AND.
180 1 pfleura2
     +    (.NOT.LSAME(TRANSA,'T'))) THEN
181 1 pfleura2
          INFO = 1
182 1 pfleura2
      ELSE IF ((.NOT.NOTB) .AND. (.NOT.CONJB) .AND.
183 1 pfleura2
     +         (.NOT.LSAME(TRANSB,'T'))) THEN
184 1 pfleura2
          INFO = 2
185 1 pfleura2
      ELSE IF (M.LT.0) THEN
186 1 pfleura2
          INFO = 3
187 1 pfleura2
      ELSE IF (N.LT.0) THEN
188 1 pfleura2
          INFO = 4
189 1 pfleura2
      ELSE IF (K.LT.0) THEN
190 1 pfleura2
          INFO = 5
191 1 pfleura2
      ELSE IF (LDA.LT.MAX(1,NROWA)) THEN
192 1 pfleura2
          INFO = 8
193 1 pfleura2
      ELSE IF (LDB.LT.MAX(1,NROWB)) THEN
194 1 pfleura2
          INFO = 10
195 1 pfleura2
      ELSE IF (LDC.LT.MAX(1,M)) THEN
196 1 pfleura2
          INFO = 13
197 1 pfleura2
      END IF
198 1 pfleura2
      IF (INFO.NE.0) THEN
199 1 pfleura2
          CALL XERBLA('ZGEMM ',INFO)
200 1 pfleura2
          RETURN
201 1 pfleura2
      END IF
202 1 pfleura2
*
203 1 pfleura2
*     Quick return if possible.
204 1 pfleura2
*
205 1 pfleura2
      IF ((M.EQ.0) .OR. (N.EQ.0) .OR.
206 1 pfleura2
     +    (((ALPHA.EQ.ZERO).OR. (K.EQ.0)).AND. (BETA.EQ.ONE))) RETURN
207 1 pfleura2
*
208 1 pfleura2
*     And when  alpha.eq.zero.
209 1 pfleura2
*
210 1 pfleura2
      IF (ALPHA.EQ.ZERO) THEN
211 1 pfleura2
          IF (BETA.EQ.ZERO) THEN
212 1 pfleura2
              DO 20 J = 1,N
213 1 pfleura2
                  DO 10 I = 1,M
214 1 pfleura2
                      C(I,J) = ZERO
215 1 pfleura2
   10             CONTINUE
216 1 pfleura2
   20         CONTINUE
217 1 pfleura2
          ELSE
218 1 pfleura2
              DO 40 J = 1,N
219 1 pfleura2
                  DO 30 I = 1,M
220 1 pfleura2
                      C(I,J) = BETA*C(I,J)
221 1 pfleura2
   30             CONTINUE
222 1 pfleura2
   40         CONTINUE
223 1 pfleura2
          END IF
224 1 pfleura2
          RETURN
225 1 pfleura2
      END IF
226 1 pfleura2
*
227 1 pfleura2
*     Start the operations.
228 1 pfleura2
*
229 1 pfleura2
      IF (NOTB) THEN
230 1 pfleura2
          IF (NOTA) THEN
231 1 pfleura2
*
232 1 pfleura2
*           Form  C := alpha*A*B + beta*C.
233 1 pfleura2
*
234 1 pfleura2
              DO 90 J = 1,N
235 1 pfleura2
                  IF (BETA.EQ.ZERO) THEN
236 1 pfleura2
                      DO 50 I = 1,M
237 1 pfleura2
                          C(I,J) = ZERO
238 1 pfleura2
   50                 CONTINUE
239 1 pfleura2
                  ELSE IF (BETA.NE.ONE) THEN
240 1 pfleura2
                      DO 60 I = 1,M
241 1 pfleura2
                          C(I,J) = BETA*C(I,J)
242 1 pfleura2
   60                 CONTINUE
243 1 pfleura2
                  END IF
244 1 pfleura2
                  DO 80 L = 1,K
245 1 pfleura2
                      IF (B(L,J).NE.ZERO) THEN
246 1 pfleura2
                          TEMP = ALPHA*B(L,J)
247 1 pfleura2
                          DO 70 I = 1,M
248 1 pfleura2
                              C(I,J) = C(I,J) + TEMP*A(I,L)
249 1 pfleura2
   70                     CONTINUE
250 1 pfleura2
                      END IF
251 1 pfleura2
   80             CONTINUE
252 1 pfleura2
   90         CONTINUE
253 1 pfleura2
          ELSE IF (CONJA) THEN
254 1 pfleura2
*
255 1 pfleura2
*           Form  C := alpha*conjg( A' )*B + beta*C.
256 1 pfleura2
*
257 1 pfleura2
              DO 120 J = 1,N
258 1 pfleura2
                  DO 110 I = 1,M
259 1 pfleura2
                      TEMP = ZERO
260 1 pfleura2
                      DO 100 L = 1,K
261 1 pfleura2
                          TEMP = TEMP + DCONJG(A(L,I))*B(L,J)
262 1 pfleura2
  100                 CONTINUE
263 1 pfleura2
                      IF (BETA.EQ.ZERO) THEN
264 1 pfleura2
                          C(I,J) = ALPHA*TEMP
265 1 pfleura2
                      ELSE
266 1 pfleura2
                          C(I,J) = ALPHA*TEMP + BETA*C(I,J)
267 1 pfleura2
                      END IF
268 1 pfleura2
  110             CONTINUE
269 1 pfleura2
  120         CONTINUE
270 1 pfleura2
          ELSE
271 1 pfleura2
*
272 1 pfleura2
*           Form  C := alpha*A'*B + beta*C
273 1 pfleura2
*
274 1 pfleura2
              DO 150 J = 1,N
275 1 pfleura2
                  DO 140 I = 1,M
276 1 pfleura2
                      TEMP = ZERO
277 1 pfleura2
                      DO 130 L = 1,K
278 1 pfleura2
                          TEMP = TEMP + A(L,I)*B(L,J)
279 1 pfleura2
  130                 CONTINUE
280 1 pfleura2
                      IF (BETA.EQ.ZERO) THEN
281 1 pfleura2
                          C(I,J) = ALPHA*TEMP
282 1 pfleura2
                      ELSE
283 1 pfleura2
                          C(I,J) = ALPHA*TEMP + BETA*C(I,J)
284 1 pfleura2
                      END IF
285 1 pfleura2
  140             CONTINUE
286 1 pfleura2
  150         CONTINUE
287 1 pfleura2
          END IF
288 1 pfleura2
      ELSE IF (NOTA) THEN
289 1 pfleura2
          IF (CONJB) THEN
290 1 pfleura2
*
291 1 pfleura2
*           Form  C := alpha*A*conjg( B' ) + beta*C.
292 1 pfleura2
*
293 1 pfleura2
              DO 200 J = 1,N
294 1 pfleura2
                  IF (BETA.EQ.ZERO) THEN
295 1 pfleura2
                      DO 160 I = 1,M
296 1 pfleura2
                          C(I,J) = ZERO
297 1 pfleura2
  160                 CONTINUE
298 1 pfleura2
                  ELSE IF (BETA.NE.ONE) THEN
299 1 pfleura2
                      DO 170 I = 1,M
300 1 pfleura2
                          C(I,J) = BETA*C(I,J)
301 1 pfleura2
  170                 CONTINUE
302 1 pfleura2
                  END IF
303 1 pfleura2
                  DO 190 L = 1,K
304 1 pfleura2
                      IF (B(J,L).NE.ZERO) THEN
305 1 pfleura2
                          TEMP = ALPHA*DCONJG(B(J,L))
306 1 pfleura2
                          DO 180 I = 1,M
307 1 pfleura2
                              C(I,J) = C(I,J) + TEMP*A(I,L)
308 1 pfleura2
  180                     CONTINUE
309 1 pfleura2
                      END IF
310 1 pfleura2
  190             CONTINUE
311 1 pfleura2
  200         CONTINUE
312 1 pfleura2
          ELSE
313 1 pfleura2
*
314 1 pfleura2
*           Form  C := alpha*A*B'          + beta*C
315 1 pfleura2
*
316 1 pfleura2
              DO 250 J = 1,N
317 1 pfleura2
                  IF (BETA.EQ.ZERO) THEN
318 1 pfleura2
                      DO 210 I = 1,M
319 1 pfleura2
                          C(I,J) = ZERO
320 1 pfleura2
  210                 CONTINUE
321 1 pfleura2
                  ELSE IF (BETA.NE.ONE) THEN
322 1 pfleura2
                      DO 220 I = 1,M
323 1 pfleura2
                          C(I,J) = BETA*C(I,J)
324 1 pfleura2
  220                 CONTINUE
325 1 pfleura2
                  END IF
326 1 pfleura2
                  DO 240 L = 1,K
327 1 pfleura2
                      IF (B(J,L).NE.ZERO) THEN
328 1 pfleura2
                          TEMP = ALPHA*B(J,L)
329 1 pfleura2
                          DO 230 I = 1,M
330 1 pfleura2
                              C(I,J) = C(I,J) + TEMP*A(I,L)
331 1 pfleura2
  230                     CONTINUE
332 1 pfleura2
                      END IF
333 1 pfleura2
  240             CONTINUE
334 1 pfleura2
  250         CONTINUE
335 1 pfleura2
          END IF
336 1 pfleura2
      ELSE IF (CONJA) THEN
337 1 pfleura2
          IF (CONJB) THEN
338 1 pfleura2
*
339 1 pfleura2
*           Form  C := alpha*conjg( A' )*conjg( B' ) + beta*C.
340 1 pfleura2
*
341 1 pfleura2
              DO 280 J = 1,N
342 1 pfleura2
                  DO 270 I = 1,M
343 1 pfleura2
                      TEMP = ZERO
344 1 pfleura2
                      DO 260 L = 1,K
345 1 pfleura2
                          TEMP = TEMP + DCONJG(A(L,I))*DCONJG(B(J,L))
346 1 pfleura2
  260                 CONTINUE
347 1 pfleura2
                      IF (BETA.EQ.ZERO) THEN
348 1 pfleura2
                          C(I,J) = ALPHA*TEMP
349 1 pfleura2
                      ELSE
350 1 pfleura2
                          C(I,J) = ALPHA*TEMP + BETA*C(I,J)
351 1 pfleura2
                      END IF
352 1 pfleura2
  270             CONTINUE
353 1 pfleura2
  280         CONTINUE
354 1 pfleura2
          ELSE
355 1 pfleura2
*
356 1 pfleura2
*           Form  C := alpha*conjg( A' )*B' + beta*C
357 1 pfleura2
*
358 1 pfleura2
              DO 310 J = 1,N
359 1 pfleura2
                  DO 300 I = 1,M
360 1 pfleura2
                      TEMP = ZERO
361 1 pfleura2
                      DO 290 L = 1,K
362 1 pfleura2
                          TEMP = TEMP + DCONJG(A(L,I))*B(J,L)
363 1 pfleura2
  290                 CONTINUE
364 1 pfleura2
                      IF (BETA.EQ.ZERO) THEN
365 1 pfleura2
                          C(I,J) = ALPHA*TEMP
366 1 pfleura2
                      ELSE
367 1 pfleura2
                          C(I,J) = ALPHA*TEMP + BETA*C(I,J)
368 1 pfleura2
                      END IF
369 1 pfleura2
  300             CONTINUE
370 1 pfleura2
  310         CONTINUE
371 1 pfleura2
          END IF
372 1 pfleura2
      ELSE
373 1 pfleura2
          IF (CONJB) THEN
374 1 pfleura2
*
375 1 pfleura2
*           Form  C := alpha*A'*conjg( B' ) + beta*C
376 1 pfleura2
*
377 1 pfleura2
              DO 340 J = 1,N
378 1 pfleura2
                  DO 330 I = 1,M
379 1 pfleura2
                      TEMP = ZERO
380 1 pfleura2
                      DO 320 L = 1,K
381 1 pfleura2
                          TEMP = TEMP + A(L,I)*DCONJG(B(J,L))
382 1 pfleura2
  320                 CONTINUE
383 1 pfleura2
                      IF (BETA.EQ.ZERO) THEN
384 1 pfleura2
                          C(I,J) = ALPHA*TEMP
385 1 pfleura2
                      ELSE
386 1 pfleura2
                          C(I,J) = ALPHA*TEMP + BETA*C(I,J)
387 1 pfleura2
                      END IF
388 1 pfleura2
  330             CONTINUE
389 1 pfleura2
  340         CONTINUE
390 1 pfleura2
          ELSE
391 1 pfleura2
*
392 1 pfleura2
*           Form  C := alpha*A'*B' + beta*C
393 1 pfleura2
*
394 1 pfleura2
              DO 370 J = 1,N
395 1 pfleura2
                  DO 360 I = 1,M
396 1 pfleura2
                      TEMP = ZERO
397 1 pfleura2
                      DO 350 L = 1,K
398 1 pfleura2
                          TEMP = TEMP + A(L,I)*B(J,L)
399 1 pfleura2
  350                 CONTINUE
400 1 pfleura2
                      IF (BETA.EQ.ZERO) THEN
401 1 pfleura2
                          C(I,J) = ALPHA*TEMP
402 1 pfleura2
                      ELSE
403 1 pfleura2
                          C(I,J) = ALPHA*TEMP + BETA*C(I,J)
404 1 pfleura2
                      END IF
405 1 pfleura2
  360             CONTINUE
406 1 pfleura2
  370         CONTINUE
407 1 pfleura2
          END IF
408 1 pfleura2
      END IF
409 1 pfleura2
*
410 1 pfleura2
      RETURN
411 1 pfleura2
*
412 1 pfleura2
*     End of ZGEMM .
413 1 pfleura2
*
414 1 pfleura2
      END