intel math kernel library wei-ren chang, department of mathematics, national taiwan university...

23
Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Upload: dennis-chandler

Post on 04-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Intel Math Kernel Library

Wei-Ren Chang, Department of Mathematics, National Taiwan University2009/03/10

Page 2: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

2 Introduction to MKL

A brief introduction

Page 3: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

3

Introduction

Introduction to MKL

MKL offers highly optimized, thread-safe math routinesfor science, engineering, and financial applications thatrequire maximum performance.

Page 4: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

4 Some information

Some information

Page 5: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

5

Intel MKL Reference Manual

Some information

Reference information covers routine functionality, parameter descriptions, interfaces and calling syntax as wellas return values. To get this information, see Intel MKL Reference Manualfirst. (/opt/intel/mkl/10.0.3.020/doc/mklman.pdf)

Page 6: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

6

user guide

Some information

user guide focuses on the usage Information needed tocall Intel MKL routines from user's applications running onthe Linux* OS. Linux usage of Intel MKL has its particularfeatures, which are described in this guide, along with

thosethat do not depend upon a particular OS.(/opt/intel/mkl/10.0.3.020/doc/userguide.pdf)

Page 7: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

7 Some examples

Some examples

Page 8: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

8

Examples

Some examples

There are five brief examples:1. Compute inner product.(sequential)2. Compute the LU factorization of a matrix.3. Solve linear system.4. Solve eigensystem. 5. Compute inner product.(parallel)

Page 9: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

9

The file names of the examples

Some examples

1. mkl_blas_f95 (mkl_blas_c)2. mkl_lapack95_f95 (mkl_lapack95_c)3. mkl_linearsym_f95 (mkl_linearsym_c)4. mkl_eigensym_f95 (mkl_eigensym_c)5. mkl_blas_f95_p (mkl_blas_c_p)

There are more examples in the Folder:/opt/intel/mkl/10.0.3.020/examples

Page 10: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB10

Inner product (sequential)

Vectors and Planes

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)

Page 11: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB11

Input parameters

Vectors and Planes

n : The length of two vectors. (Here n = 5) inca : Specifies the increment for the elements of vec_a.

(Here inca = 1)incb : Specifies the increment for the elements of vec_b.

(Here incb = 1) vec_a : The first vector. vec_b : The second vector.

Page 12: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB12

Output parameters

Vectors and Planes

dot_result: The final result.

Page 13: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB13

Inner product (parallel)

Vectors and Planes

You have to reedit the makefile:

FC=mpif90

MKL_INCLUDE =/opt/intel/mkl/10.0.3.020/include

MKL_PATH =/opt/intel/mkl/10.0.3.020/lib/em64t

EXE=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

Page 14: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB14

LU factorization

Vectors and Planes

! Define the matrix a(1,1) = 1

a(1,2) = 3

a(2,1) = 2

a(2,2) = 1

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

Page 15: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB15

Input parameters

Vectors and Planes

a : The matrix. m : The number of rows in the matrix a. n : The number of columns in the matrix a. lda : The first dimension of a. (Here lda = 2)

Page 16: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB16

Output parameters

Vectors and Planes

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 was interchanged with row ipiv(i). info : If info=0, the execution is successful. If info = -i, the i-th parameter had an illegal value. If info = i, uii is 0. The factorization has been completed, but U is exactly singular.

Page 17: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB17

Linear System (fortran)

Vectors and Planes

! Define the matrix

a(1,1) = 1 a(1,2) = 3

a(2,1) = 2

a(2,2) = 1

! Define the right-hand side rhs(1) = 1.0

rhs(2) = 1.0

! Solve the linear system call dgesv(n,nrhs,a,lda,ipiv,rhs,ldb,info)

Page 18: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB18

Input parameters

Vectors and Planes

n : The number of linear equations, that is, the order of the matrix A. (Here n = 2) rhs : Right-hand side. lda : The leading dimension of matrix A . (Here lda = 2) nrhs : The number of right-hand sides. (Here nrhs = 1)

Page 19: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB19

Output parameters

Vectors and Planes

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 : If info=0, the execution is successful. If info = -i, the i-th parameter had an illegal value If info = i, U(i, i) is exactly zero. The factorization has been completed, but the factor U is exactly singular so the solution could not be computed.

Page 20: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB20

Eigensystem (symmetric)

Vectors and Planes

! Define the matrixdsyev a(1,1) = 1.0

a(1,2) = 2.0

a(2,1) = 2.0

a(2,2) = 3.0

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

Page 21: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB21

Input parameters

Vectors and Planes

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

If jobz = 'V', then eigenvalues and eigenvectors are computed. uplo : If uplo = 'U', a stores the upper triangular part of A.

If uplo = 'L', a stores the lower triangular part of A. lda : The first dimension of A. (Here lda = 2) work : a workspace array, its dimension max(1, lwork).

lwork : The dimension of the array work. (lwork >= 2*lda+1)

Page 22: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB22

Output parameters

Vectors and Planes

wigval : contains the eigenvalues of the matrix A in ascending order. info : If info=0, the execution is successful. If info = -i, the i-th parameter had an illegal value. If 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.

Page 23: Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University 2009/03/10

Introduction to MATLAB23

Reference

Vectors and Planes

Intel® Math Kernel Library Reference Manual Intel® Math Kernel Library for the Linux* OS User’s Guide