- BLAS Libraries
- How to run BLAS from a Fortran Program
- How to run BLAS from a C program
- How to run BLAS from a C++ program
There are four different libraries that include the Basic Linear Algebra Subprograms (BLAS) routines:
- BLAS library from the Netlib Repository
- This library was compiled using the Intel Compiler or other high-performance Fortran compiler that was purchased for the cluster. This library is the simplest one to link to and use.
- ATLAS library
- When this library was built, it automatically optimized its performance for whatever system it was built on, in this case, these routines are optimized for the cluster compute nodes.
- Intel-MKL library
- The Intel-MKL library includes the BLAS routines. The Intel-MKL library performed very well in our benchmarks.
- GNU Scientific Library (GSL)
- GSL includes a C version of the BLAS routines.
For a comparison of these libraries see: BLAS Benchmark.
- The BLAS library from the Netlib Repository is installed in: /u/local/apps/blas/current/
- The ATLAS library is installed in: /u/local/apps/atlas/current/
- The Intel-MKL library is installed in: /u/local/compilers/intel/current/current/mkl/
- The GSL library is installed in: /u/local/apps/gsl/current/
To compile and link with the BLAS library from the Netlib Repository:
ifort pgm.f -L$BLAS_HOME -lblas
To compile and link with the ATLAS library:
ifort pgm.f -L$ATLAS_HOME -lf77blas -latlas
To compile and link with the Intel-MKL library please refer to How to Use the Intel-MKL Libraries.
- Replace pgm.f(90) with the name of the file containing your source code
- Replace pgm with the name of the executable to be created.
- Set BLAS_HOME to: /u/local/apps/blas/current
- Set ATLAS_HOME to: /u/local/apps/atlas/current
How to use a BLAS routine from GSL
In your program include the appropriate GSL header files as follows:
To compile and link enter:
CC pgm.c -I$GSL_HOME/include -L$GSL_HOME/lib -lgsl -lgslcblas -lm [-static] -o pgm
- Replace CC with either gcc or icc depending on which compiler you want to use.
- Replace pgm.c with the name of the file containing your source code
- Replace pgm with the name of the executable to be created
- Set GSL_HOME to: /u/local/apps/gsl/current
If you omit -static, you will have to set the LD_LIBRARY_PATH environment variable at run time to include $GSL_HOME/lib
How to use a BLAS routine from Netlib, ATLAS or Intel-MKL
To use BLAS from a C program, replace ifort with icc and add an _ to the end of the subroutine name. For example to call sgemm code:
extern void sgemm_( char *, char *, int *, int *, int * float *, float *, int *, float *, int *, float *, float *, int * );
If you use gcc instead of icc, you additionally have to add:
to the command used to compile and link.
To use BLAS from a C++ program you must declare each BLAS function you will call as being extern as in the following example:
extern “C” void sgemm_( char *, char *, int *, int *, int * float *, float *, int *, float *, int *, float *, float *, int * );
code the function name (with _ appended) and the argument list for the function you are calling.
To compile and link, replace ifort with icpc.