9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LAPACK/BLAS の設定メモ (Ubuntu)

Last updated at Posted at 2018-10-19

動作環境

Ubuntu 18.04.1
LAPACK 3.8.0
gcc 7.3.0
gfortran 7.3.0
make 4.1
cmake 3.10.2

ダウンロード

以下のアドレスからダウンロードできる.
http://www.netlib.org/lapack/lapack-3.8.0.tar.gz

ビルド

  • 任意の場所に lapack-3.8.0 を解凍し,そのディレクトリへ移動する.

  • make.inc.example の内容を make.inc へコピーする.

$ cp make.inc.example make.inc
  • 以下のように make する.
$ make blaslib
$ make lapacklib
$ make cblaslib
$ make lapackelib

上記の操作で, librefblas.a, liblapack.a, libcblas.a, liblapacke.a の4つのファイルが得られる.

  • 4つの静的ライブラリファイルを /usr/local/lib へコピーする.
$ sudo cp ./librefblas.a /usr/lib/libblas.a
$ sudo cp ./liblapack.a /usr/lib/liblapack.a
$ sudo cp ./libcblas.a /usr/lib/libcblas.a
$ sudo cp ./liblapacke.a /usr/lib/liblapacke.a
  • include ファイルを /usr/local/include へコピーする.
$ sudo cp ./CBLAS/include/cblas*.h /usr/include/
$ sudo cp ./LAPACKE/include/lapacke*.h /usr/include/

動作確認

以下のサイトを参考にしたプログラムで動作確認した.

hoge.c
/* Calling CGEQRF and CUNGQR to compute Q without workspace querying */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <lapacke.h>
#include <cblas.h>

int main (int argc, const char * argv[])
{
   lapack_complex_float *a,*tau,*r,one,zero;
   lapack_int info,m,n,lda;
   int i,j;
   float err=0.0;
   m = 10;   n = 5;   lda = m;
   one = lapack_make_complex_float(1.0,0.0);
   zero= lapack_make_complex_float(0.0,0.0);
   a = calloc(m*n,sizeof(lapack_complex_float));
   r = calloc(n*n,sizeof(lapack_complex_float));
   tau = calloc(m,sizeof(lapack_complex_float));
   for(j=0;j<n;j++)
      for(i=0;i<m;i++)
         a[i+j*m] = lapack_make_complex_float(i+1,j+1);
   info = LAPACKE_cgeqrf(LAPACK_COL_MAJOR,m,n,a,lda,tau);
   info = LAPACKE_cungqr(LAPACK_COL_MAJOR,m,n,n,a,lda,tau);
   for(j=0;j<n;j++)
      for(i=0;i<n;i++)
         r[i+j*n]=(i==j)?-one:zero;
   cblas_cgemm(CblasColMajor,CblasConjTrans,CblasNoTrans,
               n,n,m,&one,a,lda,a,lda,&one,r,n );
   for(i=0;i<n;i++)
      for(j=0;j<n;j++)
         err=fmax(err,cabs(r[i+j*n]));
   printf("error=%e\n",err);
   free(tau);
   free(r);
   free(a);
   return(info);
}

結果は以下のようになった.

$ gcc -o hoge hoge.c -llapacke -lcblas -llapack -lblas -lm -lgfortran
$ ./hoge
error=2.384186e-07
9
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?