# ?gemm3m

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

## Syntax

FORTRAN 77:

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

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

Fortran 95:

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

## Description

The ?gemm3m routines perform a matrix-matrix operation with general complex matrices. These routines are similar to the ?gemm routines, but they used matrix multiplications (see Application Notes below).

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

  COMPLEX for cgemm3m

  DOUBLE COMPLEX for zgemm3m

  Specifies the scalar alpha.

a

  COMPLEX for cgemm3m

  DOUBLE COMPLEX for zgemm3m

  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

  COMPLEX for cgemm3m

  DOUBLE COMPLEX for zgemm3m

  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

  COMPLEX for cgemm3m

  DOUBLE COMPLEX for zgemm3m

  Specifies the scalar beta.

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

c

  COMPLEX for cgemm3m

  DOUBLE COMPLEX for zgemm3m

  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 gemm3m 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.

## Application Notes

These routines perform the complex multiplication by forming the real and imaginary parts of the input matrices. It allows to use three real matrix multiplications and five real matrix additions, instead of the conventional four real matrix multiplications and two real matrix additions. The use of three real matrix multiplications only gives a 25% reduction of time in matrix operations. This can result in significant savings in computing time for large matrices.

If the errors in the floating point calculations satisfy the following conditions:

`fl(x op y)=(x op y)(1+δ),|δ|≤u, op=×,/, fl(x±y)=x(1+α)±y(1+β), |α|,|β|≤u`

then for n-by-n matrix`Ĉ=fl(C1+iC2)= fl((A1+iA2)(B1+iB2))=Ĉ1+iĈ2` the following estimations are correct

`║Ĉ1-C2║≤ 2(n+1)u║A║∞║B║∞+O(u2)`,

`║Ĉ2-C1║≤ 4(n+4)u║A║∞║B║∞+O(u2)`,

where `║A║∞=max(║A1║∞,║A2║∞)`, and `║B║∞=max(║B1║∞,║B2║∞)`.

and hence the matrix multiplications are stable.

Parent topic: BLAS Level 3 Routines