Why MKL_Mem_Stat just returns 0?

Why MKL_Mem_Stat just returns 0?

I am using mkl example from the manual. However, the values returned from MKL_Mem_stat is just 0. Why?
Code is here:

double *a, *b, *c;

int n, i;

double alpha, beta;

MKL_INT64 AllocatedBytes;

int N_AllocatedBuffers;

alpha = 1.1; beta = -1.2;

n = 1000;

a = (double*)MKL_malloc(n*n*sizeof(double),128);

b = (double*)MKL_malloc(n*n*sizeof(double),128);

c = (double*)MKL_malloc(n*n*sizeof(double),128);

for (i=0;i<(n*n);i++) {

a[i] = (double)(i+1);

b[i] = (double)(-i-1);

c[i] = 0.0;



AllocatedBytes = MKL_Mem_Stat(&N_AllocatedBuffers);

printf("\\nDGEMM uses %ld bytes in %d buffers \\n",(long)AllocatedBytes,N_AllocatedBuffers);


AllocatedBytes = MKL_Mem_Stat(&N_AllocatedBuffers);

printf("MKL_FreeBuffers uses %ld bytes in %d buffers \\n",(long)AllocatedBytes,N_AllocatedBuffers);

if (AllocatedBytes > 0) {

printf("\\nMKL memory leak!");

printf("\\nAfter MKL_FreeBuffers there are %ld bytes in %d buffers",






return 0;

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


I noticed this following line is commented:


MKL_Mem_Stat() will compuate the internal MKL buffer (when call dgemm()) it will use. To improve the performance, MKL has memory manager that may allocate some memory buffers used by MKL functions. MKL_Mem_Stat() will return the memory used the the memory buffer.


Thank you for your explanation. So the MKL_Mem_stat doesn't report the real allicated memory size after MKL_malloc?
Or MKL_malloc doesn't really allocat until it is used?

MKL_Mem_Stat tracks the internal memory allocate by the MKL computation functions. These memory buffers are not visible to the users. For MKL_malloc, it is used by user to allocate the memory externally. Users can this call to allocate the memory by themselves, and use MKL_free the free these memory. It is actually allocate the memory.


From MKL 10.3 Update 4MKL_Mem_stat returns whole memory, including MKL_malloc. But thetest should be modified, becauseMKL_FreeBuffers freesmemory used only inside MKL, so user's memory allocated by MKL_malloc should be freed before calling MKL_Mem_stat and checking

if (AllocatedBytes > 0) { printf("\nMKL memory leak!");

Leave a Comment

Please sign in to add a comment. Not a member? Join today