Skip to content

Commit f8e810b

Browse files
Merge pull request #77 from alliander-opensource/feature/internal-sparse-solver
Use internal sparse solver to replace EIGEN and MKL
2 parents 6dc636c + cf0c276 commit f8e810b

37 files changed

+1330
-1498
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,19 @@ jobs:
2828
strategy:
2929
matrix:
3030
build-option: [ Debug, Release ]
31-
sparse-solver: [ EIGEN, MKL, MKL_RUNTIME ]
3231

3332
steps:
3433
- uses: actions/checkout@v3
3534

3635
- name: Run build script
37-
run: ./build.sh ${{ matrix.build-option }} ${{ matrix.sparse-solver }}
36+
run: ./build.sh ${{ matrix.build-option }}
3837

3938
build-cpp-test-windows:
4039
if: (github.event_name == 'push') || (github.event_name == 'workflow_dispatch') || (!startsWith(github.head_ref, 'release'))
4140
runs-on: windows-latest
4241
strategy:
4342
matrix:
4443
build-option: [ Debug, Release ]
45-
sparse-solver: [ EIGEN, MKL, MKL_RUNTIME ]
46-
env:
47-
MKL_INCLUDE: C:\conda_envs\cpp_pkgs\Library\include
48-
MKL_LIB: C:\conda_envs\cpp_pkgs\Library\lib
4944

