I do a blas matrix/vector product with this simple code:
#include "mkl.h"
#include <stdio.h>
int main(){
const int M = 2;
const int N = 3;
double *x = new double[N];
double *A = new double[M*N];
double *b = new double[M];
for (int i = 0; i < M; i++){
b[i] = 0.0; //Not necessary but anyway...
for (int j = 0; j < N; j++){
A[j * M + i] = i + j * 2;
}
}
for (int j = 0; j < N; j++)
x[j] = j*j;
const int incr = 1;
const double alpha = 1.0;
const double beta = 0.0;
const char no = 'N';
dgemv(&no, &M, &N, &alpha, A, &M, x, &incr, &beta, b, &incr );
printf("b = [%e %e]'\n",b[0],b[1]);
delete[] x;
delete[] A;
delete[] b;
}
While the displayed result is as expected ([18, 23]), Intel Inspector finds one invalid memory access and 2 invalid partial memory access when calling dgemv. The invalid memory access and one invalid partial memory access are related to memory allocated corresponding to the vector b. The second invalid partial memory access is related with the memory allocated for A. I do not get any error if I use a static array.
It also happens with other MKL functions, such as dgesv or when I try to use cblas_dgemv. I use Intel Inspector XE 2016 and intel C++ Compiler 16.0 with MKL sequential.
Is my dgemv call wrong, or is that a false positive. Anyone experienced that?
Thanks
EDIT:
As suggested by Josh Milthorpe: the error appears only on small-size arrays, probably because MKL is trying to access memory in large chunks for efficiency.
I did several tests, and M needs to be at least 20 in order to not get an error. N can be any positive number. I suppose that this is not a bug, and MKL is just accessing memory outside of the allocated space for the matrix, but does not alter or really use it.