本文主要是介绍【OpenBLAS】Ubuntu16.04安装OpenBLAS,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载安装
git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS
make -j8
编译没有错误后进行install,我指定了安装的目录为/home/mjsun/git/openblas_git/OpenBLAS_build,具体执行的命令为:
make PREFIX=/home/mjsun/git/openblas_git/OpenBLAS_build install
这之后会在OpenBLAS_BUILD文件夹中出现bin,include,lib3个文件夹,这时需要将lib中的libopenblas.so.0文件加入到lib目录中,不然系统找不到在那个位置,具体执行操作:
sudo ln -s /home/mjsun/git/openblas_git/OpenBLAS_build/lib/libopenblas.so.0 /usr/lib/libopenblas.so.0
要想caffe中能编译通过,
需要再环境变量添加lib,具体代码为:
$ echo 'export LD_LIBRARY_PATH=/home/mjsun/git/openblas_git/OpenBLAS_build/lib:$LD_LIBRARY_PATH' >> ~/.bashrc $ source ~/.bashrc
如果还不行就换使用
$ echo 'export LIBRARY_PATH=/home/mjsun/git/openblas_git/OpenBLAS_build/lib:$LIBRARY_PATH' >> ~/.bashrc $ source ~/.bashrc
测试
首先新建test.c文件,test.c中的代码如下
#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;
}
在命令行中运行以下命令 ,生成a.out可执行文件:
gcc test.c -I /home/mjsun/git/openblas_git/OpenBLAS_build/include -L /home/mjsun/git/openblas_git/OpenBLAS_build/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/xiaxuesong666/article/details/88887027
这篇关于【OpenBLAS】Ubuntu16.04安装OpenBLAS的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!