Skip to content

Commit

Permalink
#633 modified install to use the libsuitesparse-dev apt package
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Oct 22, 2019
1 parent 606603f commit 7080ae8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 73 deletions.
37 changes: 20 additions & 17 deletions CMakeLists.txt
Expand Up @@ -23,25 +23,28 @@ TARGET_LINK_LIBRARIES(klu PRIVATE ${RT})

## KLU ------
## Add the includes
set(KLU_INCLUDE_DIR "SuiteSparse/KLU/Include")
set(AMD_INCLUDE_DIR "SuiteSparse/AMD/Include")
set(COLAMD_INCLUDE_DIR "SuiteSparse/COLAMD/Include")
set(BTF_INCLUDE_DIR "SuiteSparse/BTF/Include")
set(SUITESPARSECONFIG_INCLUDE_DIR "SuiteSparse/SuiteSparse_config")
TARGET_INCLUDE_DIRECTORIES(klu PRIVATE
${AMD_INCLUDE_DIR}
${COLAMD_INCLUDE_DIR}
${BTF_INCLUDE_DIR}
${SUITESPARSECONFIG_INCLUDE_DIR}
${KLU_INCLUDE_DIR}
)
# set(KLU_INCLUDE_DIR "SuiteSparse/KLU/Include")
# set(AMD_INCLUDE_DIR "SuiteSparse/AMD/Include")
# set(COLAMD_INCLUDE_DIR "SuiteSparse/COLAMD/Include")
# set(BTF_INCLUDE_DIR "SuiteSparse/BTF/Include")
# set(SUITESPARSECONFIG_INCLUDE_DIR "SuiteSparse/SuiteSparse_config")
# TARGET_INCLUDE_DIRECTORIES(klu PRIVATE
# ${AMD_INCLUDE_DIR}
# ${COLAMD_INCLUDE_DIR}
# ${BTF_INCLUDE_DIR}
# ${SUITESPARSECONFIG_INCLUDE_DIR}
# ${KLU_INCLUDE_DIR}
# )

# set(SUITESPARSE_INCLUDE_DIR "/usr/include/suitesparse")
INCLUDE_DIRECTORIES(${SUITESPARSE_INCLUDE_DIR})

