# ?gemm

Computes a scalar-matrix-matrix product and adds the result to a scalar-matrix product.

## Syntax

FORTRAN 77:

call sgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)

call dgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)

call cgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)

call zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)

Fortran 95:

call gemm(a, b, c [,transa][,transb] [,alpha][,beta])

## Description

The ?gemm routines perform a matrix-matrix operation with general matrices. The operation is defined as
`C := alpha*op(A)*op(B) + beta*C,`

where:

`op(x)` is one of `op(x) = x`, or `op(x) = x'`, or `op(x) = conjg(x')`,

alpha and beta are scalars,

A, B and C are matrices:

`op(A)` is an m-by-k matrix,

`op(B)` is a k-by-n matrix,

C is an m-by-n matrix.

## Input Parameters

transa

  CHARACTER*1. Specifies the form of `op(A)` used in the matrix multiplication:

  if `transa = 'N'` or `'n'`, then `op(A) = A`;

  if `transa = 'T'` or `'t'`, then `op(A) = A'`;

  if `transa = 'C'` or `'c'`, then `op(A) = conjg(A')`.

transb

  CHARACTER*1. Specifies the form of `op(B)` used in the matrix multiplication:

  if `transb = 'N'` or `'n'`, then `op(B) = B`;

  if `transb = 'T'` or `'t'`, then `op(B) = B'`;

  if `transb = 'C'` or `'c'`, then `op(B) = conjg(B')`.

m

  INTEGER. Specifies the number of rows of the matrix `op(A)` and of the matrix C. The value of m must be at least zero.

n

  INTEGER. Specifies the number of columns of the matrix `op(B)` and the number of columns of the matrix C.

  The value of n must be at least zero.

k

  INTEGER. Specifies the number of columns of the matrix `op(A)` and the number of rows of the matrix `op(B)`.

  The value of k must be at least zero.

alpha

  REAL for sgemm

  DOUBLE PRECISION for dgemm

  COMPLEX for cgemm

  DOUBLE COMPLEX for zgemm

  Specifies the scalar alpha.

a

  REAL for sgemm

  DOUBLE PRECISION for dgemm

  COMPLEX for cgemm

  DOUBLE COMPLEX for zgemm

  Array, DIMENSION (lda, ka), where ka is k when `transa= 'N'` or 'n', and is m otherwise. Before entry with `transa= 'N'` or 'n', the leading m-by-k part of the array a must contain the matrix A, otherwise the leading k-by-m part of the array a must contain the matrix A.

lda

  INTEGER. Specifies the first dimension of a as declared in the calling (sub)program. When `transa= 'N'` or 'n', then lda must be at least `max(1, m)`, otherwise lda must be at least `max(1, k)`.

b

  REAL for sgemm

  DOUBLE PRECISION for dgemm

  COMPLEX for cgemm

  DOUBLE COMPLEX for zgemm

  Array, DIMENSION (ldb, kb), where kb is n when `transb = 'N'` or 'n', and is k otherwise. Before entry with `transb = 'N'` or 'n', the leading k-by-n part of the array b must contain the matrix B, otherwise the leading n-by-k part of the array b must contain the matrix B.

ldb

  INTEGER. Specifies the first dimension of b as declared in the calling (sub)program. When `transb = 'N'` or 'n', then ldb must be at least `max(1, k)`, otherwise ldb must be at least `max(1, n)`.

beta

  REAL for sgemm

  DOUBLE PRECISION for dgemm

  COMPLEX for cgemm

  DOUBLE COMPLEX for zgemm

  Specifies the scalar beta.

  When beta is equal to zero, then c need not be set on input.

c

  REAL for sgemm

  DOUBLE PRECISION for dgemm

  COMPLEX for cgemm

  DOUBLE COMPLEX for zgemm

  Array, DIMENSION (ldc, n).

  Before entry, the leading m-by-n part of the array c must contain the matrix C, except when beta is equal to zero, in which case c need not be set on entry.

ldc

  INTEGER. Specifies the first dimension of c as declared in the calling (sub)program. The value of ldc must be at least `max(1, m)`.

## Output Parameters

c

  Overwritten by the m-by-n matrix `(alpha*op(A)*op(B) + beta*C)`.

## Fortran 95 Interface Notes

Routines in Fortran 95 interface have fewer arguments in the calling sequence than their FORTRAN 77 counterparts. For general conventions applied to skip redundant or reconstructible arguments, see Fortran 95 Interface Conventions.

Specific details for the routine gemm interface are the following:

a

  Holds the matrix A of size (ma,ka) where

  `ka = k` if `transa= 'N'`,

  `ka = m` otherwise,

  `ma = m` if `transa= 'N'`,

  `ma = k` otherwise.

b

  Holds the matrix B of size (mb,kb) where

  `kb = n` if `transb = 'N'`,

  `kb = k` otherwise,

  `mb = k` if `transb = 'N'`,

  `mb = n` otherwise.

c

  Holds the matrix C of size (m,n).

transa

  Must be 'N', 'C', or 'T'.

  The default value is 'N'.

transb

  Must be 'N', 'C', or 'T'.

  The default value is 'N'.

alpha

  The default value is 1.

beta

  The default value is 1.

Parent topic: BLAS Level 3 Routines