# NAG FL Interfacef11xaf (real_​gen_​matvec)

## 1Purpose

f11xaf computes a matrix-vector or transposed matrix-vector product involving a real sparse nonsymmetric matrix stored in coordinate storage format.

## 2Specification

Fortran Interface
 Subroutine f11xaf ( n, nnz, a, irow, icol, x, y,
 Integer, Intent (In) :: n, nnz, irow(nnz), icol(nnz) Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: a(nnz), x(n) Real (Kind=nag_wp), Intent (Out) :: y(n) Character (1), Intent (In) :: trans, check
#include <nag.h>
 void f11xaf_ (const char *trans, const Integer *n, const Integer *nnz, const double a[], const Integer irow[], const Integer icol[], const char *check, const double x[], double y[], Integer *ifail, const Charlen length_trans, const Charlen length_check)
The routine may be called by the names f11xaf or nagf_sparse_real_gen_matvec.

## 3Description

f11xaf computes either the matrix-vector product $y=Ax$, or the transposed matrix-vector product $y={A}^{\mathrm{T}}x$, according to the value of the argument trans, where $A$ is an $n$ by $n$ sparse nonsymmetric matrix, of arbitrary sparsity pattern. The matrix $A$ is stored in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). The array a stores all nonzero elements of $A$, while arrays irow and icol store the corresponding row and column indices respectively.
It is envisaged that a common use of f11xaf will be to compute the matrix-vector product required in the application of f11bef to sparse linear systems. An illustration of this usage appears in Section 10 in f11ddf.

None.

## 5Arguments

1: $\mathbf{trans}$Character(1) Input
On entry: specifies whether or not the matrix $A$ is transposed.
${\mathbf{trans}}=\text{'N'}$
$y=Ax$ is computed.
${\mathbf{trans}}=\text{'T'}$
$y={A}^{\mathrm{T}}x$ is computed.
Constraint: ${\mathbf{trans}}=\text{'N'}$ or $\text{'T'}$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 1$.
3: $\mathbf{nnz}$Integer Input
On entry: the number of nonzero elements in the matrix $A$.
Constraint: $1\le {\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
4: $\mathbf{a}\left({\mathbf{nnz}}\right)$Real (Kind=nag_wp) array Input
On entry: the nonzero elements in the matrix $A$, ordered by increasing row index, and by increasing column index within each row. Multiple entries for the same row and column indices are not permitted. The routine f11zaf may be used to order the elements in this way.
5: $\mathbf{irow}\left({\mathbf{nnz}}\right)$Integer array Input
6: $\mathbf{icol}\left({\mathbf{nnz}}\right)$Integer array Input
On entry: the row and column indices of the nonzero elements supplied in array a.
Constraints:
irow and icol must satisfy the following constraints (which may be imposed by a call to f11zaf):
• $1\le {\mathbf{irow}}\left(\mathit{i}\right)\le {\mathbf{n}}$ and $1\le {\mathbf{icol}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnz}}$;
• ${\mathbf{irow}}\left(\mathit{i}-1\right)<{\mathbf{irow}}\left(\mathit{i}\right)$ or ${\mathbf{irow}}\left(\mathit{i}-1\right)={\mathbf{irow}}\left(\mathit{i}\right)$ and ${\mathbf{icol}}\left(\mathit{i}-1\right)<{\mathbf{icol}}\left(\mathit{i}\right)$, for $\mathit{i}=2,3,\dots ,{\mathbf{nnz}}$.
7: $\mathbf{check}$Character(1) Input
On entry: specifies whether or not the CS representation of the matrix $A$, values of n, nnz, irow and icol should be checked.
${\mathbf{check}}=\text{'C'}$
Checks are carried on the values of n, nnz, irow and icol.
${\mathbf{check}}=\text{'N'}$
None of these checks are carried out.
Constraint: ${\mathbf{check}}=\text{'C'}$ or $\text{'N'}$.
8: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the vector $x$.
9: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the vector $y$.
10: $\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{check}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{check}}=\text{'C'}$ or $\text{'N'}$.
On entry, ${\mathbf{trans}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{trans}}=\text{'N'}$ or $\text{'T'}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{nnz}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnz}}\ge 1$.
On entry, ${\mathbf{nnz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nnz}}\le {{\mathbf{n}}}^{2}$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{a}}\left(i\right)$ is out of order: $i=〈\mathit{\text{value}}〉$.
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{icol}}\left(i\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{icol}}\left(i\right)\ge 1$ and ${\mathbf{icol}}\left(i\right)\le {\mathbf{n}}$.
On entry, $i=〈\mathit{\text{value}}〉$, ${\mathbf{irow}}\left(i\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irow}}\left(i\right)\ge 1$ and ${\mathbf{irow}}\left(i\right)\le {\mathbf{n}}$.
On entry, the location (${\mathbf{irow}}\left(\mathit{I}\right),{\mathbf{icol}}\left(\mathit{I}\right)$) is a duplicate: $\mathit{I}=〈\mathit{\text{value}}〉$.
A nonzero element has been supplied which does not lie within the matrix $A$, is out of order, or has duplicate row and column indices. Consider calling f11zaf to reorder and sum or remove duplicates.
${\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 computed vector $y$ satisfies the error bound:
• ${‖y-Ax‖}_{\infty }\le c\left(n\right)\epsilon {‖A‖}_{\infty }{‖x‖}_{\infty }$, if ${\mathbf{trans}}=\text{'N'}$, or
• ${‖y-{A}^{\mathrm{T}}x‖}_{\infty }\le c\left(n\right)\epsilon {‖{A}^{\mathrm{T}}‖}_{\infty }{‖x‖}_{\infty }$, if ${\mathbf{trans}}=\text{'T'}$,
where $c\left(n\right)$ is a modest linear function of $n$, and $\epsilon$ is the machine precision.

## 8Parallelism and Performance

f11xaf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f11xaf 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.

### 9.1Timing

The time taken for a call to f11xaf is proportional to nnz.

### 9.2Use of check

It is expected that a common use of f11xaf will be to compute the matrix-vector product required in the application of f11bef to sparse linear systems. In this situation f11xaf is likely to be called many times with the same matrix $A$. In the interests of both reliability and efficiency you are recommended to set ${\mathbf{check}}=\text{'C'}$ for the first of such calls, and to set ${\mathbf{check}}=\text{'N'}$ for all subsequent calls.

## 10Example

This example reads in a sparse matrix $A$ and a vector $x$. It then calls f11xaf to compute the matrix-vector product $y=Ax$ and the transposed matrix-vector product $y={A}^{\mathrm{T}}x$.

### 10.1Program Text

Program Text (f11xafe.f90)

### 10.2Program Data

Program Data (f11xafe.d)

### 10.3Program Results

Program Results (f11xafe.r)