Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 427 lines (389 sloc) 13.2 KB
#!/bin/bash
# Configure script for R package generation
#
#
#
#Sys.setenv(PKG_CONFIG_PATH=paste(Sys.getenv("PKG_CONFIG_PATH"),paste(.libPaths(),"exageostat/lib/pkgconfig",sep='/',collapse=':'),sep=':'))
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${R_HOME}/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_LIBS_USER/exageostat/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$R_LIBS/exageostat/lib/pkgconfig
#Get the number of CPUs
cpucores=`getconf _NPROCESSORS_ONLN`
#cpucores=1
#VARIABLES
MAKE=${MAKE:-make -j $(cpucores) -l $((cpucores + 1))}
BASEDIR=$(pwd)
TMPDIR=$BASEDIR/_$$
BUILD_DEPENDENCIES='true'
err=0
CUDAVALUE="OFF"
MPIVALUE="OFF"
mkdir -p $TMPDIR
SETUP_DIR=${R_PACKAGE_DIR:-''}
print_usage() {
echo "usage: $0 [--enable-mpi|--disable-mpi] [--prefix /path/to/install]"
}
while [ -n "$1" ]
do
case "$1" in
--enable-cuda)
CUDAVALUE="ON"
shift
;;
--enable-mpi)
MPIVALUE="ON"
shift
;;
--disable-mpi)
MPIVALUE="OFF"
shift
;;
--build-deps)
BUILD_DEPENDENCIES='true'
shift
;;
--no-build-deps)
BUILD_DEPENDENCIES='false'
shift
;;
--prefix)
shift
SETUP_DIR=$1
# Set this paths as rpath during compilation
rpaths="-Wl,-rpath=$SETUP_DIR/lib -L$SETUP_DIR/lib "
echo "LDFLAGS += $rpaths " >> $BASEDIR/src/Makefile
shift
;;
--help|-h)
print_usage
exit 0
;;
*)
print_usage
exit 1
;;
esac
done
if [ -z "$SETUP_DIR" ]; then
# Use RLIBS for setup dir
arr=(`Rscript -e '.libPaths()' | awk '{printf "%s ",$2}'`)
for i in ${!arr[*]};
do
dir=`echo ${arr[$i]}|tr -d \"`
if [ -d "$dir" ] && [ -w "$dir" ]
then
SETUP_DIR="$dir/exageostat"
break
fi
done
fi
mkdir -p $SETUP_DIR
if [ -z "$SETUP_DIR" ]
then
echo "Check your .libPaths() in R. Could not find a writable directory."
exit 1;
fi
PREFIX=$SETUP_DIR
############################## Check OS
echo "Finding the current os type"
echo
osType=$(uname)
case "$osType" in
"Darwin")
{
echo "Running on Mac OSX."
CURRENT_OS="OSX"
LIBEXT="dylib"
export DYLD_LIBRARY_PATH=$PREFIX/lib:$DYLD_LIBRARY_PATH
} ;;
"Linux")
{
echo "Running on LINUX."
CURRENT_OS="LINUX"
LIBEXT="so"
export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
} ;;
*)
{
echo "Unsupported OS, exiting"
exit
} ;;
esac
# check submodules just in case
#git submodule update --init --recursive 2>&1 >/dev/null || true
##### check and build dependencies
# prepare environment
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
if [ -n "$MKLROOT" ] && [ -d "$MKLROOT" ]; then
echo "mkl_dir directory exists!"
echo "Great... continue set-up"
source ${MKLROOT}/bin/mklvars.sh intel64
DEFINE_BLAS_LIBS_CMAKE="-DBLAS_LIBRARIES='-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl'"
#DEFINE_BLAS_LIBS_CMAKE="-DBLAS_LIBRARIES='-L${MKLROOT}/lib\ -Wl,-rpath,${MKLROOT}/lib\ -lmkl_intel_lp64\ -lmkl_sequential\ -lmkl_core\ -lpthread\ -lm\ -ldl'"
XFLAG="-DBLA_VENDOR=Intel"
else
echo "MKL not found, trying to compile and use OpenBLAS"
XFLAG="-DBLA_VENDOR=Open"
USE_OPENBLAS='true'
fi
#set pkgconfig path including possible installation dir
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$SETUP_DIR/lib/pkgconfig
# openblas
if [ "true" == "$USE_OPENBLAS" ]
then
_OPENBLAS='false'
if pkg-config --exists openblas
then
#check for lapacke.h
_LOCATION=`pkg-config --variable=includedir openblas`
if stat "${_LOCATION}/lapacke.h" >/dev/null 2>&1
then
_LOCATION=`pkg-config --variable=libdir openblas`
echo "OpenBLAS FOUND in [$_LOCATION]"
_OPENBLAS='true'
fi
fi
if [ "false" == "${_OPENBLAS}" ]
then
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building OpenBLAS..."
cd $TMPDIR
wget https://github.com/xianyi/OpenBLAS/archive/v0.3.7.tar.gz -O - | tar -zx
cd OpenBLAS-0.3.7
$MAKE -j PREFIX=$PREFIX >/dev/null|| $MAKE PREFIX=$PREFIX || { echo 'OpenBLAS installation failed' ; exit 1; }
$MAKE install PREFIX=$PREFIX
export CPATH=$PREFIX/include:$CPATH
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
OPENBLAS_CFLAGS=`pkg-config --variable=includedir openblas`
OPENBLAS_LIBS=`pkg-config --variable=libdir openblas`
PKG_CPPFLAGS=`pkg-config --variable=includedir openblas`
PKG_LIBS=-l$PREFIX/lib/libopenblas.so
echo "========================="
echo $PKG_LIBS
echo "+++++++++++++++++++++++++="
#DEFINE_BLAS_LIBS_CMAKE="-DBLAS_DIR='${PREFIX}' -DCBLAS_DIR='${PREFIX}' -DLAPACK_DIR='${PREFIX}' -DLAPACKE_DIR='${PREFIX}' -DTMG='${PREFIX}'"
#export OPENBLAS_CFLAGS=-I$PREFIX/include
#export OPENBLAS_LIBS=-L$PREFIX/lib
#export BLAS_OPENBLAS_CFLAGS=-I{$PREFIX/include
export BLAS_OPENBLAS_LIBS=-l$PREFIX/lib/libopenblas.so
#cp $PREFIX/lib/libopenblas.so $BASEDIR/src
#export BLAS_LIBS=-L{$PREFIX}/lib
else
echo "####################"
echo "OpenBLAS NOT FOUND"
echo "Please download it from: https://github.com/xianyi/OpenBLAS/releases"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
fi
# gsl
if pkg-config --exists --atleast-version=2 gsl
then
_LOCATION=`pkg-config --variable=prefix gsl`
echo "gsl FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building GSL..."
cd $TMPDIR
wget https://ftp.gnu.org/gnu/gsl/gsl-2.4.tar.gz -O - | tar -zx
cd gsl-2.4
./configure --prefix=$PREFIX
$MAKE || $MAKE VERBOSE=1 || { echo 'GSL installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "gsl NOT FOUND"
echo "Please download it from: https://ftp.gnu.org/gnu/gsl/gsl-2.4.tar.gz"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
echo "==========================================="
#EXAGEOSTAT_CONFIG=`Rscript -e '.libPaths()' | awk '{printf "%s/exageostat/lib/pkgconfig:",substr($2,2,length($2)-2)}'`
echo ${R_HOME}
echo "==========================================="
echo $R_LIBS_USER
echo "==========================================="
echo $R_LIBS
echo "==========================================="
#Rscript -e '.libPaths()'
echo $PKG_LIBS
echo "==========================================="
echo $PKG_CXXFLAGS
echo "==========================================="
echo $PKG_CONFIG_PATH
echo "==========================================="
echo $PKG_CPPFLAGS
echo "==========================================="
nm $PREFIX/lib/libopenblas.so | grep "LAPACKE_slarfb_work"
echo "==========================================="
# nlopt
if pkg-config --exists --atleast-version=2.4 nlopt
then
_LOCATION=`pkg-config --variable=prefix nlopt`
echo "nlopt FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building NLOPT..."
cd $TMPDIR
wget http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz -O - | tar -zx
cd nlopt-2.4.2
./configure --enable-shared --without-guile --prefix=$PREFIX
$MAKE || $MAKE VERBOSE=1 || { echo 'NLOPT installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "nlopt NOT FOUND"
echo "Please download it from: http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# hwloc
if pkg-config --exists hwloc
then
_LOCATION=`pkg-config --variable=prefix hwloc`
echo "hwloc FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building Hwloc..."
cd $TMPDIR
wget https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.5.tar.gz -O - | tar -zx
cd hwloc-1.11.5
./configure --prefix=$PREFIX
$MAKE || $MAKE VERBOSE=1 || { echo 'HWLOC installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "hwloc NOT FOUND"
echo "Please download it from: https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.5.tar.gz"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# StarPU
if pkg-config --exists --atleast-version=1.2 libstarpu
then
_LOCATION=`pkg-config --variable=prefix libstarpu`
echo "StarPU FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building StarPU..."
cd $TMPDIR
wget http://starpu.gforge.inria.fr/files/starpu-1.2.5/starpu-1.2.5.tar.gz -O - | tar -zx
cd starpu-1.2.5
if [ "$CUDAVALUE" == "ON" ]; then
./configure --enable-cuda --disable-opencl --prefix=$PREFIX --enable-blas-lib=none
else
./configure --disable-cuda --disable-opencl --prefix=$PREFIX --enable-blas-lib=none
fi
$MAKE || $MAKE VERBOSE=1 || { echo 'STARPU installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "StarPU NOT FOUND"
echo "Please download it from: http://starpu.gforge.inria.fr/files/"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
cd $BASEDIR
set -x
# CHAMELEON
if pkg-config --exists chameleon
then
_LOCATION=`pkg-config --variable=prefix chameleon`
echo "CHAMELEON FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building CHAMELEON..."
cd $BASEDIR/src/hicma/chameleon
mkdir -p build && cd build
rm -rf ./CMake*
cmake -DCHAMELEON_USE_MPI=$MPIVALUE -DCHAMELEON_USE_CUDA=$CUDAVALUE -DCHAMELEON_ENABLE_EXAMPLE=OFF -DCHAMELEON_ENABLE_TESTING=OFF -DCHAMELEON_ENABLE_TIMING=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$PREFIX "$DEFINE_BLAS_LIBS_CMAKE" ..
$MAKE || $MAKE VERBOSE=1 || { echo 'CHAMELEON installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "CHAMELEON NOT FOUND"
echo "Please download it from: https://gitlab.inria.fr/solverstack/chameleon.git"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# starsh
if pkg-config --exists --atleast-version=0.1.1 starsh
then
_LOCATION=`pkg-config --variable=prefix starsh`
echo "starsh FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building STARS-H..."
cd $BASEDIR/src/stars-h
mkdir -p build && cd build
rm -rf ./CMake*
cmake -DCMAKE_C_FLAGS=-fPIC -DOPENMP=OFF -DSTARPU=OFF -DEXAMPLES=OFF -DTESTING=OFF -DMPI=$MPIVALUE -DCMAKE_INSTALL_PREFIX=$PREFIX "$XFLAG" "$DEFINE_BLAS_LIBS_CMAKE" ..
$MAKE || $MAKE VERBOSE=1 || { echo 'STARS-H installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "starsh NOT FOUND"
echo "Please download it from: https://github.com/ecrc/stars-h"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# hicma
if pkg-config --exists hicma
then
_LOCATION=`pkg-config --variable=prefix hicma`
echo "hicma FOUND in [$_LOCATION]"
else
if [ "$BUILD_DEPENDENCIES" == "true" ]
then
echo "Building HiCMA..."
cd $BASEDIR/src/hicma/
mkdir -p build && cd build
rm -rf ./CMake*
cmake -DHICMA_USE_MPI=$MPIVALUE -DBUILD_SHARED_LIBS=ON -DHICMA_ENABLE_TESTING=OFF -DHICMA_ENABLE_TIMING=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX "$XFLAG" "$DEFINE_BLAS_LIBS_CMAKE" ..
$MAKE || $MAKE VERBOSE=1 || { echo 'HICMA installation failed' ; exit 1; }
$MAKE install
else
echo "####################"
echo "hicma NOT FOUND"
echo "Please download it from: https://github.com/ecrc/hicma"
echo "After installing it, set the proper PKG_CONFIG_PATH variable"
echo ""
err=1
fi
fi
# use rpaths in makefile
# TODO use a R defined value por PREFIX and have this directly in the Makefile
#Dummy makefile in src to trigger real one from cmake.
cd $BASEDIR/
rm -rf ./CMakeFiles ./CMakeCache.txt
cmake -DCMAKE_BUILD_TYPE="Release" -DCMAKE_C_FLAGS_RELEASE="-O3 -Ofast" -DBUILD_SHARED_LIBS=ON -DEXAGEOSTAT_EXAMPLES=OFF "$XFLAG" "$DEFINE_BLAS_LIBS_CMAKE" -DEXAGEOSTAT_USE_MPI=$MPIVALUE -DEXAGEOSTAT_USE_HICMA=ON ./src
echo "======================================"
echo "$(ls $PREFIX/lib)"
echo "======================================"
cat > src/Makefile << EOF
.PHONY: all clean
all:
(cd .. && make VERBOSE=1 && cp ./lib*.${LIBEXT} ./src/exageostat.so)
EOF
exit $err
You can’t perform that action at this time.