MKL dtrsv输出错误



我正试图正确使用'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 nn");
  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... nn");
    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.nn");
  printf ("n Result x: n");
  for (j = 0; j < n; j++) {
    printf ("%fn", x[i]);
  }

  printf ("n Deallocating memory nn");
  mkl_free(A);
  mkl_free(b);
  mkl_free(x);
  printf (" Example completed. nn");
  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. 

知道我在这里可能做错了什么吗?

尽管我认为我已经仔细检查过了,但休息了一会儿后,我意识到我最初的错误:

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

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

相关内容

  • 没有找到相关文章

最新更新