How to install Chaste on Ubuntu in preparation for using the MATLAB interface to cell-based Chaste

This guide is only for set up. The files for operating the MATLAB interface for cell-based Chaste have not yet been released.

This guide is the result of the project undertaken by Tom Dunton at the MathWorks. It is known to work with Chaste (revision 15715) and MATLAB R2012a - stray from these versions at your own risk. These instructions have been followed successfully on 64bit versions of Ubuntu 11.10 and 12.04. To avoid conflicting with any existing versions of Chaste, it is advisable to install Ubuntu as a virtual machine on your current system - at least that is what I did while working on the Windows computers at the MathWorks.

MATLAB is distributed with its own versions of BLAS, LAPACK, Boost, CVODE, HDF5, Xerces (almost all of the libraries that Chaste uses!). To circumvent the issues this raises, we have to rebuild some of Chaste's dependencies, so that they use MATLAB's versions of some libraries.

Throughout this guide, you should be able to copy the entire text within each command box and past it into a terminal window to complete the installation.



Install the Chaste dependencies with the following commands. These are taken from the installation instructions for the chaste-dependencies.deb package.

sudo bash -c 'echo "deb /" >> /etc/apt/sources.list.d/chaste.list'
sudo apt-key adv --recv-keys --keyserver 422C4D99
sudo apt-get update
sudo apt-get install --install-recommends chaste-dependencies
sudo apt-get install `dpkg -s chaste-dependencies | egrep "^Suggests" | \
cut -d "," -f 1-111 --output-delimiter " " | cut -d ":" -f 2`


You must then install MATLAB (version R2012a) before proceeding.

Environmental variables

In order for Chaste's hostconfig system to work successfully, the following environmental variables need to be set in your $HOME/.profile file. These environment variables are read by the Chaste host configuration script attached to this guide ( The examples given below should be correct if you installed Chaste's dependencies using the instructions above and used the default installation options for MATLAB. If you used different options, you will need to change these locations to match your configuration, both in these instructions and within

Directory where you will install Chaste and any re-compiled dependencies (default is $HOME/Chaste).
Root directory of your MATLAB installation (default is /usr/local/MATLAB/R2012a).
Download location of the files attached to this guide (default is $HOME/Downloads ).
echo "export CHASTE=$HOME/Chaste" >> $HOME/.profile
echo "export MATLABROOT=/usr/local/MATLAB/R2012a" >> $HOME/.profile
echo "export DOWNLOAD_DIR=$HOME/Downloads" >> $HOME/.profile

Before performing the steps outlined below, you need to download all of the attached files to $DOWNLOAD_DIR - click on each attachment, then at the bottom of the page there is a link to download in original format. You will also need to log out and back in again, so that your modified .profile file is loaded.


The BLAS and LAPACK libraries used by MATLAB do not use int, but instead use ptrdiff_t, so we have to recompile PETSc after applying the attached petsc.patch file. We also have to stop PETSc from catching the signal SIGSEGV, since MATLAB uses this for internal communication. To compile PETSc with the necessary changes, execute these commands in a terminal window.

mkdir -p $CHASTE
tar xvzf petsc-3.1-p4.tar.gz
rm -f petsc-3.1-p4.tar.gz
mv petsc-3.1-p4 petsc
cd petsc
patch -p0 <$DOWNLOAD_DIR/petsc.patch
export PETSC_DIR=$(pwd)
export PETSC_ARCH=openmpi-debug 
./config/ --LDFLAGS="-Wl,-rpath,$MATLABROOT/bin/glnxa64,-rpath,$MATLABROOT/sys/os/glnxa64" \
--with-blas-lib=$MATLABROOT/bin/glnxa64/ --with-lapack-lib=$MATLABROOT/bin/glnxa64/ \
--download-openmpi=1 --download-hypre=1 --with-x=0 --with-clanguage=cxx --with-shared=1 --CXXFLAGS="-DPETSC_MISSING_SIGSEGV"
make all

For any PETSc test to pass, you will need to force it to load the newer versions of the gfortran and stdc++ libraries, which are shipped with Ubuntu, eg. for running the post-install tests of PETSc, you would issue the following command instead of that issued by the builder.

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/ make test


MATLAB ships with Boost 1.44, but this version is known to have some bugs with the serialization (see here for details). We will therefore need to install a patched Boost, keeping to the same version as that used by MATLAB to avoid conflicts.

mkdir -p $CHASTE
tar xvzf boost_1_44_0.tar.gz
rm -f boost_1_44_0.tar.gz
mv boost_1_44_0 boost
cd boost
patch -p0 <$DOWNLOAD_DIR/boost.patch
./ --prefix=. --with-libraries=serialization,system,filesystem
./bjam install


We also need to install the correct version of HDF5 for MATLAB (v1.8.6).

tar xvzf hdf5-1.8.6.tar.gz
rm -f hdf5-1.8.6.tar.gz
cd hdf5-1.8.6
export CC=$CHASTE/petsc/openmpi-debug/bin/mpicc
CFLAGS=-O1 ./configure --enable-parallel --prefix=$CHASTE/hdf5 --enable-shared
cd test
make check
cd ../testpar
make check
cd ..
make install
cd ..
rm -rf hdf5-1.8.6
unset CC


Firstly we need to get the Chaste source from the SVN repository.

svn --username anonymous --revision 15715 checkout src

When prompted for your password enter your email address.

cd $CHASTE/src
cp $DOWNLOAD_DIR/ python/hostconfig/

We should now be able to build Chaste. We must, however, ensure that we preload the gfrotran and stdc++ libraries as described above, otherwise the incorrect versions included in the MATLAB directory will be used. We also need to preload the HDF5 library, to avoid using the version distributed with MATLAB.

cd $CHASTE/src
LD_PRELOAD=$CHASTE/hdf5/lib/ \
scons cl=1 build=GccOpt

When you have confirmed that all the tests have passed, you must then install the Chaste libraries and headers to a single location.

cd $CHASTE/src
LD_PRELOAD=$CHASTE/hdf5/lib/ \
scons co=1 cl=1 build=GccOpt install_prefix=$CHASTE install


Your system is now ready to run the MATLAB interface for cell-based Chaste.

Last modified 8 years ago Last modified on Jun 22, 2012, 9:21:25 PM

Attachments (3)

Download all attachments as: .zip