以前のリビジョンの文書です


ifort for linux

  • linux版は非商用に限り無償(アカデミックの用途に使う場合はアカデミックライセンスが必要
  • ライセンスの発行のために登録が必要。
  • MKLも一緒に入ってくる。

インストール方法

ubuntu 9.10 on Xeon にintel fortran compilerをインストールしたときのメモ

インストールに必要なopenjdk-6-jre,ia32-libsをインストール.

sudo apt-get install openjdk-6-jre ia32-libs

openjdk-6-jreにしたのは気分.sunのjavaでも可.

http://hogehoge よりソースをダウンロード.

tar xzvf hogehoge.tgz
sudo ./install.sh

途中で32bitのcompatibility librariesのことで下記のような文句を言われるかも.

32-bit libraries not found on this system.
This product release requires the presence of 32-bit compatibility libraries
when running on Intel(R) 64 architecture systems. One or more of these libraries
could not be found:
    libstdc++
    libstdc++5
    glibc
    libgcc
Without these libraries, the compiler will not function properly.  Please refer 
to Release Notes for more information.

ia32-libsを入れていれば,libstdc++5が入っているはずなのでリンク.

sudo ln -s /usr/lib/libstdc++.so.5.0.7 /usr/lib32/libstdc++.so.5

もう一度ライブラリを読み込ませればOK.

ubuntu 9.04にintel fortranコンパイラをインストール

1.インテルのページからifortのパッケージをダウンロード

2.install.sh の実行

ここでは、ver11.0.074 intel64版をインストール。

$ tar xzvf l_cprof_p_11.0.074_intel64.tgz
$ cd l_cprof_p_11.0.074_intel64
$ sudo ./install.sh

言われるがままに進む。途中パスワードの認証(activation)が必要。 インストール直前にbinutilsあたりでヴァージョンの違いについて文句を言われる。 おそらくifortが要求するヴァージョンよりもubuntuにインストールされているパッケージのヴァージョンの方が新しいので問題ないFIXME。 パッケージが不足している場合インストール中にメッセージが出る。 メッセージを読んで必要なものを入れる1)

$ sudo apt-get install libstdc++5 g++ binutils sun-java6-jre

64bitの場合、32bitがどうのこうのというエラーが出るかもしれないので、ia32-libsもインストール。

$ sudo apt-get install ia32-libs

3.環境変数の設定を行う。

環境変数の設定

まず、ifortのパスを通したり、ライブラリのパスを通すため、環境変数の設定を行う。

bashの場合

使用前に端末で以下を入力2)

$ . /opt/intel/Compiler/11.0/074/bin/ifortvars.sh [ia32|intel64|ia64]

あるいは、~/.bashrcの最後の行に以下を追記。

$ . /opt/intel/Compiler/11.0/074/bin/ifortvars.sh [ia32|intel64|ia64]

csh系の場合

$ . /opt/intel/Compiler/11.0/074/bin/ifortvars.csh [ia32|intel64|ia64]

とするか、~/.cshrcを編集FIXME

zshの場合

$ . /opt/intel/Compiler/11.0/074/bin/ifortvars.sh [ia32|intel64|ia64]

とすると、

/opt/intel/Compiler/11.0/074/bin/ifortvars.sh:82: = not found

なんてエラーが出る。 おそらくbashとzshの文法の違い。 エラーが出たシェルの == を = に書き直せば、うまく動作する。 例えば、intel64の場合、/opt/intel/Compiler/11.0/074/bin/ifortvars.shと/opt/intel/Compiler/11.0/074/bin/intel64/ifortvars_intel64.shの2つを書き換えればよい。複数のユーザーで使用している場合は、*.shを*.zshにコピーするなどの変更を加えるなどして、zsh専用のファイルを作るのがお行儀が良いかも。 以下の2ファイルを作成すればよい。

  • /opt/intel/Compiler/11.0/074/bin/ifortvars.zsh
  • /opt/intel/Compiler/11.0/074/bin/intel64/ifortvars_intel64.zsh

こんな感じかしら(32bit版の場合)FIXME

$ sudo sh -c "sed 's/==/=/g' /opt/intel/Compiler/11.0/074/bin/ifortvars.sh > /opt/intel/Compiler/11.0/074/bin/ifortvars.zsh"\\
$ sudo sh -c "sed 's/==/=/g' /opt/intel/Compiler/11.0/074/bin/ia32/ifortvars_ia32.sh > /opt/intel/Compiler/11.0/074/bin/ia32/ifortvars_ia32.zsh"\\
$ sudo sh -c "sed -i -e 's/.sh/.zsh/g' /opt/intel/Compiler/11.0/074/bin/ifortvars.zsh"

sudo sh -c “ “はsudoでリダイレクトするときの常套手段。

コンパイラオプション

http://accc.riken.jp/HPC/training/text.html

http://www.k.mei.titech.ac.jp/~stamura/NumericalComputation-Tips.html これくらいオプションをつけて実行すれば,だいたいエラーは検出されそう.

ifort -check all -warn declarations -CB -fpe0 -traceback

コンパイラオプションも参照のこと

改行の抑制

ifortでは出力時に勝手に改行する仕様になっている。 改行を抑制するためには、Format文を使用すればよい。

適当なやり方。

    write(*,'(100f)') a(:)

きちんとしたやり方。以下2chより引用。

http://pc12.2ch.net/test/read.cgi/tech/1163319215/532

532 名前:デフォルトの名無しさん [sage]: 2009/03/27(金) 05:59:41  
亀だけど、Ifortなら<>がお勧め。
多次元配列の最初の数を入れることが多いです
例
program main
implicit none
integer,parameter :: num = 9
integer :: ii,jj
real :: arry(num,num)
do ii=1,num
do jj = 1,num
arry(ii,jj) = ii*jj
enddo
enddo

