UMBC logo
UMBC High Performance Computing Facility
Please note that this page is under construction. We are documenting the 240-node cluster maya that will be available after Summer 2014. Currently, the 84-node cluster tara still operates independently, until it becomes part of maya at the end of Summer 2014. Please see the 2013 Resources Pages under the Resources tab for tara information.
How to use MKL on maya

Introduction

MKL (Math Kernel Library) is a library of math procedures from Intel, which includes BLAS, LAPACK, and ScaLAPACK. On this page, we will show how to start using MKL with the Intel compiler on maya. Before you begin, make sure to read the tutorial for compiling C programs.

To follow along, ensure that you have the Intel compiler module loaded.

[araim1@maya-usr1 ~]$ module list
Currently Loaded Modulefiles:
  1) gcc/4.8.1                     2) slurm/2.5.7
  3) intel/2013_sp1                4) mvapich2/intel/2013_sp1/1.9
[araim1@maya-usr1 ~]$
The serial examples do not depend on the "mvapich2/intel/2013_sp1/1.9" module. Next, run the following script to ensure your environment is set to use MKL. (Note the "." at the beginning of the command).
[araim1@maya-usr1 ~]$ . /usr/cluster/intel/composer_xe_2013_sp1/mkl/bin/mklvars.sh intel64
Extensive documentation about programming with MKL can be found at Intel's reference manual.

BLAS Example: Matrix Multiply

Consider three matrices \(A \in \mathbb{R}^{m \times k} \), \(B \in \mathbb{R}^{k \times n} \), and \(C \in \mathbb{R}^{m \times n} \), where all are represented as double precision floating point numbers. We will demonstrate the use of the "dgemm" function which computes \[ C = \alpha AB + \beta C. \] We will take \(\alpha = 1\) and \(\beta = 0\) to compute the simple matrix multiplication \( C = AB \). MKL has several versions of this function; we will use "cblas_dgemm", which has bit friendlier "C-style" interface than other variants. The most important line in the code is
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans,
   m, n, k, 1.0, A, m, B, k, 0.0, C, m);
Also notice in the Makefile that the option "-mkl" is given in CFLAGS, which enables the use of MKL. Next we compile and run the code.
[araim1@maya-usr1 matrix-multply]$ make clean
rm -f *.o matrix-multiply
[araim1@maya-usr1 matrix-multply]$ make
icc -O3 -std=c99 -mkl   -c matrix-multiply.c -o matrix-multiply.o
icc -O3 -std=c99 -mkl   matrix-multiply.o -o matrix-multiply  
[araim1@maya-usr1 matrix-multply]$ ./matrix-multiply 
Matrix A (3 x 5) is:
  1.0000  0.7290  0.5314  0.3874  0.2824
  0.9000  0.6561  0.4783  0.3487  0.2542
  0.8100  0.5905  0.4305  0.3138  0.2288

Matrix B (5 x 4) is:
  1.0000  0.5905  0.3487  0.2059
  0.9000  0.5314  0.3138  0.1853
  0.8100  0.4783  0.2824  0.1668
  0.7290  0.4305  0.2542  0.1501
  0.6561  0.3874  0.2288  0.1351

Matrix C (3 x 4) = AB is:
  2.5543  1.5083  0.8906  0.5259
  2.2989  1.3575  0.8016  0.4733
  2.0690  1.2217  0.7214  0.4260
[araim1@maya-usr1 matrix-multply]$
For more information about matrix multiplication with MKL, see this tutorial from Intel.

LAPACK Example: SVD

Given a matrix \(A \in \mathbb{R}^{m \times n} \), we will demonstrate the LAPACK "dgesvd" function for computing the singular value decomposition (SVD) \[ A = U S V^T, \] where \(S \in \mathbb{R}^{m \times n}\) is a diagonal matrix of singular values, \(U \in \mathbb{R}^{m \times m}\), and \(V^T \in \mathbb{R}^{n \times n}\). The MKL function call we will use is "LAPACKE_dgesvd". The most important line in the code, where the SVD is being computed, is
int info = LAPACKE_dgesvd(CblasColMajor, 'A', 'A', m, n, A, m, S, U, m,
   VT, n, superb);
Next we compile and run the code.
[araim1@maya-usr1 svd]$ make
icc -O3 -std=c99 -mkl   -c -o matrix-svd.o matrix-svd.c
icc -O3 -std=c99 -mkl   matrix-svd.o -o matrix-svd  
[araim1@maya-usr1 svd]$ ./matrix-svd 
Matrix A (3 x 4) is:
  1.0000  0.5000  0.3333  0.2500
  0.5000  0.3333  0.2500  0.2000
  0.3333  0.2500  0.2000  0.1667

Matrix U (3 x 3) is:
 -0.8199  0.5563  0.1349
 -0.4662 -0.5123 -0.7213
 -0.3322 -0.6543  0.6794

Vector S (3 x 1) is:
  1.4519
  0.1433
  0.0042

Matrix VT (4 x 4) is:
 -0.8015 -0.4466 -0.3143 -0.2435
  0.5729 -0.3919 -0.5127 -0.5053
  0.1692 -0.7398  0.1245  0.6392
 -0.0263  0.3157 -0.7892  0.5261
[araim1@maya-usr1 svd]$