Blas DGEMV输入错误

时间:2013-05-09 12:30:10

标签: blas

我无法弄清楚为什么一个blas调用会引发错误。问题调用是最后一次调用。代码编译没有问题,运行正常,直到此调用失败,并显示以下消息。

  

** ACML错误:输入DGEMV参数编号6时出现非法值

据我所知,输入类型是正确的,数组a是正确的 我真的很感激能够深入了解这个问题。 感谢

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cblas.h"
#include "array_alloc.h"

int main( void )
{
  double **a, **A;
  double  *b, *B, *C;

  int *ipiv;
  int n, nrhs;
  int info;
  int i, j;

  printf( "How big a matrix?\n" );
  fscanf( stdin, "%i", &n );

  /* Allocate the matrix and set it to random values but
     with a big value on the diagonal. This makes sure we don't
     accidentally get a singular matrix */
  a = alloc_2d_double( n, n );
  A= alloc_2d_double( n, n );

  for( i = 0; i < n; i++ ){
    for( j = 0; j < n; j++ ){
      a[ i ][ j ] = ( ( double ) rand() ) / RAND_MAX;
    }
    a[ i ][ i ] = a[ i ][ i ] + n;
  }
  memcpy(A[0],a[0],n*n*sizeof(double)+1);


  /* Allocate and initalise b */
  b = alloc_1d_double( n );
  B = alloc_1d_double( n );
  C = alloc_1d_double( n );

  for( i = 0; i < n; i++ ){
    b[ i ] = 1;
  }

  cblas_dcopy(n,b,1,B,1);
  /* the pivot array */
  ipiv = alloc_1d_int( n );

  /* Note we MUST pass pointers, so have to use a temporary var */
  nrhs = 1;

  /* Call the Fortran. We need one underscore on our system*/
  dgesv_(  &n, &nrhs, a[ 0 ], &n, ipiv, b, &n, &info );

  /* Tell the world the results */
  printf( "info = %i\n", info );
  for( i = 0; i < n; i++ ){
    printf( "%4i ", i );
    printf( "%12.8f", b[ i ] );
    printf( "\n" );
  }

  /* Want to check my lapack result with blas */

cblas_dgemv(CblasRowMajor,CblasTrans,n,n,1.0,A[0],1,B,1,0.0,C,1);

return 0;
}

1 个答案:

答案 0 :(得分:3)

领先维度(LDA)至少需要与RowMajor矩阵的列数(n)一样大。你传递的LDA为1。

另外,我对你的矩阵类型有点怀疑;在没有看到如何实现alloc_2d_double的情况下,无法确定是否正确布置矩阵。一般来说,使用BLAS样式矩阵(具有行或列步长的连续数组)混合指针到指针样式的“矩阵”是一种代码气味。 (但是,可能正确执行,您可能正确处理它;我们无法判断您发布的代码是否属于这种情况。)