# NAG Library Routine Document

## 1Purpose

f12anf is a setup routine in a suite of routines consisting of f12anf, f12apf, f12aqf, f12arf and f12asf. It is used to find some of the eigenvalues (and optionally the corresponding eigenvectors) of a standard or generalized eigenvalue problem defined by complex nonsymmetric matrices.
The suite of routines is suitable for the solution of large sparse, standard or generalized, nonsymmetric complex eigenproblems where only a few eigenvalues from a selected range of the spectrum are required.

## 2Specification

Fortran Interface
 Subroutine f12anf ( n, nev, ncv, comm,
 Integer, Intent (In) :: n, nev, ncv, licomm, lcomm Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: icomm(max(1,licomm)) Complex (Kind=nag_wp), Intent (Out) :: comm(max(1,lcomm))
#include <nagmk26.h>
 void f12anf_ (const Integer *n, const Integer *nev, const Integer *ncv, Integer icomm[], const Integer *licomm, Complex comm[], const Integer *lcomm, Integer *ifail)

## 3Description

The suite of routines is designed to calculate some of the eigenvalues, $\lambda$, (and optionally the corresponding eigenvectors, $x$) of a standard complex eigenvalue problem $Ax=\lambda x$, or of a generalized complex eigenvalue problem $Ax=\lambda Bx$ of order $n$, where $n$ is large and the coefficient matrices $A$ and $B$ are sparse, complex and nonsymmetric. The suite can also be used to find selected eigenvalues/eigenvectors of smaller scale dense, complex and nonsymmetric problems.
f12anf is a setup routine which must be called before f12apf, the reverse communication iterative solver, and before f12arf, the options setting routine. f12aqf is a post-processing routine that must be called following a successful final exit from f12apf, while f12asf can be used to return additional monitoring information during the computation.
This setup routine initializes the communication arrays, sets (to their default values) all options that can be set by you via the option setting routine f12arf, and checks that the lengths of the communication arrays as passed by you are of sufficient length. For details of the options available and how to set them see Section 11.1 in f12arf.

## 4References

Lehoucq R B (2001) Implicitly restarted Arnoldi methods and subspace iteration SIAM Journal on Matrix Analysis and Applications 23 551–562
Lehoucq R B and Scott J A (1996) An evaluation of software for computing eigenvalues of sparse nonsymmetric matrices Preprint MCS-P547-1195 Argonne National Laboratory
Lehoucq R B and Sorensen D C (1996) Deflation techniques for an implicitly restarted Arnoldi iteration SIAM Journal on Matrix Analysis and Applications 17 789–821
Lehoucq R B, Sorensen D C and Yang C (1998) ARPACK Users' Guide: Solution of Large-scale Eigenvalue Problems with Implicitly Restarted Arnoldi Methods SIAM, Philidelphia

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: the order of the matrix $A$ (and the order of the matrix $B$ for the generalized problem) that defines the eigenvalue problem.
Constraint: ${\mathbf{n}}>0$.
2:     $\mathbf{nev}$ – IntegerInput
On entry: the number of eigenvalues to be computed.
Constraint: $0<{\mathbf{nev}}<{\mathbf{n}}-1$.
3:     $\mathbf{ncv}$ – IntegerInput
On entry: the number of Arnoldi basis vectors to use during the computation.
At present there is no a priori analysis to guide the selection of ncv relative to nev. However, it is recommended that ${\mathbf{ncv}}\ge 2×{\mathbf{nev}}+1$. If many problems of the same type are to be solved, you should experiment with increasing ncv while keeping nev fixed for a given test problem. This will usually decrease the required number of matrix-vector operations but it also increases the work and storage required to maintain the orthogonal basis vectors. The optimal ‘cross-over’ with respect to CPU time is problem dependent and must be determined empirically.
Constraint: ${\mathbf{nev}}+1<{\mathbf{ncv}}\le {\mathbf{n}}$.
4:     $\mathbf{icomm}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{licomm}}\right)\right)$ – Integer arrayCommunication Array
On exit: contains data to be communicated to the other routines in the suite.
5:     $\mathbf{licomm}$ – IntegerInput
On entry: the dimension of the array icomm as declared in the (sub)program from which f12anf is called.
If ${\mathbf{licomm}}=-1$, a workspace query is assumed and the routine only calculates the required dimensions of icomm and comm, which it returns in ${\mathbf{icomm}}\left(1\right)$ and ${\mathbf{comm}}\left(1\right)$ respectively.
Constraint: .
6:     $\mathbf{comm}\left(\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{lcomm}}\right)\right)$ – Complex (Kind=nag_wp) arrayCommunication Array
On exit: contains data to be communicated to the other routines in the suite.
7:     $\mathbf{lcomm}$ – IntegerInput
On entry: the dimension of the array comm as declared in the (sub)program from which f12anf is called.
If ${\mathbf{lcomm}}=-1$, a workspace query is assumed and the routine only calculates the dimensions of icomm and comm required by f12apf, which it returns in ${\mathbf{icomm}}\left(1\right)$ and ${\mathbf{comm}}\left(1\right)$ respectively.
Constraint: .
8:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . 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  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  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{n}}\le 0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{nev}}\le 0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{ncv}}<{\mathbf{nev}}+2$ or ${\mathbf{ncv}}>{\mathbf{n}}$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{licomm}}<140$ and ${\mathbf{licomm}}\ne -1$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{lcomm}}<3×{\mathbf{n}}+3×{\mathbf{ncv}}×{\mathbf{ncv}}+5×{\mathbf{ncv}}+60$ and ${\mathbf{lcomm}}\ne -1$.
${\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.

Not applicable.

## 8Parallelism and Performance

f12anf is not threaded in any implementation.

None.

## 10Example

This example solves $Ax=\lambda x$ in regular mode, where $A$ is obtained from the standard central difference discretization of the convection-diffusion operator $\frac{{\partial }^{2}u}{\partial {x}^{2}}+\frac{{\partial }^{2}u}{\partial {y}^{2}}+\rho \frac{\partial u}{\partial x}$ on the unit square, with zero Dirichlet boundary conditions. The eigenvalues of largest magnitude are found.

### 10.1Program Text

Program Text (f12anfe.f90)

### 10.2Program Data

Program Data (f12anfe.d)

### 10.3Program Results

Program Results (f12anfe.r)