LAPACK/BLAS
LAPACK/BLAS
Basic Linear Algebra Subprograms (BLAS) library is an archive of common combination of Vector, and Matrix operations. Switch -llapack, and -lblas are usually used in the code compilation.
Library/Compiler Version
To check the version of Intel Compilers, type:
ifort --version
output:
ifort (IFORT) 17.0.1 20161005
Copyright (C) 1985-2016 Intel Corporation. All rights reserved.
If you need to use different version of intel compilers than the default version in HPC, please check the modules and then load the appropriate one.
module avail intel
output:
----------- /usr/local/share/modulefiles/Core ------------
intel/17 (L)
Both BLAS and LAPACK are installed in the LAPACK module:
module spider lapack
outputs:
------------------------------------------------------
lapack:
------------------------------------------------------
Description:
provides routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems. The associated matrix factorizations (LU, Cholesky, QR, SVD, Schur, generalized Schur) are also provided, as are related computations such as reordering of the Schur factorizations and estimating condition numbers. Dense and banded matrices are handled, but not general sparse matrices. In all areas, similar functionality is provided for real and complex matrices, in both single and double precision.
Versions:
lapack/3.7.0
------------------------------------------------------
For detailed information about a specific "lapack" module (including how to load the modules) use the module's full name.
For example:
$ module spider lapack/3.7.0
------------------------------------------------------
Load the appropriate module. Do the same for lapack and blas.
module load intel/<version>
Running Lapack/Blas in HPC
Copy the sample LAPACK code (mat_inv.f90) inverts a Non-Hermitian Complex Matrix.
COMPLEX MAT(2,2), WORK(2)
INTEGER PIVOT(2), STAT
MAT(1,1)=(1,1)
MAT(1,2)=(2,-1)
MAT(2,1)=(3,1)
MAT(2,2)=(4,-1)
CALL CGETRF(2,2,MAT,2,PIVOT,STAT)
CALL CGETRI(2,MAT,2,2,WORK,2,STAT)
PRINT *, MAT
END
Interactive
Request a compute node
srun --pty bash
Load the lapack and blas modules
module load lapack
Compile with lapack and blas libraries
ifort mat_inv.f90 -lblas -llapack
Run
./a.out
Batch
Copy the content in your file (let's say job.slurm) in the same directory where the Fortran code is.
#!/bin/bash
#SBATCH --time=00:10:00
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -J lapack-blas-test
#SBATCH -o output
module load lapack
cp -r * $PFSDIR
cd $PFSDIR
ifort mat_inv.f90 -lblas -llapack
./a.out
cp -ru * $SLURM_SUBMIT_DIR
Submit the job
sbatch job.slurm
The output will be in the output file. Verification: type inv([1+i, 2-i; 3+i, 4-i]) in MATLAB:
(-0.6000000,-0.7000001) (9.9999920E-02,0.7000000) (0.4000000,0.3000001)\
(0.1000000,-0.3000000)
Note on GNU compilers
If you want to use the GNU compilers, the above examples work in a similar way. The only differences are:
load gcc via module load gcc
replace any instance of ifort by gfortran.