I am trying to properly use 'cblas_dtrsv' however I do not get right output and I do not know why. Here is my example(dtrsv_example.c)
#include <stdio.h>
#include <stdlib.h>
#include "mkl.h"
int main()
{
double *A, *b, *x;
int m, n, k, i, j;
m = 4, k = 4, n = 4;
printf (" Allocating memory for matrices aligned on 64-byte boundary for better \n"
" performance \n\n");
A = (double *)mkl_malloc( m*k*sizeof( double ), 64 );
b = (double *)mkl_malloc( n*sizeof( double ), 64 );
x = (double *)mkl_malloc( n*sizeof( double ), 64 );
if (A == NULL || b == NULL || x == NULL) {
printf( "\n ERROR: Can't allocate memory for matrices. Aborting... \n\n");
mkl_free(A);
mkl_free(b);
mkl_free(x);
return 1;
}
A[0] = 11;
for (i = 0; i < m; i++) {
for (j = 0; j <= i; j++) {
A[j + i*m] = (double)(j+i*m);
}
}
for (i = 0; i < n; i++) {
x[i] = (i+1)*5.0;
}
printf ("\n Computations completed.\n\n");
printf ("\n Result x: \n");
for (j = 0; j < n; j++) {
printf ("%f\n", x[i]);
}
printf ("\n Deallocating memory \n\n");
mkl_free(A);
mkl_free(b);
mkl_free(x);
printf (" Example completed. \n\n");
return 0;
}
Compilation seems fine:
icc -c -Wall -c -o dtrsv_example.o dtrsv_example.c
icc dtrsv_example.o -o dtrsv_example -L/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -lpthread -lm
However, I get the wrong result:
./dtrsv_example
Computations completed.
Result x:
0.000000
0.000000
0.000000
0.000000
Deallocating memory
Example completed.
Any ideas of what I might be doing wrong here?