1

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

** 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;
}
4

1 回答 1

3

前导维度 (LDA) 至少需要与 RowMajor 矩阵的列数 (n) 一样大。你通过的 LDA 为 1。

另外,我对您的矩阵类型有点怀疑;如果不了解如何alloc_2d_double实现,则无法确定您是否正确布置了矩阵。一般来说,将指针到指针样式的“矩阵”与 BLAS 样式的矩阵(具有行或列跨度的连续数组)混合在一起有点代码味道。(但是,可以正确执行,并且您很可能正在正确处理它;只是无法从您发布的代码中判断是否是这种情况)。

于 2013-05-09T12:35:56.430 回答