NAG Library Routine Document

f01cwf  (complex_addsub)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

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

2
Specification

Fortran Interface
Subroutine f01cwf ( transa, transb, m, n, alpha, a, lda, beta, b, ldb, c, ldc, ifail)
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
C Header Interface
#include nagmk26.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)

3
Description

f01cwf performs one of the operations where A, B and C are matrices, α and β 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 α, β is equal to zero, unity or minus unity. The matrices, or their transposes, must be compatible for addition. A and B are either m by n or n by m matrices, depending on whether they are to be transposed before addition. C is an m by n matrix.

4
References

None.

5
Arguments

1:     transa – Character(1)Input
2:     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 transb='N'
The matrix will not be transposed.
transa or transb='T'
The matrix will be transposed.
transa or transb='C'
The matrix will be transposed and conjugated.
Constraint: transa​ or ​transb='N', 'T' or 'C'.
3:     m – IntegerInput
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: m0.
4:     n – IntegerInput
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: n0.
5:     alpha – Complex (Kind=nag_wp)Input
On entry: the scalar α, by which matrix A is multiplied before addition.
6:     alda* – Complex (Kind=nag_wp) arrayInput
Note: the second dimension of the array a must be at least max1,n if alpha0 and transa='N', max1,m if alpha0 and transa='T' or 'C' and at least 1 if alpha=0.
On entry: the matrix A. If α=0, the array a is not referenced.
7:     lda – IntegerInput
On entry: the first dimension of the array a as declared in the (sub)program from which f01cwf is called.
Constraints:
  • if transa='N', ldamax1,m;
  • otherwise ldamax1,n.
8:     beta – Complex (Kind=nag_wp)Input
On entry: the scalar β, by which matrix B is multiplied before addition.
9:     bldb* – Complex (Kind=nag_wp) arrayInput
Note: the second dimension of the array b must be at least max1,n if beta0 and transb='N', max1,m if beta0 and transb='T' or 'C' and at least 1 if beta=0.
On entry: the matrix B. If β=0, the array b is not referenced.
10:   ldb – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f01cwf is called.
Constraints:
  • if transb='N', ldbmax1,m;
  • otherwise ldbmax1,n.
11:   cldc* – Complex (Kind=nag_wp) arrayOutput
Note: the second dimension of the array c must be at least max1,n.
On exit: the elements of the m by n matrix C.
12:   ldc – IntegerInput
On entry: the first dimension of the array c as declared in the (sub)program from which f01cwf is called.
Constraint: ldcmax1,m.
13:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ 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​ 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 -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry 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:
ifail=1
On entry,one or both of transa or transb is not equal to 'N', 'T' or 'C'.
ifail=2
On entry,one or both of m or n is less than 0.
ifail=3
On entry,lda<max1,P, where P=m if transa='N', and P=n otherwise.
ifail=4
On entry,ldb<max1,P, where P=m if transb='N', and P=n otherwise.
ifail=5
On entry,ldc<max1,m.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The results returned by f01cwf are accurate to machine precision.

8
Parallelism 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.

9
Further Comments

The time taken for a call of f01cwf varies with m, n and the values of α and β. The routine is quickest if either or both of α and β are equal to zero, or plus or minus unity.

10
Example

The following program reads in a pair of matrices A and 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.1
Program Text

Program Text (f01cwfe.f90)

10.2
Program Data

Program Data (f01cwfe.d)

10.3
Program Results

Program Results (f01cwfe.r)

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