5045
steps:
5146
- uses: actions/checkout@v3
@@ -57,25 +52,24 @@ jobs:
5752
- name: Install conda environment
5853
# TODO removed pinned v2 of catch2, see https://github.com/alliander-opensource/power-grid-model/issues/73
5954
run: |
60-
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen nlohmann_json mkl mkl-devel mkl-include catch2==2.13.9
55+
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen nlohmann_json catch2==2.13.9
6156
6257
- name: Build and test
6358
run: |
6459
$vsPath = &(Join-Path ${env:ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') -property installationpath
6560
Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
6661
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64'
6762
$env:Path += ";C:\conda_envs\cpp_pkgs\Library\bin"
68-
mkdir cpp_build_${{ matrix.build-option }}_${{ matrix.sparse-solver }}
69-
cd cpp_build_${{ matrix.build-option }}_${{ matrix.sparse-solver }}
63+
mkdir cpp_build_${{ matrix.build-option }}
64+
cd cpp_build_${{ matrix.build-option }}
7065
# generate cmake cache
7166
cmake .. `
7267
-G "Ninja" `
7368
-DCMAKE_BUILD_TYPE=${{ matrix.build-option }} `
74-
-DPOWER_GRID_MODEL_SPARSE_SOLVER=${{ matrix.sparse-solver }} `
7569
-DCMAKE_PREFIX_PATH=C:\conda_envs\cpp_pkgs\Library `
7670
-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1
7771
# build
78-
cmake --build . --verbose
72+
cmake --build . --verbose -j 1
7973
# test
8074
.\tests\cpp_unit_tests\power_grid_model_unit_tests.exe
8175
@@ -85,12 +79,9 @@ jobs:
8579
strategy:
8680
matrix:
8781
build-option: [ Debug, Release ]
88-
sparse-solver: [ EIGEN, MKL, MKL_RUNTIME ]
8982
env:
9083
CC: clang
9184
CXX: clang++
92-
MKL_INCLUDE: /usr/local/include
93-
MKL_LIB: /usr/local/lib
9485
CMAKE_PREFIX_PATH: /usr/local
9586

9687
steps:
@@ -101,14 +92,10 @@ jobs:
10192
run: |
10293
brew install ninja boost eigen nlohmann-json
10394
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/5e5abb11bf49787d01164c4066119365262c21ed/Formula/catch2.rb > $(find $(brew --repository) -name catch2.rb) && brew reinstall catch2
104-
sudo pip3 install mkl mkl-devel mkl-include
10595
10696
- name: Build and test
10797
run: |
108-
# environment
109-
export LD_LIBRARY_PATH=${MKL_LIB}:${LD_LIBRARY_PATH}
110-
# bash
111-
./build.sh ${{ matrix.build-option }} ${{ matrix.sparse-solver }}
98+
./build.sh ${{ matrix.build-option }}
11299
113100
build-and-test-python:
114101
strategy:
@@ -122,9 +109,6 @@ jobs:
122109
boost:
123110
eigen:
124111
cibw_build: "cp*-manylinux_x86_64 cp*-manylinux_aarch64"
125-
test_cmd: >
126-
pytest {package}/tests &&
127-
LD_LIBRARY_PATH= pytest {package}/tests
128112
archs: "x86_64 aarch64"
129113
- platform: macos
130114
os: macos-latest
@@ -134,9 +118,6 @@ jobs:
134118
eigen: /usr/local/include/eigen3
135119
cibw_build: cp*-macosx_*
136120
archs: "x86_64 arm64"
137-
test_cmd: >
138-
pytest {package}/tests &&
139-
LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH} pytest {package}/tests
140121
- platform: windows
141122
os: windows-latest
142123
cc:
@@ -145,7 +126,6 @@ jobs:
145126
eigen: C:\conda_envs\cpp_pkgs\Library\include\eigen3
146127
cibw_build: cp*-win_amd64
147128
archs: AMD64
148-
test_cmd: pytest {package}/tests
149129

150130
runs-on: ${{ matrix.os }}
151131
needs: [build-cpp-test-linux, build-cpp-test-windows, build-cpp-test-macos]
@@ -160,7 +140,7 @@ jobs:
160140
CIBW_BUILD: ${{ matrix.cibw_build }}
161141
CIBW_ARCHS: ${{ matrix.archs }}
162142
CIBW_TEST_REQUIRES: pytest pytest-cov
163-
CIBW_TEST_COMMAND: ${{ matrix.test_cmd }}
143+
CIBW_TEST_COMMAND: pytest {package}/tests
164144
# Skip trying to test arm64 builds on Intel Macs
165145
CIBW_TEST_SKIP: "*-macosx_arm64 *-macosx_universal2:arm64"
166146
CIBW_MANYLINUX_X86_64_IMAGE: ghcr.io/alliander-opensource/power-grid-model-build-env
@@ -169,11 +149,10 @@ jobs:
169149
CIBW_BEFORE_ALL_MACOS: >
170150
which clang++ &&
171151
clang++ --version &&
172-
brew install boost eigen &&
173-
sudo pip3 install mkl mkl-devel mkl-include
152+
brew install boost eigen
174153
MACOSX_DEPLOYMENT_TARGET: 10.15
175154
CIBW_BEFORE_ALL_WINDOWS : >
176-
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen mkl
155+
conda create --yes -p C:\conda_envs\cpp_pkgs -c conda-forge boost-cpp eigen
177156
178157
steps:
179158
- uses: actions/checkout@v3

.github/workflows/sonar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Run build-wrapper for C++
6262
run: |
6363
mkdir cpp_build
64-
cmake -S . -B cpp_build -GNinja -DCMAKE_BUILD_TYPE=Debug -DPOWER_GRID_MODEL_SPARSE_SOLVER=EIGEN -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
64+
cmake -S . -B cpp_build -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
6565
VERBOSE=1 build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build cpp_build/
6666
6767
- name: C++ test and coverage

CMakeLists.txt

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,23 @@ else()
3131
add_compile_options(-Wall -Wextra -pedantic -Werror)
3232
add_compile_options(-Wno-deprecated-copy) # bug in boost
3333
if(UNIX AND NOT APPLE)
34-
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.1)
35-
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.2)
36-
# test coverage for debug build in linux
37-
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
34+
# test coverage for debug build in linux, if specified
35+
if ((CMAKE_BUILD_TYPE STREQUAL "Debug") AND (DEFINED POWER_GRID_MODEL_COVERAGE) AND (POWER_GRID_MODEL_COVERAGE EQUAL 1))
3836
add_compile_options(-fprofile-arcs -ftest-coverage)
3937
add_link_options(-fprofile-arcs)
4038
endif()
4139
else()
42-
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .1.dylib)
43-
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .2.dylib)
4440
endif()
4541
# thread
4642
find_package(Threads REQUIRED)
4743
target_link_libraries(power_grid_model INTERFACE Threads::Threads)
4844
endif()
4945

50-
51-
# sparse solver, default eigen
52-
if (NOT DEFINED POWER_GRID_MODEL_SPARSE_SOLVER)
53-
set(POWER_GRID_MODEL_SPARSE_SOLVER "EIGEN")
54-
endif()
55-
56-
# use mkl solver
57-
if((POWER_GRID_MODEL_SPARSE_SOLVER STREQUAL "MKL") OR (POWER_GRID_MODEL_SPARSE_SOLVER STREQUAL "MKL_RUNTIME"))
58-
# check load mkl at runtime or link-time
59-
if(POWER_GRID_MODEL_SPARSE_SOLVER STREQUAL "MKL_RUNTIME")
60-
target_compile_definitions(power_grid_model INTERFACE POWER_GRID_MODEL_USE_MKL_AT_RUNTIME=1)
61-
target_link_libraries(power_grid_model INTERFACE ${CMAKE_DL_LIBS})
62-
else()
63-
if(NOT DEFINED ENV{MKL_INCLUDE})
64-
message(FATAL_ERROR "MKL include dir not found!")
65-
endif()
66-
if(NOT DEFINED ENV{MKL_LIB})
67-
message(FATAL_ERROR "MKL lib dir not found!")
68-
endif()
69-
# mkl
70-
target_include_directories(power_grid_model INTERFACE $ENV{MKL_INCLUDE})
71-
list(APPEND CMAKE_PREFIX_PATH "$ENV{MKL_LIB}")
72-
find_library(MKL_RT mkl_rt)
73-
message("${MKL_RT}")
74-
target_compile_definitions(power_grid_model INTERFACE POWER_GRID_MODEL_USE_MKL=1)
75-
target_link_libraries(power_grid_model INTERFACE "${MKL_RT}")
76-
endif()
46+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
47+
# using GCC
48+
add_compile_options(-Wno-maybe-uninitialized) # bug in boost
7749
endif()
7850

79-
8051
# get tests
8152
add_subdirectory(tests/cpp_unit_tests)
8253

@@ -85,3 +56,4 @@ if(DEFINED POWER_GRID_MODEL_BUILD_BENCHMARK AND POWER_GRID_MODEL_BUILD_BENCHMARK
8556
add_subdirectory(tests/benchmark_cpp)
8657
endif()
8758

59+

CMakeSettings.json

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,54 +23,6 @@
2323
"ctestCommandArgs": "",
2424
"inheritEnvironments": [ "msvc_x64_x64" ],
2525
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"
26-
},
27-
{
28-
"name": "x64-Debug-MKL",
29-
"generator": "Ninja",
30-
"configurationType": "Debug",
31-
"buildRoot": "${projectDir}\\cpp_build\\${name}",
32-
"installRoot": "${projectDir}\\install\\${name}",
33-
"cmakeCommandArgs": "-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1 -DPOWER_GRID_MODEL_SPARSE_SOLVER=MKL",
34-
"buildCommandArgs": "-v",
35-
"ctestCommandArgs": "",
36-
"inheritEnvironments": [ "msvc_x64_x64" ],
37-
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"
38-
},
39-
{
40-
"name": "x64-Release-MKL",
41-
"generator": "Ninja",
42-
"configurationType": "RelWithDebInfo",
43-
"buildRoot": "${projectDir}\\cpp_build\\${name}",
44-
"installRoot": "${projectDir}\\install\\${name}",
45-
"cmakeCommandArgs": "-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1 -DPOWER_GRID_MODEL_SPARSE_SOLVER=MKL",
46-
"buildCommandArgs": "-v",
47-
"ctestCommandArgs": "",
48-
"inheritEnvironments": [ "msvc_x64_x64" ],
49-
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"
50-
},
51-
{
52-
"name": "x64-Debug-MKL-at-runtime",
53-
"generator": "Ninja",
54-
"configurationType": "Debug",
55-
"buildRoot": "${projectDir}\\cpp_build\\${name}",
56-
"installRoot": "${projectDir}\\install\\${name}",
57-
"cmakeCommandArgs": "-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1 -DPOWER_GRID_MODEL_SPARSE_SOLVER=MKL_RUNTIME",
58-
"buildCommandArgs": "-v",
59-
"ctestCommandArgs": "",
60-
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
61-
"inheritEnvironments": [ "msvc_x64_x64" ]
62-
},
63-
{
64-
"name": "x64-Release-MKL-at-runtime",
65-
"generator": "Ninja",
66-
"configurationType": "RelWithDebInfo",
67-
"buildRoot": "${projectDir}\\cpp_build\\${name}",
68-
"installRoot": "${projectDir}\\install\\${name}",
69-
"cmakeCommandArgs": "-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1 -DPOWER_GRID_MODEL_SPARSE_SOLVER=MKL_RUNTIME",
70-
"buildCommandArgs": "-v",
71-
"ctestCommandArgs": "",
72-
"cmakeToolchain": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake",
73-
"inheritEnvironments": [ "msvc_x64_x64" ]
7426
}
7527
]
7628
}

README.md

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,8 @@ Currently, it supports the following calculations:
2929

3030
# Installation
3131

32-
## Runtime Dependencies
32+
## Install from PyPI
3333

34-
The only Python runtime dependency is
35-
[numpy](https://numpy.org/). It will be automatically installed as the requirements.
36-
Moreover, the library optionally depends on
37-
[Intel Math Kernel Library (mkl)](https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl.html),
38-
for its [PARDISO](https://www.intel.com/content/www/us/en/develop/documentation/onemkl-developer-reference-c/top/sparse-solver-routines/onemkl-pardiso-parallel-direct-sparse-solver-iface.html) sparse solver.
39-
It is recommended to install `mkl` because it gives huge performance boosts.
40-
41-
The easiest way to install `mkl` is using `pip` or `conda`:
42-
43-
```
44-
pip install mkl
45-
```
46-
47-
or
48-
49-
```
50-
conda install -c conda-forge mkl
51-
```
52-
53-
You need to add the path to the `mkl` runtime file `libmkl_rt.so` or `mkl_rt.dll` the environment variable
54-
`LD_LIBRARY_PATH` in Linux or `Path` in Windows (`conda` does this automatically in the environment).
55-
If the library can find `mkl` runtime, it uses it as the sparse solver.
56-
It is recommended to set the environment variable `MKL_THREADING_LAYER` to `SEQUENTIAL`,
57-
as multi-threading is handled in a higher level.
58-
If the library cannot find `mkl` runtime, it will fall back to an internally built-in (and much slower)
59-
[Eigen SparseLU](https://eigen.tuxfamily.org/dox/classEigen_1_1SparseLU.html) solver.
60-
61-
## Install from Pre-built Binary Package
62-
63-
The `power-grid-model` python package is pre-built for Windows, Linux, and macOS (both Intel and Arm-based),
64-
for Python version 3.8, 3.9, and 3.10.
6534
You can directly install the package from PyPI.
6635

6736
```
@@ -208,13 +177,6 @@ which are licensed under their own respective Open-Source licenses.
208177
SPDX-License-Identifier headers are used to show which license is applicable.
209178
The concerning license files can be found in the LICENSES directory.
210179

211-
## Intel Math Kernel Library License
212-
213-
The `power-grid-model` does not bundle or redistribute any MKL runtime library.
214-
It only detects if MKL library is installed in the target system.
215-
If so, it will use the library to accelerate the calculation.
216-
The user is responsible to acquire a suitable MKL license.
217-
218180
# Contributing
219181
Please read [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) and [CONTRIBUTING](CONTRIBUTING.md) for details on the process
220182
for submitting pull requests to us.

build.sh

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set -e
88

99
usage() {
10-
echo "$0 {Debug/Release} {EIGEN,MKL,MKL_RUNTIME}"
10+
echo "$0 {Debug/Release}"
1111
}
1212

1313
if [ ! "$1" = "Debug" ] && [ ! "$1" = "Release" ]; then
@@ -16,13 +16,13 @@ if [ ! "$1" = "Debug" ] && [ ! "$1" = "Release" ]; then
1616
exit 1;
1717
fi
1818

19-
if [ ! "$2" = "EIGEN" ] && [ ! "$2" = "MKL" ] && [ ! "$2" = "MKL_RUNTIME" ]; then
20-
echo "Missing second argument"
21-
usage
22-
exit 1;
19+
if [[ $2 == "Coverage" ]]; then
20+
BUILD_COVERAGE=-DPOWER_GRID_MODEL_COVERAGE=1
21+
else
22+
BUILD_COVERAGE=
2323
fi
2424

25-
BUILD_DIR=cpp_build_$1_$2
25+
BUILD_DIR=cpp_build_$1
2626
echo "Build dir: ${BUILD_DIR}"
2727

2828
if [[ ! -z "${VCPKG_ROOT}" ]]; then
@@ -41,27 +41,19 @@ cd ${BUILD_DIR}
4141
# generate
4242
cmake .. -GNinja \
4343
-DCMAKE_BUILD_TYPE=$1 \
44-
-DPOWER_GRID_MODEL_SPARSE_SOLVER=$2 \
4544
${PATH_FOR_CMAKE} \
46-
-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1
45+
-DPOWER_GRID_MODEL_BUILD_BENCHMARK=1 \
46+
${BUILD_COVERAGE}
4747
# build
4848
VERBOSE=1 cmake --build .
4949
# test
50+
./tests/cpp_unit_tests/power_grid_model_unit_tests
5051

51-
if [[ $2 == "MKL_RUNTIME" ]]; then
52-
LD_LIBRARY_PATH= ./tests/cpp_unit_tests/power_grid_model_unit_tests
53-
LD_LIBRARY_PATH= POWER_GRID_MODEL_SPARSE_SOLVER=MKL ./tests/cpp_unit_tests/power_grid_model_unit_tests
54-
LD_LIBRARY_PATH=${MKL_LIB} ./tests/cpp_unit_tests/power_grid_model_unit_tests
55-
LD_LIBRARY_PATH=${MKL_LIB} POWER_GRID_MODEL_SPARSE_SOLVER=MKL ./tests/cpp_unit_tests/power_grid_model_unit_tests
56-
POWER_GRID_MODEL_SPARSE_SOLVER=EIGEN ./tests/cpp_unit_tests/power_grid_model_unit_tests
57-
else
58-
LD_LIBRARY_PATH=${MKL_LIB} ./tests/cpp_unit_tests/power_grid_model_unit_tests
59-
fi
6052

6153

6254
cd ..
6355
# test coverage report for debug build and for linux
64-
if [[ "$1" = "Debug" ]] && [[ $3 == "Coverage" ]]; then
56+
if [[ "$1" = "Debug" ]] && [[ $2 == "Coverage" ]]; then
6557
echo "Generating coverage report..."
6658
if [[ ${CXX} == "clang++"* ]]; then
6759
GCOV_TOOL="--gcov-tool llvm-gcov.sh"

0 commit comments

Comments
 (0)