1 intel mathematics kernel library (mkl) quickstart cola lab, department of mathematics, nat’l...

24
1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

Upload: edwin-scot-potter

Post on 27-Dec-2015

237 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

1

Intel Mathematics Kernel Library (MKL) Quickstart

COLA Lab, Department of Mathematics, Nat’l Taiwan University2010/05/11

Page 2: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

2 Intel MKL Quickstart

Credits

Credits

Wei-Ren Chang 張為仁 (slides and codes, 2009/03/10) Lien-Chi Lai 賴鍊奇 (slides, 2010/05/11)

Page 3: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

3 Intel MKL Quickstart

A Brief Introduction

Page 4: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

4 Intel MKL Quickstart

Intel MKL: Intel Math Kernel Library

Introduction

Availability: Windows, LinuxFunctionality Dense and Sparse Linear Algebra: BLAS, LAPACK Sparse Solvers: Direct and Iterative Solvers Fast Fourier Transforms Cluster Support: ScaLAPACK, Cluster FFTFeatures and Benefits Automatic parallelization Standard APIs in C and Fortran

Page 5: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

5 Intel MKL Quickstart

User Guide

MKL User Guide Installation Development Environment Configuration Performance and Memory Management Language-specific Usage Options Default documents directory /opt/intel/mkl/10.2.1.017/doc/userguide.pdf

User Guide

Page 6: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

6 Intel MKL Quickstart

Reference Manual

MKL Reference Manual The routines and functions description APIs in C and Fortran Interfaces and calling syntax Default documents directory /opt/intel/mkl/10.2.1.017/doc/mklman.pdf

Reference Manual

Page 7: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

7 Intel MKL Quickstart

Some Examples

Page 8: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

8 Intel MKL Quickstart

Examples

Brief examples to Compute Inner product (sequential) Compute the LU factorization of a matrix Solve linear system Solve eigen system Compute Inner product (parallel)

Examples

Page 9: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

9 Intel MKL Quickstart

Directories containing the source codes

mkl_blas_f95 (mkl_blas_c) mkl_lapack95_f95 (mkl_lapack95_c) mkl_linearsym_f95 (mkl_linearsym_c) mkl_eigensym_f95 (mkl_eigensym_c) mkl_blas_f95_p (mkl_blas_c_p)

File names

Page 10: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

10

Intel MKL Quickstart

Inner product (sequential)

Examples

do ii = 1,n

vec_a(ii) = 1.25*ii

vec_b(ii) = 0.75*ii

end do

dot_result = ddot(n,vec_a,inca,vec_b,incb)

Inner product

Page 11: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

11

Intel MKL Quickstart

Input parameters

Inner product

dot_result = ddot(n,vec_a,inca,vec_b,incb)

n: The length of two vectors. inca: Specifies the increment for the elements of vec_a incb: Specifies the increment for the elements of vec_b vec_a: The fitsr vector vec_b: The second vector

Input parameters

Page 12: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

12

Intel MKL Quickstart

Output parameters

Inner product

dot_result: The final result

Output parameters

Page 13: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

13

Intel MKL Quickstart

Inner product (parallel)

Examples

Makefile clips

FC=mpif90

MKL_INCLUDE =/opt/intel/mkl/10.0.3.020/includeMKL_PATH =/opt/intel/mkl/10.0.3.020/lib/em64tEXE=blas_f95.exe

blas_f:$(FC) -o $(EXE) blas_f.f90 -I$(MKL_INCLUDE)

-L$(MKL_PATH) -lmkl_intel_lp64

-lmkl_intel_thread -lmkl_core -lguide

-lpthread

Inner product (parallel)

Page 14: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

14

Intel MKL Quickstart

LU factorization

Examples

Define the matrixa(1,1)= 1a(1,2)= 3a(2,1)= 2a(2,2)= 1

Compute LU factorizationcall dgetrf(m,n,a,lda,ipiv,info)

