# NAG Library Routine Document

## 1Purpose

f01ckf returns with the result of the multiplication of two matrices $B$ and $C$ in the matrix $A$, with the option to overwrite $B$ or $C$.

## 2Specification

Fortran Interface
 Subroutine f01ckf ( a, b, c, n, p, m, z, iz, opt,
 Integer, Intent (In) :: n, p, m, iz, opt Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (Inout) :: b(n,m), c(m,p) Real (Kind=nag_wp), Intent (Out) :: a(n,p), z(iz)
#include nagmk26.h
 void f01ckf_ (double a[], double b[], double c[], const Integer *n, const Integer *p, const Integer *m, double z[], const Integer *iz, const Integer *opt, Integer *ifail)

## 3Description

The $n$ by $m$ matrix $B$ is post-multiplied by the $m$ by $p$ matrix $C$. If ${\mathbf{opt}}=1$ the result is formed in the $n$ by $p$ matrix $A$. If ${\mathbf{opt}}=2$, $m$ must equal $p$, and the result is written back to $B$. If ${\mathbf{opt}}=3$, $n$ must equal $m$, and the result is written back to $C$.

None.

## 5Arguments

1:     $\mathbf{a}\left({\mathbf{n}},{\mathbf{p}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: if ${\mathbf{opt}}=1$, a contains the result of the matrix multiplication.
2:     $\mathbf{b}\left({\mathbf{n}},{\mathbf{m}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: the $n$ by $m$ matrix $B$.
On exit: if ${\mathbf{opt}}=2$, b contains the result of the multiplication.
3:     $\mathbf{c}\left({\mathbf{m}},{\mathbf{p}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: the $m$ by $p$ matrix $C$.
On exit: if ${\mathbf{opt}}=3$, c contains the result of the multiplication.
4:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of rows of the array $A$ and of the array $B$.
Constraints:
• if ${\mathbf{opt}}=3$, ${\mathbf{n}}={\mathbf{m}}$;
• otherwise ${\mathbf{n}}\ge 1$.
5:     $\mathbf{p}$ – IntegerInput
On entry: $p$, the number of columns of the array $A$ and of the array $C$.
Constraints:
• if ${\mathbf{opt}}=2$, ${\mathbf{p}}={\mathbf{m}}$;
• otherwise ${\mathbf{p}}\ge 1$.
6:     $\mathbf{m}$ – IntegerInput
On entry: $m$, the number of columns of the array $B$ and rows of the array $C$.
Constraints:
• if ${\mathbf{opt}}=2$, ${\mathbf{m}}={\mathbf{p}}$;
• if ${\mathbf{opt}}=3$, ${\mathbf{m}}={\mathbf{n}}$;
• if ${\mathbf{opt}}\ne 1$, ${\mathbf{m}}\le {\mathbf{iz}}$;
• otherwise ${\mathbf{m}}\ge 1$.
7:     $\mathbf{z}\left({\mathbf{iz}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
8:     $\mathbf{iz}$ – IntegerInput
On entry: the dimension of the array z as declared in the (sub)program from which f01ckf is called.
Constraints:
• if ${\mathbf{opt}}=1$, ${\mathbf{iz}}\ge 1$;
• if ${\mathbf{opt}}\ne 1$, ${\mathbf{iz}}\ge {\mathbf{m}}$.
9:     $\mathbf{opt}$ – IntegerInput
On entry: the value of opt determines which array is to contain the final result.
${\mathbf{opt}}=1$
a must be distinct from b and c and, on exit, contains the result. b and c need not be distinct in this case.
${\mathbf{opt}}=2$
b must be distinct from c and on exit, contains the result. a is not used in this case and need not be distinct from b or c.
${\mathbf{opt}}=3$
c must be distinct from b and on exit, contains the result. a is not used in this case and need not be distinct from b or c.
Constraint: $1\le {\mathbf{opt}}\le 3$.
10:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, m or p or ${\mathbf{n}}\le 0$.
${\mathbf{ifail}}=2$
${\mathbf{opt}}=2$ and ${\mathbf{m}}\ne {\mathbf{p}}$.
${\mathbf{ifail}}=3$
${\mathbf{opt}}=3$ and ${\mathbf{n}}\ne {\mathbf{m}}$.
${\mathbf{ifail}}=4$
${\mathbf{opt}}\ne 1$ and ${\mathbf{iz}}<{\mathbf{m}}$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

Each element of the result is effectively computed as an inner product using basic precision.

## 8Parallelism and Performance

f01ckf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The time taken by f01ckf is approximately proportional to $mnp$.

## 10Example

This example multiplies the $2$ by $3$ matrix $B$ and the $3$ by $2$ matrix $C$ together and places the result in the $2$ by $2$ matrix $A$.

### 10.1Program Text

Program Text (f01ckfe.f90)

### 10.2Program Data

Program Data (f01ckfe.d)

### 10.3Program Results

Program Results (f01ckfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017