系统相关
首页 > 系统相关> > ubuntu 18.04中编译安装使用 lapack 示例

ubuntu 18.04中编译安装使用 lapack 示例

作者:互联网

0.0 拉取 ubuntu:18.04 docker image:
    sudo docker pull ubuntu:18.04
0.1 启动docker:
sudo docker run --name  Lapack_running -it         \
-v /dev:/dev -v /usr/src/:/usr/src -v /lib/modules/:/lib/modules --privileged --cap-add=ALL ubuntu:18.04

以下是docker内操作:
0.2 mv /etc/apt/sources.list /etc/apt/sources.list.backupLL
0.3 echo "deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse" > /etc/apt/sources.list
0.4 apt-get update && apt-get upgrade
0.5 apt-get install vim
0.6 将下面的ubuntu18.04 163 源全部加入到 /etc/apt/sources.list 中: vim /etc/apt/sources.list
0.7 apt-get update && apt-get upgrade
0.8 安装必要软件:
    apt-get install python3 gfortran wget make
0.8 mkdir 并且 cd 至源码目录
0.9 下载lapack包:
    wget https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.0.tar.gz
0.10 解压:
    tar -zxvf v3.10.0.tar.gz

0.11 cd lapack-3.10.0
0.12  cp make.inc.example make.inc

0.13 vim Makefile 并且将12和13行修改为如下:
#lib: lapacklib tmglib
lib: blaslib variants lapacklib tmglib

0.14 开始编译:
    make -j32

0.15  cd LAPACKE   #cd 进入LAPACKE文件夹,这里是lapack的C语言接口源码
0.16 编译LAPACKE:
    sudo make -j32  # 编译lapacke
0.17 手动安装lapacke:
    cp include/*.h /usr/local/include   #将lapacke的头文件复制到系统头文件目录
0.18 手动安装lapack:
    cd .. #返回上级目录 lapack-3.10.0/
    cp *.a /usr/local/lib # 将生成的所有库文件复制到系统库目录

0.19 使用示例:
    在系统中任意文件夹中,将如下代码存储为helloLapack.c

//helloLapack.c

#include <stdio.h>
#include <lapacke.h>

int main (int argc, const char * argv[])
{
   double a[5*3] = {1,2,3,4,5,1,3,5,2,4,1,4,2,5,3};
   double b[5*2] = {-10,12,14,16,18,-3,14,12,16,16};
   lapack_int info,m,n,lda,ldb,nrhs;
   int i,j;

   m = 5;
   n = 3;
   nrhs = 2;
   lda = 5;
   ldb = 5;

   info = LAPACKE_dgels(LAPACK_COL_MAJOR,'N',m,n,nrhs,a,lda,b,ldb);

   for(i=0;i<n;i++)
   {
      for(j=0;j<nrhs;j++)
      {
         printf("%lf ",b[i+ldb*j]);
      }
      printf("\n");
   }
   return(info);
}


0.20 使用gfortran进行编译:
    gfortran helloLapack.c -llapacke -llapack -lrefblas -o helloLapack

0.21 执行示例:
    ./helloLapack
    打印结果为:
    2.000000 1.000000
    1.000000 1.000000
    1.000000 2.000000

https://blog.csdn.net/zouyu1746430162/article/details/53374693
https://blog.csdn.net/mlnotes/article/details/9676269
https://blog.csdn.net/yuanxing14/article/details/41744461
https://blog.csdn.net/chishuideyu/article/details/78351063
https://my.oschina.net/u/4325212/blog/3908072

标签:18.04,get,lapack,示例,apt,cd,blog,https
来源: https://blog.csdn.net/eloudy/article/details/121932748