UO Quantum Control Cluster: Configuring and Building Octave



Introduction

Octave is a very nice piece of software, but unfortunately it can be a real pain to compile from source, especially if you want to enable a few features that you can't otherwise get with prebuilt RPMs and such. This is what worked for me to build octave with atlas/lapack to speed up linear algebra, fftw to speed up Fourier transforms, and using the Intel compilers (Fortran, C, C++), which generally outperform the corresponding GNU compilers.

This is what worked under CentOS 5.2, though the approaches here should work fairly generally. Getting the right compiler flags in each case took some tinkering, which is why I'm posting these notes here. You can also see how Octave is configured (and thus what is available) on the QC cluster. Many more capabilities could be built in, but these were the ones I thought were most useful.

Is it worth all this effort over plain old Octave? Well, a really dumb benchmark is to run the following in Octave:

A=rand(5000,5000);
tic,b=A*A;toc

On the head node of the QC cluster (specifications), I got the following results:

So the answer is, clearly yes! ATLAS especially makes the big difference in the open-source case, and Intel MKL in the more expensive case.


Install FFTW:

In /usr/local/src:

wget http://www.fftw.org/fftw-3.2.tar.gz
tar xvzf fftw-3.2.tar.gz
cd fftw-3.2
./configure --with-pic
make
make install

Compile LAPACK:
cd /usr/local/src
wget http://www.netlib.org/lapack/lapack.tgz
tar xvzf lapack.tgz
cd lapack-3.2
cp make.inc.example make.inc
vi make.inc

Now change the compiler to ifort, in particular change the following lines in make.inc to read:

FORTRAN  = ifort -warn declarations -fpic
OPTS     = -O3
DRVOPTS  = $(OPTS)
NOOPT    =
LOADER   = ifort
LOADOPTS =

Now continue with building...

cd BLAS/SRC
make
cd ../..
make

Compile ATLAS:

The loop below assumes you're doing this all in bash.