write(6,'(<num>F)') arry
end program 

MKL

概要

パッケージ名
lapack 密行列やバンド行列を直説法で解く
lapack95 密行列やバンド行列を直説法で解く
blas95 マトベク演算や内積演算を行う
sparse_blas95 疎行列のマトベク演算行う
pardiso 疎行列を直説法で解く。(条件数の大きい問題向き)
fgmres 疎行列をFlexibleGMRESで解く。

MKLのコンパイラオプションは以下のとおり。

-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]

[ ]はあってもなくても良い、{ }はどちらか選択という意味。 -L<MKL path> -I<MKL path>は pathが通っていれば明示する必要なし。

Intel(R) Math Kernel Library for the Linux* OS User's Guideに以下のような記述あり。

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

libguideとlibiompはどちらかを選べば良いのだが、並列化をするのであれば、libiompを選択した方がよいかも。FIXME

lapack

  • ifortと一緒にインストールされる.
  • 環境変数の設定をしておけばパスを通す必要はない.
$ ifort file.f90  -lmkl -lmkl_lapack  -lmkl_em64t -lguide -lmkl_solver

lapack95

  • 線形方程式を解くパッケージ。
  • 固有値の計算や特異値分解も可能。
  • mklのlapack95はlapack90のラッパーらしい。
  • 自分でmakeする必要あり。

ライブラリの作成

  • libem64t, intel64の部分は環境に応じて適当に。オプションも適当に。デフォルトで十分そうなので、オプションはなくても良さそう。
$ cd /opt/intel/Compiler/11.0/074/mkl/examples/lapack95/
$ sudo gnome-terminal

新しく開いた端末で作業3)

 
# . /opt/intel/Compiler/11.0/074/bin/ifortvars.sh intel64
# make libem64t 
# exit

サンプルコード 

コードのサンプルは /opt/intel/mkl/10.1.0.015/examples/lapack95/source/ にあり。ここではgesv.f90を参考にしながら説明。

コンパイルオプション(intel64)

$ 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

コンパイルオプション(ia32)

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

使い方

/opt/intel/mkl/10.1.0.015/examples/lapack95/source/gesv.f90 の最初

      USE MKL95_PRECISION, ONLY: WP => SP
      USE MKL95_LAPACK, ONLY: GESV
  • 単精度はSP、倍精度はDPを使用する。
  • 呼び出すサブルーチン名をONLYの後に書く。

/opt/intel/mkl/10.1.0.015/examples/lapack95/source/gesv.f90 の中頃

      CALL GESV(  A, B )
      CALL GESV(  AA, BB(:,1), IPIV, INFO )
  • 引数の数が違うのはfortran90のoptional属性によるもの。
  • LIBRARY_PATHやINCLUDEの環境変数を追加するか,libやmodを適切な位置に動かすのが良いかも.(makeほげほげで設定できないのかしら.未確認.FIXME

blas95

  • マトベク演算やらをしてくれるパッケージ。
  • matmulよりも高速。(多分)
  • 自分でmakeする必要あり。

ライブラリの作成

  • libem64t, intel64の部分は環境に応じて適当に。オプションも適当に。デフォルトで十分そうなので、オプションはなくても良さそう。
  • ライブラリの作成方法はlapack95と同じ。
$ cd /opt/intel/Compiler/11.0/074/mkl/interfaces/blas95
$ sudo gnome-terminal
# . /opt/intel/Compiler/11.0/074/bin/ifortvars.sh intel64
# make libem64t 
# exit

サンプルコード 

コンパイルオプション

コードのサンプルは /opt/intel/Compiler/11.0/074/mkl/examples/blas95/source/ にあり。ここでは dgemmx.f90を参考にしながら説明。

$ 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
  • /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 のはじめのあたり。

      use mkl95_precision, only: wp => dp
      use mkl95_blas, only: gemm
  • lapack95と同様にspで単精度、dpで倍精度。
  • gemmは呼び出すルーチン名

sparse_blas95

pardiso/MKL

コンパイルオプション

  • 77でも90でもコンパイル方法は同じ。(ファイルの拡張子が異なるだけ)
  • includeする場合はパスの設定が必要.(ifortvars.*shを読み込んでいる場合は,設定済み)

intel64の場合

$ ifort hoge.f90 -lmkl_solver_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core   -liomp5 -lpthread

ia32の場合

$ ifort hoge.f90 -lmkl_solver -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread

コメント

  • mkl_pardiso.f90をincludeせずに,mkl_pardiso.f90と一緒にコンパイルするやり方もあり。
$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

サンプル コード

f77のコードは /opt/intel/Compiler/11.0/074/mkl/examples/solver/source/ 内にあり。

fortran90

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

fortran77

fortran90のサンプルを書き換え。

      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

fgmres

前処理を効率的に行えるようGMRESを改良したもの。前処理に反復解法が使える。

FIXME

1) sun-java6-jreはjavaを要求されるからインストールしてみた。 正しいかどうか不明FIXME。binutilsは最初から入ってるかも。
2) [ia32|intel64|ia64]は正規表現
3) sudo make libem64tとすると、「ifort: コマンドが見つかりませんでした」と怒られる。そのため、スーパーユーザー用の端末を開き、パスを通してから作業。sudoで端末を開くのは、ちょっとお行儀悪いかも。sudoに環境変数を引き継ぐやり方もありそう…
ifort.1261621513.txt.gz · 最終更新: 2009/12/24 11:25 by saito
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0