11020070-0_Vol16No2.indd



Similar documents
線形代数演算ライブラリBLASとLAPACKの 基礎と実践1

線形代数演算ライブラリBLASとLAPACKの 基礎と実践1

線形代数演算ライブラリBLASとLAPACKの 基礎と実践1

_Vol16No3.indd

untitled

理研スーパーコンピュータ・システム

倍々精度RgemmのnVidia C2050上への実装と応用

CMSI教育計算科学技術特論A_中田真秀

4 倍精度基本線形代数ルーチン群 QPBLAS の紹介 [index] 1. Introduction 2. Double-double algorithm 3. QPBLAS 4. QPBLAS-GPU 5. Summary 佐々成正 1, 山田進 1, 町田昌彦 1, 今村俊幸 2, 奥田洋司

Untitled

3.2 Linux root vi(vim) vi emacs emacs 4 Linux Kernel Linux Git 4.1 Git Git Linux Linux Linus Fedora root yum install global(debian Ubuntu apt-get inst

インテル(R) Visual Fortran Composer XE

ストリーミング SIMD 拡張命令2 (SSE2) を使用した SAXPY/DAXPY

211 年ハイパフォーマンスコンピューティングと計算科学シンポジウム Computing Symposium 211 HPCS /1/18 a a 1 a 2 a 3 a a GPU Graphics Processing Unit GPU CPU GPU GPGPU G

DPD Software Development Products Overview

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

Second-semi.PDF

(Basic Theory of Information Processing) 1

. UNIX, Linux, KNOPPIX. C,.,., ( 1 ) p. 2

2 2.1 Mac OS CPU Mac OS tar zxf zpares_0.9.6.tar.gz cd zpares_0.9.6 Mac Makefile Mekefile.inc cp Makefile.inc/make.inc.gfortran.seq.macosx make

2008 ( 13 ) C LAPACK 2008 ( 13 )C LAPACK p. 1

C

14 2 Scilab Scilab GUI インタグラフ プリタ描画各種ライブラリ (LAPACK, ODEPACK, ) SciNOTES ハードウェア (CPU, GPU) 21 Scilab SciNotes 呼び出し 3 変数ブラウザ 1 ファイルブラウザ 2 コンソール 4 コマンド履歴

2 1. Ubuntu 1.1 OS OS OS ( OS ) OS ( OS ) VMware Player VMware Player jp/download/player/ URL VMware Plaeyr VMware

bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows ˆ Windows10 64bit Wi

1 (bit ) ( ) PC WS CPU IEEE754 standard ( 24bit) ( 53bit)

第52回日本生殖医学会総会・学術講演会

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

スパコンに通じる並列プログラミングの基礎

第101回 日本美容外科学会誌/nbgkp‐01(大扉)

27巻3号/FUJSYU03‐107(プログラム)

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

パーキンソン病治療ガイドライン2002

GPU.....

tnbp59-20_Web:P1/ky108679509610002943

c a a ca c c% c11 c12

●70974_100_AC009160_KAPヘ<3099>ーシス自動車約款(11.10).indb

ex01.dvi

Slide 1

[1] [2] [3] (RTT) 2. Android OS Android OS Google OS 69.7% [4] 1 Android Linux [5] Linux OS Android Runtime Dalvik Dalvik UI Application(Home,T

Java

( CUDA CUDA CUDA CUDA ( NVIDIA CUDA I

高性能計算研究室の紹介 High Performance Computing Lab.

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

07-二村幸孝・出口大輔.indd

Intel® Compilers Professional Editions

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

: : : TSTank 2

電気通信大学 I 類 情報系 情報 ネットワーク工学専攻 CED 2018 システム利用ガイド ver1.2 CED 管理者 学術技師 島崎俊介 教育研究技師部 実験実習支援センター 2018 年 3 月 29 日 1 ログイン ログアウト手順について 1.1 ログイン手順 CentOS 1. モニ


★分冊3-説明資料PDF用/02-PDF個別

™ƒŒì„³001†`028.pwd

76

' % % &! #


康乘聡子(P105‐121)/康乘聡子 p105‐121

‡Æ‡Ý‡©457_01-12

スパコンに通じる並列プログラミングの基礎

untitled

Microsoft PowerPoint - sales2.ppt

comment.dvi

TSUBAME2.0 における GPU の 活用方法 東京工業大学学術国際情報センター丸山直也第 10 回 GPU コンピューティング講習会 2011 年 9 月 28 日


ex01.dvi

cpp1.dvi

Transcription:

2552 チュートリアル BLAS, LAPACK 2 1 BLAS, LAPACKチュートリアル パート1 ( 簡 単 な 使 い 方 とプログラミング) 中 田 真 秀 1 読 者 の 想 定 BLAS [1], LAPACK [2] 2 線 形 代 数 の 重 要 性 について Google Page Rank 3D CPU 筆 者 紹 介 BLAS LAPACK http://accc.riken.jp/maho/ 3 BLAS, LAPACKとは 何 か: 世 界 最 高 の 線 形 代 数 演 算 パッケージ BLAS [1] LAPACK [2] BLAS, LAPACK (1)BLAS とは? BLAS Basic Linear Algebra Subprograms FORTRAN77 BLAS BLAS reference BLAS BLAS Level 1, Level 2Level 3 x, y, A, B, C 36 計 算 工 学

BLAS, LAPACK 1 2553 Level 1 BLAS - DAXPY DDOT y αx + y dot x T y 1 2 15 4 Level 2 BLAS - -DGEMV y αax + βy DTRSV x A 1 b 3 4 254 Level 3 BLAS- - DGEMM DSYRK C αab + βc C αaa T + βc 5 6 4 BLAS, LAPACKを 使 う 上 での 注 意 点 BLAS, LAPACK FORTRAN (1)Column major, row majorに 注 意 2 1 column major, row major 1, 4, 2, 5, 3, 6 1column major 1, 2, 3, 4, 5, 6 2row major FROTRAN, Matlab, Octave column major C, C++ row major C, C++ DTRSM B αa 1 B 7 9 Quick reference (2)LAPACK とは? LAPACK Linear Algebra PACKage BLAS LU QR Schur Schur BLAS 3.2Fortran 90 2011/2/15 3.3.0 C API, CS Level 3 BLAS 3.3.0 1632 400 CPU, OS web 9000 図 1 Column Major: 行 列 のデータは 列 方 向 にメモリに 格 納 される 図 2 Row Major: 行 列 のデータは 行 方 向 にメモリに 格 納 される 図 3 Leading Dimensionの 考 え 方 :M N 行 列 Aは より 大 きなLDA N 行 列 の 部 分 行 列 と 扱 うことがある Vol.16, No.2 2011 37

2554 (2) 行 列 のLeading dimensionとは? leading dimension 3 BLAS, LAPACK LDA, LDB M N A LDA N A i, j C/C++ A[i + j*m] A[i + j*lda] LU Chokesky LAPACK (3)FORTRAN, C, C++ の 配 列 のスタートの 違 い FORTRAN 1C, C++ 0 1 N FOR- TRAN0 n C, C++ x i FORTRAN X I C, C++ x[i-1] A i, j FORTRAN A I,J C, C++ column major A[i 1+ j 1 * lda] 5 BLAS, LAPACKの 現 状 について BLAS, LAPACK reference BLAS L1, L2, L3 BLAS 1970 Intel MKL Math Kernel Library AMD ACML AMD Core Math Library GotoBLAS2 ATLAS BLAS, LAPACK GotoBLAS2Intel MKL GotoBLAS2 [3] GotoBLAS2 BLAS, LAPACK CPU, OS BLASLAPACK3.1.1 ATLAS [4] R.Clint Whaley BLAS LAPACK BLAS 2001 GotoBLAS2 %10% BLAS, LAPACK BLAS, LAPACK Gaussian, Gamess, ADF, VASP CPLEX, NUOPT, GLPK Ruby, Python, Perl, Java, C, Mathematica, Maple, Matlab, R, octave, SciLab Top 500 [5] Top 500LINPACK DGEMM - BLAS, LAPACK [6] ScaLAPACK GPU BLAS, LAPACK [7] CPU CPU 10 nvidia GPU MAGMA BLAS, LAPACK [8] 10 23 16 Krylov BLAS,LAPACK MPACK 6 Ubuntu 10.04x86(Lucid Lynx)デスクトップ 版 でBLAS, LAPACKを 実 際 に 使 ってみる BLAS, LAPACK GotoBLAS2 Octave [9] C++ BLAS, LAPACK OS Mac Linux Windows (1) 前 準 備 OS Ubuntu 10.04 x86 Lucid Lynx [10] OS 38 計 算 工 学

BLAS, LAPACK 1 2555 VirtualBox [11] /home/maho $ \ $ sudo apt-get install patch gfortran g++ \ libblas-dev octave3.2 (2)GotoBLAS2のインストール GotoBLAS2 1.13 http://www.tacc.utexas.edu/tacc-projects/gotoblas2/ $ cd ; cp <somewhere>/gotoblas2-1.13_bsd.tar.gz. $ tar xvfz GotoBLAS2-1.13_bsd.tar.gz $ cd GotoBLAS2 $./quickbuild.64bit... ln -fs libgoto2_nehalemp-r1.13.so libgoto2.so GotoBLAS build complete. OS...Linux Architecture...x86_64 BINARY...64bit C compiler...gcc(command line : gcc) Fortran compiler...gfortran \ (command line : gfortran) Library Name...libgoto2_nehalemp-r1.13.a\ (Multi threaded; Max num-threads is 8) Intel Core i7 920 2.66GHz 2 (3)OctaveでGotoBLAS2の 威 力 を 体 感 する Octave [9] Matlab BLAS, LAPACK Intel Core i7 920 2.66GHz, TurboBoost 42.56GFlops, 1GFlops 1 reference BLAS, ATLAS, GotoBLAS2 GFlops BLAS DGEMM BLAS, LAPACK reference $ LD_PRELOAD=/usr/lib/libblas.so:\ /usr/lib/liblapack.so; export LD_PRELOAD ATLAS Ubuntu $ LD_PRELOAD=/usr/lib/atlas/libblas.so:/usr/\ lib/atlas/liblapack.so; export LD_PRELOAD $ LD_PRELOAD=/home/maho/GotoBLAS2/\ libgoto2.so; export LD_PRELOAD BLAS $ octave... GFLOPS = 1.6865 4% Ubuntu ATLAS $ LD_PRELOAD=/usr/lib/atlas/libblas.so; \ export LD_PRELOAD $ octave... GFLOPS = 7.0291 16.5% ATLAS ATLAS 3.9.36 GFLOPS = 32.824 77.1% GotoBLAS2 $ LD_PRELOAD=/home/maho/GotoBLAS2/libgoto2.so ;\ export LD_PRELOAD $ octave... GFLOPS = 39.068 91.2% octave:1> n=4000; A=rand(n); B=(A+A )/2; octave:2> tic(); eig(b); toc(); GotoBLAS2 Vol.16, No.2 2011 39

2556 Elapsed time is 8.05604 seconds. reference BLAS Elapsed time is 37.7076 seconds. ATLAS Elapsed time is 33.5624 seconds. ATLAS 3.9.36 Elapsed time is 26.4307 seconds. ans=[ [ 2.10e+01, 3.36e+02, 7.08e+01];\ [ -6.40e+01, 5.14e+02, 9.50e+01];\ [ 2.10e+02, 3.10e+01, 4.75e+01] ] #check by Matlab/Octave by: alpha * A * B + beta * C (5)LAPACK 実 習 :C++から 行 列 の 固 有 ベクトル 固 有 値 を 求 めるDSYEVを 使 ってみる LAPACK C++ DSYEV GotoBLAS2 ATLAS 4.2 ATLAS reference BLAS GotoBLAS2 (4)BLAS 実 習 :C++から 行 列 - 行 列 積 DGEMMを 使 う - DGEMM α=3, β= 2 C αab + βc 4 $ g++ -static -pthread dgemm_demo.cpp -o \ dgemm_demo -L/home/maho/GotoBLAS2/ -lgoto2 Octave & $./dgemm_demo # dgemm demo... A =[ [ 1.00e+00, 8.00e+00, 3.00e+00];\ [ 2.00e+00, 1.00e+01, 8.00e+00];\ [ 9.00e+00, -5.00e+00, -1.00e+00] ] B =[ [ 9.00e+00, 8.00e+00, 3.00e+00];\ [ 3.00e+00, 1.10e+01, 2.30e+00];\ [ -8.00e+00, 6.00e+00, 1.00e+00] ] C =[ [ 3.00e+00, 3.00e+00, 1.20e+00];\ [ 8.00e+00, 4.00e+00, 8.00e+00];\ [ 6.00e+00, 1.00e+00, -2.00e+00]] alpha = 3.000e+00 beta = -2.000e+00 // dgemm test public domain #include <stdio.h> extern "C" { #define ADD_ #include <cblas_f77.h> //Matlab/Octave format void printmat(int N, int M, double *A, int LDA) { double mtmp; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { mtmp = A[i + j * LDA]; printf("%5.2e", mtmp); if (j < M - 1) printf(", "); if (i < N - 1) printf("]; "); else printf("] "); printf("]"); int main() { int n = 3; double alpha, beta; double *A = new double[n*n]; double *B = new double[n*n]; double *C = new double[n*n]; A[0+0*n]=1; A[0+1*n]= 8; A[0+2*n]= 3; A[1+0*n]=2; A[1+1*n]=10; A[1+2*n]= 8; A[2+0*n]=9; A[2+1*n]=-5; A[2+2*n]=-1; B[0+0*n]= 9; B[0+1*n]= 8; B[0+2*n]=3; B[1+0*n]= 3; B[1+1*n]=11; B[1+2*n]=2.3; B[2+0*n]=-8; B[2+1*n]= 6; B[2+2*n]=1; C[0+0*n]=3; C[0+1*n]=3; C[0+2*n]=1.2; C[1+0*n]=8; C[1+1*n]=4; C[1+2*n]=8; C[2+0*n]=6; C[2+1*n]=1; C[2+2*n]=-2; printf("# dgemm demo...\n"); printf("a =");printmat(n,n,a,n);printf("\n"); printf("b =");printmat(n,n,b,n);printf("\n"); printf("c =");printmat(n,n,c,n);printf("\n"); alpha = 3.0; beta = -2.0; F77_dgemm("n", "n", &n, &n, &n, &alpha, A, &n, B, &n, &beta, C, &n); printf("alpha = %5.3e\n", alpha); printf("beta = %5.3e\n", beta); printf("ans="); printmat(n,n,c,n); printf("\n"); 40 計 算 工 学

BLAS, LAPACK 1 2557 printf("#check by Matlab/Octave by:\n"); printf("alpha * A * B + beta * C =\n"); delete[]c; delete[]b; delete[]a; 図 4 C++でのDGEMMのサンプル 行 列 - 行 列 積 を 求 め る ファイル 名 は dgemm_demo.cpp とすること 0.40973,1.57715,10.83258 v 1, v 2, v 3 v 1= 0.914357,0.216411,0.342225 v 2= 0.040122, 0.792606,0.608413 v 3= 0.402916,0.570037,0.716042 5 $ g++ -static -pthread eigenvalue_demo.cpp \ -o eigenvalue_demo -L/home/maho/GotoBLAS2/ \ -lgoto2 -lgfortran Octave & $./eigenvalue_demo A =[ [ 1.00e+00, 2.00e+00, 3.00e+00];\ [ 2.00e+00, 5.00e+00, 4.00e+00];\ [ 3.00e+00, 4.00e+00, 6.00e+00] ] #eigenvalues w =[ [ -4.10e-01]; [ 1.58e+00]; [ 1.08e+01] ] #eigenvecs U =[ [ -9.14e-01, 2.16e-01, 3.42e-01];\ [ 4.01e-02, -7.93e-01, 6.08e-01];\ [ 4.03e-01, 5.70e-01, 7.16e-01] ] #Check Matlab/Octave by: eig(a) U *A*U //dsyev test public domain #include <iostream> #include <stdio.h> extern "C" int dsyev_(const char *jobz, const char *uplo, int *n, double *a, int *lda, double *w, double *work, int *lwork, int *info); //Matlab/Octave format void printmat(int N, int M, double *A, int LDA) { double mtmp; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { mtmp = A[i + j * LDA]; printf("%5.2e", mtmp); if (j < M - 1) printf(", "); if (i < N - 1) printf("]; "); else printf("] "); printf("]"); int main() { int n = 3; int lwork, info; double *A = new double[n*n]; double *w = new double[n]; //setting A matrix A[0+0*n]=1;A[0+1*n]=2;A[0+2*n]=3; A[1+0*n]=2;A[1+1*n]=5;A[1+2*n]=4; A[2+0*n]=3;A[2+1*n]=4;A[2+2*n]=6; printf("a ="); printmat(n, n, A, n); printf("\n"); lwork = -1; double *work = new double[1]; dsyev_("v", "U", &n, A, &n, w, work, &lwork, &info); lwork = (int)work[0]; delete[]work; work = new double[std::max((int) 1, lwork)]; //get Eigenvalue dsyev_("v", "U", &n, A, &n, w, work, &lwork, &info); //print out some results. printf("#eigenvalues \n"); printf("w ="); printmat(n, 1, w, 1); printf("\n"); printf("#eigenvecs \n"); printf("u ="); printmat(n, n, A, n); printf("\n"); printf("#check Matlab/Octave by:\n"); printf("eig(a)\n"); printf("u'*a*u\n"); delete[]work; delete[]w; delete[]a; 図 5 C++でのDSYEV 対 角 化 固 有 ベクトルを 求 めるサ ンプル ファイル 名 は eigenvalue_demo.cpp とする こと 7 終 わりと 次 回 予 告 BLAS LAPACK 謝 辞 参 考 文 献 [1] http://www.netlib.org/blas/ [2] http://www.netlib.org/lapack/ [3] http://www.tacc.utexas.edu/tacc-projects/gotoblas2/ [4] http://math-atlas.sourceforge.net/ [5] http://www.top500.org/ [6] http://www.netlib.org/scalapack/ [7] http://icl.cs.utk.edu/magma/ [8] http://mplapack.sourceforge.net/ [9] http://www.gnu.org/software/octave/ [10] http://www.ubuntulinux.jp/ [11] http://www.virtualbox.org/ Vol.16, No.2 2011 41