cd /usr/local/src
wget http://superb-east.dl.sourceforge.net/sourceforge/math-atlas/atlas3.8.2.tar.bz2
tar xvjf atlas3.8.2.tar.bz2
cd ATLAS
mkdir intel-build-dir
cd !$
/usr/local/src/ATLAS/configure --with-netlib-lapack=/usr/local/src/lapack-3.2/lapack_LINUX-INTEL.a -C ic icc -F ic '-O3 -fpic' -C if ifort -F if '-O3 -fpic' -Fa alg -fpic
make
make check
cd lib
make shared
make ptshared
for i in /usr/local/src/ATLAS/intel-build-dir/lib/*.so; do echo $i; ln -sf $i /usr/local/lib/.; done

Now check /etc/ld.so.conf to make sure /usr/local/bin is in there somewhere. If not, then you can do the following (run ldconfig either way).

echo /usr/local/lib >> /etc/ld.so.conf
ldconfig

Compile Octave:

Not all of Octave's tests are successful, but close enough (it was about the same with plain Octave and gcc).

cd /usr/local/src
wget ftp://ftp.octave.org/pub/octave/octave-3.0.3.tar.bz2
tar xvjf octave-3.0.3.tar.bz2
cd octave-3.0.3
export CC=icc
export CPP='icc -E'
export CXX=icpc
export CXXPP='icpc -E'
export F77=ifort
export FFLAGS='-fpic -O3'
export CFLAGS='-fpic -I/usr/local/src/ATLAS/intel-build-dir/include -L/usr/local/src/ATLAS/intel-build-dir/lib'
export CXXFLAGS='-fpic -I/usr/local/src/ATLAS/intel-build-dir/include -L/usr/local/src/ATLAS/intel-build-dir/lib'

./configure --enable-shared --enable-dl --disable-static --with-fftw --with-fastblas=/usr/local/src/ATLAS/intel-build-dir/lib/libatlas.so --with-lapack=/usr/local/src/ATLAS/intel-build-dir/lib/liblapack.so
make
make check
make install

Install Octave-Forge:

First, install a few prerequisites from RPMs:

http://stokkeland.name/mirror/centos/5.1/updates/x86_64/RPMS/ghostscript-devel-8.15.2-9.3.el5.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/lcms-devel-1.15-1.2.2.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/libwmf-devel-0.2.8.4-10.1.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/libwmf-0.2.8.4-10.1.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/ImageMagick-6.2.8.0-4.el5_1.1.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/ImageMagick-c++-6.2.8.0-4.el5_1.1.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/ImageMagick-c++-devel-6.2.8.0-4.el5_1.1.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/ImageMagick-devel-6.2.8.0-4.el5_1.1.x86_64.rpm
http://ftp.riken.jp/Linux/centos/5.2/os/x86_64/CentOS/zenity-2.16.0-2.el5.x86_64.rpm

Now the GNU Scientific Library (clear the environment variables set above, this failed when I compiled it with Intel compilers; you want the GNU compilers).

cd /usr/local/src
wget ftp://ftp.gnu.org/gnu/gsl/gsl-1.12.tar.gz
tar xvzf gsl-1.12.tar.gz
cd gsl-1.12
./configure
make
make check
make install

Now GiNaC, for symbolic capabilities (not all tests passed when checking GiNaC)...

cd /usr/local/src
wget http://www.ginac.de/CLN/cln-1.2.2.tar.bz2
tar xvjf cln-1.2.2.tar.bz2
cd cln-1.2.2
./configure
make
make check
make install
cd /usr/local/src
wget http://www.ginac.de/ginac-1.4.4.tar.bz2
tar xvjf ginac-1.4.4.tar.bz2
cd ginac-1.4.4
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure
make
make check
make install

Finally, get Octave-Forge...

wget http://internap.dl.sourceforge.net/sourceforge/octave/octave-forge-bundle-20080831.tar.gz
tar xvzf octave-forge-bundle-20080831.tar.gz
cd octave-forge-bundle-20080831/main
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Now start up Octave (type 'octave'), and install some packages in the main section. These installed without complaining, which doesn't guarantee they're fully functional.

pkg install audio-1.1.2.tar.gz
pkg install benchmark-1.0.0.tar.gz
pkg install combinatorics-1.0.7.tar.gz
pkg install miscellaneous-1.0.7.tar.gz
pkg install optim-1.0.4.tar.gz
pkg install data-smoothing-1.1.1.tar.gz
pkg install signal-1.0.8.tar.gz
pkg install communications-1.0.8.tar.gz
pkg install ga-0.9.4.tar.gz
pkg install general-1.0.7.tar.gz
pkg install gsl-1.0.7.tar.gz
pkg install ident-1.0.6.tar.gz
pkg install image-1.0.8.tar.gz
pkg install io-1.0.7.tar.gz
pkg install linear-algebra-1.0.6.tar.gz
pkg install missing-functions-1.0.1.tar.gz
pkg install odebvp-1.0.5.tar.gz
pkg install odepkg-0.6.4.tar.gz
pkg install optim-1.0.4.tar.gz
pkg install optiminterp-0.3.1.tar.gz
pkg install parallel-1.0.7.tar.gz
pkg install physicalconstants-0.1.6.tar.gz
pkg install plot-1.0.6.tar.gz
pkg install signal-1.0.8.tar.gz
pkg install sockets-1.0.5.tar.gz
pkg install specfun-1.0.7.tar.gz
pkg install special-matrix-1.0.6.tar.gz
pkg install splines-1.0.6.tar.gz
pkg install statistics-1.0.7.tar.gz
pkg install strings-1.0.6.tar.gz
pkg install struct-1.0.6.tar.gz
pkg install time-1.0.8.tar.gz
pkg install zenity-0.5.6.tar.gz
pkg install symbolic-1.0.7.tar.gz

Update: Install newer version of Octave with Intel MKL:

I didn't have as good luck with Octave 3.4.2. This compilation was for MKL v. 10.0.010, which didn't include interfaces for FFTW, so the libraries compiled above are used. GraphicsMagick had to be installed. There also seemed to be problems with the newer version of gcc (4.6.0) and other libraries installed, so these were temporarily disabled with the following:

cd /usr/local/bin
mv gcc gcc.O
mv c++ c++.O
mv cpp cpp.O
mv g++ g++.O
mv /usr/local/atlas/lib/libf77blas.a /usr/local/atlas/lib/libf77blas.a.O
mv /usr/local/lib/gcc /usr/local/lib/gcc.O
mv /usr/local/include/c++ /usr/local/include/c++.O

Now for octave. Note the installation is into /usr/local/octave-3.2.4, so the path must also be adjusted to use this.

cd /usr/local/src
wget ftp://ftp.octave.org/pub/octave/octave-3.2.4.tar.bz2
tar xvjf octave-3.2.4.tar.bz2
cd octave-3.2.4
export CC=icc
export CPP='icc -E'
export CXX=icpc
export CXXPP='icpc -E'
export F77=ifort
export FFLAGS='-fpic -O3'
export CFLAGS='-fpic -O3 -DMKL_LP64 -DM_PI=3.1415926535897932384'
export CXXFLAGS='-fpic -O3'
export CPPFLAGS='-I/opt/intel/mkl/10.0.010/include -I/opt/intel/mkl/10.0.010/include/fftw'
export LDFLAGS='-L/opt/intel/mkl/10.0.010/lib/em64t/lib -L/opt/intel/mkl/10.0.010/lib/em64t/'
./configure --prefix=/usr/local/octave-3.2.4 --with-blas="-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -openmp -lpthread" --with-lapack="-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -openmp -lpthread"
make
make check
make install

Then octave-forge; the first command below and 'make uninstall' in the old octave source get the old installation out of the way.:

mv /usr/local/share/octave /usr/local/share/octave.O
http://downloads.sourceforge.net/octave/octave-forge-bundle-20090607.tar.gz
tar xvzf octave-forge-bundle-20090607.tar.gz
cd octave-forge-bundle-20090607
/usr/local/octave-3.2.4/bin/octave

Then from within octave:

pkg install main/audio-1.1.4.tar.gz
pkg install main/miscellaneous-1.0.9.tar.gz
pkg install main/optim-1.0.6.tar.gz
pkg install main/combinatorics-1.0.9.tar.gz
pkg install main/data-smoothing-1.2.0.tar.gz
pkg install main/general-1.1.3.tar.gz 
pkg install main/gsl-1.0.8.tar.gz 
pkg install main/image-1.0.10.tar.gz 
pkg install main/informationtheory-0.1.8.tar.gz
pkg install main/io-1.0.9.tar.gz 
pkg install main/linear-algebra-1.0.8.tar.gz 
pkg install main/missing-functions-1.0.2.tar.gz
pkg install main/odepkg-0.6.7.tar.gz
pkg install main/physicalconstants-0.1.7.tar.gz
pkg install main/plot-1.0.7.tar.gz
pkg install main/specfun-1.0.8.tar.gz
pkg install main/signal-1.0.10.tar.gz
pkg install main/sockets-1.0.5.tar.gz
pkg install main/splines-1.0.7.tar.gz
pkg install main/statistics-1.0.9.tar.gz
pkg install main/strings-1.0.7.tar.gz
pkg install main/time-1.0.9.tar.gz
pkg install main/zenity-0.5.7.tar.gz
pkg install main/symbolic-1.0.9.tar.gz