ubuntu源碼安裝openblas

1 git clone https://github.com/xianyi/OpenBLAS.git
2 cd OpenBLAS
3 make -j8
4 sudo make PREFIX=/usr/local/OpenBLAS install

然後測試

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

int main(){

        int n;                          /*! array size */
        double da;                      /*! double constant */
        double *dx;                     /*! input double array */
        int incx;                        /*! input stride */
        double *dy;                      /*! output double array */
        int incy;                       /*! output stride */

        int i;

        n = 10;
        da = 10;
        dx = (double*)malloc(sizeof(double)*n);
        incx = 1;
        dy = (double*)malloc(sizeof(double)*n);
        incy = 1;

        for(i=0;i<n;i++){
                dx[i] = 9-i;
                dy[i] = i;
                printf("%f ",dy[i]);    //輸出原來的dy
        }
        printf("\n");

        cblas_daxpy(n, da, dx,incx, dy, incy);  //運行daxpy程序
    //    cblas_dcopy(n, dx,incx, dy, incy);      //運行dcopy程序

        for(i=0;i<n;i++){
            printf("%f ",dy[i]);   //輸出計算後的dy
        }
        printf("\n");

        return 0;   
}  

gcc test.c -I /usr/local/OpenBLAS/include/ -L/usr/local/OpenBLAS/lib -lopenblas
./a.out
測試結果
0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000 90.000000 81.000000 72.000000 63.000000 54.000000 45.000000 36.000000 27.000000 18.000000 9.000000

參考資料:
https://blog.csdn.net/qq_15505637/article/details/77450329
https://blog.csdn.net/y5492853/article/details/79558194

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章