Skip to content

Commit 1b8f74d

Browse files
committed
add conditional LAPACK build support for SUNDIALS
modules options to enable/disable LAPACK backend for SUNDIALS rename LAPACK support definition for SUNDIALS wrapper skip iterative solver inclusion for SUNDIALS (add when supported) use markdown format for SUNDIALS module description
1 parent 714802c commit 1b8f74d

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

meson_options.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ option('sundials', type : 'string', value : '',
99
description : 'SUNDIALS install path')
1010
option('sundials_vec', type : 'string', value : 'serial',
1111
description : 'SUNDIALS vector implementation')
12+
option('sundials_lapack', type : 'boolean', value : false,
13+
description : 'LAPACK support for SUNDIALS')

modules/sundials/Makefile

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
# Makefile: SUNDIALS interface library
22
LIB ?= mpt_sundials
33
#
4-
# additional build flags
5-
# DEFINES += SUNDIALS_WITH_LAPACK=1
6-
DIR_SUNDIALS ?= ${MPT_PREFIX}/math/sundials-3.1.0/build
4+
# precompiled object location
5+
DIR_SUNDIALS_OBJ ?= ${MPT_PREFIX}/math/sundials-3.1.0/build
6+
# include directories
7+
DIR_SUNDIALS_INC ?= ${MPT_PREFIX}/include
8+
INC = . ${DIR_SUNDIALS_INC}
9+
#
10+
# SUNDIALS modules to include in shared library
711
sundials_lapack = sunlinsol_lapackband sunlinsol_lapackdense
8-
sundials_matrix = sunmat_band sunmat_dense
912
sundials_direct = sunlinsol_band sunlinsol_dense ${sundials_lapack}
10-
sundials_iter = sunlinsol_pcg sunlinsol_spbcgs
1113
sundials_elements = cvode ida kinsol ${sundials_iter} ${sundials_direct} nvec_ser
12-
INC = . ${MPT_PREFIX}/include ${DIR_SUNDIALS}/include/
1314
#
1415
# shared library version
1516
SHLIB_MAJOR = 1
1617
SHLIB_MINOR = 0
1718
SHLIB_TEENY = 0
1819
# linker settings
19-
LDLIBS += -llapack -lblas
20+
ifneq (${sundials_lapack},)
21+
DEF += MPT_WITH_LAPACK
22+
LDLIBS += -llapack -lblas
23+
endif
2024
LDLIBS += -lm
21-
LINK = ${CC}
2225
#
2326
# shared components
2427
mod_require = ${mod_ivp} ufcn_dae ufcn_ode
@@ -30,9 +33,8 @@ sources = $(wildcard sundials_*.c)
3033

3134
SRCS := ${sources} ${sources_cvode} ${sources_ida}
3235

33-
MATH_OBJS_STATIC != env DIR_SUNDIALS="${DIR_SUNDIALS}" LIBRARY_TYPE=static ./sundials_collect.sh ${sundials_elements}
34-
MATH_OBJS_SHARED != env DIR_SUNDIALS="${DIR_SUNDIALS}" LIBRARY_TYPE=shared ./sundials_collect.sh ${sundials_elements}
35-
MATH_OBJS = ${MATH_OBJS_STATIC} ${MATH_OBJS_SHARED}
36+
MATH_OBJS_STATIC != env DIR_SUNDIALS="${DIR_SUNDIALS_OBJ}" LIBRARY_TYPE=static ./sundials_collect.sh ${sundials_elements}
37+
MATH_OBJS_SHARED != env DIR_SUNDIALS="${DIR_SUNDIALS_OBJ}" LIBRARY_TYPE=shared ./sundials_collect.sh ${sundials_elements}
3638
#
3739
# headers to export
3840
HEADER = sundials.h

modules/sundials/meson.build

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sundials_dir_lib = join_paths(sundials_dir, 'lib')
55
sundials_dir_inc = include_directories(join_paths(sundials_dir, 'include'))
66

77
sundials_deps = [ cc.find_library('sundials_nvec' + get_option('sundials_vec'), dirs : sundials_dir_lib) ]
8-
8+
sundials_args = []
99
sundials_ida = cc.find_library('sundials_ida', required : false, dirs : sundials_dir_lib)
1010
sundials_cvode = cc.find_library('sundials_cvode', required : false, dirs : sundials_dir_lib)
1111
sundials_kinsol = cc.find_library('sundials_kinsol', required : false, dirs : sundials_dir_lib)
@@ -35,18 +35,22 @@ endif
3535
sundials_deps += cc.find_library('sundials_sunlinsolband', dirs : sundials_dir_lib)
3636
sundials_deps += cc.find_library('sundials_sunlinsoldense', dirs : sundials_dir_lib)
3737