## Link Libraries
find_library(KLU klu PATHS "SuiteSparse/KLU/Lib" NO_DEFAULT_PATH)
find_library(AMD amd PATHS "SuiteSparse/AMD/Lib" NO_DEFAULT_PATH)
find_library(COLAMD colamd PATHS "SuiteSparse/COLAMD/Lib" NO_DEFAULT_PATH)
find_library(BTF btf PATHS "SuiteSparse/BTF/Lib" NO_DEFAULT_PATH)
find_library(SUITESPARSE_CONFIG suitesparseconfig PATHS "SuiteSparse/SuiteSparse_config" NO_DEFAULT_PATH)
find_library(KLU klu)
find_library(AMD amd)
find_library(COLAMD colamd)
find_library(BTF btf)
find_library(SUITESPARSE_CONFIG suitesparseconfig)
TARGET_LINK_LIBRARIES(klu PRIVATE
${KLU}
${AMD}
Expand Down
34 changes: 7 additions & 27 deletions INSTALL-LINUX.md
Expand Up @@ -158,33 +158,13 @@ To install KLU, from within the main PyBaMM directory type
Note that this script has only been tested on Ubuntu 18.04.3 LTS. If this script does not work for you, you can try following the step-by-step instructions below:

#### Download and Build SuiteSparse (KLU)
The sparse linear solver, KLU, is contained within SuiteSparse. For more information on the installation process please refer to the README.txt contained in the SuiteSparse download.

In PyBaMM home directory, i.e.
```
cd PyBaMM
```
download SuiteSparse using:
```bash
wget http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-5.4.0.tar.gz -O SuiteSparse-5.4.0.tar.gz
```
Unpack the compressed SuiteSparse files using:
The sparse linear solver, KLU, is contained within SuiteSparse. Suitesparse is available on the apt store on Debian based systems (e.g. Ubuntu). Therefore, it can be installed by simply typing
```bash
tar -xvf SuiteSparse-5.4.0.tar.gz
```
and remove the .tar.gz file to keep your directory clean using:
```bash
rm SuiteSparse-5.4.0.tar.gz
```
Now build SuiteSparse using:
```bash
cd SuiteSparse
make
cd ..
sudo apt install suitesparse-dev
```
and set the path of the SuiteSparse directory for reference later:
We will need to know the location of the include directories for suitesparse. In ubuntu, this can be set with the following
```bash
SUITESPARSE_DIR=`pwd`/SuiteSparse
SUITESPARSE_INCLUDE_DIR="/usr/include/suitesparse"
```

#### Download and build Sundials 4.1.0
Expand Down Expand Up @@ -219,7 +199,7 @@ cmake -DBLAS_ENABLE=ON\
-DEXAMPLES_ENABLE:BOOL=OFF\
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ../sundials-4.1.0/\
-DKLU_ENABLE=ON\
-DSUITESPARSE_DIR=$SUITESPARSE_DIR\
-DSUITESPARSE_INCLUDE_DIR=$SUITESPARSE_INCLUDE_DIR\
../sundials-4.1.0
make install
```
Expand All @@ -246,9 +226,9 @@ pip install pybind11
#### Build the KLU wrapper
We now have all the tools to build a shared library to interface to the KLU solver. Within your PyBaMM home directory build the required Makefile using
```
cmake .
cmake -DSUITESPARSE_INCLUDE_DIR=$SUITESPARSE_INCLUDE_DIR.
```
This will automatically find the latest version of python installed on your machine. If you are using an older version (e.g python3.6) within your virtual environment, then you instead can use `cmake -DPYBIND11_PYTHON_VERSION=3.6 .`.
This will automatically find the headers for the latest version of python installed on your machine. If you are using an older version (e.g python3.6) within your virtual environment, then you instead can use `cmake -DPYBIND11_PYTHON_VERSION=3.6 .`.

You can now simply run make to build the library (you can just run this command if you make some changes to klu.cpp)
```
Expand Down
14 changes: 1 addition & 13 deletions scripts/install_sundials_4.1.0.sh
@@ -1,18 +1,6 @@
#!/bin/bash
CURRENT_DIR=`pwd`

# build SparseSuite to use KLU sparse linear solver
SUITESPARSE_URL=http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-5.4.0.tar.gz
SUITESPARSE_NAME=SuiteSparse-5.4.0.tar.gz
wget $SUITESPARSE_URL -O $SUITESPARSE_NAME
tar -xvf $SUITESPARSE_NAME
SUITESPARSE_DIR=$CURRENT_DIR/SuiteSparse
cd $SUITESPARSE_DIR
make clean
make
cd $CURRENT_DIR
rm $SUITESPARSE_NAME

# install sundials-4.1.0
SUNDIALS_URL=https://computing.llnl.gov/projects/sundials/download/sundials-4.1.0.tar.gz
SUNDIALS_NAME=sundials-4.1.0.tar.gz
Expand Down Expand Up @@ -44,7 +32,7 @@ cmake -DBLAS_ENABLE=ON\
-DEXAMPLES_ENABLE:BOOL=OFF\
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ../sundials-4.1.0/\
-DKLU_ENABLE=ON\
-DSUITESPARSE_DIR=$SUITESPARSE_DIR\
-DSUITESPARSE_INCLUDE_DIR="/usr/include/suitesparse"\
../sundials-4.1.0


Expand Down
40 changes: 25 additions & 15 deletions scripts/replace-cmake/CMakeLists.txt
Expand Up @@ -995,27 +995,37 @@ IF(KLU_ENABLE)

# setting the paths for KLU directly without testing - scott marquis
# INCLUDE(SundialsKLU)
set(KLU_LIBRARY ${SUITESPARSE_DIR}/KLU/Lib/libklu.a)
set(AMD_LIBRARY ${SUITESPARSE_DIR}/AMD/Lib/libamd.a)
set(COLAMD_LIBRARY ${SUITESPARSE_DIR}/COLAMD/Lib/libcolamd.a)
set(BTF_LIBRARY ${SUITESPARSE_DIR}/BTF/Lib/libbtf.a)
set(SUITESPARSECONFIG_LIBRARY ${SUITESPARSE_DIR}/SuiteSparse_config/libsuitesparseconfig.a)
# set(KLU_LIBRARY ${SUITESPARSE_DIR}/KLU/Lib/libklu.a)
# set(AMD_LIBRARY ${SUITESPARSE_DIR}/AMD/Lib/libamd.a)
# set(COLAMD_LIBRARY ${SUITESPARSE_DIR}/COLAMD/Lib/libcolamd.a)
# set(BTF_LIBRARY ${SUITESPARSE_DIR}/BTF/Lib/libbtf.a)
# set(SUITESPARSECONFIG_LIBRARY ${SUITESPARSE_DIR}/SuiteSparse_config/libsuitesparseconfig.a)
# set(KLU_LIBRARIES ${KLU_LIBRARY} ${AMD_LIBRARY} ${COLAMD_LIBRARY} ${BTF_LIBRARY} ${SUITESPARSECONFIG_LIBRARY})

find_library(KLU_LIBRARY klu)
find_library(AMD_LIBRARY amd)
find_library(COLAMD_LIBRARY colamd)
find_library(BTF_LIBRARY btf)
find_library(SUITESPARSECONFIG_LIBRARY suitesparseconfig)
set(KLU_LIBRARIES ${KLU_LIBRARY} ${AMD_LIBRARY} ${COLAMD_LIBRARY} ${BTF_LIBRARY} ${SUITESPARSECONFIG_LIBRARY})


set(KLU_FOUND TRUE)

IF(KLU_FOUND)
# include is now simply /usr/include
# IF(KLU_FOUND)
# sundials_config.h symbol
SET(SUNDIALS_KLU TRUE)
set(KLU_INCLUDE_DIR ${SUITESPARSE_DIR}/KLU/Include)
set(AMD_INCLUDE_DIR ${SUITESPARSE_DIR}/AMD/Include)
set(COLAMD_INCLUDE_DIR ${SUITESPARSE_DIR}/COLAMD/Include)
set(BTF_INCLUDE_DIR ${SUITESPARSE_DIR}/BTF/Include)
set(SUITESPARSECONFIG_INCLUDE_DIR ${SUITESPARSE_DIR}/SuiteSparse_config)

INCLUDE_DIRECTORIES(${AMD_INCLUDE_DIR} ${COLAMD_INCLUDE_DIR} ${BTF_INCLUDE_DIR} ${SUITESPARSECONFIG_INCLUDE_DIR} ${KLU_INCLUDE_DIR})
ENDIF(KLU_FOUND)
# SET(SUNDIALS_KLU TRUE)
# set(KLU_INCLUDE_DIR ${SUITESPARSE_DIR}/KLU/Include)
# set(AMD_INCLUDE_DIR ${SUITESPARSE_DIR}/AMD/Include)
# set(COLAMD_INCLUDE_DIR ${SUITESPARSE_DIR}/COLAMD/Include)
# set(BTF_INCLUDE_DIR ${SUITESPARSE_DIR}/BTF/Include)
# set(SUITESPARSECONFIG_INCLUDE_DIR ${SUITESPARSE_DIR}/SuiteSparse_config)

# INCLUDE_DIRECTORIES(${AMD_INCLUDE_DIR} ${COLAMD_INCLUDE_DIR} ${BTF_INCLUDE_DIR} ${SUITESPARSECONFIG_INCLUDE_DIR} ${KLU_INCLUDE_DIR})
# ENDIF(KLU_FOUND)
# set(SUITESPARSE_INCLUDE_DIR "/usr/include/suitesparse") # leave for user to set
INCLUDE_DIRECTORIES(${SUITESPARSE_INCLUDE_DIR})

IF(KLU_LIBRARIES AND NOT KLU_FOUND)
PRINT_WARNING("KLU not functional - support will not be provided"
Expand Down

0 comments on commit 7080ae8

Please sign in to comment.