## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

f01cwf adds two complex matrices, each one optionally transposed and multiplied by a scalar.

## 2Specification

Fortran Interface
 Subroutine f01cwf ( m, n, a, lda, beta, b, ldb, c, ldc,
 Integer, Intent (In) :: m, n, lda, ldb, ldc Integer, Intent (Inout) :: ifail Complex (Kind=nag_wp), Intent (In) :: alpha, a(lda,*), beta, b(ldb,*) Complex (Kind=nag_wp), Intent (Inout) :: c(ldc,*) Character (1), Intent (In) :: transa, transb
#include <nag.h>
 void f01cwf_ (const char *transa, const char *transb, const Integer *m, const Integer *n, const Complex *alpha, const Complex a[], const Integer *lda, const Complex *beta, const Complex b[], const Integer *ldb, Complex c[], const Integer *ldc, Integer *ifail, const Charlen length_transa, const Charlen length_transb)
The routine may be called by the names f01cwf or nagf_matop_complex_addsub.

## 3Description

f01cwf performs one of the operations
• $C≔\alpha A+\beta B$,
• $C≔\alpha {A}^{\mathrm{T}}+\beta B$,
• $C≔\alpha {A}^{\mathrm{H}}+\beta B$,
• $C≔\alpha A+\beta {B}^{\mathrm{T}}$,
• $C≔\alpha {A}^{\mathrm{T}}+\beta {B}^{\mathrm{T}}$,
• $C≔\alpha {A}^{\mathrm{H}}+\beta {B}^{\mathrm{T}}$,
• $C≔\alpha A+\beta {B}^{\mathrm{H}}$,
• $C≔\alpha {A}^{\mathrm{T}}+\beta {B}^{\mathrm{H}}$ or
• $C≔\alpha {A}^{\mathrm{H}}+\beta {B}^{\mathrm{H}}$,
where $A$, $B$ and $C$ are matrices, $\alpha$ and $\beta$ are scalars, $T$ denotes transposition and $H$ denotes conjugate transposition. For efficiency, the routine contains special code for the cases when one or both of $\alpha$, $\beta$ is equal to zero, unity or minus unity. The matrices, or their transposes, must be compatible for addition. $A$ and $B$ are either $m×n$ or $n×m$ matrices, depending on whether they are to be transposed before addition. $C$ is an $m×n$ matrix.

None.

## 5Arguments

1: $\mathbf{transa}$Character(1) Input
2: $\mathbf{transb}$Character(1) Input
On entry: transa and transb must specify whether or not the matrix $A$ and the matrix $B$, respectively, are to be transposed before addition.
transa or ${\mathbf{transb}}=\text{'N'}$
The matrix will not be transposed.
transa or ${\mathbf{transb}}=\text{'T'}$
The matrix will be transposed.
transa or ${\mathbf{transb}}=\text{'C'}$
The matrix will be transposed and conjugated.
Constraint: ${\mathbf{transa}}\text{​ or ​}{\mathbf{transb}}=\text{'N'}$, $\text{'T'}$ or $\text{'C'}$.
3: $\mathbf{m}$Integer Input
On entry: $m$, the number of rows of the matrices $A$ and $B$ or their transposes. Also the number of rows of the matrix $C$.
Constraint: ${\mathbf{m}}\ge 0$.
4: $\mathbf{n}$Integer Input
On entry: $n$, the number of columns of the matrices $A$ and $B$ or their transposes. Also the number of columns of the matrix $C$.
Constraint: ${\mathbf{n}}\ge 0$.
5: $\mathbf{alpha}$Complex (Kind=nag_wp) Input
On entry: the scalar $\alpha$, by which matrix $A$ is multiplied before addition.
6: $\mathbf{a}\left({\mathbf{lda}},*\right)$Complex (Kind=nag_wp) array Input
Note: the second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{alpha}}\ne 0$ and ${\mathbf{transa}}=\text{'N'}$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ if ${\mathbf{alpha}}\ne 0$ and ${\mathbf{transa}}=\text{'T'}$ or $\text{'C'}$ and at least $1$ if ${\mathbf{alpha}}=0$.
On entry: the matrix $A$. If $\alpha =0$, the array a is not referenced.
7: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f01cwf is called.
Constraints:
• if ${\mathbf{transa}}=\text{'N'}$, ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
8: $\mathbf{beta}$Complex (Kind=nag_wp) Input
On entry: the scalar $\beta$, by which matrix $B$ is multiplied before addition.
9: $\mathbf{b}\left({\mathbf{ldb}},*\right)$Complex (Kind=nag_wp) array Input
Note: the second dimension of the array b must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$ if ${\mathbf{beta}}\ne 0$ and ${\mathbf{transb}}=\text{'N'}$, $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$ if ${\mathbf{beta}}\ne 0$ and ${\mathbf{transb}}=\text{'T'}$ or $\text{'C'}$ and at least $1$ if ${\mathbf{beta}}=0$.
On entry: the matrix $B$. If $\beta =0$, the array b is not referenced.
10: $\mathbf{ldb}$Integer Input
On entry: the first dimension of the array b as declared in the (sub)program from which f01cwf is called.
Constraints:
• if ${\mathbf{transb}}=\text{'N'}$, ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$;
• otherwise ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
11: $\mathbf{c}\left({\mathbf{ldc}},*\right)$Complex (Kind=nag_wp) array Output
Note: the second dimension of the array c must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On exit: the elements of the $m×n$ matrix $C$.
12: $\mathbf{ldc}$Integer Input
On entry: the first dimension of the array c as declared in the (sub)program from which f01cwf is called.
Constraint: ${\mathbf{ldc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
13: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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, ${\mathbf{transa}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{transa}}=\text{'N'}$, $\text{'T'}$ or $\text{'C'}$.
On entry, ${\mathbf{transb}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{transb}}=\text{'N'}$, $\text{'T'}$ or $\text{'C'}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 0$ and ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{lda}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{transa}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
On entry, ${\mathbf{lda}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{transa}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{lda}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{ldb}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{transb}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
On entry, ${\mathbf{ldb}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{transb}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{ldc}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldc}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The results returned by f01cwf are accurate to machine precision.

## 8Parallelism and Performance

f01cwf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
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 for a call of f01cwf varies with m, n and the values of $\alpha$ and $\beta$. The routine is quickest if either or both of $\alpha$ and $\beta$ are equal to zero, or plus or minus unity.

## 10Example

The following program reads in a pair of matrices $A$ and ${\mathbf{b}}$, along with values for transa, transb, alpha and beta, and adds them together, printing the result matrix $C$. The process is continued until the end of the input stream is reached.

### 10.1Program Text

Program Text (f01cwfe.f90)

### 10.2Program Data

Program Data (f01cwfe.d)

### 10.3Program Results

Program Results (f01cwfe.r)