Skip to content

Commit

Permalink
pybamm-team#633 created a cmake file for klu
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Oct 9, 2019
1 parent 6964708 commit 2364aef
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ pyvenv.cfg
sundials
sundials4
SuiteSparse

# cmakefiles
CMakeFiles
Makefile
*.cmake
*.so
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third-party/pybind11"]
path = third-party/pybind11
url = https://github.com/pybind/pybind11.git
55 changes: 55 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.10)
project(klu)

set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_subdirectory(third-party/pybind11)
pybind11_add_module(klu pybamm/solvers/c_solvers/klu.cpp)

# Sundials
set(SUNDIALS_INCLUDE "sundials4/include")
TARGET_INCLUDE_DIRECTORIES(klu PRIVATE ${SUNDIALS_INCLUDE})

find_library(SUNMATSPARSE sundials_sunmatrixsparse PATHS "sundials4/lib")
find_library(IDA sundials_ida PATHS "sundials4/lib")
find_library(NVECTOR sundials_nvecserial PATHS "sundials4/lib")
find_library(SUNKLU sundials_sunlinsolklu PATHS "sundials4/lib")
TARGET_LINK_LIBRARIES(klu PRIVATE ${SUNMATSPARSE} ${IDA} ${NVECTOR} ${SUNKLU})

# System libraries
find_library(RT rt)
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}
)

## Link Libraries
find_library(KLU klu PATHS "SuiteSparse/KLU/Lib")
find_library(AMD amd PATHS "SuiteSparse/AMD/Lib")
find_library(COLAMD colamd PATHS "SuiteSparse/COLAMD/Lib")
find_library(BTF btf PATHS "SuiteSparse/BTF/Lib")
find_library(SUITESPARSE_CONFIG suitesparseconfig PATHS "SuiteSparse/SuiteSparse_config")
TARGET_LINK_LIBRARIES(klu PRIVATE
${KLU}
${AMD}
${COLAMD}
${BTF}
${SUITESPARSE_CONFIG}
)

# ---------------

File renamed without changes.
Binary file not shown.
3 changes: 2 additions & 1 deletion pybamm/solvers/klu_sparse_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pybamm

import numpy as np
from .c_solvers import klu

import klu
import scipy.sparse as sparse


Expand Down
1 change: 1 addition & 0 deletions third-party/pybind11
Submodule pybind11 added at 6cb584

0 comments on commit 2364aef

Please sign in to comment.