# Using FLENS-BLAS

FLENS-BLAS is built on top of CXXBLAS and utilizes FLENS matrix/vector types. Main benefits are:

• It is easier to use as functions from FLENS-BLAS require less arguments

• Technical details like are encapsulated in the implementation and hidden from the user. You pass complete matrix/vector types instead of things like pointers and dimensions. This makes your code less error prone.

## Toy Example

We use the same example as before, i.e. we compute $$y = \beta y + \alpha\,A^T x + z$$ where $$\alpha, \beta$$ are scalars, $$x, y, z$$ are (dense) vectors and $$A$$ is a (general) matrix (with full storage).

Using FLENS-BLAS for this task we

• first call mv which internally calls gemv from CXXBLAS

• and subsequently axpy which internnaly calls axpy from CXXBLAS.

As long as you do not compile with -DNDEBUG the FLENS-BLAS layer also does some error-checking on its arguments.

## Example Code

#include <flens/flens.cxx>
#include <iostream>

using namespace flens;
using namespace std;

int
main()
{
typedef double                               T;
typedef DenseVector<Array<T> >               DEVector;
typedef GeMatrix<FullStorage<T, ColMajor> >  GEMatrix;

const T  alpha = 1.5,
beta = 2.5;

DEVector x(3), y(3), z(3);
x = 123;
y = 234;
z = 345;

GEMatrix A(3,3);
A = 123,
567,
543;

blas::mv(Trans, alpha, A, x, beta, y);

blas::axpy(T(1), z, y);

cout << "y = " << y << endl;

return 0;
}

Compute $$y = \beta y + \alpha A^T x$$

blas::mv(Trans, alpha, A, x, beta, y);

Compute the update $$y = y + z$$

blas::axpy(T(1), z, y);

## Compile and Run

$shell> cd flens/examples$shell> g++ -Wall -std=c++11 -I../.. tut02-page02-example.cc
\$shell> ./a.out
y =
47           50.5             54