Octave とは,MATLAB に互換の数値解析ソフトウエアです.
◆ この Web ページでは,Octave のソースコードをダウンロードし, Ubuntu や Fedora 上でビルドしてインストールする手順を図解などで説明します.
◆ なぜ,ソースコードからビルドするのか?
などの場合には,この Web ページの手順が参考になるでしょう.
※ Octave をパッケージ (yum) を使ってインストールしたい(わざわざソースコードからビルドしない) 場合は,別の Web ページを見てください.
※ Cygwin での Octave のビルドとインストールについては,別の Web ページで説明しています.
※ liboctave の使い方については,別の Web ページで説明しています.liboctave を使って,Octave の行列関係の機能を呼び出すような C++ のプログラムを簡単に作ることができます.
※ 貴重な
※ 関連Webページ: Octave を用いた信号処理,画像処理
【要点】
BLAS(Basic Linear Algebra Subprograms)とは,行列演算,ベクトル演算の機能をもったプログラム群です. GotoBLAS や ATLAS は,無料で使えるソフトウエアの中では,BLAS 実装の決定版といってよいでしょう.※ 他にも,優れた実装が複数あります.
<BLAS の機能の概要(ごく一部)>
LAPACK とは,行列に関する種々の計算(連立1次方程式,固有値問題,などなど多数)のソフトウエアです. LAPACK は Octave に必要です.
※ GotoBLAS は素晴らしいプログラムで,しかも,無料で使えます.但し,GotoBLAS はフリーソフトウエアではありません.「再配布や,商用・業務利用は原則不可」と明記されています. 再配布不可ですから,ソースコードやビルドしたバイナリを人にあげることはできません(パソコンを借りてインストールしてあげる,ということも難しい,という意味です).
※ GotoBLAS のライセンス条項に「不安」がある場合は,ATLAS を使うことも検討してください.(決して違法なことはしないように).
※ ATLAS も素晴らしいプログラムで,無料で使えます. ATLAS は BSD ライセンスとなっているようです.ライセンスは,各自でよく確認してください. ライセンスからいうと,GotoBLAS より使い勝手が良さそうです.
【この Web ページで行うこと】
http://www.gnu.org/software/octave/ Octave の本家 からソースコードをダウンロードします.
本 Web ページは,Linux での Octave のビルドとインストール法に焦点をあてていますが, 本 Web ページの作成にあたっては, まず, 「octave for windowsメモの筆者」様(http://www.tatsuromatsuoka.com/octave/jpn/OctaveWinMemo.html)に, 2ちゃんねる (http://2ch.net/) の「データ解析ツールoctaveを語ろう」掲示板での議論を通して,数々の貴重なご教示,コメント頂きました. ありがとうございました.
Metis は再配布不可.ビルドしたバイナリであっても再配布不可
GotoBLAS は再配布不可.ビルドしたバイナリであっても再配布不可
あった方が SuiteSparse の実行形式プログラムのビルドなどもできて便利.
などなど.
敬意を込めて, 「octave for windowsメモの筆者」様の URL を記しておきます. http://www.tatsuromatsuoka.com/octave/jpn/OctaveWinMemo.html
⇒ この Web ページは,分かりやすく,また,Octave に関係する種々の有益な情報が載ったページです. 情報の宝庫,オンリーワンの Web ページと言ってよいでしょう.
楽をしたいのでシェルスクリプトを作りました。 1つ1つコマンドを入力したい(シェルスクリプトにしたくない)場合については、この Web ページの下で説明しています。 Octave バージョン 3.6.1 のダウンロードとビルドとインストールが行われます.前提ソフトウエアとして用いる graphicsmagick, curl, gsl, fftw3, glpk, qrupdate, suitesparce, lapack, atlas のインストールも行います。 Ubuntu 11.10 を用いて動作確認済みです.
■
#!/bin/bash
sudo apt-get -yV install build-essential
# GNU gcc, g++, gfortran を使う場合: gcc, g++, gfortran
# Intel Compiler を使う場合: CC=icc, icpc, ifort
if [ -x /opt/intel/bin/icc ]; then
if [ -x /opt/intel/bin/ifort ]; then
echo USE Intel Compiler
export USEINTEL=YES
fi
fi
if [ -x /opt/intel/bin/compilervars.sh ]; then
echo USE Intel MKL
export USEMKL=YES
fi
if [ "$USEMKL" = "YES" ]; then
if [ `arch` = 'i686' ]; then
source /opt/intel/bin/compilervars.sh ia32
fi
if [ `arch` = 'x86_64' ]; then
source /opt/intel/bin/compilervars.sh intel64
fi
fi
# octave 前提ソフトウエア (Octave build dependency softwares)
cd /tmp; sudo apt-get source octave3.2
cd /tmp; sudo apt-get build-dep octave3.2
# /etc/ld.so.conf
sudo cp /etc/ld.so.conf /etc/ld.so.conf.$$
echo "/usr/local/lib" | sudo tee -a >> /etc/ld.so.conf
echo "/usr/local/lib/octave/3.6.1" | sudo tee -a >> /etc/ld.so.conf
sudo /sbin/ldconfig
# graphicsmagick
sudo apt-get -yV --force-yes install graphicsmagick-dbg
sudo apt-get -yV --force-yes install graphicsmagick
sudo apt-get -yV --force-yes install graphicsmagick-imagemagick-compat
sudo apt-get -yV --force-yes install graphicsmagick-libmagick-dev-compat
sudo apt-get -yV --force-yes install libgraphics-magick-perl
sudo apt-get -yV --force-yes install libgraphicsmagick++1-dev
sudo apt-get -yV --force-yes install libgraphicsmagick++3
sudo apt-get -yV --force-yes install libgraphicsmagick1-dev
sudo apt-get -yV --force-yes install libgraphicsmagick3
# curl
sudo apt-get -yV install curl
sudo apt-get -yV install libcurl3-dbg
sudo apt-get -yV install libcurl3-gnutls
sudo apt-get -yV install libcurl3
sudo apt-get -yV install libcurl4-gnutls-dev
# gsl
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
mkdir /tmp/gsl
cd /tmp/gsl
apt-get source gsl
sudo apt-get -yV build-dep gsl
cd gsl-*
CC=icc CXX=icpc F77=ifort dpkg-buildpackage -rfakeroot
cd ..
sudo dpkg -i *.deb
else
# package install
sudo apt-get -yV install gsl-bin
sudo apt-get -yV install libgsl0-dbg
sudo apt-get -yV install libgsl0-dev
sudo apt-get -yV install libgsl0ldbl
fi
# fftw3
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
mkdir /tmp/fftw3
cd /tmp/fftw3
apt-get source fftw3
sudo apt-get -yV build-dep fftw3
cd fftw3-*
CC=icc CXX=icpc F77=ifort dpkg-buildpackage -rfakeroot
cd ..
sudo dpkg -i *.deb
else
# package install
sudo apt-get -yV install libfftw3-3
sudo apt-get -yV install libfftw3-dev
sudo apt-get -yV install libfftw3-doc
fi
# glpk
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
mkdir /tmp/glpk
cd /tmp/glpk
apt-get source glpk
sudo apt-get -yV install libiodbc2-dev
sudo apt-get -yV build-dep glpk
cd glpk-*
CC=icc CXX=icpc F77=ifort dpkg-buildpackage -rfakeroot
cd ..
sudo dpkg -i *.deb
else
# package install
sudo apt-get -yV install glpk-doc
sudo apt-get -yV install glpk-utils
sudo apt-get -yV install libglpk-dev
sudo apt-get -yV install libglpk0-dbg
sudo apt-get -yV install libglpk0
sudo apt-get -yV install glpk
fi
# qrupdte
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
mkdir /tmp/qrupdate
cd /tmp/qrupdate
apt-get source qrupdate
sudo apt-get -yV build-dep qrupdate
cd qrupdate-*
CC=icc CXX=icpc F77=ifort dpkg-buildpackage -rfakeroot
cd ..
sudo dpkg -i *.deb
else
# package install
sudo apt-get -yV --force-yes install libqrupdate-dev
sudo apt-get -yV --force-yes install libqrupdate1
fi
# arpack
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
mkdir /tmp/arpack
cd /tmp/arpack
apt-get source arpack
sudo apt-get -yV build-dep arpack
cd arpack-*
CC=icc CXX=icpc F77=ifort dpkg-buildpackage -rfakeroot
cd ..
sudo dpkg -i *.deb
else
# package install
sudo apt-get -yV --force-yes install libarpack2-dbg
sudo apt-get -yV --force-yes install libarpack2-dev
sudo apt-get -yV --force-yes install libarpack2
fi
# suitesparse-metis
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
mkdir /tmp/suitesparse-metis
cd /tmp/suitesparse-metis
apt-get source suitesparse-metis
sudo apt-get -yV build-dep suitesparse-metis
cd suitesparse-metis-*
CC=icc CXX=icpc F77=ifort dpkg-buildpackage -rfakeroot
cd ..
sudo dpkg -i *.deb
else
# package install
sudo apt-get -yV --force-yes install libsuitesparse-metis-3.1.0
sudo apt-get -yV --force-yes install libsuitesparse-metis-dbg
sudo apt-get -yV --force-yes install libsuitesparse-metis-dev
fi
# LAPACK をパッケージを用いてインストール (install the LAPACK softwares using package)
sudo apt-get -yV --force-yes install liblapack-dev
sudo apt-get -yV --force-yes install liblapack-test
sudo apt-get -yV --force-yes install liblapack-doc
sudo apt-get -yV --force-yes install liblapack3gf
sudo apt-get -yV --force-yes install liblapack-pic
# ATLAS をパッケージを用いてインストール (install the ATLAS softwares using package)
sudo apt-get -yV install libatlas-base-dev
sudo apt-get -yV install libatlas-dev
sudo apt-get -yV install libatlas-doc
sudo apt-get -yV install libatlas-test
sudo apt-get -yV install libatlas3gf-base
# BLAS 参照実装のダウンロードとビルド (Download BLAS reference implementarion and build it and install it)
cd /tmp
if [ ! -f blas.tgz ]; then
wget http://netlib.org/blas/blas.tgz
fi
rm -rf BLAS
tar -xvzof blas.tgz
cd /tmp/BLAS
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler
if [ `arch` = 'i686' ]; then
make LOADER="ifort -fPIC" FORTRAN="ifort -m32 -fPIC"
elif [ `arch` = 'x86_64' ]; then
make LOADER="ifort -fPIC" FORTRAN="ifort -m64 -fPIC"
fi
else
# GNU Compiler
if [ `arch` = 'i686' ]; then
make LOADER="gfortran -fPIC" FORTRAN="gfortran -m32 -fPIC"
elif [ `arch` = 'x86_64' ]; then
make LOADER="gfortran -fPIC" FORTRAN="gfortran -m64 -fPIC"
fi
fi
cp /tmp/BLAS/blas_LINUX.a /usr/local/lib/libblas_LINUX.a
# Octave のダウンロードとビルドとインストール
cd /tmp
if [ ! -f octave-3.6.1.tar.gz ]; then
wget ftp://ftp.gnu.org/gnu/octave/octave-3.6.1.tar.gz
fi
sudo rm -rf octave-3.6.1
tar -xvzof octave-3.6.1.tar.gz
cd octave-3.6.1
if [ "$USEINTEL" = "YES" ]; then
# Intel Compiler (インテル C++ Composer XE Linux 版, インテル Fortran Composer XE Linux 版を使う場合)
if [ `arch` = 'i686' ]; then
echo "source /opt/intel/bin/compilervars.sh ia32" >> ~/.bashrc
elif [ `arch` = 'x86_64' ]; then
echo "source /opt/intel/bin/compilervars.sh intel64" >> ~/.bashrc
fi
#
# コンパイル時のエラー回避のため
cat libgnu/malloca.c | fgrep -v verify > /tmp/malloca.c.$$
cp /tmp/malloca.c.$$ libgnu/malloca.c
# cat libcruft/arpack/util/second.f | sed 's/INTRINSIC/EXTERNAL/g' > /tmp/second.f.$$
# cp /tmp/second.f.$$ libcruft/arpack/util/second.f
cat libgnu/stdio.h | sed "s/_GL_CXXALIAS_SYS (getchar, int, (void));/\/\/_GL_CXXALIAS_SYS (getchar, int, (void));/g" | sed "s/_GL_CXXALIAS_SYS (putchar, int, (int c));/\/\/_GL_CXXALIAS_SYS (putchar, int, (int c));/g" | sed "s/_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));/\/\/_GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args));/g" > /tmp/stdio.h.$$
cp /tmp/stdio.h.$$ libgnu/stdio.h
if [ `arch` = 'i686' ]; then
# Ubuntu 32 bit version
CC=icc CXX=icpc F77=ifort F1="-fPIC -DPIC -O2 -I/opt/include/mkl/include/ia32 -I/opt/include/mkl/include -I/opt/include/include/ia32 -I/opt/include/include -I/usr/local/include" LDFLAGS="-L/opt/intel/lib/ia32 -L/opt/intel/mkl/lib/ia32" LIBS="-lmetis" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lmkl_intel -lmkl_core -lmkl_intel_thread -liomp5 -lpthread" --with-lapack="-lmkl_lapack95 -lmkl_intel -lmkl_core -lmkl_intel_thread -liomp5 -lpthread"
elif [ `arch` = 'x86_64' ]; then
# Ubuntu 64 bit version
CC=icc CXX=icpc F77=ifort F1="-fPIC -DPIC -O2 -I/opt/include/mkl/include/intel64 -I/opt/include/mkl/include -I/opt/include/include/intel64 -I/opt/include/include -I/usr/local/include" LDFLAGS="-L/opt/intel/lib/intel64 -L/opt/intel/mkl/lib/intel64" LIBS="-lmetis" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread" --with-lapack="-lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread"
fi
else
# GNU Compiler (GNU のコンパイラを使う場合)
if [ `arch` = 'i686' && -d /opt/intel/mkl/lib/ia32 ]; then
# try to use Intel MKL 32bit (GNU のコンパイラ + インテル マス・カーネル・ライブラリー Linux 版)
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/opt/include/mkl/include/ia32 -I/opt/include/mkl/include -I/opt/include/include/ia32 -I/opt/include/include -I/usr/local/include" LDFLAGS="-L/opt/intel/lib/ia32 -L/opt/intel/mkl/lib/ia32" LIBS="-lmetis" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lmkl_gf -lmkl_core -lmkl_intel_thread -liomp5 -lpthread" --with-lapack="-lmkl_lapack95 -lmkl_gf -lmkl_core -lmkl_intel_thread -liomp5 -lpthread"
elif [ `arch` = 'x86_64' && -d /opt/intel/mkl/lib/intel64 ]; then
# try to use Intel MKL 64bit
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/opt/include/mkl/include/intel64 -I/opt/include/mkl/include -I/opt/include/include/intel64 -I/opt/include/include -I/usr/local/include" LDFLAGS="-L/opt/intel/lib/intel64 -L/opt/intel/mkl/lib/intel64" LIBS="-lmetis" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lmkl_gf_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread" --with-lapack="-lmkl_lapack95_lp64 -lmkl_gf_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread"
elif [ -f /usr/lib/atlas-base/libptf77blas.a ]; then
# Ubuntu package LAPACK and ATLAS (GNU のコンパイラ + Ubuntu のパッケージでインストールされた ATLAS と LAPACK)
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/include/atlas -I/usr/local/include" LDFLAGS="-L/usr/lib/atlas-base -L/usr/local/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lptcblas -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl" --with-lapack="-llapack_atlas -llapack -lptcblas -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl"
elif [ -f /usr/local/atlas/lib/libptf77blas.a ]; then
# LAPACK and ATLAS build from source
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/local/include -I/usr/local/atlas/include" LDFLAGS="-L/usr/local/lib -L/usr/local/atlas/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lptcblas -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl" --with-lapack="-ltmglib -llapack -lptcblas -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl"
elif [ -f /usr/lib/ibgoto2.a ]; then
# GotoBLAS
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/local/include" LDFLAGS="-L/usr/local/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lcblas -lgoto2 -lgfortran -lgomp -lpthread -ldl" --with-lapack="-llapack -ltmglib -lcblas -lgoto2 -lgfortran -lgomp -lpthread -ldl"
else
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/include/atlas -I/usr/local/include" LDFLAGS="-L/usr/lib/atlas-base -L/usr/local/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lf77blas -latlas -lgfortran -lgomp -lpthread -ldl" --with-lapack="-llapack -lf77blas -latlas -lgfortran -lgomp -lpthread -ldl"
fi
fi
# memo
# LIBS="-lmetis" CFLAGS="-I/usr/local/include -I/usr/local/atlas/include -mieee-fp -DH5_USE_16_API -fomit-frame-pointer -mfpmath=sse -msse3 -fno-schedule-insns2 -fopenmp -fno-tree-loop-optimize -fno-tree-vectorize -fexceptions -march=native -O3 -fopenmp" CPPFLAGS="-I/usr/local/include -I/usr/local/atlas/include -mieee-fp -DH5_USE_16_API -fomit-frame-pointer -mfpmath=sse -msse3 -fno-schedule-insns2 -fopenmp -fno-tree-loop-optimize -fno-tree-vectorize -fexceptions -march=native -O3 -fopenmp" FFLAGS="-DH5_USE_16_API -fomit-frame-pointer -mfpmath=sse -msse3 -fno-schedule-insns2 -fopenmp -fno-tree-loop-optimize -fno-tree-vectorize -fexceptions -march=native -O3 -fopenmp" ./configure --enable-static --enable-shared --enable-dl --with-blas="-L/usr/local/atlas/lib -lptf77blas /usr/local/atlas/lib/libatlas.a -lgfortran -lpthread -lgomp" --with-lapack="-llapack_LINUX -ltmglib_LINUX -L/usr/local/atlas/lib -lptf77blas /usr/local/atlas/lib/libatlas.a -lgfortran -lpthread -lgomp"
make -j4
make check
sudo make install
Ubuntu の他のバージョンでも同様の手順になります
sudo apt-get -yV update sudo apt-get -yV upgrade sudo reboot
# 前提ソフトウエア cd /tmp; sudo apt-get source octave3.2 cd /tmp; sudo apt-get build-dep octave3.2 # 開発環境等 sudo apt-get -yV install make sudo apt-get -yV install patch sudo apt-get -yV install build-essential sudo apt-get -yV install autoconf sudo apt-get -yV install automake sudo apt-get -yV install autogen sudo apt-get -yV install flex sudo apt-get -yV install bison sudo apt-get -yV install gawk sudo apt-get -yV install libtool sudo apt-get -yV install ccache sudo apt-get -yV install binutils sudo apt-get -yV install openssl sudo apt-get -yV install libgmp3-devel sudo apt-get -yV install libmpfr-dev sudo apt-get -yV install libppl-dev sudo apt-get -yV install libmpc-dev sudo apt-get -yV install glpk sudo apt-get -yV install libfltk1.1-dev sudo apt-get -yV install cpp-4.4 sudo apt-get -yV install gcc-4.4 sudo apt-get -yV install g++-4.4 sudo apt-get -yV install gfortran sudo apt-get -yV install gfortran-4.4 sudo apt-get -yV install libreadline-dev # sudo apt-get -yV install gperf sudo apt-get -yV install libqhull-dev sudo apt-get -yV install libftgl-dev sudo apt-get -yV install libgomp1 # gsl sudo apt-get -yV install gsl-bin sudo apt-get -yV install libgsl0-dev sudo apt-get -yV install libgsl0-dbg sudo apt-get -yV install libgsl0ldbl # fftw3 sudo apt-get -yV install libfftw3-3 sudo apt-get -yV install libfftw3-dev sudo apt-get -yV install libfftw3-doc # graphicsmagick sudo apt-get -yV install graphicsmagick-dbg sudo apt-get -yV install graphicsmagick sudo apt-get -yV install libgraphics-magick-perl sudo apt-get -yV install libgraphicsmagick++1-dev sudo apt-get -yV install libgraphicsmagick++3 sudo apt-get -yV install libgraphicsmagick1-dev sudo apt-get -yV install libgraphicsmagick3 # curl sudo apt-get -yV install curl sudo apt-get -yV install libcurl3-dbg sudo apt-get -yV install libcurl3-gnutls sudo apt-get -yV install libcurl3 sudo apt-get -yV install libcurl4-gnutls-dev sudo apt-get -yV install gnuplot # lapack sudo apt-get -yV install liblapack-dev sudo apt-get -yV install liblapack-doc sudo apt-get -yV install liblapack-pic sudo apt-get -yV install liblapack-test sudo apt-get -yV install liblapack3gf # atlas sudo apt-get -yV install libatlas-base-dev sudo apt-get -yV install libatlas-dev sudo apt-get -yV install libatlas-doc sudo apt-get -yV install libatlas-test sudo apt-get -yV install libatlas3gf-base # qrupdate sudo apt-get -yV install libqrupdate-dev sudo apt-get -yV install libqrupdate1 # arpack sudo apt-get -yV install libarpack2-dbg sudo apt-get -yV install libarpack2-dev sudo apt-get -yV install libarpack2 # SuiteSparse sudo apt-get -yV install libamd2 sudo apt-get -yV install libbtf1 sudo apt-get -yV install libcamd2 sudo apt-get -yV install libccolamd2 sudo apt-get -yV install libcholmod1 sudo apt-get -yV install libcolamd2 sudo apt-get -yV install libcsparse2 sudo apt-get -yV install libcxsparse2 sudo apt-get -yV install libklu1 sudo apt-get -yV install libldl2 sudo apt-get -yV install libsuitesparse-dbg sudo apt-get -yV install libsuitesparse-dev sudo apt-get -yV install libsuitesparse-doc sudo apt-get -yV install libumfpack5 sudo apt-get -yV install libsuitesparse-metis sudo apt-get -yV install libsuitesparse-metis-dev
インストール前に「yum check-update; yum update」を実行しておくとトラブルが減るでしょう. これは更新可能な全パッケージを更新するという操作です.
yum check-update yum update
Octave のビルドとインストールに必要になる次のソフトウエアをインストール済みであること.
参考 Web ページ: http://www.rpmfind.net//linux/RPM/fedora/devel/src/octave-3.2.2-5.fc12.src.html
※ 要するに,「yum install <パッケージ名>」で簡単にインストールできます.
下記の操作を1度だけ行う
cd /usr/lib64/atlas for i in *.so.3; do echo $i ln -s $i `basename $i .3` done
あとで Octave のビルド時に configure を実行しますが,configure でエラーが出る場合,あるいは、octave のテスト時にエラーが出る場合など、 ソースコードからビルドし,インストールすることでエラーが回避できる可能性があります. (それぞれの Web ページを見てください).
※かなり時間がかかりますので、エラーが出たときのみに試すのがいいと考えます。
<それぞれのインストール手順の Web ページへのリンク>
ここで行うことは, Octave ソースコードをダウンロードすること.
ダウンロードが始まる.
あとで役に立つことが多いので、ダウンロードしておく.
cd /tmp sudo rm -rf octave-3.6.1 tar -xvjof octave-3.6.1.tar.gz
結果の確認(実行結果の例をここに示す).
設定例は次の通り
■ Octave バージョン 3.6.1 の場合
/usr/local/lib /usr/local/lib/octave/3.6.1
◆ Ubuntu 12.04 での設定例
configure の実行については,いくつかの場合を説明します.
■ Ubuntu の場合 ■
◆ configure の操作例
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/opt/include/mkl/include/intel64 -I/opt/include/mkl/include -I/opt/include/include/intel64 -I/opt/include/include -I/usr/local/include" LDFLAGS="-L/opt/intel/lib/intel64 -L/opt/intel/mkl/lib/intel64" LIBS="-lmetis" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lmkl_gf_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread" --with-lapack="-lmkl_lapack95_lp64 -lmkl_gf_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread"
ATLAS のインストールの後, コンソールで次の操作を行う.
◆ configure の操作例
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/include/atlas -I/usr/local/include" LDFLAGS="-L/usr/lib/atlas-base -L/usr/local/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl" --with-lapack="-llapack_atlas -llapack -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl"
ATLAS のインストールの後, コンソールで次の操作を行う.
◆ configure の操作例
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/local/include -I/usr/local/atlas/include" LDFLAGS="-L/usr/local/lib -L/usr/local/atlas/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lptcblas -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl" --with-lapack="-ltmglib -llapack -lptcblas -lptf77blas -latlas -lgfortran -lgomp -lpthread -ldl"
GotoBLAS のビルドとインストールの後, コンソールで次の操作を行う.
◆ configure の操作例
F1="-fPIC -DPIC -fomit-frame-pointer -O2 -I/usr/local/include" LDFLAGS="-L/usr/local/lib" LIBS="-lmetis -lgfortran -lgomp -lpthread -ldl" CFLAGS="$F1" CPPFLAGS="$F1" FFLAGS="$F1" ./configure --enable-static --enable-shared --enable-dl --with-blas="-lcblas -lgoto2 -lgfortran -lgomp -lpthread -ldl" --with-lapack="-llapack -ltmglib -lcblas -lgoto2 -lgfortran -lgomp -lpthread -ldl"
■ Fedora の場合 ■
◆ configure の操作例 1:
ATLAS は yum を使ってすでにインストール済みで,それを使いたい場合は,コンソールで次の操作を行う.
cd octave-3.6.1 CC=gcc CXX=g++ F77=gfortran LIBS="-lm" CFLAGS="-O3 -fexceptions" CPPFLAGS="-O3 -fexceptions" FFLAGS="-O3 -fexceptions" ./configure --prefix=/usr/local --enable-static --enable-shared --enable-dl --disable-static --with-blas="-L/usr/lib64/atlas -lptf77blas -latlas -lgfortran -lpthread" --with-lapack="-L/usr/lib64/atlas -llapack" --with-qrupdate-libdir=/usr/local/lib
※ なお,metis をリンクしたい場合には「LIBS="-lmetis -lm"」を付ける.
※ OpenMP も使いたい場合は,CFLAGS と CPPFLAGS に「-fopenmp」を付ける
※ Core2 プロセッサであり,かつ,64 ビット Linux を使っている場合.
※ -mnative は Pentium 系のマシンにおいて「そのマシンの CPU に特化したコードを生成する」という意味.詳しくは「gcc -E -v -march=native -」
つまり,以下の通り
cd octave-3.6.1 CC=gcc CXX=g++ F77=gfortran LIBS="-lm" CFLAGS="-O3 -fexceptions -m64 -march=native -mfpmath=sse -msse4.2" CPPFLAGS="-O3 -fexceptions -m64 -march=native -mfpmath=sse -msse4.2" FFLAGS="-O3 -fexceptions -m64 -march=native -mfpmath=sse -msse4.2" ./configure --prefix=/usr/local --enable-static --enable-shared --enable-dl --disable-static --with-blas="-L/usr/lib64/atlas -lptf77blas -latlas -lgfortran -lpthread" --with-lapack="-L/usr/lib64/atlas -llapack" --with-qrupdate-libdir=/usr/local/lib
◆ configure の操作例 2:
ATLAS を自前でビルドした場合で,それを使いたい場合は,コンソールで次の操作を行う.
ATLAS を自前でビルドした場合には「-L/usr/lib64/atlas」の部分は「-L/usr/local/atlas/lib」のように変える.例えば,次のようになる.
p ※ ATLAS は自前でビルドするよりも,yum atlas-devel でインストールした方が楽だと思います.
GotoBLAS のビルドとインストールの後, コンソールで次の操作を行う.
◆ configure の操作例
cd octave-3.6.1 CC=gcc CXX=g++ F77=gfortran LIBS="-lm" CFLAGS="-O3 -fexceptions" CPPFLAGS="-fexceptions" FFLAGS="-O3 -fexceptions" ./configure --prefix=/usr/local --enable-static --enable-shared --enable-dl --disable-static --with-blas="-lgoto -lgfortran -lpthread" --with-lapack="-llapack_LINUX -ltmglib_LINUX" --with-qrupdate-libdir=/usr/local/lib
※ なお,metis をリンクしたい場合には「LIBS="-lmetis -lm"」を付ける.
※ エラーメッセージが出ていないこと を確認してください
■ Ubuntu の場合 ■
◆ configure の実行結果例
◆ configure の実行結果例
◆ configure の実行結果例
■ Fedora の場合 ■
Fedora での configure の実行結果例
libgnu/stdio.h を次のように変更
libgnu/verify.h の 「#define _GL_HAVE_STATIC_ASSERT 1」の行をコメントアウト
make -j4
■ Ubuntu の場合 ■
◆ make の実行結果例
◆ make の実行結果例
◆ make の実行結果例
◆ make の実行結果例
■ Fedora の場合 ■
Fedora での make の実行結果例
(octave バージョン 3.2.3 の場合)
make check
■ Ubuntu の場合 ■
◆ make check の実行結果例
◆ make check の実行結果例
◆ make check の実行結果例
◆ make check の実行結果例
※ Octave バージョン 3.2.4 の場合, 次のようなエラーが出る場合がある.
scripts/image/imread.m ... octave: magick/semaphore.c:525: LockSemaphoreInfo: Assertion `semaphore_info != (SemaphoreInfo *) ((void *)0)' failed. panic: Aborted -- stopping myself...
これは,GraphicsMagick の新しいバージョンに,Octave バージョン 3.2.4 が対応していないことに起因するエラーである. GraphicsMagick の古いバージョンをインストールすることで解決する場合がある.
■ Fedora の場合 ■
Fedora での make check の実行結果例
Octave バージョン 3.2.3 の場合
sudo make install
□ Ubuntu での実行結果例
http://sourceforge.net/projects/octave
詳しい手順は,この Web ページの上の方に記述しています.
cd /tmp tar -xvzof octave-forge-bundle-200900607.tar.gz
ホームディレクトリに,ファイル「.octaverc」を作成しておく. 下記の「pkg install ...」の実行時に 「UINT_64_C was not declared in this scope」のようなエラーが出ることを防ぐために、下記の設定を行う.
setenv("CFLAGS", "-D__STDC_CONSTANT_MACROS");
setenv("CXXFLAGS", "-D__STDC_CONSTANT_MACROS");
octave を起動し,「pkg install ...」でインストールします.
for i in /tmp/octave-forge-bundle-20090607/main/*.tar.gz; do echo $i; echo "pkg install -global -forge `basename $i .tar.gz | sed 's/\-[0-9\.]*//g'`" | sudo octave; done
「pkg install -global -forge ...」を使って簡単に追加できる.
for i in NaN-2.0.4 actuarial-1.1.0 bim-1.0.1 control-2.1.53 dataframe-0.8.2 econometrics-1.0.8 es-0.0.4 fenv-0.1.0 fits-1.0.1 fl-core-1.0.0 fpl-1.2.0 ga-0.9.8 general-1.2.2 generate_html-0.1.3 gnuplot-1.0.1 gpc-0.1.7 image-1.0.14 io-1.0.14 java-1.2.7 linear-algebra-2.0.0 miscellaneous-1.0.11 msh-1.0.2 nan-2.4.1 nlwing2-1.2.0 nnet-0.1.13 nurbs-1.3.3 ocs-0.1.1 octcdf-1.1.2 octgpr-1.2.0 octproj-1.0.2 ode-1.0.1 odepkg-0.6.12 openmpi_ext-1.0.2 optim-1.0.16 optiminterp-0.3.3 parallel-2.0.5 plot-1.0.8 pt_br-1.0.9 signal-1.0.11 sockets-1.0.7 specfun-1.0.9 statistics-1.0.10 struct-1.0.9 tsa-4.1.0 vrml-1.0.11 fuzzy-logic-toolkit-0.2.3; do echo $i; echo "pkg install -global -forge `echo $i | sed 's/\-[0-9\.]*//g'`" | sudo octave; done
「pkg install -global -forge ...」を使って簡単に更新できる.
for i in /tmp/octave-forge-bundle-20090607/main/*.tar.gz; do echo $i; echo "pkg install -global -forge `basename $i .tar.gz | sed 's/\-[0-9\.]*//g'`" | sudo octave; done for i in /tmp/octave-forge-bundle-20090607/extra/*.tar.gz; do echo $i; echo "pkg install -global -forge `basename $i .tar.gz | sed 's/\-[0-9\.]*//g'`" | sudo octave; done
ためしに、video パッケージの機能を使って,avi 形式のビデオファイルの読み込みと、フレーム100番の表示を行ってみます。 (OpenCV に付属の avi ファイルを使っています)
pkg load video
img = aviread("/usr/local/share/opencv/samples/c/tree.avi", 100);
imshow(img);
※ (参考情報)個別のパッケージのインストール方法
なお,octave の「pkg install」だとエラーメッセージが分かりにくいので, エラーが出るけど原因が分からないという場合, 下記のようなコマンドを実行して,エラーの有無を確認するという方法もあります.
cd main tar -xvzof image-1.0.10.tar.gz cd image-1.0.10 cd src sh autogen.sh CFLAGS="-I/usr/local/include/octave-3.6.1 -I/usr/local/include" LDFLAGS="-L/usr/local/lib/octave-3.6.1 -L/usr/local/lib" LIBS="-lavcodec -lavdevice -lavutil -lavformat -lswscale -lpng12 -lm" ./configure make LIBS="-lavcodec -lavdevice -lavutil -lavformat -lswscale -lpng12 -lm" make install
実測値の概要
【お断り】プログラムのテストを行っていない.他のプロセスを止めるなどしていない(従って,比較ではなく,傾向を見るための参考値だと思ってください).※ 単位は秒で,3桁目を四捨五入.
| yum を使ってインストール | 本ページの手順でビルド (yum でインストールした ATLAS をリンク) | Intel MKL | |||
| (a) | 行列と行列の積 | X = rand(2000,2000); Y = rand(2000,2000); Z = X * Y | 10.3 | 0.48 | 0.41 |
| (b) | LU 分解 (LU decomposition) | X = rand(2000,2000); [L, U, P] = lu(X) | 0.82 | 0.83 | 0.28 |
| (c) | 正方行列の逆行列 | X = rand(2000,2000); [Z, RCOND] = inv(X) | 2.2 | 2.2 | 0.62 |
| (d) | 行列式 (determinant) | X = rand(2000,2000); [D, RCOND] = det(X) | 0.78 | 0.76 | 0.24 |
| (e) | Singular Value Decomposition (SVD), X = U*S*V | X = rand(2000,2000); [U, S, V] = svd(X) | 122 | 100 | to be filled |
| (f) | QR factorization | X = rand(2000,2000); [Q, R, P] = qr(X) | 14.4 | 3.9 | 3.1 |
| (g) | 分散共分散行列 | X = rand(2000,2000), Y = rand(2000,2000); Z = cov(X, Y) | 10.8 | 0.57 | 0.51 |
| (h) | 分散共分散行列の固有値と固有ベクトル(主成分分析) | X = rand(2000,2000); [v, L] = eig( cov(X) ) | 33 | 19.8 | 4.0 |
| (i) | princpmp 関数による主成分分析 | X = rand(2000,2000); [pc, z, w, Tsq] = princomp(X) | 127 | to be filled | (error) |
| (j) | 2次元の畳み込み(コンボリューション) | X = rand(2000,2000); B = rand(21); Z = conv2(X, B, 'full') | 6.6 | 5.7 | 5.4 |
| (k) | 2次元の高速フーリエ変換 (FFT) | X = rand(2000,2000); Z = fft2(X, 2000, 2000) | 0.159 | 0.155 | 0.22 |
| (l) | convex hull | x = rand(1000000,1); y = rand(1000000,1); H = convhull(x, y) | 0.89 | 0.79 | 1.22 |
【実測値の例】Intel Xeon W3520, Octave バージョン 3.2.3
to be filled
(i) princpmp 関数による主成分分析: X = rand(2000,2000); [pc, z, w, Tsq] = princomp(X)
【実測値の例】Intel Xeon W3520, Octave バージョン 3.2.3, Intel MKL
今度は,Octave を Intel Math Kernel Library (Intel MKL) とリンクしてみる.
SVD は make check でエラーが出るので,性能測定から除外(エラーの原因が不明で,とりあえずあきらめる.まず間違いなく MKL の責任ではない)
(e) Singular Value Decomposition (SVD), X = U*S*V: X = rand(2000,2000); [U, S, V] = svd(X)