LU factorization

Page 15: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

15

Intel MKL Quickstart

Input parameters

LU factorization

call dgetrf(m,n,a,lda,ipiv,info)

a: The matrix. m: The number of rows in the matrix a n: The number of columns in the matrix a lda: The fitsr dimension of a

Input parameters

Page 16: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

16

Intel MKL Quickstart

Output parameters

LU factorization

call dgetrf(m,n,a,lda,ipiv,info)

a: overwritten by L and U. The unit diagonal elements of L are skipped

ipiv: An array, dimension at least max(1,min(m,n)). The pivot indices: row i is interchanged with row ipiv(i)

info: info=0, the execution is successful info=-i, the i-th parameter had an illegal value info= i, uii is 0. The factorization has been completed, but U

is exactly singular

Output parameters

Page 17: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

17

Intel MKL Quickstart

Linear System (Fortran)

Examples

Define the matrixa(1,1)= 1a(1,2)= 3a(2,1)= 2a(2,2)= 1Define the right-hand siderhs(1)= 1.0rhs(2)= 1.0

Solve the linear systemcall dgesv(n,nrhs,a,lda,ipiv,ths,ldb,info)

Linear System

Page 18: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

18

Intel MKL Quickstart

Input parameters

Linear System

call dgesv(n,nrhs,a,lda,ipiv,ths,ldb,info)

n: The number of linear equations, that is, the order of the matrix a

rhs: Right-hand side lda: The leading dimension of matrix a nrhs: The number of right-hand sides

Input parameters

Page 19: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

19

Intel MKL Quickstart

Output parameters

Linear System

call dgesv(n,nrhs,a,lda,ipiv,ths,ldb,info)

ipiv: An array, dimension at least max(1,min(m,n)). The pivot indices: row i was interchanged with row ipiv(i)

rhs: Overwritten by the solution matrix a info: info=0, the execution is successful info=-i, the i-th parameter had an illegal value info= i, U(i,i) is 0. The factorization has been completed, but

U is exactly singular, so the solution could not be computed

Output parameters

Page 20: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

20

Intel MKL Quickstart

Eigensystem (symmetric)

Examples

Define the matrixdsyeva(1,1)= 1.0a(1,2)= 2.0a(2,1)= 2.0a(2,2)= 3.0

Call MKL functioncall dsyev(jobz,uplo,dim,a,lda,eigval,work,lwork,info)

Eigensystem

Page 21: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

21

Intel MKL Quickstart

Input parameters

Eigensystem

call dsyev(jobz,uplo,dim,a,lda,eigval,work,lwork,info)

jobz: If jobz='N', then only eigenvalues are computed jobz: If jobz='V', then eigenvalues are eigenvectors are

computed uplo: If uplo='U', a stores the upper triangular part of a uplo: If uplo='L', a stores the lower triangular part of a lda: The first dimension of a work: a workspace array, its dimension max(1,lwork) lwork: The dimension of the array work

Input parameters

Page 22: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

22

Intel MKL Quickstart

Output parameterscall dsyev(jobz,uplo,dim,a,lda,eigval,work,lwork,info)

wigval: contains the eigenvalues of the matrix a in ascending order

info: info=0, the execution is successful info=-i, the i-th parameter had an illegal value info= i, then the algorithm failed to converge; I indicates the

number of elements of an intermediate tridiagonal form which did not converge to zero

Output parametersEigensystem

Page 23: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

23

Intel MKL Quickstart

References

Page 24: 1 Intel Mathematics Kernel Library (MKL) Quickstart COLA Lab, Department of Mathematics, Nat’l Taiwan University 2010/05/11

24

Intel MKL Quickstart

Reference

Intel® Math Kernel Library Reference Manual (mklman.pdf) Intel® Math Kernel Library for the Linux OS User’s Guide

(userguide.pdf) http://software.intel.com/en-us/articles/intel-math-kernel-library-documentation/

Reference