240 likes | 428 Vues
Intel Math Kernel Library. Wei- Ren Chang , Department of Mathematics, National Taiwan University 2009/03/10. A brief introduction. Introduction. MKL offers highly optimized, thread-safe math routines for science, engineering, and financial applications that
E N D
Intel Math Kernel Library Wei-Ren Chang, Department of Mathematics, National Taiwan University2009/03/10
Introduction MKL offers highly optimized, thread-safe math routines for science, engineering, and financial applications that require maximum performance.
Intel MKL Reference Manual Reference information covers routine functionality, parameter descriptions, interfaces and calling syntax as well as return values. To get this information, see Intel MKL Reference Manual first. (/opt/intel/mkl/10.0.3.020/doc/mklman.pdf)
user guide user guide focuses on the usage Information needed to call Intel MKL routines from user's applications running on the Linux* OS. Linux usage of Intel MKL has its particular features, which are described in this guide, along with those that do not depend upon a particular OS. (/opt/intel/mkl/10.0.3.020/doc/userguide.pdf)
Examples There are five brief examples: • Compute inner product.(sequential) • Compute the LU factorization of a matrix. • Solve linear system. • Solve eigensystem. • Compute inner product.(parallel)
The file names of the examples • 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) There are more examples in the Folder: /opt/intel/mkl/10.0.3.020/examples
Inner product (sequential) 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) Introduction to MATLAB
Input parameters 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. Introduction to MATLAB
Output parameters dot_result: The final result. Introduction to MATLAB
Inner product (parallel) 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 Introduction to MATLAB
LU factorization ! Define the matrix a(1,1) = 1 a(1,2) = 3 a(2,1) = 2 a(2,2) = 1 ! Compute LU factorization call dgetrf(m,n,a,lda,ipiv,info) Introduction to MATLAB
Input parameters 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) Introduction to MATLAB
Output parameters 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. Introduction to MATLAB
Linear System (fortran) ! 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) Introduction to MATLAB
Input parameters 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) Introduction to MATLAB
Output parameters 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. Introduction to MATLAB
Eigensystem (symmetric) ! 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 function Call dsyev(jobz,uplo,dim,a,lda,eigval,work,lwork,info) Introduction to MATLAB
Input parameters jobz: If jobz = 'N', then only eigenvaluesare 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) Introduction to MATLAB
Output parameters 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 tridiagonalform which did not converge to zero. Introduction to MATLAB
Reference Intel® Math Kernel Library Reference Manual Intel® Math Kernel Library for the Linux* OS User’s Guide Introduction to MATLAB