2013-05-09 1 views
0

blas 호출이 왜 n 오류를 발생시키는 지 알아내는 데 문제가 있습니다. 문제는 마지막 blas 호출입니다. 코드는 문제없이 컴파일되고이 호출이 다음 메시지와 함께 실패 할 때까지 정상적으로 실행됩니다.Blas DGEMV 입력 오류

** ACML error: on entry to DGEMV parameter number 6 had an illegal value

는 지금까지 내가 모든 걸 말할 수있는 입력 유형이 올바른지 및 배열 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; 
} 

답변

3

하나의 주요 치수 (LDA)는 RowMajor 행렬 열 (N)의 수와 적어도 커야 할 필요가있다. LDA가 1을 넘었습니다.

별도로, 매트릭스 유형이 약간 의심 스럽습니다. alloc_2d_double이 구현 된 방법을 보지 않고도 매트릭스를 올바르게 레이아웃하는지 여부를 확인할 방법이 없습니다. 일반적으로 BLAS 스타일의 행렬 (행 또는 열의 보폭이 연속 된 배열)을 사용하여 포인터와 포인터 스타일의 행렬을 섞어 쓰면 코드 냄새가 난다. (그러나 올바르게 수행하려면 일 수 있으며 적절하게 처리해야 할 수도 있습니다. 게시 한 코드의 사례인지 여부는 알 수 없습니다).