Previous Next Contents Generated Index Doc Set Home



Product of Two General Matrices

The subroutines described in this section compute one of the following results for the general matrices A, B, and C, and the scalars and :

Operation
TRANSA
TRANSB
Matrix A
Matrix B

'N' or 'n'

'N' or 'n'

m x k

k x n

'T' or 't'

'N' or 'n'

k x m

k x n

'N' or 'n'

'T' or 't'

m x k

n x k

'T' or 't'

'T' or 't'

k x m

n x k

'C' or 'c'

'N' or 'n'

k x m

k x n

'N' or 'n'

'C' or 'c'

m x k

n x k

'C' or 'c'

'C' or 'c'

k x m

n x k

'T' or 't'

'C' or 'c'

k x m

n x k

'C' or 'c'

'T' or 't'

k x m

n x k

Calling Sequence

CALL DGEMM 
(TRANSA, TRANSB, M, N, K, DALPHA, DA, LDA, DB, LDB, 
DBETA, DC, LDC)
CALL SGEMM 
(TRANSA, TRANSB, M, N, K, SALPHA, SA, LDA, SB, LDB, 
SBETA, SC, LDC)
CALL ZGEMM 
(TRANSA, TRANSB, M, N, K, ZALPHA, ZA, LDA, ZB, LDB, 
ZBETA, ZC, LDC)
CALL CGEMM 
(TRANSA, TRANSB, M, N, K, CALPHA, CA, LDA, CB, LDB, 
CBETA, CC, LDC)






void dgemm 
(char transa, char transb, int m, int n, int k, double 
dalpha, double *da, int lda, double *db, int ldb, 
double dbeta, double *dc, int ldc)
void sgemm 
(char transa, char transb, int m, int n, int k, float 
salpha, float *sa, int lda, float *sb, int ldb, float 
sbeta, float *sc, int ldc)
void zgemm 
(char transa, char transb, int m, int n, int k, 
doublecomplex *zalpha, doublecomplex *za, int lda, 
doublecomplex *zb, int ldb, doublecomplex *zbeta, 
doublecomplex *zc, int ldc)
void cgemm 
(char transa, char transb, int m, int n, int k, complex 
*calpha, complex *ca, int lda, complex *cb, int ldb, 
complex *cbeta, complex *cc, int ldc)

Arguments

TRANSA

Indicates how to use the matrix stored in the array A. The legal values for TRANSA are listed below. Any value not listed below is illegal.

'N' or 'n'

Use the matrix as it is stored in A.

'T' or 't'

Use the transpose of the matrix stored in A.

'C' or 'c'

Use the conjugate transpose of the matrix stored in A.

TRANSB

Indicates how to use the matrix stored in the array B. The legal values for TRANSB are listed below. Any value not listed below is illegal.

'N' or 'n'

Use the matrix as it is stored in B.

'T' or 't'

Use the transpose of the matrix stored in B.

'C' or 'c'

Use the conjugate transpose of the matrix stored in B.

M, N, K

Indicate the size of the matrices as shown in the table above.
M, N, K 0.

xALPHA

Scalar that scales the input value of the matrix in A.

xA

Two-dimensional array in which one of the input matrices is stored.

LDA

Leading dimension of the array A as specified in the dimension or type statement. LDA max (1,K).
If TRANSA = 'N' or 'n', LDA max (1,M).

xB

Two-dimensional array in which one of the input matrices is stored.

LDB

Leading dimension of the array B as specified in the dimension or type statement. LDB max(1,N).

If TRANSB = 'N' or 'n', LDB max (1,K).

xBETA

Scalar that scales the input value of the matrix stored in C.

xC

An M × N array.

On entry, an input matrix.

On exit, the result matrix.

LDC

Leading dimension of the array C as specified in the dimension or type statement. LDC max (1,M).

Sample Program

 
      PROGRAM TEST
      IMPLICIT NONE
C
      INTEGER           K, LDA, LDB, LDC, M, N
      PARAMETER        (K = 3)
      PARAMETER        (M = 3)
      PARAMETER        (N = 2)
      PARAMETER        (LDA = M)
      PARAMETER        (LDB = K)
      PARAMETER        (LDC = M)
C
      DOUBLE PRECISION  A(LDA,K), ALPHA, B(LDB,N), BETA, C(LDC,N)
      INTEGER           I, J
C
      EXTERNAL          DGEMM
C
C     Initialize the arrays A, B, and C to store the matrices A,
C     B, and C shown below.
C
C          0  0  1        2  5        100  100
C     A =  0  1  0    B = 3  6    C = 100  100
C          1  0  0        4  7        100  100
C
      DATA A / 0.0D0, 0.0D0, 1.0D0, 0.0D0, 1.0D0, 0.0D0,
     $         1.0D0, 0.0D0, 0.0D0 /
      DATA B / 2.0D0, 3.0D0, 4.0D0, 5.0D0, 6.0D0, 7.0D0 /
      DATA C / 6*1.0D2 /
C
      PRINT 1000
      PRINT 1010, ((A(I,J), J = 1, K), I = 1, M)
      PRINT 1020
      PRINT 1030, ((B(I,J), J = 1, N), I = 1, K)
      PRINT 1040
      PRINT 1030, ((C(I,J), J = 1, N), I = 1, M)
      ALPHA = 2.0D0
      BETA = 3.0D0
      CALL DGEMM ('NOT TRANSPOSED A', 'NOT TRANSPOSED B', M, N,
     $            K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
      PRINT 1050
      PRINT 1030, ((C(I,J), J = 1, N), I = 1, M)
C
 1000 FORMAT (1X, 'A:')
 1010 FORMAT (3(3X, F5.1))
 1020 FORMAT (/1X, 'B:')
 1030 FORMAT (2(3X, F5.1))
 1040 FORMAT (/1X, 'C:')
 1050 FORMAT (/1X, 'AB + C')
C
      END
 

Sample Output

 
 A:
     0.0     0.0     1.0
     0.0     1.0     0.0
     1.0     0.0     0.0



 B:
     2.0     5.0
     3.0     6.0
     4.0     7.0



 C:
   100.0   100.0
   100.0   100.0
   100.0   100.0



 AB + C
   308.0   314.0
   306.0   312.0
   304.0   310.0






Previous Next Contents Generated Index Doc Set Home