MKL dtrsv错误输出

时间:2014-06-02 11:08:42

标签: linear-algebra blas intel-mkl

我正在努力正确使用' cblas_dtrsv'但我没有得到正确的输出,我不知道为什么。这是我的例子(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;
}

编译似乎很好:

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

然而,我得到了错误的结果:

./dtrsv_example
Computations completed.


 Result x: 
0.000000
0.000000
0.000000
0.000000

 Deallocating memory 

 Example completed. 

我在这里做错了什么想法?

1 个答案:

答案 0 :(得分:0)

即使我以为我仔细检查了它,但在休息之后我意识到我的初学者错误:

  for (j = 0; j < n; j++) {
    printf ("%f\n", x[i]);
  }

它应该是x[j]! 希望其他人可以使用我的示例来了解如何使用cblas_dtrsv接口。