|
Boost.Numeric.Bindings.Blas |
For calculating y += a * x
where y
and x
are vectors of doubles and a
a scalar, the BLAS daxpy function can be used. On many systems optimised BLAS libraries are available which provide optimal performance. The BLAS bindings can be used to call these functions on uBLAS vectors, std::vector's and many other C++ classes modelling vectors.
Many BLAS implementations are written in Fortran. Therefor, when calling these functions from C or C++, the way these symbols are written in the object file (by the Fortran compiler) need to be matched. Many compilers for instance add an extra understore to the function name or store function names always in capitals.
To match the function names as stored in the BLAS library, a macro FORTRAN_ID
can be used on the function name. This macro will, dependent on the toolset, change the function-name to match the corresponding function in the BLAS library.
See blas_names.h
At the second level, C signatures are provided which map directly onto the BLAS functions. The mapping from Fortran to C types is as follows:
Fortran type | Mapped to C type |
REAL | float |
DOUBLE | double |
COMPLEX | fcomplex_t |
COMPLEX*16 | dcomplex_t |
traits/type.h
. These are respectively typedefs to float and double but pointers to fcomplex_ or dcomplex_t are supposed to point to two consecutive floating points in memory that represent the real and imaginary value.
Note that all arguments are passed by reference to match the calling conventions used by Fortran compilers. Note also that these signatures are const-correct although const-ness is not mentioned in the BLAS standard. If not const-correct however, using the bindings would require to cast many consts away.
See blas.h
The C layer of bindings provide different functions for every operation with different datatypes. To provide generics, at this level overloaded functions are available that can be called for all supported datatypes.
See blas_overloads.hpp
The flexibility of the BLAS functions also have a price. BLAS functions allow vectors to have increments different from one or only manipulate parts of matrices (taking into account the leading dimension of the matrix). This requires however all functions to have many arguments. But many of the information that needs to be passes on to BLAS is already contained in C++ matrix libraries. Therefor high level bindings are provided which require you to only specify the containers and the operation you want to perform on them.
See blas1.hpp, blas2.hpp and blas3.hpp