2016-03-04 84 views
0

我無法運行openblas cblas測試程序。當乘以方矩陣時,我的Cblas完美運行,但是當我用非方矩陣嘗試時,我得到錯誤「分段錯誤 - 核心拋棄」 我檢查並重新檢查了尺寸問題,但它們似乎是正確的,所以我想知道可能會發生什麼是錯的。當我輸入m = 200而不是m = 300時,它完美地工作。非方矩陣Openblas cblas分段錯誤

例如,下面的程序無法正常工作

#include <iostream> 
    #include <stdlib.h> 

    extern "C" 
    { 
    #include <cblas.h> 
    } 



    using namespace std; 

    int main() 
    { 
     double *a,*x, *y, *z; 
     int m,k; 
     m=300; k=200; 

     a = (double *) malloc(m*k*sizeof(double)); 
     x = (double *) malloc (k*sizeof(double)); 
     y = (double *) malloc (m*sizeof(double)); 
     z = (double *) malloc (m*sizeof(double)); 

     int i; 

     for (i = 0; i < (m*k); ++i) 
     { 
      a[i] = 1; 
     } 

     for (i = 0; i < (k); ++i) 
     { 
      x[i] = 1; 
     } 

     for (i = 0; i < (m); ++i) 
     { 
      y[i] = 100 ; 
     } 

     cblas_dcopy(m,y,1,z,1); 
     cblas_dgemv(CblasRowMajor,CblasNoTrans,m,k,1.0, a ,m ,x, 1, 1.0, z, 1); 


     for (int i = 0; i<m; ++i) 
     { 
      cout<<z[i]<<endl; 
     } 

     free (a); 
     free (x) ; 
     free (y) ; 
     free (z) ; 

     return 0; 
     } 

在此先感謝

回答

0

我已經想通了這個問題很多:BLAS的文件(自帶的參數中給出的參數LDA在矩陣之後)對應於他們稱之爲「矩陣的主要維度」。只有在COLMAJOR系統(由Fortran使用)中將矩陣行數作爲LDA傳遞,如果您在C或C++中使用cblas,則必須將列數作爲LDA傳遞,因爲使用了ROWMAJOR系統。

希望這可以幫助未來的人