Ubuntu16.04安装openBLAS

Ubuntu 16.04 安装OpenBLAS步骤

1
2
3
4
5
git clone git://github.com/xianyi/OpenBLAS
cd OpenBLAS
sudo apt-get install gfortran
sudo make FC=gfortran
sudo make install

最后安装在/opt

然后执行以下命令:

1
ln -s /opt/OpenBLAS/lib/libopenblas.so.0   /usr/lib/libopenblas.so.0

建立一个c.c文件,输入以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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可执行文件

1
gcc c.c  -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas

输入

1
./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

安装成功

-------------本文结束感谢您的阅读-------------