MTSOS: BLAS tips

BLAS stands for Basic Linear Algebra Subroutines and is a library of linear algebra subroutines that have been optimized for a particular system. Thus rather than manually writing out these operators one can call the BLAS subroutine as they have been optimized with respect to hardware to perform much faster. Many systems already include BLAS (for example LAPACK includes BLAS, and most Mac releases) but if not, one can download an optimized implementation which can be found from the BLAS page or it can be compiled using ATLAS. Aside from being necessary for MTSOS, many users may want to use these functions in their custom barrier and dynamics functions. Below we explain the BLAS interface for C that is provided with MATLAB, which is also the interface used by most Mac implementations, for several useful functions.

NOTE: This interface is different from the ATLAS ANSI/ISO C BLAS API Reference which will result from ATLAS, and different from the C interface in the BLAS Standard. Should a BLAS library with a different interface be used, modifications may be necessary to the MTSOS code (there are three calls to dgemv in MTSOS.c).

dgemv

Calculates y = alpha A x+beta y. Note that ptrdiff_t is the result of pointer subtraction, and can be considered an int.

void dgemv( char* trans, ptrdiff_t* m, ptrdiff_t*n, double* alpha,

double* A, ptrdiff_t* lda, double* x, ptrdiff_t* incx, double* beta,
double* y, ptrdiff_t* incy)

char* trans N: matrix A is provided in column first order
T: matrix A is provided in row order (alternatively, this will take the transpose of A)
ptrdiff_t* m the number of rows in A
ptrdiff_t* n the number of columns in A
double* alpha alpha
double* A an array that is a column first (if you set trans = N) representation of A
ptrdiff_t* lda typically m (the number of rows in A); A(i,j) is found at A[i + lda*j] (assuming indices start at 0)
double* x an array with the value of x
ptrdiff_t* incx typically 1; the value of x(i) is found at x[i*incx]
double* beta beta; if only Ax is desired, set to zero
double* y an array with the value of y in which the solution will be stored; must be at least size m
ptrdiff_t* incy typically 1; the value of y(i) is found at y[i*incy]

dsyr

Calculates A = alpha x x ^ T + A where A is symmetric. Note that ptrdiff_t is the result of pointer subtraction can can be considered an int.

char* uplo L: the solution and values of A are stored in the lower triangular portion of the matrix
U: the solution and values of A are stored in the upper triangular portion of the matrix
ptrdiff_t* n the length of the vector x
double* alpha alpha
double* x an array with the value of x
ptrdiff_t* incx an integer such that x(i) can be found at x[i*incx]
double* A a length ntimes n array where the values of A are either stored in the indices corresponding to a lower triangular matrix (uplo = L) or an upper triangular matrix (uplo = U); this is also the array that will store the soluiton
ptrdiff_t* lda an integer such that A(i,j) is found at A[i+lda*j]

dgemm

Calculates C=alpha AB + beta C. Note that ptrdiff_t is the result of pointer subtraction can can be considered an int.

char* transa N: matrix A is provided in column first order
T: matrix A is provided in row order (alternatively, this will take the transpose of A)
char* transb N: matrix B is provided in column first order
T: matrix B is provided in row order (alternatively, this will take the transpose of B)
ptrdiff_t* m the number of rows in A (if transa = N)
ptrdiff_t* n the number of columns in B (if transb = N)
ptrdiff_t* k the number of columns in A and by association the number of rows in B (assuming transa = transb = N
double* alpha alpha
double* a a size mtimesk array representing A
ptrdiff_t* lda typically, m; an integer such that A(i,j) can be found at A[i+lda*j]
double* b a size ktimesn array representing B
ptrdiff_t* ldb typically, k; an integer such that B(i,j) can be found at B[i+ldb*j]
double* beta beta
double* c a size mtimesn array representing C (column first); this matrix will be overwritten to contain the solution
ptrdiff_t* ldc typically, m; an integer such that the C(i,j) is found at C[i+ldc*j]