I'm writing finite difference method program.
I'm using Intel Math Kernel Library.
For example, 1000x1000 matrix A and 1000x1000 matrix B.
In Intel MKL, A*B using cblas_dgemm() function took about 600 ms.
In MATLAB, A*B took about 800 ms.
I thought MKL is very fast.
However, 1000x1000 matrix A and 1000x1 vector B,
and A\B (mldivide) in MATLAB, it took 40 ms,
but in MKL, using LAPACKE_dgesv, it took 400 ms!
so my question is,
Why in mldivide, MATLAB is so fast and MKL is so slow?
matrix A and vector B is whole filled with random values.
I'm using
MATLAB R2012b
Visual Studio 2015
Intel Parallel Studio XE 2016 Update 3 Cluster Edition
Thank you.
EDITED
first, C++ code.
#include "mkl.h"
#include "time.h"
int n = 1000;
double *a = (double *)malloc(sizeof(double) * n * n);
for(int i = 0;i < n * n;i++) a[i] = rand();
double *b = (double *)malloc(sizeof(double) * n);
for(int i = 0;i < n;i++) b[i] = rand();
int *ipiv = (int *)malloc(sizeof(int) * n);
time_t now = clock();
int info = LAPACKE_dgesv(LAPACK_ROW_MAJOR,n,1,a,n,ipiv,b,1);
time_t ms = clock() - now;
printf("%d ms",ms);
Second, MATLAB code.
n = 1000;
a = rand(n,n);
b = rand(n,1);
tic;
c = a\b;
toc * 1000
I think I didn't mistake in measuring time.
Thank you.