Skip to content

Commit 8fe36cc

Browse files
committed
Update to latest SUNDIALS
1 parent c067d86 commit 8fe36cc

5 files changed

Lines changed: 76 additions & 62 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Fidimag solves finite-difference micromagnetic problems and supports atomistic s
2020
See: [https://fidimag.readthedocs.io/en/latest/install.html](https://fidimag.readthedocs.io/en/latest/install.html)
2121

2222
### Features
23-
* Optimal LLG equation integration using modern [Sundial's v6](https://github.com/LLNL/sundials/) CVODE solver
23+
* Optimal LLG equation integration using modern [Sundial's v7](https://github.com/LLNL/sundials/) CVODE solver
2424
* Offers LLG and LLG with spin torque terms (Zhang-Li and Sloncewski)
2525
* Calculations using the Geodesic-Nudged-Elastic-Band and String methods to compute energy barriers.
2626
* Exchange, Zeeman, Demagnetising, Uniaxial Anisotropy energy classes.

bin/install-sundials.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ set -e
55
# when SUNDIALS moved to a CMake-based installation. Will install locally.
66
# It may need environment variables to work, like `export CC=gcc` in ARCHER.
77

8+
# Parse command line arguments
9+
SILENT=true
10+
if [[ "$1" == "--not-silent" ]]; then
11+
SILENT=false
12+
fi
13+
814
# Github release from Sundials repository
915
# https://github.com/LLNL/sundials
10-
SUNDIALS_TAG=v6.6.1
11-
SUNDIALS=sundials-6.6.1
16+
SUNDIALS_TAG=v7.6.0
17+
SUNDIALS=sundials-7.6.0
1218

1319
# Make sure CMake is installed, since SUNDIALS requires it.
1420
type cmake >/dev/null 2>&1 || { printf "CMake required to build SUNDIALS. You can install it by typing: \nsudo apt install cmake\n"; exit 1;}
@@ -42,10 +48,15 @@ download_and_cmake_install() {
4248
cmake ${4} ../${2}
4349

4450
echo "Compiling and installing "${2}"."
45-
{
51+
if [ "$SILENT" = true ]; then
52+
{
53+
make -j2
54+
make install
55+
} > /dev/null
56+
else
4657
make -j2
4758
make install
48-
} > /dev/null
59+
fi
4960

5061
echo "Cleaning up."
5162
cd ..

doc/install.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ though many Linux distributions come with these. Using the scripts provided in F
3737
bash install-fftw.sh
3838
bash install-sundials.sh
3939
40+
The installation script will automatically download and build SUNDIALS v7.6.0.
41+
4042
Python library dependencies are specified in the `pyproject.toml` file. We can install the `fidimag` library in editable mode, using `pip`:
4143

4244
.. code-block:: bash

fidimag/common/sundials/cvode.pyx

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ cdef extern from "sundials/sundials_context.h":
1010
struct _SUNContext:
1111
pass
1212
ctypedef _SUNContext *SUNContext
13+
void* SUN_COMM_NULL
1314
int SUNContext_Create(void *comm, SUNContext *ctx)
1415
int SUNContext_Free(SUNContext *ctx)
1516

1617

1718
cdef extern from "sundials/sundials_types.h":
18-
ctypedef double realtype
19-
ctypedef bint booleantype
19+
ctypedef double sunsunrealtype
20+
ctypedef bint sunsunbooleantype
2021

2122
# Types for the Sundials Linear System initialization
2223
cdef extern from "sundials/sundials_matrix.h":
@@ -42,22 +43,22 @@ cdef extern from "sundials/sundials_nvector.h":
4243

4344

4445
cdef extern from "nvector/nvector_serial.h":
45-
cdef N_Vector N_VMake_Serial(long int vec_length, realtype *v_data, SUNContext sunctx)
46+
cdef N_Vector N_VMake_Serial(long int vec_length, double *v_data, SUNContext sunctx)
4647
struct _N_VectorContent_Serial:
4748
long int length
48-
realtype *data
49-
booleantype own_data
49+
double *data
50+
int own_data
5051

5152
ctypedef _N_VectorContent_Serial *N_VectorContent_Serial
5253

5354

5455
cdef extern from "nvector/nvector_openmp.h":
55-
cdef N_Vector N_VMake_OpenMP(long int vec_length, realtype *v_data, int num_threads, SUNContext sunctx)
56+
cdef N_Vector N_VMake_OpenMP(long int vec_length, double *v_data, int num_threads, SUNContext sunctx)
5657

5758
struct _N_VectorContent_OpenMP:
5859
long int length
59-
realtype *data
60-
booleantype own_data
60+
double *data
61+
int own_data
6162
int num_threads
6263

6364
ctypedef _N_VectorContent_OpenMP *N_VectorContent_OpenMP
@@ -100,34 +101,34 @@ cdef extern from "cvode/cvode.h":
100101
int CV_BAD_DKY
101102
int CV_TOO_CLOSE
102103

103-
ctypedef int (*CVRhsFn)(realtype t, N_Vector y, N_Vector ydot, void *user_data)
104-
ctypedef int (*CVRootFn)(realtype t, N_Vector y, realtype *gout, void *user_data)
104+
ctypedef int (*CVRhsFn)(double t, N_Vector y, N_Vector ydot, void *user_data)
105+
ctypedef int (*CVRootFn)(double t, N_Vector y, double *gout, void *user_data)
105106

106107
void *CVodeCreate(int lmm, SUNContext sunctx)
107-
# int CVode "CVode"(void *cvode_mem, realtype tout, N_Vector yout, realtype *tret, int itask) nogil
108+
# int CVode "CVode"(void *cvode_mem, double tout, N_Vector yout, double *tret, int itask) nogil
108109
int CVodeSetUserData(void *cvode_mem, void *user_data)
109110
int CVodeSetMaxOrd(void *cvode_mem, int maxord)
110111
int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps)
111112
int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil)
112-
int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet)
113-
int CVodeSetInitStep(void *cvode_mem, realtype hin)
114-
int CVodeSetMinStep(void *cvode_mem, realtype hmin)
115-
int CVodeSetMaxStep(void *cvode_mem, realtype hmax)
116-
int CVodeSetStopTime(void *cvode_mem, realtype tstop)
113+
int CVodeSetStabLimDet(void *cvode_mem, int stldet)
114+
int CVodeSetInitStep(void *cvode_mem, double hin)
115+
int CVodeSetMinStep(void *cvode_mem, double hmin)
116+
int CVodeSetMaxStep(void *cvode_mem, double hmax)
117+
int CVodeSetStopTime(void *cvode_mem, double tstop)
117118
int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef)
118119
int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor)
119120
int CVodeSetMaxConvFails(void *cvode_mem, int maxncf)
120-
int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef)
121+
int CVodeSetNonlinConvCoef(void *cvode_mem, double nlscoef)
121122
int CVodeSetIterType(void *cvode_mem, int iter)
122123
int CVodeSetRootDirection(void *cvode_mem, int *rootdir)
123124
int CVodeSetNoInactiveRootWarn(void *cvode_mem)
124-
int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0)
125-
int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0)
126-
int CVodeSStolerances(void *cvode_mem, realtype reltol, realtype abstol)
127-
int CVodeSVtolerances(void *cvode_mem, realtype reltol, N_Vector abstol)
125+
int CVodeInit(void *cvode_mem, CVRhsFn f, double t0, N_Vector y0)
126+
int CVodeReInit(void *cvode_mem, double t0, N_Vector y0)
127+
int CVodeSStolerances(void *cvode_mem, double reltol, double abstol)
128+
int CVodeSVtolerances(void *cvode_mem, double reltol, N_Vector abstol)
128129
int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g)
129-
int CVode(void *cvode_mem, realtype tout, N_Vector yout, realtype *tret, int itask)
130-
int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky)
130+
int CVode(void *cvode_mem, double tout, N_Vector yout, double *tret, int itask)
131+
int CVodeGetDky(void *cvode_mem, double t, int k, N_Vector dky)
131132
int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw)
132133
int CVodeGetNumSteps(void *cvode_mem, long int *nsteps)
133134
int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals)
@@ -136,20 +137,20 @@ cdef extern from "cvode/cvode.h":
136137
int CVodeGetLastOrder(void *cvode_mem, int *qlast)
137138
int CVodeGetCurrentOrder(void *cvode_mem, int *qcur)
138139
int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred)
139-
int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused)
140-
int CVodeGetLastStep(void *cvode_mem, realtype *hlast)
141-
int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur)
142-
int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur)
143-
int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfac)
140+
int CVodeGetActualInitStep(void *cvode_mem, double *hinused)
141+
int CVodeGetLastStep(void *cvode_mem, double *hlast)
142+
int CVodeGetCurrentStep(void *cvode_mem, double *hcur)
143+
int CVodeGetCurrentTime(void *cvode_mem, double *tcur)
144+
int CVodeGetTolScaleFactor(void *cvode_mem, double *tolsfac)
144145
int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight)
145146
int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele)
146147
int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals)
147148
int CVodeGetRootInfo(void *cvode_mem, int *rootsfound)
148149
int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps,
149150
long int *nfevals, long int *nlinsetups,
150151
long int *netfails, int *qlast,
151-
int *qcur, realtype *hinused, realtype *hlast,
152-
realtype *hcur, realtype *tcur)
152+
int *qcur, double *hinused, double *hlast,
153+
double *hcur, double *tcur)
153154
int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters)
154155
int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails)
155156
int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters, long int *nncfails)
@@ -180,17 +181,17 @@ cdef extern from "cvode/cvode_ls.h":
180181
# int CVSpilsSetPrecType(void *cvode_mem, int pretype)
181182
# int CVSpilsSetGSType(void *cvode_mem, int gstype)
182183
# int CVSpilsSetMaxl(void *cvode_mem, int maxl)
183-
# int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac)
184-
185-
ctypedef int (*CVLsPrecSetupFn)(realtype t, N_Vector y, N_Vector fy,
186-
booleantype jok, booleantype *jcurPtr,
187-
realtype gamma, void *user_data);
188-
ctypedef int (*CVLsPrecSolveFn)(realtype t, N_Vector y, N_Vector fy,
189-
N_Vector r, N_Vector z, realtype gamma,
190-
realtype delta, int lr, void *user_data);
191-
ctypedef int (*CVLsJacTimesSetupFn)(realtype t, N_Vector y,
184+
# int CVSpilsSetEpsLin(void *cvode_mem, sunrealtype eplifac)
185+
186+
ctypedef int (*CVLsPrecSetupFn)(double t, N_Vector y, N_Vector fy,
187+
int jok, int *jcurPtr,
188+
double gamma, void *user_data);
189+
ctypedef int (*CVLsPrecSolveFn)(double t, N_Vector y, N_Vector fy,
190+
N_Vector r, N_Vector z, double gamma,
191+
double delta, int lr, void *user_data);
192+
ctypedef int (*CVLsJacTimesSetupFn)(double t, N_Vector y,
192193
N_Vector fy, void *user_data);
193-
ctypedef int (*CVLsJacTimesVecFn)(N_Vector v, N_Vector Jv, realtype t,
194+
ctypedef int (*CVLsJacTimesVecFn)(N_Vector v, N_Vector Jv, double t,
194195
N_Vector y, N_Vector fy,
195196
void *user_data, N_Vector tmp);
196197

@@ -312,8 +313,8 @@ cdef int cv_jtimes_openmp(N_Vector v, N_Vector Jv, double t, N_Vector y, N_Vecto
312313
return 0
313314

314315

315-
# static int PSolve(realtype tn, N_Vector u, N_Vector fu, N_Vector r, N_Vector z,
316-
# realtype gamma, realtype delta, int lr, void *user_data);
316+
# static int PSolve(sunrealtype tn, N_Vector u, N_Vector fu, N_Vector r, N_Vector z,
317+
# sunrealtype gamma, sunrealtype delta, int lr, void *user_data);
317318
cdef int psolve(double t, N_Vector y, N_Vector fy, N_Vector r, N_Vector z,
318319
double gamma, double delta, int lr, void * user_data):
319320
copy_nv2nv(z, r)
@@ -375,7 +376,7 @@ cdef class CvodeSolver(object):
375376
# All of the SUNDIALS objects (vectors, linear and nonlinear solvers, matrices, etc.)
376377
# that collectively form a SUNDIALS simulation, hold a reference to a common simulation context object
377378
# defined by the SUNContext class.
378-
SUNContext_Create(NULL, & self.sunctx);
379+
SUNContext_Create(SUN_COMM_NULL, & self.sunctx);
379380

380381
# The recommended choices for lmm are CV ADAMS for nonstiff problems and CV BDF for
381382
# stiff problems. The default Newton iteration is recommended for stiff problems, and
@@ -504,10 +505,10 @@ cdef class CvodeSolver(object):
504505
return 0
505506

506507
# From exmaples: cvDiurnal_kry.c in Sundials repo:
507-
# static int Precond(realtype tn, N_Vector u, N_Vector fu, booleantype jok,
508-
# booleantype *jcurPtr, realtype gamma, void *user_data)
509-
cdef int Precond(self, double t, N_Vector y, N_Vector fy, booleantype jok,
510-
booleantype * jcurPtr, double gamma, void * user_data):
508+
# static int Precond(sunrealtype tn, N_Vector u, N_Vector fu, sunbooleantype jok,
509+
# sunbooleantype *jcurPtr, sunrealtype gamma, void *user_data)
510+
cdef int Precond(self, double t, N_Vector y, N_Vector fy, int jok,
511+
int * jcurPtr, double gamma, void * user_data):
511512
if not jok:
512513
copy_nv2arr(y, self.y)
513514
return 0
@@ -600,7 +601,7 @@ cdef class CvodeSolver_OpenMP(object):
600601
if jtimes_fun is not None:
601602
self.has_jtimes = 1
602603

603-
SUNContext_Create(NULL, & self.sunctx);
604+
SUNContext_Create(SUN_COMM_NULL, & self.sunctx);
604605
# Newton iterator is set by default now (Sundials 4.0)
605606
self.cvode_mem = CVodeCreate(CV_BDF, self.sunctx)
606607

@@ -702,7 +703,7 @@ cdef class CvodeSolver_OpenMP(object):
702703
return 0
703704

704705
cdef int Precond(self, double t, N_Vector y, N_Vector fy,
705-
booleantype jok, booleantype * jcurPtr, double gamma,
706+
int jok, int * jcurPtr, double gamma,
706707
void * user_data):
707708
if not jok:
708709
copy_nv2arr_openmp(y, self.y)

setup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@
2525
# rpath: run-time search path for the sundials (cvode) and fftw library objects
2626
com_link = ['-Wl,-rpath,{},-rpath,{}'.format(str(LIB_DIR), str(LIB_DIR64)), '-fopenmp']
2727
lib_paths = [str(LIB_DIR), str(LIB_DIR64)]
28-
com_libs = ['m', 'fftw3_omp', 'fftw3', 'sundials_cvodes', 'sundials_nvecserial', 'sundials_nvecopenmp', 'blas', 'lapack']
28+
com_libs = ['m', 'fftw3_omp', 'fftw3', 'sundials_core', 'sundials_cvodes', 'sundials_nvecserial', 'sundials_nvecopenmp', 'blas', 'lapack']
2929
com_args = ['-O3', '-Wno-cpp', '-Wno-unused-function', '-Wall', '-std=c99', '-fopenmp']
3030
com_args_cpp = ['-O3', '-Wno-unused-function', '-Wall', '-std=c++14', '-fopenmp']
3131

32-
if 'SUNDIALS_INC' in os.environ:
33-
com_inc.append(os.environ['SUNDIALS_INC'])
34-
35-
if 'FFTW_INC' in os.environ:
36-
com_inc.append(os.environ['FFTW_INC'])
37-
3832
# Find all .pyx files with extensions (source files) -> relative paths
3933
ROOT_DIR = MODULE_DIR / 'fidimag'
4034
source_files = [s for s in ROOT_DIR.rglob('*.pyx')] # Paths
@@ -49,6 +43,12 @@
4943

5044
com_inc = [numpy.get_include(), str(INCLUDE_DIR)]
5145

46+
if 'SUNDIALS_INC' in os.environ:
47+
com_inc.append(os.environ['SUNDIALS_INC'])
48+
49+
if 'FFTW_INC' in os.environ:
50+
com_inc.append(os.environ['FFTW_INC'])
51+
5252
ext_modules = []
5353
for i, (module, src) in enumerate(zip(ext_names, source_files)):
5454
print(sYellow + f"Compiling module {module}" + sReset)
@@ -109,7 +109,7 @@ def get_version():
109109
raise Exception("Couldn't find __version__ in %s" % pkg_init_path)
110110

111111

112-
nthreads = multiprocessing.cpu_count()
112+
nthreads = 0 # Disabled parallel compilation due to Python 3.14 multiprocessing issues (0 = no multiprocessing)
113113
print(sYellow + f'Building with {nthreads} threads' + sReset)
114114
setup(
115115
name='fidimag',

0 commit comments

Comments
 (0)