X03AAF (PDF version)
X03 Chapter Contents
X03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

X03AAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

X03AAF calculates the value of a scalar product using basic precision or additional precision and adds it to a basic precision or additional precision initial value.

2  Specification

SUBROUTINE X03AAF ( A, ISIZEA, B, ISIZEB, N, ISTEPA, ISTEPB, C1, C2, D1, D2, SW, IFAIL)
INTEGER  ISIZEA, ISIZEB, N, ISTEPA, ISTEPB, IFAIL
REAL (KIND=nag_wp)  A(ISIZEA), B(ISIZEB), C1, C2, D1, D2
LOGICAL  SW

3  Description

X03AAF calculates the scalar product of two real vectors and adds it to an initial value c to give a correctly rounded result d:
d=c+i=1naibi.
If n<1, d=c.
The vector elements ai and bi are stored in selected elements of the one-dimensional array parameters A and B, which in the subroutine from which X03AAF is called may be identified with parts of possibly multidimensional arrays according to the standard Fortran rules. For example, the vectors may be parts of a row or column of a matrix. See Section 5 for details, and Section 9 for an example.
Both the initial value c and the result d are defined by a pair of real variables, so that they may take either basic precision or additional precision values.
(a) If SW=.TRUE., the products are accumulated in additional precision, and on exit the result is available either in basic precision, correctly rounded, or in additional precision.
(b) If SW=.FALSE., the products are accumulated in basic precision, and the result is returned in basic precision.
This routine is designed primarily for use as an auxiliary routine by other routines in the NAG Library, especially those in the chapters on Linear Algebra.

4  References

None.

5  Parameters

1:     A(ISIZEA) – REAL (KIND=nag_wp) arrayInput
On entry: the elements of the first vector.
The ith vector element is stored in the array element Ai-1×ISTEPA+1. In your subroutine from which X03AAF is called, A can be part of a multidimensional array and the actual argument must be the array element containing the first vector element.
2:     ISIZEA – INTEGERInput
On entry: the dimension of the array A as declared in the (sub)program from which X03AAF is called.
The upper bound for ISIZEA is found by multiplying together the dimensions of A as declared in your subroutine from which X03AAF is called, subtracting the starting position and adding 1.
Constraint: ISIZEAN-1×ISTEPA+1.
3:     B(ISIZEB) – REAL (KIND=nag_wp) arrayInput
On entry: the elements of the second vector.
The ith vector element is stored in the array element Bi-1×ISTEPB+1. In your subroutine from which X03AAF is called, B can be part of a multidimensional array and the actual argument must be the array element containing the first vector element.
4:     ISIZEB – INTEGERInput
On entry: the dimension of the array B as declared in the (sub)program from which X03AAF is called.
The upper bound for ISIZEB is found by multiplying together the dimensions of B as declared in your subroutine from which X03AAF is called, subtracting the starting position and adding 1.
Constraint: ISIZEBN-1×ISTEPB+1.
5:     N – INTEGERInput
On entry: n, the number of elements in the scalar product.
6:     ISTEPA – INTEGERInput
On entry: the step length between elements of the first vector in array A.
Constraint: ISTEPA>0.
7:     ISTEPB – INTEGERInput
On entry: the step length between elements of the second vector in array B.
Constraint: ISTEPB>0.
8:     C1 – REAL (KIND=nag_wp)Input
9:     C2 – REAL (KIND=nag_wp)Input
On entry: C1 and C2 must specify the initial value c: c=C1+C2. Normally, if c is in additional precision, C1 specifies the most significant part and C2 the least significant part; if c is in basic precision, then C1 specifies c and C2 must have the value 0.0. Both C1 and C2 must be defined on entry.
10:   D1 – REAL (KIND=nag_wp)Output
11:   D2 – REAL (KIND=nag_wp)Output
On exit: the result d.
If the calculation is in additional precision (SW=.TRUE.),
  • D1=d rounded to basic precision;
  • D2=d-D1,
thus D1 holds the correctly rounded basic precision result and the sum D1+D2 gives the result in additional precision. D2 may have the opposite sign to D1.
If the calculation is in basic precision (SW=.FALSE.),
  • D1=d;
  • D2=0.0.
12:   SW – LOGICALInput
On entry: the precision to be used in the calculation.
SW=.TRUE.
additional precision.
SW=.FALSE.
basic precision.
13:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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,ISTEPA0,
orISTEPB0.
IFAIL=2
On entry,ISIZEA>N-1×ISTEPA+1,
orISIZEB>N-1×ISTEPB+1.

7  Accuracy

If the calculation is an additional precision, the rounded basic precision result D1 is correct to full implementation accuracy, provided that exceptionally severe cancellation does not occur in the summation. If the calculation is in basic precision, such accuracy cannot be guaranteed.

8  Further Comments

The time taken by X03AAF is approximately proportional to n and also depends on whether basic precision or additional precision is used.
On exit the variables D1 and D2 may be used directly to supply a basic precision or additional precision initial value for a subsequent call of X03AAF.

9  Example

This example calculates the scalar product of the second column of the matrix A and the vector B, and add it to an initial value 1.0 where
A= -2 -3 7 2 -5 3 -9 1 0 ,  B= 8 -4 -2 .

9.1  Program Text

Program Text (x03aafe.f90)

9.2  Program Data

Program Data (x03aafe.d)

9.3  Program Results

Program Results (x03aafe.r)


X03AAF (PDF version)
X03 Chapter Contents
X03 Chapter Introduction
NAG Library Manual

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