Ceci est une ancienne révision du document !


MKL vs LAPACK

We strongly encourage the use of MKL instead of Lapack because MKL is more efficient and optimized for the CPU architecture.

Let's use dgesv to solve a random linear system.

randomsys.f90
program randomsys
    implicit none
    real(kind=8), dimension(:),allocatable :: x,b
    real(kind=8), dimension(:,:),allocatable :: a
    real(kind=8) :: err
    integer :: i, info, lda, ldb, nrhs, n
    integer, dimension(:), allocatable :: ipiv
 
    ! initialize random number generator seed
    ! if you remove this, the same numbers will be generated each
    ! time you run this code.
    call init_random_seed()  
 
    print *, "Input n ... "
    read *, n
 
    allocate(a(n,n))
    allocate(b(n))
    allocate(x(n))
    allocate(ipiv(n))
 
    call random_number(a)
    call random_number(x)
    b = matmul(a,x) ! compute RHS
 
    nrhs = 1 ! number of right hand sides in b
    lda = n  ! leading dimension of a
    ldb = n  ! leading dimension of b
 
    call dgesv(n, nrhs, a, lda, ipiv, b, ldb, info)
 
    ! Note: the solution is returned in b
    ! and a has been changed.
 
    ! compare computed solution to original x:
    print *, "         x          computed       rel. error"
    i=n
    ! do i=1,n
        err = abs(x(i)-b(i))/abs(x(i))
        print '(3d16.6)', x(i),b(i),err
    !  enddo
 
    deallocate(a,b,ipiv)
 
end program randomsys
$ module load gcc
$ gfortran -O2 randomsys.f90 -o randomsys_lapack.exe -lblas -llapack 
$ module load intel/14.0.2
$ ifort -O2 -mkl randomsys.f90 -o randomsys_mkl.exe  
NLAPACKMKL (1 core) MKL (16 core)
10001sxx
20004sxx
400014sxx
800041sxx
  • bench_mkl_lapack.1477052182.txt.gz
  • Dernière modification : 2016/10/21 12:16
  • de admin