Using the Basic Linear Algebra Subprograms (BLAS)

Four Basic Linear Algebra Subprograms (BLAS) functions are shipped with XL C/C++ in the libxlopt library. The functions consist of the following:

Because the BLAS routines are written in Fortran, all parameters are passed to them by reference, and all arrays are stored in column-major order.

Note:
Some error-handling code has been removed from the BLAS functions in libxlopt, and no error messages are emitted for calls to the these functions.

BLAS function syntax describes the prototypes and parameters for the XL C/C++ BLAS functions. The interfaces for these functions are similar to those of the equivalent BLAS functions shipped in IBM's Engineering and Scientific Subroutine Library (ESSL); for more detailed information and examples of usage of these functions, you may wish to consult the Engineering and Scientific Subroutine Library Guide and Reference, available at http://publib.boulder.ibm.com/clresctr/windows/public/esslbooks.html .

Linking the libxlopt library describes how to link to the XL C/C++ libxlopt library if you are also using a third-party BLAS library.

BLAS function syntax

The prototypes for the sgemv and dgemv functions are as follows:

void sgemv(const char *trans, int *m, int *n, float *alpha,
					void *a, int *lda, void *x, int *incx, 
					float *beta, void *y, int *incy);
void dgemv(const char *trans, int *m, int *n, double *alpha,
					void *a, int *lda, void *x, int *incx,
				  double *beta, void *y, int *incy);

The parameters are as follows:

trans
is a single character indicating the form of the input matrix a, where:
m
represents: The number of rows must be greater than or equal to zero, and less than the leading dimension of the matrix a (specified in lda)
n
represents: The number of columns must be greater than or equal to zero.
alpha
is the scaling constant for matrix a
a
is the input matrix of float (for sgemv) or double (for dgemv) values
lda
is the leading dimension of the array specified by a. The leading dimension must be greater than zero. The leading dimension must be greater than or equal to 1 and greater than or equal to the value specified in m.
x
is the input vector of float (for sgemv) or double (for dgemv) values.
incx
is the stride for vector x. It can have any value.
beta
is the scaling constant for vector y
y
is the output vector of float (for sgemv) or double (for dgemv) values.
incy
is the stride for vector y. It must not be zero.
Note:
Vector y must have no common elements with matrix a or vector x; otherwise, the results are unpredictable.

The prototypes for the sgemm and dgemm functions are as follows:

void sgemm(const char *transa, const char *transb,
   int *l, int *n, int *m, float *alpha,
   const void *a, int *lda, void *b, int *ldb,
   float *beta, void *c, int *ldc);
void dgemm(const char *transa, const char *transb,
   int *l, int *n, int *m, double *alpha, 
   const void *a, int *lda, void *b, int *ldb, 
   double *beta, void *c, int *ldc);

The parameters are as follows:

transa
is a single character indicating the form of the input matrix a, where:
transb
is a single character indicating the form of the input matrix b, where:
l
represents the number of rows in output matrix c. The number of rows must be greater than or equal to zero, and less than the leading dimension of c.
n
represents the number of columns in output matrix c. The number of columns must be greater than or equal to zero.
m
represents: and: m must be greater than or equal to zero.
alpha
is the scaling constant for matrix a
a
is the input matrix a of float (for sgemm) or double (for dgemm) values
lda
is the leading dimension of the array specified by a. The leading dimension must be greater than zero. If transa is specified as 'N' or 'n', the leading dimension must be greater than or equal to 1. If transa is specified as 'T' or 't', the leading dimension must be greater than or equal to the value specified in m.
b
is the input matrix b of float (for sgemm) or double (for dgemm) values.
ldb
is the leading dimension of the array specified by b. The leading dimension must be greater than zero. If transb is specified as 'N' or 'n', the leading dimension must be greater than or equal to the value specified in m. If transa is specified as 'T' or 't', the leading dimension must be greater than or equal to the value specified in n.
beta
is the scaling constant for matrix c
c
is the output matrix c of float (for sgemm) or double (for dgemm) values.
ldc
is the leading dimension of the array specified by c. The leading dimension must be greater than zero. If transb is specified as 'N' or 'n', the leading dimension must be greater than or equal to 0 and greater than or equal to the value specified in l.
Note:
Matrix c must have no common elements with matrices a or b; otherwise, the results are unpredictable.

By default, the libxlopt library is linked with any application you compile with XL C/C++. However, if you are using a third-party BLAS library, but want to use the BLAS routines shipped with libxlopt, you must specify the libxlopt library before any other BLAS library on the command line at link time. For example, if your other BLAS library is called libblas, you would compile your code with the following command:

xlc app.c -lxlopt -lblas

The compiler will call the sgemv, dgemv, sgemm, and dgemm functions from the libxlopt library, and all other BLAS functions in the libblas library.