我很难弄明白为什么一个blas电话会抛出n个错误。问题电话是最后一个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;
}发布于 2013-05-09 12:35:56
领先维度(LDA)至少需要与RowMajor矩阵的列数(n)一样大。你的LDA值是1。
另外,我对您的矩阵类型有些怀疑;如果不了解alloc_2d_double是如何实现的,就无法确定您是否正确地布局了矩阵。一般来说,将指针到指针样式的“矩阵”与BLAS样式的矩阵(具有行或列步长的连续数组)混合在一起是一种代码气味。(然而,正确的操作是可能的,而且您很可能正在正确地处理它;只是不可能从您发布的代码中判断是否是这种情况)。
https://stackoverflow.com/questions/16461816
复制相似问题