Last active
November 22, 2020 02:57
-
-
Save dangom/7c9664bb2bf2c3a1e99cd4f3cd037168 to your computer and use it in GitHub Desktop.
Install Berkeley Advanced Reconstruction Toolbox without admin rights on a CentOS machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Time-stamp: <2017-07-19 15:06:39 dangom> | |
# Script for installing BART and dependencies from source on a CentOS machine without admin rights. | |
# Steps: | |
# 1. Build OpenBLAS from source to enable support for LAPACKE C API. | |
# 2. Build FFTW3 from source to enable float32 support (fftw defaults to double precision. BART doesn't) | |
# 3. Link against Matlab2016, because something changed in Matlab2017 and the BART build breaks. | |
# 4. Download Cmake >= 3 since cluster ships with old cmake 2.8 | |
# Prerequisites: - gcc | |
# - wget | |
# Piggybackable libs already installed in our cluster, so we don't build from source. | |
# - libpng-devel | |
# On error, exit. | |
set -e | |
module unload rsi | |
# Set a target installation directory. | |
target_dir="$HOME/bin/bart" | |
# Define the versions we want (where we expect things to work) | |
fftw3_version="3.3.6-pl2" | |
openblas_version="0.2.19" | |
bart_version="0.4.01" | |
cmake_version="3.8.2" | |
matlab_version="R2016a" | |
fftw3_name="fftw-${fftw3_version}" | |
openblas_name="v${openblas_version}" | |
bart_name="v${bart_version}" | |
cmake_name="cmake-${cmake_version}-Linux-x86_64" | |
matlab_root="/opt/matlab/${matlab_version}" | |
matlab_glnxa="${matlab_root}/bin/glnxa64" | |
matlab_config="-DMATLAB_ENG_LIBRARY=${matlab_glnxa}/libeng.so -DMATLAB_INCLUDE_DIR=${matlab_root}/extern/include -DMATLAB_MAT_LIBRARY=${matlab_glnxa}/libmat.so -DMATLAB_MEX_LIBRARY=${matlab_glnxa}/libmex.so -DMATLAB_MX_LIBRARY=${matlab_glnxa}/libmx.so -DMATLAB_ROOT=${matlab_root}" | |
# Always be kind. | |
# Always be kind. | |
currdir=$(pwd) | |
builddir=$(mktemp -d) | |
echo "" | |
echo "" | |
echo "Building will take place under $builddir" | |
echo "" | |
echo "" | |
cd $builddir | |
# Build OpenBLAS | |
wget -O openblas_${openblas_name}.tar.gz https://github.com/xianyi/OpenBLAS/archive/${openblas_name}.tar.gz | |
tar xvzf openblas_${openblas_name}.tar.gz && cd OpenBLAS-${openblas_version} | |
make all | |
make netlib | |
make PREFIX=${target_dir}/deps/openblas install | |
cd - | |
# Build FFTW3 | |
wget -O fftw_${fftw3_name}.tar.gz http://fftw.org/${fftw3_name}.tar.gz | |
tar xvzf fftw_${fftw3_name}.tar.gz && cd ${fftw3_name} | |
CFLAGS="-fPIC" CPPFLAGS="-fPIC" ./configure --prefix=$target_dir/deps/fftw --enable-float --enable-threads # Note the tricky flag: --enable-float | |
make && make install | |
cd - | |
# Download cmake. | |
wget -O cmake_${cmake_version}.tar.gz https://cmake.org/files/v3.8/${cmake_name}.tar.gz | |
tar xvzf cmake_${cmake_version}.tar.gz | |
# Finally, build BART and test it. | |
wget -O bart_${bart_name}.tar.gz https://github.com/mrirecon/bart/archive/${bart_name}.tar.gz | |
tar xvzf bart_${bart_name}.tar.gz && cd bart-${bart_version} | |
mkdir build && cd build | |
# Compile and link BART against our downloaded dependencies. | |
# Also make sure it'll use the fftw includes that we downloaded, not the system ones, if available. | |
CFLAGS="-I${target_dir}/deps/fftw/include -fPIC" $builddir/${cmake_name}/bin/cmake -DCMAKE_INSTALL_PREFIX:PATH=${target_dir} -DLINALG_VENDOR=OpenBLAS -DOpenBLAS_DIR=${target_dir}/deps/openblas ${matlab_config} -DFFTWF_LIB=${target_dir}/deps/fftw/lib/libfftw3f.a -DFFTWF_THREADS_LIB=${target_dir}/deps/fftw/lib/libfftw3f_threads.a .. | |
sed --in-place 's/bin\/glnxa64 /bin\/glnxa64 -L\/opt\/matlab\/R2016a\/sys\/os\/glnxa64 /' CMakeFiles/mat2cfl.dir/link.txt | |
sed --in-place 's/glnxa64:/glnxa64:\/opt\/matlab\/R2016a\/sys\/os\/glnxa64:/' CMakeFiles/mat2cfl.dir/link.txt | |
sed --in-place 's/glnxa64:/glnxa64:\/opt\/matlab\/R2016a\/sys\/os\/glnxa64:/' cmake_install.cmake | |
make && make test | |
if [ $? -eq 0 ]; then # Only install if make test returns success. | |
make install | |
cp mat2cfl ${target_dir}/bin/ | |
cp -r ../matlab ../startup.m ${target_dir}/bin/ | |
# Run benchmarks. | |
${target_dir}/bin/bench | |
echo "BART successfully installed under ${target_dir}" | |
echo "You may add ${target_dir}/bin to your PATH to have BART always available for you!!" | |
echo "" | |
else | |
echo "BART installation failed. Sorry for that. Fix the installation script and try again! Good luck!" | |
fi | |
cd ${currdir} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment