ユーザ用ツール

サイト用ツール


fortran:ifort

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
fortran:ifort [2013/12/25 11:12]
saito [MKL]
fortran:ifort [2017/10/03 12:55] (現在)
ライン 69: ライン 69:
 ifort sample.f90 -mkl ifort sample.f90 -mkl
 </​code>​ </​code>​
-===== 概要 ​===== +====== CSRへの変換 ====== 
-^パッケジ名^^ +pardisoはCSRフォーマトを用いるが,coordinateフォーから変換するサブルーチンが用意されてる.
-|[[ifort#​lapack]] |密行列やバンド行列を直説法で解く | +
-|[[ifort#​lapack95]] |密行列やバンド行列を直説法で解く | +
-|[[ifort#​blas95]] ​  |マトベク演算や内積演算行う ​    | +
-|[[ifort#​sparse_blas95]] ​  ​|疎行列のマトベク演算行う ​    | +
-|[[ifort#​pardiso]] ​ |疎行列を直説法で解く。(条件数の大き問題向き) ​  | +
-|[[ifort#​fgmres]] ​  ​|疎行列をFlexibleGMRESで解く。 ​   |+
  
 +https://​software.intel.com/​en-us/​node/​468628
  
-MKLのコンパイラオプションは以下のとおり。 +フォーマットについてはちらから.
-<​file>​ +
--L<MKL path> -I<MKL path> +
-[-lmkl_lapack95] [-lmkl_blas95] +
-[cluster components] +
-[{-lmkl_{intel,​ intel_ilp64,​ intel_lp64, intel_sp2dp,​ gf, gf_ilp64, gf_lp64}] +
-[-lmkl_{intel_thread,​ sequential}] +
-[{-lmkl_solver,​ -lmkl_solver_lp64,​ -lmkl_solver_ilp64}] +
-{{[-lmkl_lapack] -lmkl_{ia32,​ em64t, ipf}},​-lmkl_core}} +
-[{-lguide, -liomp5}] [-lpthread] [-lm] +
-</​file>​ +
-[ ]はあっもなくても良い、{ }ちらか選択という意味。 +
--L<MKL path> -I<MKL path>は pathが通っていれば明示する必要なし。+
  
-[[http://www.ncsa.uiuc.edu/UserInfo/​Resources/​Hardware/​SGIAltix/​Doc/​mkl10/​doc/​userguide.pdf|Intel(R) Math Kernel Library for the Linux* OS User's Guide]]に以下のような記述あり。 +https://software.intel.com/en-us/node/471374
-<​file>​ +
-You are strongly encouraged to dynamically link in Intel® Legacy OpenMP* run-time +
-library libguide and Intel® Compatibility OpenMP* run-time library libiomp. Linking to +
-static OpenMP run-time library is not recommended,​ as it is very easy with layered +
-software to link in more than one copy of the library. This causes performance problems +
-(too many threads) and may cause correctness problems if more than one copy is +
-initialized. +
-You are advised to link with libguide and libiomp dynamically even if other libraries are +
-linked statically. +
-</file> +
-<​file>​ +
-The second relevant component is the Compiler Support RTL Layer. Prior to Intel MKL 10.0, +
-this layer only included the Intel® Legacy OpenMP* run-time compiler library libguide. +
-Now you have a new choice to use the Intel® Compatibility OpenMP* run-time compiler +
-library libiomp. The Compatibility library provides support for one additional threading +
-compiler on Linux (gnu). That is, a program threaded with a gnu compiler can safely be +
-linked with Intel MKL and libiomp and execute efficiently and effectively. +
-</file> +
-libguideとlibiompはどちらかを選べば良いのだが、並列化をするのであれば、libiompを選択した方がよいかも。FIXME+
  
 +Fortranの場合,job(1:​8)に与える数値は以下の通りで(だいたい)OK.
 +|job(1)=1|the matrix in the coordinate format is converted to the CSR format.|
 +|job(2)=1|one-based indexing for the matrix in CSR format is used.|
 +|job(3)=1|one-based indexing for the matrix in coordinate format is used.|
 +|job(4)|特に設定不要|
 +|job(5)=nnz| sets number of the non-zero elements of the matrix A if job(1)=1.|
 +|job(6)=0| all arrays acsr, ja, ia are filled in for the output storage.|
  
 +<code fortran>
  
-===== lapack ===== 
-  * ifortと一緒にインストールされる. 
-  * 環境変数の設定をしておけばパスを通す必要はない. 
- 
-ifort Version 12.0では以下のようにすれば動いた.FIXME 
-<code bash> 
-ifort hoge.f90 -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread 
 </​code>​ </​code>​
 +====== pardiso の使い方======
 +pardisoを用いた連立一時方程式の解き方.
  
-ver 11くらい+スパコンの
 <​code>​ <​code>​
-ifort file.f90  -lmkl -lmkl_lapack ​ -lmkl_em64t -lguide -lmkl_solver+/​opt/​app/​intel/​composer_xe_2013.5.192/​mkl/​examples/​solverf/​source/​
 </​code>​ </​code>​
-===== lapack95 ===== +入っているサンプルを参考に,走せたいログ作成する. 
- +include文が大事 
-  * [[http://​www.netlib.org/​lapack95/​|lapack95]] +自分プログラム
-  * [[http://​www.netlib.org/​lapack95/​lug95/​|lapack95のhtmlドキュメント]] +
-  * 線形方程式を解くパッケージ。 +
-  * 固有値の計算や特異値分解も可能。 +
-  * mklのlapack95はlapack90のラッパーらしい。 +
-  * 自分でmakeする必要あり。 +
- +
-==== ライブラリの作成 ==== +
-  * libem64t, intel64の部分は環境応じ適当に。オプションも適当に。デフォルトで十分そうなので、オプションはなくても良さそう。 +
-<​code>​ +
-$ cd /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​ +
-$ sudo gnome-terminal +
-</​code>​ +
-新しく開た端末で作業((sudo make libem64tとすと、「ifort:​ コマンドが見つかりませんでした」と怒られる。そのため、スーパーユーザー用の端末を開き、パスを通してから作業。sudoで端末を開くのは、ちょっとお行儀悪いかも。sudoに環境変数を引き継ぐやり方もありそう…))。 +
-<​code>​  +
-# . /​opt/​intel/​Compiler/​11.0/​074/​bin/​ifortvars.sh intel64 +
-# make libem64t  +
-# exit +
-</​code>​ +
- +
-==== サンプルド ==== +
- +
-コードのサンプルは /​opt/​intel/​mkl/​10.1.0.015/​examples/​lapack95/​source/​ にあり。ここではgesv.f90を参考にしなが説明。 +
-=== コンパイルオション(intel64) === +
- +
-(2010.06.22追記)最近のver.はイブラリの場所が変わったようだ.(というか今まで間違ったファイル使ってだけかも... +
-Fortran90でLapack95使ったときのコンパイルコマンドfile.f90ところは適当修正して下さい. +
-<code bash> +
-ifort file.f90 -L/​opt/​intel/​Compiler/​11.1/​069/​mkl/​lib/​em64t/​ -I /​opt/​intel/​Compiler/​11.1/​069/​mkl/​include/​em64t/​lp64/​ -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lguide -lpthread -O2 +
-</​code>​ +
- +
-以下,古い情報 +
-<code bash> +
-$ ifort /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​source/​gesv.f90 -L/​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​lib/​em64t/​ -I /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​lib/​em64t -lmkl_lapack95 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lguide -lpthread +
-$ ./a.out < /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​data/​gesv.d +
-</​code>​ +
-=== コンパイルオプション(ia32) === +
-<code bash> +
-ifort /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​source/​gesv.f90 -L/​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​lib/​32 ​ -I /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​lib/​32/​ -lmkl_lapack95 -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread +
-$ ./a.out < /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​lapack95/​data/​gesv.d +
-</​code>​ +
-=== 使い方 === +
-/​opt/​intel/​mkl/​10.1.0.015/​examples/​lapack95/​source/​gesv.f90 の最初+
 <code fortran> <code fortran>
-      USE MKL95_PRECISION,​ ONLY: WP => SP +include '​mkl_pardiso.f77'​
-      USE MKL95_LAPACK,​ ONLY: GESV+
 </​code>​ </​code>​
-  * 単精度はSP、倍精度はDPを使用する。 +
-  * 呼び出すサブルーチン名をONLYの後に書く。 +
- +
-/​opt/​intel/​mkl/​10.1.0.015/​examples/​lapack95/​source/​gesv.f90 の中頃+
 <code fortran> <code fortran>
-      CALL GESV(  A, B )+include '​mkl_pardiso.f90'​
 </​code>​ </​code>​
-<code fortran>​ +を入れ
-      CALL GESV(  AA, BB(:,1), IPIV, INFO ) +
-</​code>​ +
-   * 引数の数が違うのはfortran90のoptional属性によもの。+
  
-  * LIBRARY_PATHやINCLUDE環境変数を追加するか,libやmodを適切な位置動かすの良いかも.(makeほげほげで設定できないのから.未確認.FIXME)+配列設定注意必要,詳くは以下を参照 
 +[http://​www.pardiso-project.org/​manual/​manual.pdf]
  
-===== blas95 ===== 
  
-  * マトベク演算やらをしてくれるッケージ。 +コンパイラオプションは
-  * matmulよりも高速。(多分) +
-  * 自分でmakeする必要あり。 +
- +
-==== ラリの作成 ==== +
-  * libem64t, intel64の部分は環境に応じて適当に。オプションも適当に。デフォルトで十分そうなので、オプションはなくても良さそう。 +
-  * ライブラリの作成方法lapack95と同じ。+
 <​code>​ <​code>​
-$ cd /​opt/​intel/​Compiler/​11.0/​074/​mkl/​interfaces/​blas95 +-mkl
-$ sudo gnome-terminal+
 </​code>​ </​code>​
-<​code>​ +お手軽♪
-# . /​opt/​intel/​Compiler/​11.0/​074/​bin/​ifortvars.sh intel64 +
-# make libem64t  +
-# exit +
-</​code>​ +
- +
-==== サンプルコード ==== +
-=== コンパイルオプション === +
-コードのサンプルは /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas95/​source/​ にあり。ここは dgemmx.f90を参考にしながら説明。 +
-<​code>​ +
-$ ifort /​opt/​intel/​Compiler/​11.0/​074/​mkl/​include/​mkl_blas.f90 ​ /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas95/​source/​dgemmx.f90 ​  /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas95/​source/​common_func.f -lmkl_blas95 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread +
-$ ./a.out < /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas/​data/​dgemmx.d +
-</​code>​ +
-  * /​opt/​intel/​Compiler/​11.0/​074/​mkl/​include/​mkl_blas.f90 はインターフェース +
-  * /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas95/​source/​dgemmx.f90 がメインプログラム +
-  * /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas95/​source/​common_func.f はdgemmxが使用している副プログラム(サブルーチン) +
- +
-=== コード === +
-/​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​blas95/​source/​dgemmx.f90 のはじめのあたり。 +
-<code fortran>​ +
-      use mkl95_precision,​ only: wp => dp +
-      use mkl95_blas, only: gemm +
-</​code>​ +
-  * lapack95と同様にspで単精度、dpで倍精度。 +
-  * gemmは呼び出すルーチン名 +
-===== sparse_blas95 ===== +
- +
-===== pardiso/MKL ===== +
- +
-  * [[http://​www.pardiso-project.org]] +
-  * 疎行列で解く。 +
-  * 直接法で解く。->​ 条件数の大きい問題に使える。 +
-  * [[http://​dx.doi.org/​10.1016/​S0167-739X(00)00076-5|理論については論文を参照]]\\ +
- +
- +
-==== コンパイルオプション ==== +
-  * 77でも90でもコンパイル方法は同じ。(ファイルの拡張子が異なるだけ) +
-  * includeする場合はパスの設定が必要.(ifortvars.*shを読み込んでいる場合は,設定済み) +
-=== intel64の場合 === +
-<​code>​ +
-$ ifort hoge.f90 -lmkl_solver_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core ​  ​-liomp5 -lpthread +
-</​code>​ +
- +
-===  ia32の場合 === +
-<​code>​ +
-$ ifort hoge.f90 -lmkl_solver -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread +
-</​code>​ +
- +
-=== コメント === +
-  * mkl_pardiso.f90をincludeせずに,mkl_pardiso.f90と一緒にコンパイルするやり方もあり。 +
-<​code>​ +
-$ifort pardiso.f90 /​opt/​intel/​Compiler/​11.0/​074/​mkl/​include/​mkl_pardiso.f90 -lmkl_solver -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread +
-</​code>​ +
- +
- +
- +
-==== サンプル コード ==== +
-f77のコードは /​opt/​intel/​Compiler/​11.0/​074/​mkl/​examples/​solver/​source/​ 内にあり。 +
- +
-=== fortran90 === +
-<code fortran>​ +
-include '​mkl_pardiso.f90'​ +
- +
-program pardiso_test +
-  use MKL_PARDISO +
-  implicit none +
-  real(8),​allocatable::​a(:​),​b(:​),​x(:​) +
-  integer::​maxfct=1,​mnum=1,​mtype,​phase=13,​n,​nzero,​nrhs=1,​iparm(64),​msglvl=0,​error +
-  type(mkl_pardiso_handle) :: pt(64) +
-  integer i,j +
-  integer,​allocatable::​ia(:​),​ja(:​),​perm(:​) +
-!!! this matrix is quoted by slatec document... +
-!       |11 12  0  0 15|   A: 11 12 15 | 21 22 | 33 35 | 44 | 51 53 55 +
-!       |21 22  0  0  0|  IA:  1       ​| ​ 4    |  6    |  8 |  9       | 12 +
-!       | 0  0 33  0 35|  JA:  1  2  5 |  1  2 |  3  5 |  4 |  1  3  5  +
-!       | 0  0  0 44  0| +
-!       ​|51 ​ 0 53  0 55| +
-!!! set parameter of pardiso +
-  pt(:​)=mkl_pardiso_handle(0) +
-  iparm(1)=0 +
-  mtype=11 +
-!!! assign values to variables +
-  n=5 +
-  nzero=11 +
-  allocate(a(nzero),​b(n),​x(n),​ia(n+1),​ja(nzero),​perm(n)) +
-  ia(:​)=(/​1,​4,​6,​8,​9,​12/​) +
-  a(:​)=(/​11.d0,​12.d0,​15.d0,​21.d0,​22.d0,​33.d0,​35.d0,​44.d0,​51.d0,​53.d0,​55.d0/​) +
-  ja(:​)=(/​1,​2,​5,​1,​2,​3,​5,​4,​1,​3,​5/​) +
-!!! calculate b when x=(/​1.d0,​2.d0,​3.d0,​4.d0,​5.d0/​) +
-  b(:)=0.d0 +
-  do i=1,5 +
-     do j=ia(i),​ia(i+1)-1 +
-        b(i)=b(i)+a(j)*ja(j) +
-     end do +
-  end do +
-!!! solve linear equation by pardiso +
-  call pardiso(pt,​maxfct,​mnum,​mtype,​phase,​n,​a,​ia,​ja,​perm,​nrhs,​iparm,​msglvl,​b,​x,​error) +
-  if(error /= 0) then  +
-     ​write(*,​*) error  +
-     ​stop +
-  end if +
-  write(*,*) x +
-end program pardiso_test +
-</​code>​ +
- +
-=== fortran77 === +
-fortran90のサンプルを書き換え。 +
-<code fortran>​ +
-      program pardiso_test +
-      implicit none +
-      integer lzero,l +
-      parameter (lzero=11,​l=5) +
-      real*8 a(lzero),​b(l),​x(l) +
-      integer maxfct,​mnum,​mtype,​phase,​n,​nzero,​nrhs,​iparm(64),​ +
-     ​$ ​    ​msglvl,​error,​pt(64),​ia(l+1),​ja(lzero),​perm(l),​i,​j +
-      data ia /​1,​4,​6,​8,​9,​12/​ +
-      data ja /​1,​2,​5,​1,​2,​3,​5,​4,​1,​3,​5/​ +
-      data a /​11.d0,​12.d0,​15.d0,​21.d0,​22.d0,​33.d0,​35.d0,​ +
-     ​$ ​    ​44.d0,​51.d0,​53.d0,​55.d0/​ +
-ccc   this matrix is quoted by slatec document... +
-c     |11 12  0  0 15|   A: 11 12 15 | 21 22 | 33 35 | 44 | 51 53 55 +
-c     |21 22  0  0  0|  IA:  1       ​| ​ 4    |  6    |  8 |  9       | 12 +
-c     | 0  0 33  0 35|  JA:  1  2  5 |  1  2 |  3  5 |  4 |  1  3  5  +
-c     | 0  0  0 44  0| +
-c     ​|51 ​ 0 53  0 55| +
-ccc   set parameter of pardiso +
-      do i=1,64 +
-         ​pt(i)=0 +
-      end do +
-      iparm(1)=0 +
-      mtype=11 +
-      maxfct=1 +
-      mnum=1 +
-      phase=13 +
-      nrhs=1 +
-      msglvl=0 +
-ccc   ​assign values to variables +
-      n=5 +
-      nzero=11 +
-ccc   ​calculate b when x=(/​1.d0,​2.d0,​3.d0,​4.d0,​5.d0/​) +
-      b(:)=0.d0 +
-      do i=1,5 +
-         do j=ia(i),​ia(i+1)-1 +
-            b(i)=b(i)+a(j)*ja(j) +
-         end do +
-      end do +
-ccc   solve linear equation by pardiso +
-      call pardiso(pt,​maxfct,​mnum,​mtype,​phase,​n,​a,​ia,​ja,​perm,​nrhs,​ +
-     ​$ ​    ​iparm,​msglvl,​b,​x,​error) +
-      if(error /= 0) then  +
-         ​write(*,​*) error  +
-         ​stop +
-      end if +
-      write(*,*) x +
-      end program +
-</​code>​ +
- +
- +
-===== fgmres ===== +
-前処理を効率的に行えるようGMRESを改良したもの。前処理に反復解法が使える。 +
- +
-FIXME+
fortran/ifort.1387937527.txt.gz · 最終更新: 2017/10/03 12:55 (外部編集)