38-
sundials_deps += cc.find_library('sundials_sunlinsollapackband', dirs : sundials_dir_lib)
39-
sundials_deps += cc.find_library('sundials_sunlinsollapackdense', dirs : sundials_dir_lib)
38+
if get_option('sundials_lapack')
39+
sundials_deps += cc.find_library('sundials_sunlinsollapackband', dirs : sundials_dir_lib)
40+
sundials_deps += cc.find_library('sundials_sunlinsollapackdense', dirs : sundials_dir_lib)
41+
sundials_args += '-DMPT_WITH_LAPACK'
42+
endif
4043

4144
sundials_deps += cc.find_library('sundials_sunmatrixdense', dirs : sundials_dir_lib)
4245
sundials_deps += cc.find_library('sundials_sunmatrixband', dirs : sundials_dir_lib)
4346

44-
# sundials_deps += libm
47+
sundials_deps += libm
4548

4649
install_data(sources : 'sundials.conf', install_dir : join_paths('etc', 'mpt.conf.d'))
4750

4851
sundials_lib = shared_library('mpt_sundials', sundials_src, 'libinfo.c',
4952
include_directories : [ solv_mod_inc ],
53+
c_args : sundials_args,
5054
install_rpath : '$ORIGIN' + ':' + sundials_dir_lib,
5155
dependencies : [ sundials_deps, modules_dep_dae, modules_dep_ode ],
5256
version : '1.0.0', soversion : '1',

modules/sundials/sundials.info

-13
This file was deleted.

modules/sundials/sundials.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SUNDIALS module for [MPT](https://github.com/becm/mpt-solver)
2+
3+
## Source Information
4+
Use solvers from [SUNDIALS](https://computation.llnl.gov/projects/sundials)
5+
library
6+
7+
## Local Build
8+
To use *SUNDIALS* libraries with `Makefile` build
9+
set `DIR_SUNDIALS_OBJ` to *SUNDIALS* CMake build directory
10+
and `DIR_SUNDIALS_INC` to *SUNDIALS* install include directory.
11+
12+
### Alternative `Makfile` build modes
13+
To use shared *SUNDIALS* libraries remove `MATH_OBJS_{SHARED,STATIC}`
14+
definitions and add *SUNDIALS* libraries to linker arguments.
15+
16+
To disable *LAPACK* support in wrapper comment out `sundials_lapack`
17+
definition.
18+
19+
### Special vector types
20+
Library creates serial *SUNDIALS* `N_Vector` instances by default.
21+
To use different vector backend, reimplement `mpt_sundials_nvector()`
22+
in user program and link in before `libmpt_sundials.so`.

modules/sundials/sundials_linear.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <cvode/cvode_impl.h>
1717
#include <cvode/cvode_direct.h>
1818

19-
#ifdef SUNDIALS_BLAS_LAPACK
19+
#ifdef MPT_WITH_LAPACK
2020
# include <sunlinsol/sunlinsol_lapackdense.h>
2121
# include <sunlinsol/sunlinsol_lapackband.h>
2222
#endif
@@ -38,7 +38,7 @@ static int setLS(MPT_SOLVER_STRUCT(sundials) *sd, SUNLinearSolver LS, SUNMatrix
3838
return 0;
3939
}
4040

41-
#ifdef SUNDIALS_BLAS_LAPACK
41+
#ifdef MPT_WITH_LAPACK
4242
/* set lapack solver jacobian method */
4343
static int setLapack(MPT_SOLVER_STRUCT(sundials) *sd, sunindextype neqs)
4444
{
@@ -145,7 +145,7 @@ extern int mpt_sundials_linear(MPT_SOLVER_STRUCT(sundials) *sd, sunindextype neq
145145
}
146146
return setLS(sd, s, 0);
147147
}
148-
#ifdef SUNDIALS_BLAS_LAPACK
148+
#ifdef MPT_WITH_LAPACK
149149
if (type == MPT_SOLVER_SUNDIALS(Lapack)) {
150150
return setLapack(sd, neqs);
151151
}

0 commit comments

Comments
 (0)