Giter Site home page Giter Site logo

llnl / sundials Goto Github PK

View Code? Open in Web Editor NEW
454.0 35.0 114.0 237.29 MB

Official development repository for SUNDIALS - a SUite of Nonlinear and DIfferential/ALgebraic equation Solvers. Pull requests are welcome for bug fixes and minor changes.

Home Page: https://computing.llnl.gov/projects/sundials

License: BSD 3-Clause "New" or "Revised" License

CMake 4.91% C 63.07% C++ 11.74% Cuda 1.95% Python 1.75% Fortran 14.85% Shell 0.82% Perl 0.08% Makefile 0.05% SWIG 0.68% Dockerfile 0.08% Jupyter Notebook 0.02%
ode-solver dae-solver nonlinear-equation-solver sensitivity-analysis time-integration scientific-computing parallel-computing hpc math-physics radiuss

sundials's Introduction

SUNDIALS: SUite of Nonlinear and DIfferential/ALgebraic equation Solvers

Version 7.0.0 (Feb 2024)

Center for Applied Scientific Computing, Lawrence Livermore National Laboratory

SUNDIALS is a family of software packages providing robust and efficient time integrators and nonlinear solvers that can easily be incorporated into existing simulation codes. The packages are designed to require minimal information from the user, allow users to supply their own data structures underneath the packages, and enable interfacing with user-supplied or third-party algebraic solvers and preconditioners.

The SUNDIALS suite consists of the following packages for ordinary differential equation (ODE) systems, differential-algebraic equation (DAE) systems, and nonlinear algebraic systems:

  • ARKODE - for integrating stiff, nonstiff, and multirate ODEs of the form $$M(t) \, y' = f_1(t,y) + f_2(t,y), \quad y(t_0) = y_0$$

  • CVODE - for integrating stiff and nonstiff ODEs of the form $$y' = f(t,y), \quad y(t_0) = y_0$$

  • CVODES - for integrating and sensitivity analysis (forward and adjoint) of ODEs of the form $$y' = f(t,y,p), \quad y(t_0) = y_0(p)$$

  • IDA - for integrating DAEs of the form $$F(t,y,y') = 0, \quad y(t_0) = y_0, \quad y'(t_0) = y_0'$$

  • IDAS - for integrating and sensitivity analysis (forward and adjoint) of DAEs of the form $$F(t,y,y',p) = 0, \quad y(t_0) = y_0(p), \quad y'(t_0) = y_0'(p)$$

  • KINSOL - for solving nonlinear algebraic systems of the form $$F(u) = 0 \quad \text{or} \quad G(u) = u$$

Installation

For installation directions see the online install guide, the installation chapter in any of the package user guides, or INSTALL_GUIDE.pdf.

Warning to users who receive more than one of the individual packages at different times: Mixing old and new versions of SUNDIALS may fail. To avoid such failures, obtain all desired package at the same time.

Support

Full user guides for all of the SUNDIALS packages are available online and in the doc directory. Additionally, the doc directory contains documentation for the package example programs.

For information on recent changes to SUNDIALS see the CHANGELOG or the introduction chapter of any package user guide.

A list of Frequently Asked Questions on build and installation procedures as well as common usage issues is available on the SUNDIALS FAQ. For dealing with systems with unphysical solutions or discontinuities see the SUNDIALS usage notes.

If you have a question not covered in the FAQ or usage notes, please submit your question to the SUNDIALS mailing list.

Contributing

Bug fixes or minor changes are preferred via a pull request to the SUNDIALS GitHub repository. For more information on contributing see the CONTRIBUTING file.

Citing

See the online documentation or CITATIONS file for information on how to cite SUNDIALS in any publications reporting work done using SUNDIALS packages.

Authors

The SUNDIALS library has been developed over many years by a number of contributors. The current SUNDIALS team consists of Cody J. Balos, David J. Gardner, Alan C. Hindmarsh, Daniel R. Reynolds, and Carol S. Woodward. We thank Radu Serban for significant and critical past contributions.

Other contributors to SUNDIALS include: James Almgren-Bell, Lawrence E. Banks, Peter N. Brown, George Byrne, Rujeko Chinomona, Scott D. Cohen, Aaron Collier, Keith E. Grant, Steven L. Lee, Shelby L. Lockhart, John Loffeld, Daniel McGreer, Yu Pan, Slaven Peles, Cosmin Petra, Steven B. Roberts, H. Hunter Schwartz, Jean M. Sexton, Dan Shumaker, Steve G. Smith, Shahbaj Sohal, Allan G. Taylor, Hilari C. Tiedeman, Chris White, Ting Yan, and Ulrike M. Yang.

License

SUNDIALS is released under the BSD 3-clause license. See the LICENSE and NOTICE files for details. All new contributions must be made under the BSD 3-clause license.

Please Note If you are using SUNDIALS with any third party libraries linked in (e.g., LAPACK, KLU, SuperLU_MT, PETSc, or hypre), be sure to review the respective license of the package as that license may have more restrictive terms than the SUNDIALS license.

SPDX-License-Identifier: BSD-3-Clause

LLNL-CODE-667205  (ARKODE)
UCRL-CODE-155951  (CVODE)
UCRL-CODE-155950  (CVODES)
UCRL-CODE-155952  (IDA)
UCRL-CODE-237203  (IDAS)
LLNL-CODE-665877  (KINSOL)

sundials's People

Contributors

avandecreme avatar balay avatar balos1 avatar cnpetra avatar cswoodward avatar drreynolds avatar gardner48 avatar johnwparent avatar jschueller avatar lebanks avatar martinjrobins avatar mmuetzel avatar mottelet avatar pelesh avatar phannebohm avatar shahbajsohal avatar steven-roberts avatar sthibaul avatar white238 avatar yhmtsai avatar yu-nix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sundials's Issues

Bug in Build?

Hi,

I have been trying to install SUNDIALS with LAPACK enabled on macOS.

I have

bash-3.2$ cmake -DCMAKE_INSTALL_PREFIX=/Users/dom/sundials/instdir -DEXAMPLES_INSTALL_PATH=/Users/dom/sundials/instdir/examples -DBLAS_ENABLE=ON -DBLAS_LIBRARIES=/usr/local/opt/openblas/lib/libblas.dylib -DLAPACK_ENABLE=ON -DLAPACK_LIBRARIES=/usr/local/opt/lapack/lib/liblapack.dylib -DSUNDIALS_INDEX_TYPE=int32_t ~/Downloads/sundials-3.1.1
-- The Fortran compiler identification is GNU 9.1.0
-- Searching for a Fortran compiler... /usr/local/bin/gfortran
-- Checking whether Fortran compiler has -isysroot
-- Checking whether Fortran compiler has -isysroot - yes
-- Checking whether Fortran compiler supports OSX deployment target flag
-- Checking whether Fortran compiler supports OSX deployment target flag - yes
-- Trying to compile and link a simple Fortran program... OK
-- Determining Fortran name-mangling scheme... OK
-- Looking for BLAS libraries... OK
-- Checking if BLAS works... OK
-- Looking for LAPACK libraries... OK
-- Checking if LAPACK works... FAILED

And indeed

bash-3.2$ cd LapackTest/
bash-3.2$ make
/usr/local/Cellar/cmake/3.14.5/bin/cmake -S/Users/dom/build-sundials-with-openblas/LapackTest -B/Users/dom/build-sundials-with-openblas/LapackTest --check-build-system CMakeFiles/Makefile.cmake 0
-- The C compiler identification is AppleClang 10.0.0.10001145
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/dom/build-sundials-with-openblas/LapackTest
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/dom/build-sundials-with-openblas/LapackTest/CMakeFiles /Users/dom/build-sundials-with-openblas/LapackTest/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/ltest.dir/build.make CMakeFiles/ltest.dir/depend
cd /Users/dom/build-sundials-with-openblas/LapackTest && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_depends "Unix Makefiles" /Users/dom/build-sundials-with-openblas/LapackTest /Users/dom/build-sundials-with-openblas/LapackTest /Users/dom/build-sundials-with-openblas/LapackTest /Users/dom/build-sundials-with-openblas/LapackTest /Users/dom/build-sundials-with-openblas/LapackTest/CMakeFiles/ltest.dir/DependInfo.cmake --color=
Scanning dependencies of target ltest
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/ltest.dir/build.make CMakeFiles/ltest.dir/build
[ 50%] Building C object CMakeFiles/ltest.dir/ltest.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc    -o CMakeFiles/ltest.dir/ltest.o   -c /Users/dom/build-sundials-with-openblas/LapackTest/ltest.c
[100%] Linking C executable ltest
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_link_script CMakeFiles/ltest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/ltest.dir/ltest.o  -o ltest /usr/local/opt/lapack/lib/liblapack.dylib 
Undefined symbols for architecture x86_64:
  "_dcopy_", referenced from:
      _main in ltest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [ltest] Error 1
make[1]: *** [CMakeFiles/ltest.dir/all] Error 2
make: *** [all] Error 2

And

bash-3.2$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/ltest.dir/ltest.o  -o ltest /usr/local/opt/lapack/lib/liblapack.dylib 
Undefined symbols for architecture x86_64:
  "_dcopy_", referenced from:
      _main in ltest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But I think the missing symbol lives in BLAS

bash-3.2$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/ltest.dir/ltest.o  -o ltest /usr/local/opt/lapack/lib/liblapack.dylib /usr/local/opt/openblas/lib/libblas.dylib

Which does actually build.

However

bash-3.2$ ./ltest
 ** On entry to DGETRF parameter number  4 had an illegal value

Which does not sound good.

If I use the accelerate framework (which gets picked up automatically) then as far as I can tell everything builds ok.

  1. Can anyone shed any light on what is going on here?

  2. How can I test that LAPACK is actually working? I tried using the Python scikits-odes package with linsolver=‘lapackdense’ and got the expected result but I am now suspicious that this did not actually invoke LAPACK.

Dominic Steinitz
[email protected]
http://idontgetoutmuch.org
Twitter: @idontgetoutmuch

BTW I (think I) have SUNDIALS building with LAPACK in nix by using (if stdenv.isDarwin then [darwin.apple_sdk.frameworks.Accelerate] else [blas, lapack]) but I have yet to try this out on linux. Of course it would be better if we could just use BLAS and LAPACK which is partly the reason for this email.

sundials 5.1 does not build on windows with mingw

We are unable to build sundials 5.1 on windows. 3.1.1 used to build fine.

JuliaPackaging/Yggdrasil#461

[02:40:11] cd /workspace/srcdir/sundials-5.1.0/build/src/cvode && /opt/bin/i686-w64-mingw32-gcc --sysroot=/opt/i686-w64-mingw32/i686-w64-mingw32/sys-root/ -DBUILD_SUNDIALS_LIBRARY -D_CRT_SECURE_NO_WARNINGS @CMakeFiles/sundials_cvode_static.dir/includes_C.rsp -lgfortran -lquadmath -O3 -DNDEBUG   -o CMakeFiles/sundials_cvode_static.dir/__/sunmatrix/sparse/sunmatrix_sparse.c.obj   -c /workspace/srcdir/sundials-5.1.0/src/sunmatrix/sparse/sunmatrix_sparse.c
[02:40:11] cd /workspace/srcdir/sundials-5.1.0/build/src/cvodes && /opt/bin/i686-w64-mingw32-gcc --sysroot=/opt/i686-w64-mingw32/i686-w64-mingw32/sys-root/ -DBUILD_SUNDIALS_LIBRARY -D_CRT_SECURE_NO_WARNINGS -Dsundials_cvodes_shared_EXPORTS @CMakeFiles/sundials_cvodes_shared.dir/includes_C.rsp -lgfortran -lquadmath -O3 -DNDEBUG   -o CMakeFiles/sundials_cvodes_shared.dir/__/sundials/sundials_iterative.c.obj   -c /workspace/srcdir/sundials-5.1.0/src/sundials/sundials_iterative.c
[02:40:11] CMakeFiles/sundials_sunlinsollapackband_shared.dir/objects.a(sunlinsol_lapackband.c.obj):sunlinsol_lapackband.c:(.text+0x42c): undefined reference to `_imp__SUNLinSolNewEmpty'
[02:40:11] CMakeFiles/sundials_sunlinsollapackband_shared.dir/objects.a(sunlinsol_lapackband.c.obj):sunlinsol_lapackband.c:(.text+0x4ae): undefined reference to `_imp__SUNLinSolFree'
[02:40:11] CMakeFiles/sundials_sunlinsollapackband_shared.dir/objects.a(sunlinsol_lapackband.c.obj):sunlinsol_lapackband.c:(.text+0x55c): undefined reference to `_imp__SUNLinSolNewEmpty'
[02:40:11] CMakeFiles/sundials_sunlinsollapackband_shared.dir/objects.a(sunlinsol_lapackband.c.obj):sunlinsol_lapackband.c:(.text+0x5de): undefined reference to `_imp__SUNLinSolFree'
[02:40:11] collect2: error: ld returned 1 exit status

KINSetMaxNewtonStep seems to have no effect (Sundials 4)

The function call KINSetMaxNewtonStep() to set the maximum stepsize for KINSOL seems to have no effect in Sundials 3.1.1. In Sundials 2.x, the function worked as expected (calling it just before KINSol). I tried to call it just before KINSol, and in the model function.

The issue is, that the default maximum stepsize = 0, if u0 is the zero vector. The value u0=0 is a standard value for simple DAEs as, e.g., defined with Modia.

When calling KINGetStepLength(..) in the model function, indeed, a steplength=0 is returned all the time, until KINSol stops with an error that the Jacobian is singular. Since KINSetMaxNewtonStep(kinmem,1000.0) was called before KINSol and in the model function, the steplength should not be zero.

Understand ARKOde vs boost::odeint performance difference

I'm seeking help in figuring out the cause of performance using dopri5 from arkode and odeint on solving Lotka-Volterra equation. The ODE itself is not essential as on other problems similar issues are noticed. The benchmark code can be found at https://github.com/metrumresearchgroup/math/blob/torsten-arkode/test/unit/math/prim/functor/debug_arkode_test.cpp

To reproduce the very different wall time

bash-3.2$ git clone --recurse-submodules --single-branch --branch  torsten-arkode https://github.com/metrumresearchgroup/math.git
bash-3.2$ ./runTests.py -j4 test/unit/math/prim/functor/debug_arkode_test.cpp
------------------------------------------------------------
mpirun -np 1 test/unit/math/prim/functor/debug_arkode_test --gtest_output="xml:test/unit/math/prim/functor/debug_arkode_test.xml"
Running main() from lib/benchmark_1.5.1/googletest/googletest/src/gtest_main.cc
[==========] Running 2 tests from 2 test suites.
[----------] Global test environment set-up.
[----------] 1 test from arkode
[ RUN      ] arkode.lotka
[       OK ] arkode.lotka (375 ms)
[----------] 1 test from arkode (375 ms total)

[----------] 1 test from odeint
[ RUN      ] odeint.lotka
[       OK ] odeint.lotka (83 ms)
[----------] 1 test from odeint (83 ms total)

[----------] Global test environment tear-down
[==========] 2 tests from 2 test suites ran. (458 ms total)
[  PASSED  ] 2 tests.

What changes can I make in the code to bring arkode performance closer to odeint? My main suspects are different error norm and adaptive controller used by the solvers. Will they cause that much difference?

ARKode XBraid documentation uses `ARKBraid_Braid()`

ark_guide-4.7.0 p. 154:

  1. Initialize the ARKBraid interface
    Call the initialization function ARKBraid_Braid() to create the XBraid core memory structure and attach
    the ARKBraid interface app and functions.

Should ARKBraid_Braid() be ARKBraid_BraidInit() instead?

Email list no longer works

I just posted to [email protected] and got a message back

To cut down on spam, the SUNDIALS-USERS list has been configured to request
positive confirmation of messages posted to the SUNDIALS-USERS-request address.
You must now confirm that the enclosed message did originate from you. To do
so, simply reply to the present message and type "OK" (without the quotes) in
the text of your message, or click on the link below. If this does not work, or
if the message did not originate from you, then contact the list owner for
assistance.

To APPROVE the message:
http://listserv.llnl.gov/SCRIPTS/wa.exe?OK=FE2ECB38&L=SUNDIALS-USERS

But if I click on the link it times out.

CMakeLists.txt misses definition of 'print_error'

When running cmake . (which I should not do) I get the error

CMake Error at CMakeLists.txt:96 (print_error):
  Unknown CMake command "print_error".

Inspecting line 96 yields print_error("In-source build prohibited.") so the actual error message is not shown.

Question: Help setting inequality constraints where the right hand side is different than 0

I am interested in using CVode to integrate with inequality constraints where the right-hand side is different than zero, e.g., y_1 < 5. What is the intended method for doing this? Should I be modifying my states so that the inequality constraint changes, i.e., change y_1 = y_1 - 5 so that the new inequality constraint is y_1 <0, or is there a different method that I can use instead? I would like to avoid modifying my states if possible.

Additionally is there some intended method of implementing a 2-sided band constraint, where a<=y<=b?

Minor issue

The links to Documentation in https://github.com/LLNL/sundials/blob/master/src/cvode/README.md don't point to the right files. I found them nonetheless.

Documentation regarding breaking changes from 4.0.0 (arkode)

Hi,

I was trying to run some tests from a library providing bindings to sundials (haskell-numerics/hmatrix#297) which got broken after the change to 4.0.0. Here's the error we get:

Configuring hmatrix-sundials-0.19.0.0...
    Preprocessing test suite 'hmatrix-sundials-testsuite' for hmatrix-sundials-0.19.0.0..
    /home/user/Projects/hmatrix/packages/sundials/In file included from .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/hmatrix-sundials-testsuite/hmatrix-sundials-testsuite-tmp/Numeric/Sundials/Arkode_hsc_make.c:1:0:
    Arkode.hsc: In function ‘main’:
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:134:16: error: ‘ARK_S_MAX’ undeclared (first use in this function); did you mean ‘ARK_NORMAL’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:134:16: note: each undeclared identifier is reported only once for each function it appears in
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:137:16: error: ‘MIN_DIRK_NUM’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:138:16: error: ‘MAX_DIRK_NUM’ undeclared (first use in this function); did you mean ‘MIN_DIRK_NUM’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:144:16: error: ‘SDIRK_2_1_2’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:146:16: error: ‘BILLINGTON_3_3_2’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:148:16: error: ‘TRBDF2_3_3_2’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:150:16: error: ‘KVAERNO_4_2_3’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:152:16: error: ‘ARK324L2SA_DIRK_4_2_3’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:154:16: error: ‘CASH_5_2_4’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:156:16: error: ‘CASH_5_3_4’ undeclared (first use in this function); did you mean ‘CASH_5_2_4’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:158:16: error: ‘SDIRK_5_3_4’ undeclared (first use in this function); did you mean ‘SDIRK_2_1_2’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:160:16: error: ‘KVAERNO_5_3_4’ undeclared (first use in this function); did you mean ‘KVAERNO_4_2_3’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:162:16: error: ‘ARK436L2SA_DIRK_6_3_4’ undeclared (first use in this function); did you mean ‘ARK324L2SA_DIRK_4_2_3’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:164:16: error: ‘KVAERNO_7_4_5’ undeclared (first use in this function); did you mean ‘KVAERNO_5_3_4’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:166:16: error: ‘ARK548L2SA_DIRK_8_4_5’ undeclared (first use in this function); did you mean ‘ARK436L2SA_DIRK_6_3_4’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:175:16: error: ‘HEUN_EULER_2_1_2’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:177:16: error: ‘BOGACKI_SHAMPINE_4_2_3’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:179:16: error: ‘ARK324L2SA_ERK_4_2_3’ undeclared (first use in this function); did you mean ‘ARK324L2SA_DIRK_4_2_3’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:181:16: error: ‘ZONNEVELD_5_3_4’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:183:16: error: ‘ARK436L2SA_ERK_6_3_4’ undeclared (first use in this function); did you mean ‘ARK436L2SA_DIRK_6_3_4’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:185:16: error: ‘SAYFY_ABURUB_6_3_4’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:187:16: error: ‘CASH_KARP_6_4_5’ undeclared (first use in this function); did you mean ‘CASH_5_3_4’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:189:16: error: ‘FEHLBERG_6_4_5’ undeclared (first use in this function); did you mean ‘CASH_KARP_6_4_5’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:191:16: error: ‘DORMAND_PRINCE_7_4_5’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:193:16: error: ‘ARK548L2SA_ERK_8_4_5’ undeclared (first use in this function); did you mean ‘ARK548L2SA_DIRK_8_4_5’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:195:16: error: ‘VERNER_8_5_6’ undeclared (first use in this function)
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^
    /home/user/Projects/hmatrix/packages/sundials/Arkode.hsc:197:16: error: ‘FEHLBERG_13_7_8’ undeclared (first use in this function); did you mean ‘FEHLBERG_6_4_5’?
    /home/user/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/template-hsc.h:38:10: note: in definition of macro ‘hsc_const’
         if ((x) < 0)                                      \
              ^

Where could I find information regarding the transition to this version?
Thanks for your time

gcc 10.1 and duplicated definitions

The issue arises from gcc 10.1 changing its default behavior compilation options to use -fno-common. Giving -fcommon fixes the issue.

When using gcc 10.1, the building process would stop with the following report:

[ 63%] Linking Fortran executable ark_bruss
cd /usr/src/packages/BUILD/sundials-5.3.0/build/examples/arkode/F90_serial && /usr/bin/cmake -E cmake_link_script CMakeFiles/ark_bruss.dir/link.txt --verbose=1
/usr/bin/gfortran -L/usr/lib64 -lopenblas_openmp -lgomp -lm -lsuperlumt_d -lsuperlu -lHYPRE_mt -lklu -fPIC -pthread -fopenmp -D__OPENMP -D__PTHREAD -O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -Wl,-z,relro -Wl,-z,now -Wl,--as-needed CMakeFiles/ark_bruss.dir/ark_bruss.f90.o -o ark_bruss ../../../src/arkode/fcmix/libsundials_farkode.a ../../../src/arkode/libsundials_arkode.so.4.3.0 ../../../src/nvector/serial/libsundials_fnvecserial.so.5.3.0 ../../../src/nvector/serial/libsundials_nvecserial.so.5.3.0 -lm /usr/lib64/librt.so -lm
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_dense.c.o):(.bss+0x18): multiple definition of F2C_IDA_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x18): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_dense.c.o):(.bss+0x8): multiple definition of F2C_ARKODE_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x8): first defined here
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_dense.c.o):(.bss+0x20): multiple definition of F2C_CVODE_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x20): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_dense.c.o):(.bss+0x10): multiple definition of F2C_KINSOL_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x10): first defined here
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_dense.c.o):(.bss+0x0): multiple definition of F2C_ARKODE_mass_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x0): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_dense.c.o):(.bss+0x18): multiple definition of F2C_IDA_linsol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x18): first defined here
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_dense.c.o):(.bss+0x8): multiple definition of F2C_ARKODE_linsol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x8): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_dense.c.o):(.bss+0x10): multiple definition of F2C_KINSOL_linsol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x10): first defined here
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_dense.c.o):(.bss+0x20): multiple definition of F2C_CVODE_linsol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x20): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_dense.c.o):(.bss+0x0): multiple definition of F2C_ARKODE_mass_sol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x0): first defined here
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(farknulllinsol.c.o):(.bss+0x8): multiple definition of F2C_ARKODE_linsol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x8): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(farknulllinsol.c.o):(.bss+0x0): multiple definition of F2C_ARKODE_mass_sol'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunlinsol_band.c.o):(.bss+0x0): first defined here
/usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(farknullmatrix.c.o):(.bss+0x8): multiple definition of F2C_ARKODE_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x8): first defined here /usr/lib64/gcc/x86_64-suse-linux/10/../../../../x86_64-suse-linux/bin/ld: ../../../src/arkode/fcmix/libsundials_farkode.a(farknullmatrix.c.o):(.bss+0x0): multiple definition of F2C_ARKODE_mass_matrix'; ../../../src/arkode/fcmix/libsundials_farkode.a(fsunmatrix_band.c.o):(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [examples/arkode/F90_serial/CMakeFiles/ark_bruss.dir/build.make:112: examples/arkode/F90_serial/ark_bruss] Error 1
make[2]: Leaving directory '/usr/src/packages/BUILD/sundials-5.3.0/build'
make[1]: *** [CMakeFiles/Makefile2:5060: examples/arkode/F90_serial/CMakeFiles/ark_bruss.dir/all] Error 2
make[1]: Leaving directory '/usr/src/packages/BUILD/sundials-5.3.0/build'
make: *** [Makefile:164: all] Error 2
make: Leaving directory '/usr/src/packages/BUILD/sundials-5.3.0/build'
error: Bad exit status from /var/tmp/rpm-tmp.UqFLKO (%install)

It should be noted that, at least, fsunmatrix_dense.c, fsunmatrix_sparse.c and fsunmatrix_band.c share clashing definitions of global variables and, perhaps, should be changed by moving the definitions to a separated file.

Best regards.

Trouble Compiling with Visual Studio and Intel Fortran

Hello dear developers,

Summary:
I am working for a University project where I have access to Windows 10, Visual studio 2013 and Intel Parallel studio 2017 or Visual Studio 2019 Community along Intel OneApi (includes Fortran Classic 2021).

For about 1 month now I am trying to compile the CVode with Fortran Interface, from Sundials 5.7 package. I hope it has thread-safely even when the Fortran interface is used. Anyways after lots of effort I managed to compile and build CVode. Though when I run the Fortran examples in debug mode the program crashes.

The steps I followed for compilation:

  1. I am using Cmake-gui version 3.21.1 (have tried this with version 3.20 too). I properly start Cmake and point it to the source, build and install directories. Everything seems normal. Cmake locates my compiler C properly. Here is some output from Cmake:
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
The C compiler identification is MSVC 19.29.30040.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdint.h
Looking for stdint.h - found
Looking for stddef.h
Looking for stddef.h - found
Check size of int64_t
Check size of int64_t - done
Using int64_t for indices
Looking for _POSIX_TIMERS
Looking for _POSIX_TIMERS - not found
Performing Test COMPILER_HAS_DEPRECATED_ATTR
Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
Performing Test COMPILER_HAS_DEPRECATED
Performing Test COMPILER_HAS_DEPRECATED - Success
Added NVECTOR_SERIAL module
Added NVECTOR_MANYVECTOR module
Added SUNMATRIX_BAND module
.
.
.

  1. The Cmake finds all the Sundial 5.7 source (Arcode, CVode....). I select only the CVode and Build_Fortran_Module_Interface and I deselect everything that has to do with testing and examples. Cmake now locates the Intel compiler properly:
Using int64_t for indices
The Fortran compiler identification is Intel 2021.2.0.20210228
Detecting Fortran compiler ABI info
Detecting Fortran compiler ABI info - done
Determine Intel Fortran Compiler Implicit Link Path
Determine Intel Fortran Compiler Implicit Link Path - done
Check for working Fortran compiler: C:/Program Files (x86)/Intel/oneAPI/compiler/2021.2.0/windows/bin/intel64/ifort.exe - skipped
Checking whether C:/Program Files (x86)/Intel/oneAPI/compiler/2021.2.0/windows/bin/intel64/ifort.exe supports Fortran 90
Checking whether C:/Program Files (x86)/Intel/oneAPI/compiler/2021.2.0/windows/bin/intel64/ifort.exe supports Fortran 90 - yes
Checking whether C:/Program Files (x86)/Intel/oneAPI/compiler/2021.2.0/windows/bin/intel64/ifort.exe supports F2003
Checking whether C:/Program Files (x86)/Intel/oneAPI/compiler/2021.2.0/windows/bin/intel64/ifort.exe supports F2003 -- yes
Added NVECTOR_SERIAL module
Added NVECTOR_SERIAL F2003 interface
Added NVECTOR_MANYVECTOR module
Added NVECTOR_MANYVECTOR F2003 Interface
Added SUNMATRIX_BAND module
Added SUNMATRIX_BAND F2003 interface
Added SUNMATRIX_DENSE module
.
.
.
  1. After pressing generate, the Visual studio 2019 project is being build. So far so good. The problems start after I open the project and try to build the "ALL_BUILD" target. The compiling stops with errors of the type:
Error	LNK1181	cannot open input file 'C:\Users\....\build_dir\src\sunmatrix\band\fmod\sundials_fsunmatrixband_mod_obj_static.dir\Debug\fsunmatrix_band_mod.f90.obj'	sundials_fsunmatrixband_mod_static	C:\Users\....\build_dir\src\sunmatrix\band\fmod\LINK	1	
  1. The reason for this kind of errors after lots of search, is caused because the visual studio 2013 & 2019 cant handle a mix C and Fortran files in same project. As very well stated here in order for the compilation to succeed a Fortran project containing all .f90 files must be created and then added to the current project created from Cmake in Build_dir. Furthermore all "....._mod_static" targets must have all their "..._mod.f90.obj" objects change their location and point to the output directory of the Fortran project created above. For example the "sundials_fcvode_mod_static" contains many objects like "fcvode_mod.f90.obj", fnvector_serial_mod.f90.obj and so on. The location of these objects is changed to the output of the custom Fortran project.

  2. A trick needed above is that all .f90 files must be renamed to duplicate their extension. For example the the fcvode_mod.f90 must be renamed to fcvode_mod.f90.f90 . This is needed because the produced fortran obj files retain inside them ".f90" and be in form "fcvode_mod.f90.obj". This is how the Cmake writes the ALL_BUILD.vcxproj file.

  3. After doing all the above the code All_Build target runs well and compiles. Though as expected the Cmake_Fortan_Flags: "/W1 /nologo /fpp /libs:dll /threads" found in the Cmake are wrongly passed to cl compiler and produce warnings of type
    cl : command line warning D9002: ignoring unknown option '/fpp' . I assume these warnings can be ignored. A bigger output of All_Build target output can be seen:

Rebuild started...
1>------ Rebuild All started: Project: ZERO_CHECK, Configuration: Release x64 ------
1>Checking Build System
2>------ Rebuild All started: Project: sundials_generic_obj_static, Configuration: Release x64 ------
2>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sundials/CMakeLists.txt
2>sundials_band.c
2>sundials_dense.c
2>sundials_direct.c
2>sundials_futils.c
2>sundials_iterative.c
2>sundials_linearsolver.c
2>sundials_math.c
2>sundials_matrix.c
2>sundials_memory.c
2>sundials_nonlinearsolver.c
2>sundials_nvector.c
2>sundials_nvector_senswrapper.c
2>sundials_version.c
2>Generating Code...
2>sundials_generic_obj_static.vcxproj -> C:\Users\...\build_dir\src\sundials\sundials_generic_obj_static.dir\Release\sundials_generic_obj_static.lib
3>------ Rebuild All started: Project: sundials_generic_static, Configuration: Release x64 ------
4>------ Rebuild All started: Project: sundials_sunmatrixdense_obj_static, Configuration: Release x64 ------
5>------ Rebuild All started: Project: sundials_sunmatrixband_obj_static, Configuration: Release x64 ------
6>------ Rebuild All started: Project: sundials_sunmatrixsparse_obj_static, Configuration: Release x64 ------
7>------ Rebuild All started: Project: sundials_sunnonlinsolfixedpoint_obj_static, Configuration: Release x64 ------
8>------ Rebuild All started: Project: sundials_sunlinsolspfgmr_obj_static, Configuration: Release x64 ------
9>------ Rebuild All started: Project: sundials_sunnonlinsolnewton_obj_static, Configuration: Release x64 ------
10>------ Rebuild All started: Project: sundials_sunlinsolspgmr_obj_static, Configuration: Release x64 ------
11>------ Rebuild All started: Project: sundials_nvecserial_obj_static, Configuration: Release x64 ------
12>------ Rebuild All started: Project: sundials_sunlinsolpcg_obj_static, Configuration: Release x64 ------
13>------ Rebuild All started: Project: sundials_sunlinsolspbcgs_obj_static, Configuration: Release x64 ------
14>------ Rebuild All started: Project: sundials_sunlinsolsptfqmr_obj_static, Configuration: Release x64 ------
3>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sundials/CMakeLists.txt
3>sundials_generic_static.vcxproj -> C:\Users\...\build_dir\src\sundials\Release\sundials_generic.lib
15>------ Rebuild All started: Project: sundials_fgeneric_mod_obj_static, Configuration: Release x64 ------
4>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunmatrix/dense/CMakeLists.txt
4>sunmatrix_dense.c
5>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunmatrix/band/CMakeLists.txt
5>sunmatrix_band.c
6>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunmatrix/sparse/CMakeLists.txt
12>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunlinsol/pcg/CMakeLists.txt
5>C:\Users\...\cvode-5.7.0\src\sunmatrix\band\sunmatrix_band.c(401,66): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
5>C:\Users\...\cvode-5.7.0\src\sunmatrix\band\sunmatrix_band.c(402,31): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
4>C:\Users\...\cvode-5.7.0\src\sunmatrix\dense\sunmatrix_dense.c(312,25): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
4>C:\Users\...\cvode-5.7.0\src\sunmatrix\dense\sunmatrix_dense.c(313,31): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
7>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunnonlinsol/fixedpoint/CMakeLists.txt
10>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunlinsol/spgmr/CMakeLists.txt
9>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunnonlinsol/newton/CMakeLists.txt
8>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunlinsol/spfgmr/CMakeLists.txt
14>Building Custom Rule C:/Users/.../cvode-5.7.0/src/sunlinsol/sptfqmr/CMakeLists.txt
12>sunlinsol_pcg.c
6>sunmatrix_sparse.c
12>C:\Users\...\cvode-5.7.0\src\sunlinsol\pcg\sunlinsol_pcg.c(523,24): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
12>C:\Users\...\cvode-5.7.0\src\sunlinsol\pcg\sunlinsol_pcg.c(524,24): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
11>Building Custom Rule C:/Users/.../cvode-5.7.0/src/nvector/serial/CMakeLists.txt
6>C:\Users\...\cvode-5.7.0\src\sunmatrix\sparse\sunmatrix_sparse.c(1022,23): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
6>C:\Users\...\cvode-5.7.0\src\sunmatrix\sparse\sunmatrix_sparse.c(1023,41): warning C4244: '=': conversion from 'sunindextype' to 'long', possible loss of data
9>sunnonlinsol_newton.c
10>sunlinsol_spgmr.c
14>sunlinsol_sptfqmr.c
.
.
.

7>sundials_sunnonlinsolfixedpoint_obj_static.vcxproj -> C:\Users\...\build_dir\src\sunnonlinsol\fixedpoint\sundials_sunnonlinsolfixedpoint_obj_static.dir\Release\sundials_sunnonlinsolfixedpoint_obj_static.lib
10>Done building project "sundials_sunlinsolspgmr_obj_static.vcxproj".
22>------ Rebuild All started: Project: sundials_sunlinsolspfgmr_static, Configuration: Release x64 ------
23>------ Rebuild All started: Project: sundials_sunnonlinsolfixedpoint_static, Configuration: Release x64 ------
24>------ Rebuild All started: Project: sundials_sunlinsolspgmr_static, Configuration: Release x64 ------
15>cl : command line warning D9002: ignoring unknown option '/fpp'
15>cl : command line warning D9002: ignoring unknown option '/libs:dll'
15>cl : command line warning D9002: ignoring unknown option '/threads'
.
.
.
1>Building Custom Rule C:/Users/.../cvode-5.7.0/src/cvode/CMakeLists.txt
61>sundials_cvode_static.vcxproj -> C:\Users\...\build_dir\src\cvode\Release\sundials_cvode.lib
60>sundials_fsunlinsolband_mod_static.vcxproj -> C:\Users\...\build_dir\src\sunlinsol\band\fmod\Release\sundials_fsunlinsolband_mod.lib
62>sundials_fsunlinsoldense_mod_static.vcxproj -> C:\Users\...\build_dir\src\sunlinsol\dense\fmod\Release\sundials_fsunlinsoldense_mod.lib
63>------ Rebuild All started: Project: sundials_fcvode_mod_obj_static, Configuration: Release x64 ------
63>Building Custom Rule C:/Users/.../cvode-5.7.0/src/cvode/fmod/CMakeLists.txt
63>cl : command line warning D9002: ignoring unknown option '/fpp'
63>cl : command line warning D9002: ignoring unknown option '/libs:dll'
63>cl : command line warning D9002: ignoring unknown option '/threads'
63>fcvode_mod.c
63>sundials_fcvode_mod_obj_static.vcxproj -> C:\Users\...\build_dir\src\cvode\fmod\sundials_fcvode_mod_obj_static.dir\Release\sundials_fcvode_mod_obj_static.lib
63>Done building project "sundials_fcvode_mod_obj_static.vcxproj".
64>------ Rebuild All started: Project: sundials_fcvode_mod_static, Configuration: Release x64 ------
64>Building Custom Rule C:/Users/.../cvode-5.7.0/src/cvode/fmod/CMakeLists.txt
64>sundials_fcvode_mod_static.vcxproj -> C:\Users\...\build_dir\src\cvode\fmod\Release\sundials_fcvode_mod.lib
65>------ Rebuild All started: Project: ALL_BUILD, Configuration: Release x64 ------
65>Building Custom Rule C:/Users/.../cvode-5.7.0/CMakeLists.txt
========== Rebuild All: 65 succeeded, 0 failed, 0 skipped ==========
  1. Time to build the Install target. A necessary step that is needed is that a folder inside the "build_dir" must be created with the name "Fortran_Static". Here all mod files found in the custom Fortran project must be copied. This is a required step since at the last step of the INSTALL target the data of "Fortran_Static" are copied to the "Install_dir/fortran".

  2. A word of caution its good to have the "Install_dir" in a directory for which the user has access to write. The "c:\program files (x86)" is not one of them. In which case the user might have to call a cmd.exe with admin rights and the call "msbuild INSTALL.vcxproj".

  3. After all the above steps I got the Install_dir with the folder containing "Fortran", "Include" and "lib" folders. The real problem starts now. After including the install_dir properly to one of the included examples (cv_analytic_sys_dns_f2003.f90) I got the following erroneous output:

 Finished initialization, starting time steps

        t           y1           y2           y3
 ------------------------------------------------------
   0.00000E+00  1.00000E+00  1.00000E+00  1.00000E+00
forrtl: severe (408): fort: (10): Subscript #1 of the array YVEC has value 2 which is greater than the upper bound of 1

Image              PC                Routine            Line        Source
libifcoremdd.dll   00007FFCBC2C736C  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A37214CE  RhsFn                     109  Example1.f90
testing_CVode.exe  00007FF7A3735700  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A3724DDA  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A372332B  MAIN__                    237  Example1.f90
testing_CVode.exe  00007FF7A3729E4E  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A372DB39  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A372DA5E  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A372D91E  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF7A372DBAE  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFD27C37034  Unknown               Unknown  Unknown
ntdll.dll          00007FFD27F42651  Unknown               Unknown  Unknown

  1. I do note that that when I configured the Cmake i removed all tests and examples so i could reduce the amount of errors and warning so I could finish the compilation. So I manually created a Fortran project for "examples/cvode/F2003_serial/cv_analytic_sys_dns_f2003.f90" with the name "testing_CVode". The crash as shown above indicates the the "yvec" is an array that contains one element only (with value "yvec(1)=1") but there is a line of code in which more elements of it are requested see "yvec(1:neq)" in fvec = matmul(Amat, yvec(1:neq)). Furthermore "yvec" gets its size from a call to the "FN_VGetArrayPointer".

yvec => FN_VGetArrayPointer(sunvec_y).

  1. A part of the code is shown below:
 integer(c_int) function RhsFn(tn, sunvec_y, sunvec_f, user_data) &
       result(ierr) bind(C,name='RhsFn')

    !======= Inclusions ===========
    use, intrinsic :: iso_c_binding
    use fsundials_nvector_mod

    !======= Declarations =========
    implicit none

    ! calling variables
    real(c_double), value :: tn        ! current time
    type(N_Vector)        :: sunvec_y  ! solution N_Vector
    type(N_Vector)        :: sunvec_f  ! rhs N_Vector
    type(c_ptr),    value :: user_data ! user-defined data

    ! pointers to data in SUNDIALS vectors
    real(c_double), pointer :: yvec(:)
    real(c_double), pointer :: fvec(:)

    ! ODE system matrix
    real(c_double) :: Amat(neq,neq)

    !======= Internals ============

    ! get data arrays from SUNDIALS vectors
    yvec => FN_VGetArrayPointer(sunvec_y)
    fvec => FN_VGetArrayPointer(sunvec_f)

    ! fill A matrix (column major ordering)
    Amat = reshape([&
         lamda/4.d0 - 23.d0/40.d0, lamda/4.d0 + 21.d0/40, lamda/2.d0 + 1.d0/20.d0,   &
         lamda/4.d0 - 3.d0/40.d0,  lamda/4.d0 + 1.d0/40,  lamda/2.d0 + 1.d0/20.d0,   &
         lamda/4.d0 + 13.d0/40.d0, lamda/4.d0 - 11.d0/40, lamda/2.d0 - 1.d0/20.d0 ], &
         [3,3])

    ! fill RHS vector f(t,y) = A*y
    fvec = matmul(Amat, yvec(1:neq))

    ! return success
    ierr = 0
    return

  end function RhsFn

  1. It seems that the "FN_VGetArrayPointer()" function returns properly only the first element of the array and fails to do the same for the rest. If the same example is compiled in release mode and not debug then the error is ignored and the output is:
 Finished initialization, starting time steps

        t           y1           y2           y3
 ------------------------------------------------------
   0.00000E+00  1.00000E+00  1.00000E+00  1.00000E+00
   5.00000E-03  7.03275E-01  7.06270E-01  4.10045E-01
   1.00000E-02  5.22668E-01  5.28650E-01  5.23171E-02
   1.50000E-02  4.12493E-01  4.21452E-01 -1.64556E-01
   2.00000E-02  3.45038E-01  3.56966E-01 -2.95998E-01
   2.50000E-02  3.03496E-01  3.18384E-01 -3.75623E-01
   3.00000E-02  2.77673E-01  2.95512E-01 -4.23820E-01
   3.50000E-02  2.61385E-01  2.82166E-01 -4.52956E-01
   4.00000E-02  2.50882E-01  2.74596E-01 -4.70529E-01
   4.50000E-02  2.43891E-01  2.70529E-01 -4.81091E-01
   5.00000E-02  2.39030E-01  2.68584E-01 -4.87399E-01

  General Solver Stats:
    Total internal steps taken =       73
    Total rhs function calls   =      105
    Num lin solver setup calls =       21
    Num error test failures    =        6
    Last method order          =        5
    Next method order          =        5
    First internal step size   = 6.86623E-06
    Last internal step size    = 1.52517E-03
    Next internal step size    = 1.52517E-03
    Current internal time      = 5.10351E-02
    Num nonlinear solver iters =      102
    Num nonlinear solver fails =        0
    Num Jacobian evaluations   =        2

  1. Which is exactly the expected output shown in the out file . Thusly the Cvode ran properly under release mode but not under debug. Moreover it seems that the "FN_VGetArrayPointer()" function shows properly the head of the array, but it ignores the rest of the body.

  2. If I were to run the cv_analytic_fp_f2003.f90 example that has only one ode equation to solve and not a system of equations( as above) then no error will occur in the debug mode. The "yvec" properly is array with only one value. Obviously all the examples that have more than one ode to solve crash as also the test "test_fnvector_serial_mod" crashes. The test contains the files "test_fnvector_serial_mod.f90", "test_nvector.f90", "test_utilities.f90" and is part of the ALL_Build (If Fortran tests are included in Cmake). Some small output of the test_fnvector_serial is:

 Serial N_Vector Fortran 2003 interface test
 SUCCESS: smoke tests passed
 PASSED test -- FN_VMake
forrtl: severe (408): fort: (10): Subscript #1 of the array XDATA has value 2 which is greater than the upper bound of 1

Image              PC                Routine            Line        Source
testing_CVode.exe  00007FF6E1FA59AC  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF6E1F931AF  CHECK_ANS                 163  test_fnvector_serial_mod.f90
testing_CVode.exe  00007FF6E1F9168B  TEST_FNVECTOR_mp_          79  test_nvector.f90
testing_CVode.exe  00007FF6E1F92F07  TEST_NVECTOR_SERI         137  test_fnvector_serial_mod.f90
testing_CVode.exe  00007FF6E1F93550  MAIN__                    204  test_fnvector_serial_mod.f90
testing_CVode.exe  00007FF6E1FAEC8E  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF6E2043389  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF6E20432AE  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF6E204316E  Unknown               Unknown  Unknown
testing_CVode.exe  00007FF6E20433FE  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFD27C37034  Unknown               Unknown  Unknown
ntdll.dll          00007FFD27F42651  Unknown               Unknown  Unknown
  1. To catch some questions before asked, I pay attention to build and release modes in Fortran and All_build projects to be compatible (despite showing output from a release mode and running example in debug mode). Also the Fortran project is in 64bit mode well.

  2. So please, I have spent too much time trying to compile Sundials/CVode under Visual studio with Intel Fortran environment, any useful input on how to fix the "Yvec" size would be greatly appreciated!!!!

Sundials issue

My code/packages were working perfectly on my old system. Now I can't use the DifferentialEquations package. I've found a minimal example when testing the Sundials package. I get the following:

(@JuliaPro_v1.5.2-1) pkg> test Sundials
Testing Sundials
Status /private/var/folders/mj/rdgm47714771kg38f8tsd23h0000gn/T/jl_Pz1A7h/Project.toml
[fa961155] CEnum v0.4.1
[864edb3b] DataStructures v0.18.8
[2b5f629d] DiffEqBase v6.48.2
[9fdde737] DiffEqOperators v4.14.0
[a077e3f3] DiffEqProblemLibrary v4.9.1
[f6369f11] ForwardDiff v0.10.12
[189a3867] Reexport v0.2.0
[c3572dad] Sundials v4.3.0
[fb77eaff] Sundials_jll v5.2.0+1
[8f399da3] Libdl
[37e2e46d] LinearAlgebra
[56ddb016] Logging
[2f01184e] SparseArrays
[8dfed614] Test
Status /private/var/folders/mj/rdgm47714771kg38f8tsd23h0000gn/T/jl_Pz1A7h/Manifest.toml
[c3fe647b] AbstractAlgebra v0.11.1
[79e6a3ab] Adapt v2.3.0
[ec485272] ArnoldiMethod v0.0.4
[4fba245c] ArrayInterface v2.13.7
[4c555306] ArrayLayouts v0.4.10
[56f22d72] Artifacts v1.3.0
[15f4f7f2] AutoHashEquals v0.2.0
[aae01518] BandedMatrices v0.15.25
[8e7c35d0] BlockArrays v0.12.14
[ffab5731] BlockBandedMatrices v0.9.5
[fa961155] CEnum v0.4.1
[a603d957] CanonicalTraits v0.2.3
[479239e8] Catalyst v5.1.1
[134e5e36] Catlab v0.9.2
[d360d2e6] ChainRulesCore v0.9.17
[3da002f7] ColorTypes v0.10.9
[5ae59095] Colors v0.12.4
[861a8166] Combinatorics v1.0.2
[bbf7d656] CommonSubexpressions v0.3.0
[34da2185] Compat v3.23.0
[e66e0078] CompilerSupportLibraries_jll v0.3.4+0
[a81c6b42] Compose v0.9.1
[187b0558] ConstructionBase v1.0.0
[adafc99b] CpuId v0.2.2
[a8cc5b0e] Crayons v4.0.4
[9a962f9c] DataAPI v1.4.0
[864edb3b] DataStructures v0.18.8
[e2d170a0] DataValueInterfaces v1.0.0
[2b5f629d] DiffEqBase v6.48.2
[c894b116] DiffEqJump v6.10.1
[9fdde737] DiffEqOperators v4.14.0
[a077e3f3] DiffEqProblemLibrary v4.9.1
[163ba53b] DiffResults v1.0.2
[b552c78f] DiffRules v1.0.1
[ffbed154] DocStringExtensions v0.8.3
[1a297f60] FillArrays v0.9.7
[53c48c17] FixedPointNumbers v0.8.4
[59287772] Formatting v0.4.1
[f6369f11] ForwardDiff v0.10.12
[069b7b12] FunctionWrappers v1.1.1
[6b9d7cbe] GeneralizedGenerated v0.2.8
[615f187c] IfElse v0.1.0
[d25df0c9] Inflate v0.1.2
[c8e1da08] IterTools v1.3.0
[42fd0dbc] IterativeSolvers v0.8.4
[82899510] IteratorInterfaceExtensions v1.0.0
[692b3bcd] JLLWrappers v1.1.3
[682c06a0] JSON v0.21.1
[b14d175d] JuliaVariables v0.2.3
[b964fa9f] LaTeXStrings v1.2.0
[2ee39098] LabelledArrays v1.3.0
[23fbe1c1] Latexify v0.14.2
[5078a376] LazyArrays v0.18.1
[d7e5e226] LazyBandedMatrices v0.3.6
[94ce4f54] Libiconv_jll v1.16.0+7
[093fc24a] LightGraphs v1.3.0
[9c8b4983] LightXML v0.9.0
[bdcacae8] LoopVectorization v0.8.26
[d8e11817] MLStyle v0.4.6
[1914dd2f] MacroTools v0.5.6
[a3b82374] MatrixFactorizations v0.6.1
[442fdcdd] Measures v0.3.1
[961ee093] ModelingToolkit v3.21.0
[46d2c3a1] MuladdMacro v0.2.2
[872c559c] NNlib v0.7.5
[77ba4419] NaNMath v0.3.4
[71a1bf82] NameResolution v0.1.5
[6fe1bfb0] OffsetArrays v1.4.0
[4536629a] OpenBLAS_jll v0.3.9+5
[efe28fd5] OpenSpecFun_jll v0.5.3+4
[bac558e1] OrderedCollections v1.3.2
[d96e819e] Parameters v0.12.1
[69de0a69] Parsers v1.0.11
[e409e4f3] PoissonRandom v0.4.0
[8162dcfd] PrettyPrint v0.2.0
[08abe8d2] PrettyTables v0.9.1
[fb686558] RandomExtensions v0.4.2
[e6cf234a] RandomNumbers v1.4.0
[3cdcf5f2] RecipesBase v1.1.0
[731186ca] RecursiveArrayTools v2.7.2
[f2c3362d] RecursiveFactorization v0.1.4
[189a3867] Reexport v0.2.0
[ae029012] Requires v1.1.0
[f2b01f46] Roots v1.0.5
[21efa798] SIMDPirates v0.8.25
[476501e8] SLEEFPirates v0.5.5
[1bc83da4] SafeTestsets v0.0.1
[699a6c99] SimpleTraits v0.9.3
[276daf66] SpecialFunctions v0.10.3
[90137ffa] StaticArrays v0.12.5
[09ab397b] StructArrays v0.4.4
[bea87d4a] SuiteSparse_jll v5.4.1+0
[c3572dad] Sundials v4.3.0
[fb77eaff] Sundials_jll v5.2.0+1
[d1185830] SymbolicUtils v0.5.2
[3783bdb8] TableTraits v1.0.0
[bd369af6] Tables v1.1.0
[a759f4b9] TimerOutputs v0.5.7
[a2a6695c] TreeViews v0.3.0
[3a884ed6] UnPack v1.0.2
[1986cc42] Unitful v1.5.0
[3d5dd08c] VectorizationBase v0.12.33
[02c8fc9c] XML2_jll v2.9.10+3
[83775a58] Zlib_jll v1.2.11+18
[700de1a5] ZygoteRules v0.2.0
[2a0f44e3] Base64
[ade2ca70] Dates
[8bb1440f] DelimitedFiles
[8ba89e20] Distributed
[b77e0a4c] InteractiveUtils
[76f85450] LibGit2
[8f399da3] Libdl
[37e2e46d] LinearAlgebra
[56ddb016] Logging
[d6f4376e] Markdown
[a63ad114] Mmap
[44cfe95a] Pkg
[de0858da] Printf
[3fa0cd96] REPL
[9a3f8284] Random
[ea8e919c] SHA
[9e88b42a] Serialization
[1a1011a3] SharedArrays
[6462fe0b] Sockets
[2f01184e] SparseArrays
[10745b16] Statistics
[4607b0f0] SuiteSparse
[8dfed614] Test
[cf7118a7] UUIDs
[4ec0a83e] Unicode
ERROR: LoadError: InitError: could not load library "/Users/awinick/.julia/artifacts/e7d0b91affa3d2eba54ffcb65b229444ec190329/lib/libcholmod.3.0.13.dylib"
dlopen(/Users/awinick/.julia/artifacts/e7d0b91affa3d2eba54ffcb65b229444ec190329/lib/libcholmod.3.0.13.dylib, 1): Library not loaded: @rpath/openblas64_.dylib
Referenced from: /Users/awinick/.julia/artifacts/e7d0b91affa3d2eba54ffcb65b229444ec190329/lib/libcholmod.3.0.13.dylib
Reason: image not found
Stacktrace:
[1] dlopen(::String, ::UInt32; throw_error::Bool) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
[2] dlopen(::String, ::UInt32) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Libdl/src/Libdl.jl:109
[3] macro expansion at /Users/awinick/.julia/packages/JLLWrappers/KuIwt/src/products/library_generators.jl:61 [inlined]
[4] init() at /Users/awinick/.julia/packages/SuiteSparse_jll/mfOg3/src/wrappers/x86_64-apple-darwin.jl:45
[5] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:697
[6] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:782
[7] _tryrequire_from_serialized(::Base.PkgId, ::UInt64, ::String) at ./loading.jl:712
[8] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:771
[9] _require(::Base.PkgId) at ./loading.jl:1007
[10] require(::Base.PkgId) at ./loading.jl:928
[11] require(::Module, ::Symbol) at ./loading.jl:923
[12] include(::Function, ::Module, ::String) at ./Base.jl:380
[13] include(::Module, ::String) at ./Base.jl:368
[14] top-level scope at none:2
[15] eval at ./boot.jl:331 [inlined]
[16] eval(::Expr) at ./client.jl:467
[17] top-level scope at ./none:3
during initialization of module SuiteSparse_jll
in expression starting at /Users/awinick/.julia/packages/Sundials/xAoTr/src/Sundials.jl:45
ERROR: LoadError: Failed to precompile Sundials [c3572dad-4567-51f8-b174-8c6c989267f4] to /Users/awinick/.julia/compiled/v1.5/Sundials/j8Ppj_4o0Jp.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1305
[3] _require(::Base.PkgId) at ./loading.jl:1030
[4] require(::Base.PkgId) at ./loading.jl:928
[5] require(::Module, ::Symbol) at ./loading.jl:923
[6] include(::String) at ./client.jl:457
[7] top-level scope at none:6
in expression starting at /Users/awinick/.julia/packages/Sundials/xAoTr/test/runtests.jl:1
ERROR: Package Sundials errored during testing

Memory leak in CVodeSensSVtolerances

Hi! Thanks for developing this package.

I have a program calling sundials and valgrind tells me it is leaking memory. After building sundials with the debug symbols, this line seems to be the culprit:

cv_mem->cv_atolSmin0 = (booleantype *)malloc(cv_mem->cv_Ns*sizeof(booleantype));

And indeed, it seems to me there is no free of "cv_atolSmin0".

Let me know if you need any more help.

minor leak in test

Caught with asan, looks like buf* is never free'd (two occurrences)?

sundials-5.4.0/examples/nvector/test_nvector.c:

   5293:  buf = (realtype*) malloc((size_t)size);
   5356:  buf = (realtype*) malloc((size_t)size);

(adding free(buf) before return allows test to pass at least).

Undefined reference in sunlinsol_lapackband on Windows with mingw

When updating sundials to version 5.2.0 for OpenModelica we noticed linking errors while compiling sundials on Windows with mingw.

How to reproduce

Our call to compile sundials looks like this:

$ cd 3rdParty/sundials/build && CC="gcc" CXX="g++" CFLAGS="-g -O2 -falign-functions" CXXFLAGS="" CPPFLAGS="" LDFLAGS="" /c/OMDev/bin/cmake/bin/cmake .. -G "MSYS Makefiles" -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DCMAKE_INSTALL_PREFIX="`pwd`" -DKLU_ENABLE:Bool=ON -DKLU_LIBRARY_DIR="/d/workspace/OpenModelica/build/lib/omc" -DKLU_INCLUDE_DIR="/d/workspace/OpenModelica/build/include/omc/c/suitesparse/Include/" -DEXAMPLES_ENABLE_C:Bool=OFF -DEXAMPLES_ENABLE_CXX:Bool=OFF -DCMAKE_C_FLAGS="-g -O2 -falign-functions -lm -L /d/workspace/OpenModelica/build/lib/omc"  -DIS_MINGW32=OFF -DIS_MINGW64=ON -DSUITESPARSECONFIG_LIBRARY="" -DLAPACK_ENABLE:Bool=ON
$ make -C 3rdParty/sundials/build install

Error message:

D:/workspace/OpenModelica/OMCompiler/3rdParty/sundials/src/sunlinsol/lapackband/sunlinsol_lapackband.c:78: undefined reference to `__imp_SUNLinSolNewEmpty'
D:/workspace/OpenModelica/OMCompiler/3rdParty/sundials/src/sunlinsol/lapackband/sunlinsol_lapackband.c:106: undefined reference to `__imp_SUNLinSolFree'

If needed I can provide the whole build log, but this should be the main error.

Our fix

A colleague found the error and fixed it in our copy.
Credits to @adrpo.

$ git diff
diff --git a/sundials/src/sunlinsol/lapackband/CMakeLists.txt b/sundials/src/sunlinsol/lapackband/CMakeLists.txt
index 2bb5a4ef..b736ed09 100644
--- a/sundials/src/sunlinsol/lapackband/CMakeLists.txt
+++ b/sundials/src/sunlinsol/lapackband/CMakeLists.txt
@@ -74,6 +74,9 @@ if(BUILD_SHARED_LIBS)
   target_link_libraries(sundials_sunlinsollapackband_shared
     PUBLIC sundials_sunmatrixband_shared ${LAPACK_LIBRARIES})
+  target_compile_definitions(sundials_sunlinsollapackband_shared
+    PUBLIC -DBUILD_SUNDIALS_LIBRARY)
+
   install(TARGETS sundials_sunlinsollapackband_shared
     DESTINATION ${CMAKE_INSTALL_LIBDIR})

Compare OpenModelica/OMCompiler-3rdParty@39075d0

System

Windows 10, 64-bit with msys2+mingw32+mingw64 from https://openmodelica.org/git/OMDev.git. For more details on the build environment see https://github.com/OpenModelica/OMCompiler/blob/master/README-OMDev-MINGW.md.

Example file build error -LNK1107 invalid or corrupt file: cannot read at 0x340 ida_example C:\Program Files (x86)\sundials\lib\sundials_arkode.dll

I was able to build/install sundials 5.3.0 in VS 2019 on windows 10 system. I followed instruction on the website.
https://computing.llnl.gov/projects/sundials/faq

However when I tried to run one of examples, idaRoberts_dns.c, I got the error:

LNK1107 invalid or corrupt file: cannot read at 0x340 ida_example C:\Program Files (x86)\sundials\lib\sundials_arkode.dll

I checked the library path and confirmed the dll file in the folder. Also I added additional include directories, set sundials library dependencies in VS project.

Can you help how to fix this issue ?

Thanks

sundials-3.1.2 fails with hypre-2.22.1: undefined reference to `hypre_ParVectorSetPartitioningOwner'

[ 51%] Linking C executable cvsRoberts_dns
cd /disk-samsung/freebsd-ports/math/sundials/work/.build/examples/cvodes/serial && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/cvsRoberts_dns.dir/link.txt --verbose=1
/usr/bin/cc -O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -fno-strict-aliasing  -fstack-protector-strong CMakeFiles/cvsRoberts_dns.dir/cvsRoberts_dns.c.o -o cvsRoberts_dns  -Wl,-rpath,/disk-samsung/freebsd-ports/math/sundials/work/.build/src/cvodes:/disk-samsung/freebsd-ports/math/sundials/work/.build/src/nvec_ser ../../../src/cvodes/libsundials_cvodes.so.3.1.2 ../../../src/nvec_ser/libsundials_nvecserial.so.3.1.2 -lm -lrt -lm 
--- examples/cvode/parhyp/CMakeFiles/cvAdvDiff_non_ph.dir/all ---
/usr/local/bin/ld: ../../../src/nvec_parhyp/libsundials_nvecparhyp.so.3.1.2: undefined reference to `hypre_ParVectorSetPartitioningOwner'
--- examples/cvodes/serial/CMakeFiles/cvsRoberts_dns.dir/all ---
[ 51%] Built target cvsRoberts_dns
--- examples/cvodes/serial/CMakeFiles/cvsFoodWeb_ASAi_kry.dir/all ---
/usr/bin/make  -f examples/cvodes/serial/CMakeFiles/cvsFoodWeb_ASAi_kry.dir/build.make examples/cvodes/serial/CMakeFiles/cvsFoodWeb_ASAi_kry.dir/depend
--- examples/cvode/parhyp/CMakeFiles/cvAdvDiff_non_ph.dir/all ---
cc: error: linker command failed with exit code 1 (use -v to see invocation)
--- examples/cvodes/serial/CMakeFiles/cvsFoodWeb_ASAi_kry.dir/all ---
--- examples/cvodes/serial/CMakeFiles/cvsFoodWeb_ASAi_kry.dir/depend ---

Segmentation fault in CVAfindIndex

I am using the adjoint sensitivity analysis functionality of sunodes, and sporadically I get segmentation faults during the backward pass. Unfortunately I could not reproduce this with a small example so far, but the coredump seems to indicate to me, that CVAfindIndex tries to access checkpoints that do not exist relatively near t0 of the forward problem, in a region where the solver is making (ridiculously?) small steps.
Screenshot from 2020-02-26 11-18-52
It seems that CVAfindIndex is trying to find a checkpoint for t = 161.33623519238427 but the largest of the 600 entries in ca_mem->dt_mem has only t = 161.33623519238293.

The details of how I'm using sundials are somewhat hidden in a python wrapper and pymc3 (I'm sampling the parameter space with an hamiltonian sampler), but here is a rough outline of what I'm doing:

  • Initialize forward and backward solvers with polynomial interpolation and checkpoints every 600
  • Repeat (a lot):
    • Change user_data
    • Call CVodeReInit and CVodeAdjReInit
    • Run forward solver
    • Call CVodeReInitB, CVodeQuadReInitB and CVodeBsolve repeatedly, as the adjoint rhs is not continuous.

The t of the segfault is nowhere near the discontinuities of the rhs, the first one of those is at t ~ 12000.

The source for the solver calls is here: https://github.com/aseyboldt/sunode/blob/master/sunode/solver.py#L365

I can also provide the coredump if that is helpful.

Error/warning reporting within MPI ranks

Hello, we use SUNDIALS in our application PeleC (https://github.com/AMReX-Combustion/PeleC). When we run at large scales, we have instances of SUNDIALS running within each rank of sometimes 1000s of ranks. When SUNDIALS reports errors/warnings, we can get GB-sized text output. What recourse or best practices are there for us to avoid this? Ideally we would want to design our code so that we only output on the MPI rank dedicated to console I/O. However, in the short term, we could get by redirecting stderr to /dev/null or something, for example, but we don't want to lose stderr in the long term.

Compilation fails on macOS if -DOPENMP_ENABLE=ON is used

The compilation fails on macOS if OpenMP is enabled:

$ cmake --version
cmake version 3.18.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ git clone [email protected]:LLNL/sundials.git
$ cd sundials && mkdir build && cd build
$ cmake ../ -DOPENMP_ENABLE=ON
-- The C compiler identification is AppleClang 11.0.0.11000033
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of int64_t
-- Check size of int64_t - done
-- Using int64_t for indices
-- Looking for _POSIX_TIMERS
-- Looking for _POSIX_TIMERS - not found
-- Found OpenMP_C: -Xclang -fopenmp (found version "3.1")
-- Found OpenMP: TRUE (found version "3.1")
-- Added NVECTOR_SERIAL module
-- Added NVECTOR_MANYVECTOR module
-- Added NVECTOR_OPENMP module
-- Added SUNMATRIX_BAND module
-- Added SUNMATRIX_DENSE module
-- Added SUNMATRIX_SPARSE module
-- Added SUNLINSOL_BAND module
-- Added SUNLINSOL_DENSE module
-- Added SUNLINSOL_PCG module
-- Added SUNLINSOL_SPBCGS module
-- Added SUNLINSOL_SPFGMR module
-- Added SUNLINSOL_SPGMR module
-- Added SUNLINSOL_SPTFQMR module
-- Added SUNNONLINSOL_NEWTON module
-- Added SUNNONLINSOL_FIXEDPOINT module
-- Added ARKODE module
-- Added CVODE module
-- Added CVODES module
-- Added IDA module
-- Added IDAS module
-- Added KINSOL module
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rlanger/Downloads/tmp/sundials_test/sundials/build
Execution time: 0h:00m:05s sec
rlanger on Raymonds-MBP-2.fritz.box in ~/Downloads/tmp/sundials_test/sundials/build(75d21h36m|master*)
$ make -j16
Scanning dependencies of target sundials_generic_static_obj
Scanning dependencies of target sundials_generic_shared_obj
Scanning dependencies of target sundials_nvecserial_shared
Scanning dependencies of target sundials_nvecmanyvector_shared
Scanning dependencies of target sundials_nvecserial_static
Scanning dependencies of target sundials_nvecmanyvector_static
Scanning dependencies of target sundials_nvecopenmp_shared
Scanning dependencies of target sundials_nvecopenmp_static
Scanning dependencies of target sundials_sunmatrixband_shared
Scanning dependencies of target sundials_sunmatrixdense_static
Scanning dependencies of target sundials_sunmatrixband_static
Scanning dependencies of target sundials_sunmatrixdense_shared
Scanning dependencies of target sundials_sunmatrixsparse_shared
Scanning dependencies of target sundials_sunmatrixsparse_static
Scanning dependencies of target sundials_sunlinsolpcg_static
Scanning dependencies of target sundials_sunlinsolpcg_shared
[  0%] Building C object src/nvector/serial/CMakeFiles/sundials_nvecserial_shared.dir/nvector_serial.c.o
[  0%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_shared.dir/sunmatrix_dense.c.o
[  0%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_shared.dir/sunmatrix_sparse.c.o
[  0%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_static.dir/sunmatrix_dense.c.o
[  1%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_shared.dir/sunmatrix_band.c.o
[  2%] Building C object src/nvector/openmp/CMakeFiles/sundials_nvecopenmp_static.dir/nvector_openmp.c.o
[  2%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_shared.dir/sunlinsol_pcg.c.o
[  2%] Building C object src/nvector/openmp/CMakeFiles/sundials_nvecopenmp_shared.dir/nvector_openmp.c.o
[  2%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_static.dir/sunmatrix_band.c.o
[  2%] Building C object src/nvector/manyvector/CMakeFiles/sundials_nvecmanyvector_shared.dir/nvector_manyvector.c.o
[  2%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_static.dir/sunmatrix_sparse.c.o
[  2%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_static.dir/sunlinsol_pcg.c.o
[  2%] Building C object src/nvector/manyvector/CMakeFiles/sundials_nvecmanyvector_static.dir/nvector_manyvector.c.o
[  2%] Building C object src/nvector/serial/CMakeFiles/sundials_nvecserial_static.dir/nvector_serial.c.o
[  2%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_band.c.o
[  2%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_band.c.o
/Users/rlanger/Downloads/tmp/sundials_test/sundials/src/nvector/openmp/nvector_openmp.c:23:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^~~~~~~
/Users/rlanger/Downloads/tmp/sundials_test/sundials/src/nvector/openmp/nvector_openmp.c:23:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^~~~~~~
1 error generated.
1 error generated.
make[2]: *** [src/nvector/openmp/CMakeFiles/sundials_nvecopenmp_shared.dir/nvector_openmp.c.o] Error 1
make[1]: *** [src/nvector/openmp/CMakeFiles/sundials_nvecopenmp_shared.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** [src/nvector/openmp/CMakeFiles/sundials_nvecopenmp_static.dir/nvector_openmp.c.o] Error 1
make[1]: *** [src/nvector/openmp/CMakeFiles/sundials_nvecopenmp_static.dir/all] Error 2
[  3%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_dense.c.o
[  3%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_static.dir/__/__/sundials/sundials_nvector.c.o
[  4%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_dense.c.o
[  4%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_static.dir/__/__/sundials/sundials_math.c.o
[  4%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_shared.dir/__/__/sundials/sundials_nvector.c.o
[  4%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_shared.dir/__/__/sundials/sundials_math.c.o
[  4%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_static.dir/__/__/sundials/sundials_nvector.c.o
[  4%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_shared.dir/__/__/sundials/sundials_nvector.c.o
[  4%] Building C object src/nvector/serial/CMakeFiles/sundials_nvecserial_shared.dir/__/__/sundials/sundials_nvector.c.o
[  4%] Building C object src/nvector/manyvector/CMakeFiles/sundials_nvecmanyvector_shared.dir/__/__/sundials/sundials_nvector.c.o
[  4%] Building C object src/nvector/manyvector/CMakeFiles/sundials_nvecmanyvector_static.dir/__/__/sundials/sundials_nvector.c.o
[  5%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_static.dir/__/__/sundials/sundials_nvector.c.o
[  6%] Building C object src/nvector/serial/CMakeFiles/sundials_nvecserial_static.dir/__/__/sundials/sundials_nvector.c.o
[  6%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_shared.dir/__/__/sundials/sundials_nvector.c.o
[  6%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_direct.c.o
[  7%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_static.dir/__/__/sundials/sundials_matrix.c.o
[  7%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_static.dir/__/__/sundials/sundials_nvector.c.o
[  7%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_shared.dir/__/__/sundials/sundials_nvector.c.o
[  7%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_direct.c.o
[  7%] Building C object src/nvector/serial/CMakeFiles/sundials_nvecserial_shared.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_static.dir/__/__/sundials/sundials_matrix.c.o
[  7%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_shared.dir/__/__/sundials/sundials_matrix.c.o
[  7%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_static.dir/__/__/sundials/sundials_matrix.c.o
[  7%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_shared.dir/__/__/sundials/sundials_matrix.c.o
[  7%] Building C object src/nvector/manyvector/CMakeFiles/sundials_nvecmanyvector_shared.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_static.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/nvector/manyvector/CMakeFiles/sundials_nvecmanyvector_static.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_shared.dir/__/__/sundials/sundials_matrix.c.o
[  7%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_static.dir/__/__/sundials/sundials_linearsolver.c.o
[  7%] Building C object src/nvector/serial/CMakeFiles/sundials_nvecserial_static.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_static.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_futils.c.o
[  7%] Building C object src/sunmatrix/dense/CMakeFiles/sundials_sunmatrixdense_shared.dir/__/__/sundials/sundials_math.c.o
[  7%] Linking C shared library libsundials_nvecserial.dylib
[  7%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_static.dir/__/__/sundials/sundials_math.c.o
[  7%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_futils.c.o
[  8%] Building C object src/sunmatrix/band/CMakeFiles/sundials_sunmatrixband_shared.dir/__/__/sundials/sundials_math.c.o
[  8%] Building C object src/sunmatrix/sparse/CMakeFiles/sundials_sunmatrixsparse_shared.dir/__/__/sundials/sundials_math.c.o
[  8%] Linking C shared library libsundials_nvecmanyvector.dylib
[  8%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_iterative.c.o
[  8%] Linking C static library libsundials_nvecmanyvector.a
[  8%] Linking C static library libsundials_nvecserial.a
[  8%] Linking C static library libsundials_sunmatrixdense.a
[  8%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_iterative.c.o
[  8%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_shared.dir/__/__/sundials/sundials_linearsolver.c.o
[  8%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_static.dir/__/__/sundials/sundials_iterative.c.o
[  8%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_linearsolver.c.o
[  8%] Linking C static library libsundials_sunmatrixsparse.a
[  8%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_math.c.o
[  8%] Linking C shared library libsundials_sunmatrixdense.dylib
[  8%] Linking C shared library libsundials_sunmatrixsparse.dylib
[  9%] Linking C static library libsundials_sunmatrixband.a
[  9%] Linking C shared library libsundials_sunmatrixband.dylib
[  9%] Building C object src/sunlinsol/pcg/CMakeFiles/sundials_sunlinsolpcg_shared.dir/__/__/sundials/sundials_iterative.c.o
[  9%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_linearsolver.c.o
[ 10%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_math.c.o
[ 10%] Linking C static library libsundials_sunlinsolpcg.a
[ 10%] Built target sundials_nvecmanyvector_static
[ 10%] Built target sundials_nvecserial_static
[ 10%] Built target sundials_sunmatrixdense_static
[ 10%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_matrix.c.o
[ 10%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_matrix.c.o
[ 10%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_nonlinearsolver.c.o
[ 10%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_nonlinearsolver.c.o
[ 10%] Built target sundials_nvecserial_shared
[ 10%] Built target sundials_nvecmanyvector_shared
[ 10%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_nvector.c.o
[ 10%] Built target sundials_sunmatrixsparse_static
[ 11%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_nvector_senswrapper.c.o
[ 11%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_nvector.c.o
[ 11%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_nvector_senswrapper.c.o
[ 11%] Building C object src/sundials/CMakeFiles/sundials_generic_static_obj.dir/sundials_version.c.o
[ 11%] Building C object src/sundials/CMakeFiles/sundials_generic_shared_obj.dir/sundials_version.c.o
[ 11%] Linking C shared library libsundials_sunlinsolpcg.dylib
[ 11%] Built target sundials_sunmatrixband_static
[ 11%] Built target sundials_sunlinsolpcg_static
[ 11%] Built target sundials_sunmatrixsparse_shared
[ 11%] Built target sundials_sunmatrixband_shared
[ 11%] Built target sundials_sunmatrixdense_shared
[ 11%] Built target sundials_generic_static_obj
[ 11%] Built target sundials_generic_shared_obj
[ 11%] Built target sundials_sunlinsolpcg_shared
make: *** [all] Error 2
Execution time: 0h:00m:01s sec

In CMake 3.12+, I have added

  if(TARGET OpenMP::OpenMP_C)
    target_link_libraries(sundials_nvecopenmp_shared PUBLIC OpenMP::OpenMP_C)
  endif()

to src/nvector/openmp/CMakeLists.txt to fix the issue. The same statement works for the static library.

I think that linking the OpenMP target is the idiomatic way of enabling OpenMP in CMake, but I have not tested this for older CMake versions or OPENMP_DEVICE_ENABLE=ON.

The targets cannot be found

Hi, I'm maintainer of vcpkg, when using sundials, I found that the current usage is not correct.

The package sundials:x64-windows provides CMake targets:

    find_package(SUNDIALS CONFIG REQUIRED)
    # Note: 24 target(s) were omitted.
    target_link_libraries(main PRIVATE SUNDIALS::KLU SUNDIALS::HYPRE SUNDIALS::MAGMA SUNDIALS::XBRAID)

It seems that all these features are disabled, since the values are all OFF in SUNDIALSConfig.cmake file.

Could you please help take a look?

Thanks in advance!

The errors are like this:

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.28.29337.0
-- The CXX compiler identification is MSVC 19.28.29337.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at F:/tool/vcpkg/scripts/buildsystems/vcpkg.cmake:660 (_add_executable):
  Target "main" links to target "SUNDIALS::KLU" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:6 (add_executable)


CMake Error at F:/tool/vcpkg/scripts/buildsystems/vcpkg.cmake:660 (_add_executable):
  Target "main" links to target "SUNDIALS::HYPRE" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:6 (add_executable)


CMake Error at F:/tool/vcpkg/scripts/buildsystems/vcpkg.cmake:660 (_add_executable):
  Target "main" links to target "SUNDIALS::XBRAID" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:6 (add_executable)


CMake Error at F:/tool/vcpkg/scripts/buildsystems/vcpkg.cmake:660 (_add_executable):
  Target "main" links to target "SUNDIALS::TRILINOS" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:6 (add_executable)

klu support with suitesparse 5.8.1 (latest)

Hi,

I'm the maintainer in NixOS of a few packages that use sundials and suitesparse as dependencies. While attempting to update our sundials from 5.3.0 to 5.6.1 I got this error when I try to build sundials 5.6.1 with suitesparse 5.8.1:

https://gist.github.com/doronbehar/e24f9fb894171c209bc436c3962ed5ee

I noticed you write in your docs that suitesparse 5.7.1 is the version that is tested for klu support, but it'd be nice if the latest version of suitesparse - available in the distributions will be supported and hence sundials will not require a custom version of suitesparse.

Regards.

Compile with OpenBlas libraries

I am trying to compile SUNDIALS with LAPACK enabled using the OpenBlas distribution. OpenBlas automatically exports in the same shared library the lapack and blas API so the build seems to be unable to find a working version of the libraries

I am currently trying to update the BinaryBuilder for Sundials v5.0.0 and If I keep this configuration for Sundials I get that LAPACK isn't functional.

-- Looking for LAPACK libraries... OK
-- Checking if LAPACK works... FAILED
CMake Warning at config/SundialsCMakeMacros.cmake:83 (message):
  ------------------------------------------------------------------------

  WARNING: LAPACK not functional

  Blas/Lapack support will not be provided

  ------------------------------------------------------------------------
Call Stack (most recent call first):
  CMakeLists.txt:914 (print_warning)

Any ideas on how to make it work?

This is my current CMAKE configuration

CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=${prefix} -DCMAKE_TOOLCHAIN_FILE=/opt/$target/$target.toolchain"
CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_BUILD_TYPE=Release -DEXAMPLES_ENABLE_C=OFF"
CMAKE_FLAGS="${CMAKE_FLAGS} -DKLU_ENABLE=ON -DKLU_INCLUDE_DIR=$prefix/include -DKLU_LIBRARY_DIR=$prefix/lib"
CMAKE_FLAGS="${CMAKE_FLAGS} -DLAPACK_ENABLE=ON -DLAPACK_LIBRARIES=$LIBBLAS"

if [[ ${nbits} == 32 ]]; then
    echo "***   32-bit BUILD   ***"
    LIBBLAS="$prefix/lib/libopenblas.so"
    cmake ${CMAKE_FLAGS} -DSUNDIALS_INDEX_TYPE=int32_t ..
else
    echo "***   64-bit BUILD   ***"
    LIBBLAS="$prefix/lib/libopenblas64_.so"
    cmake ${CMAKE_FLAGS} ..
fi

FCVODE tries to deallocate linear solver and matrix objects twice, leading to errors

Here is an example program. It tries to to run two integrations with FCVODE.

module vars
  integer*8 neqs
end module

program test
  use vars
  implicit none
  neqs = 1
  call cvoderun(neqs)
  neqs = 2
  call cvoderun(neqs)
end program

subroutine cvoderun(neq)
  implicit none
  integer*8, intent(in) :: neq
  INTEGER*4 IER, METH, IATOL, ITASK
  INTEGER*8 IOUT(25), IPAR(2)
  DOUBLE PRECISION RTOL, ATOL, T0, T, TOUT
  DOUBLE PRECISION U(neq), ROUT(10), RPAR(5)

  t0 = 0
  meth = 1
  iatol = 1
  rtol = 1.d-3
  atol = 1.d-10
  itask = 1
  Tout = 1.d0

  U = 1.d0 ! initial conditions
  CALL FNVINITS(1, NEQ, IER)
  call FSUNDENSEMATINIT(1,neq,neq,ier)
  call FSUNDENSELINSOLINIT(1,ier)
  CALL FCVMALLOC(T0, U, METH, IATOL, RTOL, ATOL, &
                IOUT, ROUT, IPAR, RPAR, IER)
  CALL FCVLSINIT(IER)
  call FCVODE(TOUT, T, U, ITASK, IER)
  print*,U
  call fcvfree
end subroutine


subroutine FCVFUN(T, U, UDOT, IPAR, RPAR, IER)
  use vars
  implicit none
  DOUBLE PRECISION T, U(*), UDOT(*), RPAR(*)
! The following declaration specification should match C type long int.
  INTEGER*8 IPAR(*)
  INTEGER*4 IER
  integer i
  do i=1,neqs
    UDOT(i) = U(i)
  enddo
  ier = 0
end subroutine

However it errors out with

test.run(65387,0x10a85edc0) malloc: *** error for object 0x7fa37b4070b0: pointer being freed was not allocated

The reason is because linear solver and matrix objects are being deallocated two times. The first deallocate occurs in call fcvfree. The second deallocate is occuring, for example, at this line. I'm not sure why the if isn't working properly.

When I comment-out the second deallocations (this line and this line) everything works properly, and valgrind confirms that there are no memory leaks.

Cheers,
Nick

MPI run hangs when using ARKBraid API

I'd much appreciate another pair of eyes on the following model. What I'm trying to do is to reproduce xbraid's toy model with ARKBraid API, with a slight modification of using 4th order method.

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

#include "braid.h"
#include "arkode/arkode_arkstep.h"     // access to ARKStep
#include "nvector/nvector_serial.h"  // access to the MPI N_Vector
#include "sunlinsol/sunlinsol_dense.h"   // access to PCG SUNLinearSolver
#include "mpi.h"                       // MPI header file
#include "arkode/arkode_xbraid.h"      // access to ARKStep + XBraid interface

static int f(realtype t, N_Vector u, N_Vector fu, void *user_data) {
  NV_Ith_S(fu, 0) = NV_Ith_S(u, 0) * 1.0;
  return 0;
}

int my_Init(braid_App app, double t, braid_Vector *u_ptr) {
  N_Vector y = N_VNew_Serial(1);
  SUNBraidVector_New(y, u_ptr);
  if (t == 0.0) { /* Initial condition */
    NV_Ith_S(y, 0) = 1.0;
  } else { /* All other time points set to arbitrary value */
    NV_Ith_S(y, 0) = 0.0;
  }
  return 0;
}

int main (int argc, char *argv[]) {
   double        tstart, tstop;
   int           ntime, rank;

   /* Initialize MPI */
   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);

   N_Vector u = N_VNew_Serial(1);

   /* Define time domain: ntime intervals */
   ntime  = 10;
   tstart = 0.0;
   tstop  = tstart + ntime/2.;
   
   // arkode
   void* udata = NULL;
   void* mem = ARKStepCreate(NULL, f, 0.0, u);
   ARKStepSStolerances(mem, 1.e-4, 1.e-5);
   ARKStepSetUserData(mem, udata);
   SUNMatrix A = SUNDenseMatrix(1 ,1);
   SUNLinearSolver LS = SUNLinSol_Dense(u, A);
   ARKStepSetLinearSolver(mem, LS, A);
   ARKStepSetOrder(mem, 4);

   braid_Core core    = NULL;  // XBraid memory structure
   braid_App app      = NULL;  // ARKode + XBraid interface structure
   ARKBraid_Create(mem, &app);
   ARKBraid_SetInitFn(app, my_Init);
   ARKBraid_SetAccessFn(app, NULL);
   ARKBraid_BraidInit(MPI_COMM_WORLD, MPI_COMM_WORLD, tstart, tstop, ntime, app, &core);
   
   /* Set some typical Braid parameters */
   braid_SetPrintLevel( core, 2);
   braid_SetMaxLevels(core, 2);
   braid_SetAbsTol(core, 1.0e-06);
   braid_SetCFactor(core, -1, 2);
   
   /* Run simulation, and then clean up */
   braid_Drive(core);

   ARKStepFree(&mem);  // Free integrator memory
   SUNLinSolFree(LS);         // Free linear solver
   N_VDestroy(u);             // Free vectors
   braid_Destroy(core);
   ARKBraid_Free(&app);
   MPI_Finalize();

   return (0);
}

The model runs fine with a single proc:

mpiexec -n 1 ./a.out

  Braid: Begin simulation, 10 time steps
  Braid: || r_0 || not available, wall time = 4.44e-04
  Braid: || r_1 || = 1.224137e-01, conv factor = 1.00e+00, wall time = 7.33e-04
  Braid: || r_2 || = 1.782877e-04, conv factor = 1.46e-03, wall time = 8.85e-04
  Braid: || r_3 || = 0.000000e+00, conv factor = 0.00e+00, wall time = 1.01e-03

  Braid Solver Stats:
  start time = 0.000000e+00
  stop time  = 5.000000e+00
  time steps = 10

  use seq soln?         = 0
  storage               = -1

  max iterations        = 100
  iterations            = 4

  residual norm         = 0.000000e+00
  stopping tolerance    = 1.000000e-06
  use relative tol?     = 0
                                          --> 2-norm TemporalNorm 

  use fmg?              = 0
  access_level          = 1
  print_level           = 2

  max number of levels  = 2
  min coarse            = 2
  number of levels      = 2
  skip down cycle       = 1
  periodic              = 0
  relax_only_cg         = 0
  finalFCRelax          = 0
  number of refinements = 0

  level   time-pts   cfactor   nrelax   Crelax Wt
      0        10        2        1        1.00
      1         5  

  wall time = 0.001166

but hangs when nproc > 1:

mpiexec -n 2 ./a.out

  Braid: Begin simulation, 10 time steps
  Braid: || r_0 || not available, wall time = 3.21e-04
....

What am I missing here?

Infinite loop in CVodeF

Under certain conditions the forward solver of cvodes enters an infinite loop if called using CV_NORMAL_STEP. If the step-size decreases until t + h = t numerically, then CVode will print a warning, but still return a 0 return value. The loop here in CVodeF will continue forever.

I do not have a reproducing example in C, but here is one that uses the sunode package to wrap sundials:

We start integrating the ode dy/dt = 1 / (t - 1) at t0 = 1 + 1e-15:

import sunode
import sunode.symode
import numpy as np

params = {'p': ()}
states = {'a': ()}

def rhs(t, y, p):
    return {
        'a': 1 / (t - 1)
    }

problem = sunode.SympyProblem(
    params=params,
    states=states,
    derivative_params=[('p',)],
    rhs_sympy=rhs,
)

solver = sunode.solver.AdjointSolver(problem)
solver.set_params_dict({'p': 0.})

h = 1e-15
tvals = np.linspace(1 + h, 1 + 1000 * h)
out, *_ = solver.make_output_buffers(tvals)

y0 = np.array(0.)
solver.solve_forward(1 + h, tvals, y0, out)

The solver prints error messages repeatedly until the maximum number of warnings in exhausted, then silently continues:

[CVODES WARNING]  CVode
  Internal t = 1 and h = 4.96507e-17 are such that t + h = t on the next step. The solver will continue anyway.


[CVODES WARNING]  CVode
  Internal t = 1 and h = 4.96507e-17 are such that t + h = t on the next step. The solver will continue anyway.


[CVODES WARNING]  CVode
  Internal t = 1 and h = 4.96507e-17 are such that t + h = t on the next step. The solver will continue anyway.


[CVODES WARNING]  CVode
  Internal t = 1 and h = 4.96507e-17 are such that t + h = t on the next step. The solver will continue anyway.


[CVODES WARNING]  CVode
  The above warning has been issued mxhnil times and will not be issued again for this problem.

CC @astoeriko

compile error on visual studio with /sdl option sundials 5

I am pretty sure this is not an actual error since there are checks in place, but apparently not ones the compiler can detect. This issue currently prevents compilation of the 5.0 release on Visual Studio with the additional security checks enabled.

1>...\sundials\src\arkode\arkode_mristep.c(539): error C4703: potentially uninitialized local pointer variable 'inner_arkls_mem' used

If the pointers are initialized to NULL the error goes away.

Tests sunlinsol/klu not using KLU_LIBRARY_DIR

The problem

When running the tests via

$ make test

I noticed that the klu tests are failing:

The following tests FAILED:
         33 - test_sunlinsol_klu_300_0_0 (Failed)
         34 - test_sunlinsol_klu_300_1_0 (Failed)
         35 - test_sunlinsol_klu_1000_0_0 (Failed)
         36 - test_sunlinsol_klu_1000_1_0 (Failed)

On the other hand in the final program our tests which are using SUNDIALS with KLU are running fine.
The problem is probably missing linker flags in the examples.

Output of make

When I rerun the test in build/examples_install/sunlinsol/klu we see that is a linking error.

$ make
/usr/bin/clang -O3 -DNDEBUG -O3 -DNDEBUG -I/path/to/sundials/build/include -I/path/to/klu/include -c test_sunlinsol.c
/usr/bin/clang -O3 -DNDEBUG -O3 -DNDEBUG -I/path/to/sundials/build/include -I/path/to/klu/include -c sundials_nvector.c
/usr/bin/clang -O3 -DNDEBUG -O3 -DNDEBUG -I/path/to/sundials/build/include -I/path/to/klu/include -c sundials_matrix.c
/usr/bin/clang -O3 -DNDEBUG -O3 -DNDEBUG -I/path/to/sundials/build/include -I/path/to/klu/include -c sundials_linearsolver.c
/usr/bin/clang -O3 -DNDEBUG -O3 -DNDEBUG -I/path/to/sundials/build/include -I/path/to/klu/include -c test_sunlinsol_klu.c
/usr/bin/clang -o test_sunlinsol_klu test_sunlinsol_klu.o test_sunlinsol.o sundials_nvector.o sundials_matrix.o sundials_linearsolver.o -O3 -DNDEBUG  -I/path/to/sundials/build/include -I/path/to/klu/include -L/path/to/sundials/build/lib -lsundials_sunlinsolklu -lsundials_nvecserial -lsundials_nvecmanyvector -lm /usr/lib/x86_64-linux-gnu/librt.so -lsundials_sunmatrixsparse -lsundials_sunmatrixdense -lsundials_sunlinsolklu   libklu.so libamd.so libcolamd.so libbtf.so -Wl,-rpath,/path/to/sundials/build/lib:
clang: error: no such file or directory: 'libklu.so'
clang: error: no such file or directory: 'libamd.so'
clang: error: no such file or directory: 'libcolamd.so'
clang: error: no such file or directory: 'libbtf.so'
Makefile:109: recipe for target 'examples_klu' failed
make: *** [examples_klu] Error 1

Test test Makefile

When we look into the Makefile from build/examples_install/sunlinsol/klu we can see that the LDFLAGS is empty and CFLAGS is not using the flags from the configure call:

# -*- mode: makefile -*-
# -----------------------------------------------------------------
# Programmer(s): Radu Serban @ LLNL
#                David J. Gardner @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2020, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------
# Makefile for  serial examples
#
# This file is generated from a template using variables
# set at configuration time. It can be used as a template for
# other user Makefiles.
# -----------------------------------------------------------------

SHELL = sh

prefix       = /path/to/sundials/build
exec_prefix  = /path/to/sundials/build
includedir   = /path/to/sundials/build/include
libdir       = /path/to/sundials/build/lib

CPP      = /usr/bin/clang
CPPFLAGS = -O3 -DNDEBUG
CC       = /usr/bin/clang
CFLAGS   = -O3 -DNDEBUG
LDFLAGS  =
LIBS     =  -lm /usr/lib/x86_64-linux-gnu/librt.so -lsundials_sunmatrixsparse -lsundials_sunmatrixdense

LINKFLAGS = -Wl,-rpath,/path/to/sundials/build/lib

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

LIBRARIES_LAPACK = -lsundials_sunlinsollapackdense -lsundials_sunlinsollapackband  -llapack -lblas
LINKFLAGS_LAPACK = ${LINKFLAGS}:

INCLUDES_KLU  = /path/to/klu/include
LIBRARIES_KLU = -lsundials_sunlinsolklu   libklu.so libamd.so libcolamd.so libbtf.so
LINKFLAGS_KLU = ${LINKFLAGS}:

INCLUDES_SLUMT  =
LIBRARIES_SLUMT = -lsundials_sunlinsolsuperlumt
LINKFLAGS_SLUMT = ${LINKFLAGS}:

TMP_INCS  = ${includedir} ${INCLUDES_SLUMT} ${INCLUDES_KLU}
INCLUDES  = $(addprefix -I, ${TMP_INCS})
LIBRARIES = -lsundials_sunlinsolklu -lsundials_nvecserial -lsundials_nvecmanyvector ${LIBS}

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

When adding the KLU_LIBRARY_DIR and CMAKE_C_FLAGS from the configure the test works correctly.

Our configure call

Our klu library is not in a default location. In addition to -DKLU_LIBRARY_DIR we pass specific linker flags in with -DCMAKE_C_FLAGS.

We are configuring with klu and some specific CMake flags:

-DKLU_ENABLE:Bool=ON \
-DKLU_LIBRARY_DIR="/some/path/to/klu-lib/" \
-DKLU_INCLUDE_DIR="/some/path/to/klu-lib/" \
-DEXAMPLES_INSTALL=ON \
-DEXAMPLES_INSTALL_PATH=./examples_install \
-DEXAMPLES_ENABLE_C:Bool=ON \
-DEXAMPLES_ENABLE_CXX:Bool=ON \
-DCMAKE_C_FLAGS="[...] -L /we/have/some/path/to/klu-lib/again/  [...]"
-DKLU_LIBRARY="libklu.so"
-DAMD_LIBRARY="libamd.so"
-DCOLAMD_LIBRARY="libcolamd.so"
-DBTF_LIBRARY="libbtf.so"
-DSUITESPARSECONFIG_LIBRARY=""

Question regarding the parallel implementations fo NVector.

Hello,

I work in systems biology and I am updating the cvode library in our "roadrunner" library for modelling biological systems. I have a question regarding the parallel versions of NVector. In the docs, its stated that vectors should be of length at least 100K before the overhead of using pthread/openMP are worth the effort. In a typical model we use an NVector much smaller that this (think 10's to 100's), but we often need to integrate many times to estimate the parameters of these models. Is there a way we could benefit from the parallel implementations, or do we just incur overhead after every time we reset the system back to t0? Hopefully my questions is clear.

Thanks, Ciaran

cv_guide.pdf: Documentation bug in SUNMatrix_Sparse section

cv_guide.pdf page 210 introduces sunmatrix sparse matrices and says "For CSC
matrices NP = N, and for CSR matrices NP = M." but on page 211 it says

Similarly, in CSR format, the same matrix could be stored as
M = 5;
N = 4;
NNZ = 8;
NP = N;

so I think we need NP = M instead of NP = N.

Wrong arguments in ClassicalGS

It seems that the two calls to ClassicalGS in sundials_spgmr.c:319 and sundials_spfgmr.c:272 have incompatible parameters. The last two should be (..., realtype *, N_Vector *) but their are (.., N_Vector, realtype *).

Help with using the Fixed Point iteration algorithm.

Hello,

I'm having a little difficulty getting the fixed point algorithm to converge to the steady state of a test system and was hoping I could recruit some help from the experts. I've been able to solve this system using the Newton Iteration algorithm without any problems, but my attempts at using fixed point seem to blow up to infinity.

I'm trying to solve this system:

  f(x) =
       dS1/dt = (k1 / (1 + (S2/K)^n)) - k3*S1 -k5*S1
       dS2/dt = k2 + k5*S1 - k4*S2

where

    S1 = 0 // though various initial conditions produce same result
    S2 = 0
    k1 = 20
    k2 = 5
    K = 1
    k3 = 5
    k5 = 2
    n = 4

The system steady state is at

 ['[S1]', '[S2]']
[0.7445984  1.29783936]

Based off of this line from the kinsol docs:

set u_{n+1} = G(u_n) =  u_n - L^{-1}F(u_n}

I'm using the following KINSysFn

int FPFunction(N_Vector y, N_Vector g, void *user_data) {
    realtype s1, s2;

    s1 = Ith(y, 1);
    s2 = Ith(y, 2);

    double v1 = k1 / (1 + pow((s2 / K), n));
    double v2 = k2;
    double v3 = k3 * s1;
    double v4 = k4 * s2;
    double v5 = k5 * s1;

    // u = [s2, s2]
    // step = simple L^-1
    // v's = F(u)

    Ith(g, 1) =  s1 - (step* (v1 - v3 - v5)) ; 
    Ith(g, 2) =  s2 - (step* (v2 + v5 - v4)) ;

    std::cout << "s1 = " << s1 << std::endl;
    std::cout << "s2 = " << s2 << std::endl;
    std::cout << "d[s1]/dy = " << Ith(g, 1) << std::endl;
    std::cout << "d[s2]/dy = " << Ith(g, 2) << std::endl;
    std::cout << std::endl;

    return (0);
}

I've pasted below the full C source file, which is heavily based on the kinRoberts_fp example. Thanks in advance for your help.

Ciaran

/**
 * The system we solve is:
 *      f(x) =
 *       dS1/dt = (k1 / (1 + (S2/K)^n)) - k3*S1 -k5*S1
 *       dS2/dt = k2 + k5*S1 - k4*S2
 * We use
 *  S1 = 0
 *  S2 = 0
 *  k1 = 20
 *  k2 = 5
 *  K = 1
 *  k3 = 5
 *  k5 = 2
 *  n = 4
 *
 * The solution to f(x) = 0 is:
 * 
 *     [0.7445984  1.29783936]
 *
 * The equivalent roadrunner/tellurium code is:
 *
    import tellurium as te
    def ss(s):
        m = te.loada(s)
        m.conservedMoietyAnalysis = True
        m.steadyState()
        print(m.getFloatingSpeciesConcentrationIds())
        print(m.getFloatingSpeciesConcentrations())
        print(m.getFullJacobian())
        print(m.getReducedJacobian())
        print(m.getReducedStoichiometryMatrix())
        print(m.getGlobalParameterIds())
        print(m.getGlobalParameterValues())
        return m
    r = ss("""
    model x
        S1 = 0;
        S2 = 0;
        v1: => S1; k1 / (1 + (S2 / K)^n);
        v2: => S2; k2;
        v3: S1 => ; k3*S1;
        v4: S2 =>; k4*S2;
        v5: S1 => S2; k5*S1;
        k1 = 20;
        k2 = 5;
        K  = 1;
        k3 = 5;
        k4 = 5 ;
        k5 = 2;
        n = 4;
    end
    """)
 *  The expected output:
 ['[S1]', '[S2]']
[0.7445984  1.29783936]
      S1,       S2
S1 [[ -7, -11.8788],
S2  [  2,       -5]]

      S1,       S2
S1 [[ -7, -11.8777],
S2  [  2,       -5]]

      v1, v2, v3, v4, v5
S1 [[  1,  0, -1,  0, -1],
S2  [  0,  1,  0, -1,  1]]

['k1', 'K', 'n', 'k2', 'k3', 'k4', 'k5']
[20.  1.  4.  5.  5.  5.  2.]

In [4]:
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <sunmatrix/sunmatrix_dense.h>
#include <sunlinsol/sunlinsol_dense.h>

#include "kinsol/kinsol.h"           /* access to KINSOL func., consts. */
#include "nvector/nvector_serial.h"  /* access to serial N_Vector       */

#define NEQ    2

#define FTOL   1.e-15 /* function tolerance */
#define STOL   1.e-15 /* step tolerance     */

#define S10 0
#define S20 0
//[  ]
//#define S10 0.7445984
//#define S20 1.29783936

#define k1  20.0
#define k2  5.0
#define K   1.0
#define k3  5.0
#define k4  5.0
#define k5  2.0
#define n   4.0

#define step 0.1


/* Accessor macro */
#define Ith(v, i)    NV_Ith_S(v,i-1)


/* Nonlinear fixed point function */
static int FPFunction(N_Vector y, N_Vector g, void *user_data);

/* Check function return values */
static int check_retval(void *returnvalue, const char *funcname, int opt);


/* -----------------------------------------------------------------------------
 * Main program
 * ---------------------------------------------------------------------------*/
int main(int argc, char *argv[]) {
    int retval = 0;
    N_Vector u = NULL;
    N_Vector scale = NULL;
    realtype tol = 1e-5;
    long int mxiter = 150;
    long int maa = 0;           /* no acceleration */
    realtype damping = 0.01; /* no damping      */
    long int nni, nfe;
    realtype *data;
    void *kmem;
    SUNMatrix J = nullptr;
    SUNLinearSolver LS = nullptr;
    /* Check if a acceleration/dampling values were provided */
    if (argc > 1) maa = (long int) atoi(argv[1]);
    if (argc > 2) damping = (realtype) atof(argv[2]);

    /* -------------------------
     * Print problem description
     * ------------------------- */


    printf("Solution method: Anderson accelerated fixed point iteration.\n");
    printf("    tolerance = %f \n", tol);
    printf("    max iters = %ld\n", mxiter);
    printf("    accel vec = %ld\n", maa);
    printf("    damping   = %f\n", damping);

    /* --------------------------------------
     * Create vectors for solution and scales
     * -------------------------------------- */

    u = N_VNew_Serial(NEQ);
    if (check_retval((void *) u, "N_VNew_Serial", 0)) return (1);

    scale = N_VClone(u);
    if (check_retval((void *) scale, "N_VClone", 0)) return (1);

    /* -----------------------------------------
     * Initialize and allocate memory for KINSOL
     * ----------------------------------------- */

    kmem = KINCreate();
    if (check_retval((void *) kmem, "KINCreate", 0)) return (1);

    /* Set number of prior residuals used in Anderson acceleration */
    retval = KINSetMAA(kmem, maa);

    retval = KINInit(kmem, FPFunction, u);
    if (check_retval(&retval, "KINInit", 1)) return (1);


    /* Create dense SUNMatrix */
    J = SUNDenseMatrix(NEQ, NEQ);
    if (check_retval((void *) J, "SUNDenseMatrix", 0)) return (1);

    /* Create dense SUNLinearSolver object */
    LS = SUNLinSol_Dense(u, J);
    if (check_retval((void *) LS, "SUNLinSol_Dense", 0)) return (1);

    /* Attach the matrix and linear solver to KINSOL */
    retval  = KINSetLinearSolver(kmem, LS, J);
    if (check_retval(&retval, "KINSetLinearSolver", 1)) return (1);

    /* -------------------
     * Set optional inputs
     * ------------------- */

    /* Specify stopping tolerance based on residual */
    retval = KINSetFuncNormTol(kmem, tol);
    if (check_retval(&retval, "KINSetFuncNormTol", 1)) return (1);

    /* Set maximum number of iterations */
    retval = KINSetNumMaxIters(kmem, mxiter);
    if (check_retval(&retval, "KINSetNumMaxItersFuncNormTol", 1)) return (1);

    /* Set Anderson acceleration damping parameter */
    retval = KINSetDampingAA(kmem, damping);
    if (check_retval(&retval, "KINSetDampingAA", 1)) return (1);

    /* -------------
     * Initial guess
     * ------------- */
    Ith(u, 1) = S10;
    Ith(u, 2) = S20;

    /* ----------------------------
     * Call KINSol to solve problem
     * ---------------------------- */

    /* No scaling used */
    N_VConst(1, scale);

    /* Call main solver */
    retval = KINSol(kmem,         /* KINSol memory block */
                    u,            /* initial guess on input; solution vector */
                    KIN_FP,       /* global strategy choice */
                    scale,        /* scaling vector, for the variable cc */
                    scale);       /* scaling vector for function values fval */
    if (check_retval(&retval, "KINSol", 1)) return (1);

    /* ------------------------------------
     * Get solver statistics
     * ------------------------------------ */

    /* get solver stats */
    retval = KINGetNumNonlinSolvIters(kmem, &nni);
    check_retval(&retval, "KINGetNumNonlinSolvIters", 1);

    retval = KINGetNumFuncEvals(kmem, &nfe);
    check_retval(&retval, "KINGetNumFuncEvals", 1);

    printf("\nFinal Statistics:\n");
    printf("Number of nonlinear iterations: %6ld\n", nni);
    printf("Number of function evaluations: %6ld\n", nfe);

    /* ------------------------------------
     * Print solution and check error
     * ------------------------------------ */

    /* check solution */
//  retval = check_ans(u, tol);

    /* -----------
     * Free memory
     * ----------- */

    N_VDestroy(u);
    N_VDestroy(scale);
    KINFree(&kmem);

    return (retval);
}


int FPFunction(N_Vector y, N_Vector g, void *user_data) {
    realtype s1, s2;

    s1 = Ith(y, 1);
    s2 = Ith(y, 2);

    double v1 = k1 / (1 + pow((s2 / K), n));
    double v2 = k2;
    double v3 = k3 * s1;
    double v4 = k4 * s2;
    double v5 = k5 * s1;

    Ith(g, 1) =  s1 - (step* (v1 - v3 - v5)) ;
    Ith(g, 2) =  s2 - (step* (v2 + v5 - v4)) ;

    std::cout << "s1 = " << s1 << std::endl;
    std::cout << "s2 = " << s2 << std::endl;
    std::cout << "d[s1]/dy = " << Ith(g, 1) << std::endl;
    std::cout << "d[s2]/dy = " << Ith(g, 2) << std::endl;
    std::cout << std::endl;

    return (0);
}

/* -----------------------------------------------------------------------------
 * Check the solution of the nonlinear system and return PASS or FAIL
 * ---------------------------------------------------------------------------*/

/* -----------------------------------------------------------------------------
 * Check function return value
 *   opt == 0 check if returned NULL pointer
 *   opt == 1 check if returned a non-zero value
 * ---------------------------------------------------------------------------*/
static int check_retval(void *returnvalue, const char *funcname, int opt) {
    int *errflag;

    /* Check if the function returned a NULL pointer -- no memory allocated */
    if (opt == 0) {
        if (returnvalue == NULL) {
            fprintf(stderr, "\nERROR: %s() failed -- returned NULL\n\n", funcname);
            return (1);
        } else {
            return (0);
        }
    }

    /* Check if the function returned an non-zero value -- internal failure */
    if (opt == 1) {
        errflag = (int *) returnvalue;
        if (*errflag != 0) {
            fprintf(stderr, "\nERROR: %s() failed -- returned %d\n\n", funcname, *errflag);
            return (1);
        } else {
            return (0);
        }
    }

    /* if we make it here then opt was not 0 or 1 */
    fprintf(stderr, "\nERROR: check_retval failed -- Invalid opt value\n\n");
    return (1);
}

Install prefix

Trying to install sundials-3.1.2 on my CentOS workstation but it fails with the following msg:

CMake Error at cmake_install.cmake:36 (FILE):
  file cannot create directory: /usr/local/include/sundials.  Maybe need
  administrative privileges.

I know this is self-explanatory but what I don't understand is that I am declaring install prefix in my $HOME directory. This is the build script I've written:

#!/bin/sh

#Package details
base=$HOME/sundials
pkg=sundials
vrs=3.1.2

#Go to sundials base folder
cd $base

#Environment variables
export srcdir=$base/$pkg-$vrs
export instdir=$base/$pkg-$vrs-install
export builddir=$base/$pkg-$vrs-build

#Do not build in-source
mkdir -p $builddir
cd $builddir

#Build
cmake \
  --DCMAKE_INSTALL_PREFIX=$instdir \
  --DMPI_ENABLE=ON   \
  --DHYPRE_ENABLE=ON \
  --DHYPRE_INCLUDE_DIR=${HYPRE_ROOT}/include \
  --DHYPRE_LIBRARY_DIR=${HYPRE_ROOT}/lib     \
  $srcdir

#Compile and install
make
make test
make install

I came across this old thread as I was looking for a workaround:
http://sundials.2283335.n4.nabble.com/The-lighter-side-of-SUNDIALS-td3239773i20.html

Is this really intentionally designed or somehow a bug? What is your suggestions?

Minor documentation error in N_VAbs

Hi,

There appears to be a very minor documentation error of the N_VAbs function of the N_Vector API. See page 91 of this document: https://computing.llnl.gov/sites/default/files/public/kin_guide.pdf

The description is:

Sets the components of the N_Vector z to be the absolute values of the components of the N_Vector x: y_i=|x_i|, i= 0,...,n−1.

I believe it should be:

Sets the components of the N_Vector z to be the absolute values of the components of the N_Vector x: z_i=|x_i|, i= 0,...,n−1.

Note the change of y_i to z_i as there is no vector y defined in this scope.

Tests fail for arkode/CXX_parallel/ark_heat2D.cpp example

If I build SUNDIALS as given here and encoded as a nix derivation thus

{ stdenv
, cmake
, fetchurl
, openmpi
, llvmPackages
, python
, liblapack
, gfortran
, lapackSupport ? true }:

let liblapackShared = liblapack.override {
  shared = true;
};
    openmp = llvmPackages.openmp;

in stdenv.mkDerivation rec {
  pname = "sundials";
  version = "5.0.0";

  buildInputs = [ python openmpi openmp ] ++ stdenv.lib.optionals (lapackSupport) [ gfortran ];
  nativeBuildInputs = [ cmake openmpi openmp ];

  src = fetchurl {
    url = "https://computing.llnl.gov/projects/${pname}/download/${pname}-${version}.tar.gz";
    sha256 = "1lvx5pddjxgyr8kqlira36kxckz7nxwc8xilzfyx0hf607n42l9l";
  };

  patches = [
    (fetchurl {
      # https://github.com/LLNL/sundials/pull/19
      url = "https://github.com/LLNL/sundials/commit/1350421eab6c5ab479de5eccf6af2dcad1eddf30.patch";
      sha256 = "0g67lixp9m85fqpb9rzz1hl1z8ibdg0ldwq5z6flj5zl8a7cw52l";
    })
    (fetchurl {
      # https://github.com/LLNL/sundials/pull/20
      url = "https://github.com/LLNL/sundials/pull/20/commits/2d951bbe1ff7842fcd0dafa28c61b0aa94015f66.patch";
      sha256 = "0lcr6m4lk14yqrxah4rdscpczny5l7m1zpfsjh8bgspadfsgk512";
    })
  ];

  cmakeFlags = [
    "-DEXAMPLES_INSTALL_PATH=${placeholder "out"}/share/examples"
  ] ++ stdenv.lib.optionals (lapackSupport) [

    "-DSUNDIALS_INDEX_SIZE=64"
    "-DMPI_ENABLE=ON"
    "-DMPI_C_COMPILER=${openmpi}/bin/mpicc"
    "-DMPI_CXX_COMPILER=${openmpi}/bin/mpicxx"
    "-DMPIEXEC_EXECUTABLE=${openmpi}/bin/mpirun"

    "-DOPENMP_ENABLE=ON"

    "-DBUILD_SHARED_LIBS=OFF"
    "-DBUILD_STATIC_LIBS=ON"

    "-DBUILD_CVODE=ON"
    "-DBUILD_CVODES=OFF"
    "-DBUILD_IDA=OFF"
    "-DBUILD_IDAS=OFF"
    "-DBUILD_ARKODE=ON"
    "-DBUILD_KINSOL=OFF"
    "-DBUILD_TESTING=ON"
    "-DSUNDIALS_DEVTESTS=ON"
    "-DEXAMPLES_ENABLE_CXX=ON"

    "-DLAPACK_ENABLE=OFF"
    "-DLAPACK_LIBRARIES=${liblapackShared}/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary};${liblapackShared}/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}"
  ];

  doCheck = true;
  preCheck = ''
    export OMP_NUM_THREADS=8
  '';
  checkPhase = "make test";

  meta = with stdenv.lib; {
    description = "Suite of nonlinear differential/algebraic equation solvers";
    homepage    = https://computation.llnl.gov/projects/sundials;
    platforms   = platforms.all;
    maintainers = with maintainers; [ flokli idontgetoutmuch ];
    license     = licenses.bsd3;
  };
}

then the tests fail

The following tests FAILED:
          8 - ark_KrylovDemo_prec (Failed)
          9 - ark_robertson (Failed)
         10 - ark_robertson_constraints (Failed)
         20 - ark_diurnal_kry_p (Failed)
         21 - ark_diurnal_kry_bbd_p (Failed)
         23 - ark_heat2D (Failed)
         29 - cvDirectDemo_ls (Failed)
         30 - cvDiurnal_kry_bp (Failed)
         31 - cvDiurnal_kry (Failed)
         33 - cvKrylovDemo_ls (Failed)
         36 - cvAdvDiff_diag_p (Failed)
         37 - cvAdvDiff_non_p (Failed)
         38 - cvDiurnal_kry_bbd_p (Failed)
         39 - cvDiurnal_kry_p (Failed)
         40 - cvDiurnal_kry_mpimanyvec (Failed)
         43 - test_nvector_mpi_1000_0 (Failed)
         44 - test_nvector_mpi_4_1000_0 (Failed)
         45 - test_nvector_mpimanyvector_serial_1_1000_100_0 (Failed)
         46 - test_nvector_mpimanyvector_parallel1_4_1000_200_0 (Failed)
         47 - test_nvector_mpimanyvector_parallel2_4_200_1000_0 (Failed)
         48 - test_nvector_mpiplusx_4_1000_9 (Failed)
         89 - test_sunlinsol_spgmr_parallel_100_1_1_50_1e-3_0 (Failed)
         90 - test_sunlinsol_spgmr_parallel_100_1_2_50_1e-3_0 (Failed)
         91 - test_sunlinsol_spgmr_parallel_100_2_1_50_1e-3_0 (Failed)
         92 - test_sunlinsol_spgmr_parallel_100_2_2_50_1e-3_0 (Failed)
         93 - test_sunlinsol_spfgmr_parallel_100_1_50_1e-3_0 (Failed)
         94 - test_sunlinsol_spfgmr_parallel_100_2_50_1e-3_0 (Failed)
         95 - test_sunlinsol_spbcgs_parallel_100_1_50_1e-3_0 (Failed)
         96 - test_sunlinsol_spbcgs_parallel_100_2_50_1e-3_0 (Failed)
         97 - test_sunlinsol_sptfqmr_parallel_100_1_50_1e-3_0 (Failed)
         98 - test_sunlinsol_sptfqmr_parallel_100_2_50_1e-3_0 (Failed)
Errors while running CTest

But if I turn off the tests

  doCheck = true;

and run

nix-shell --pure -I nixpkgs=~/nixpkgs test.nix
mpicxx ark_heat2D.cpp -lm -lsundials_arkode -lsundials_nvecparallel -o ark_heat2D
mpiexec -n 4 ./ark_heat2D

then I can reproduce the results in the documentation :)

2D Heat PDE test problem:
   nprocs = 4
   nx = 60
   ny = 120
   kx = 0.5
   ky = 0.75
   rtol = 1e-05
   atol = 1e-10
   nxl (proc 0) = 30
   nyl (proc 0) = 60

        t      ||u||_rms
   ----------------------
    0.000000    0.000000
    0.015000    0.005780
    0.030000    0.009224
    0.045000    0.011275
    0.060000    0.012497
    0.075000    0.013224
    0.090000    0.013658
    0.105000    0.013916
    0.120000    0.014070
    0.135000    0.014162
    0.150000    0.014216
    0.165000    0.014249
    0.180000    0.014268
    0.195000    0.014280
    0.210000    0.014287
    0.225000    0.014291
    0.240000    0.014293
    0.255000    0.014295
    0.270000    0.014295
    0.285000    0.014296
    0.300000    0.014296
   ----------------------

Final Solver Statistics:
   Internal solver steps = 51 (attempted = 51)
   Total RHS evals:  Fe = 0,  Fi = 513
   Total linear solver setups = 18
   Total linear iterations = 4451
   Total number of Jacobian-vector products = 4451
   Total number of Preconditioner setups = 1
   Total number of Preconditioner solves = 4666
   Total number of linear solver convergence failures = 215
   Total number of Newton iterations = 255
   Total number of nonlinear solver convergence failures = 0
   Total number of error test failures = 0

The tests fail on both macos and ubuntu.

Does anyone have any idea why the tests are failing?

@flokli

KINInit leaks memory on successive calls

Calling KINInit more than once in a particular context leaks memory.

KINInit calls KINAllocVectors here:

allocOK = KINAllocVectors(kin_mem, tmpl);

which in turn assigns to kin_unew here:

kin_mem->kin_unew = N_VClone(tmpl);

without checking whether kin_unew was previously assigned. This causes the N_Vector kin_unew held from the previous init to be leaked.

It appears that a call to KINFreeVectors in the prologue of KINAllocVectors will catch this and be safe, except potentially

kin_mem->kin_lrw -= 5*kin_mem->kin_lrw1;
kin_mem->kin_liw -= 5*kin_mem->kin_liw1;
which are not covered by a null check.

(related to LLNL/GridDyn#53)

cmake error in windows 10 to build sundials 5.7.0

Hello

I have been using sundials 5.5.0 in windows 10 with visual studio 19.

I am trying to build the 5.7.0 version in the same computer but I got cmake error in CMake3.21.1 (3.18.2 also ) gui.

Could you help to fix this issue ?

Thanks,
Wonseok

Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19043.
The C compiler identification is MSVC 19.27.29111.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdint.h
Looking for stdint.h - found
Looking for stddef.h
Looking for stddef.h - found
Check size of int64_t
Check size of int64_t - done
Using int64_t for indices
Looking for _POSIX_TIMERS
Looking for _POSIX_TIMERS - not found
CMake Error at CMakeLists.txt:187 (add_subdirectory):
  add_subdirectory given source "src" which is not an existing directory.


CMake Error at CMakeLists.txt:192 (add_subdirectory):
  add_subdirectory given source "examples" which is not an existing
  directory.

Configuring incomplete, errors occurred!
See also "D:/Sundials/sundials5.7.0/sundials-5.7.0-build/CMakeFiles/CMakeOutput.log".
See also "D:/Sundials/sundials5.7.0/sundials-5.7.0-build/CMakeFiles/CMakeError.log".

ENABLE_LAPACK=ON fails because it ignores LDFLAGS

/usr/local/bin/cmake -E cmake_link_script CMakeFiles/ltest.dir/link.txt --verbose=1
/usr/bin/cc -O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing CMakeFiles/ltest.dir/ltest.o -o ltest  -lopenblas -lopenblas 
ld: error: unable to find library -lopenblas
ld: error: unable to find library -lopenblas
cc: error: linker command failed with exit code 1 (use -v to see invocation)

These LDFLAGS were ignored:
LDFLAGS="-Wl,-rpath=/usr/local/lib/gcc10 -L/usr/local/lib/gcc10 -B/usr/local/bin -L/usr/local/lib -fstack-protector-strong -L/usr/local/lib"

OS: FreeBSD 13

Segmentation fault in CVAdataStore

For some parameter values I get a segmentation fault while doing adjoint sensitivity analysis.
The problematic point is line 2033 in the following snippet:

sundials/src/cvodes/cvodea.c

Lines 2027 to 2037 in 0c83e0b

i = 1;
do {
flag = CVode(cv_mem, ck_mem->ck_t1, ca_mem->ca_ytmp, &t, CV_ONE_STEP);
if (flag < 0) return(CV_FWD_FAIL);
dt_mem[i]->t = t;
ca_mem->ca_IMstore(cv_mem, dt_mem[i]);
i++;
} while ( sign*(ck_mem->ck_t1 - t) > ZERO );

It seems that the index i is not checked for being inside the bounds of the dt_mem array.
If I add the check if (i > ca_mem->ca_nsteps) return(CV_FWD_FAIL); at the beginning of the loop body the segmentation fault is solved.
However, I am not sure if this is the correct thing to do or if index i should always be inside the bounds and the actual problem lies elsewhere.

Static Analysis Identifies 821 Potential Issues

Our continuous integration pipeline performs static analysis on all source code. As we integrated SUNDIALS into one of our projects, the static analysis on the sources identified 821 potential issues:

Issue Kind Count
Dead assignment 323
Dereference of null pointer 152
Result of operation is garbage or undefined 18
Uninitialized argument value 23
Leak 9
Memory leak 282
Allocator sizeof operand mismatch 14
Total 821

The typical pattern for null pointer dereference (the more concerning case) is as follows:

while (IDAB_mem != NULL) {
    if( which == IDAB_mem->ida_index ) break;
    IDAB_mem = IDAB_mem->ida_next;
}  
N_VScale(ONE, IDAB_mem->ida_yy, yy);

In the above pattern (observed in line 1549 of file src/idas/idaa.c) we see that when IDAB_mem is in fact NULL, execution will proceed directly to N_VScale(ONE, IDAB_mem->ida_yy, yy), resulting in a dereference of null pointer. All 821 issues are described in detail in https://www.nablazerolabs.com/sundials/.

Floating-point underflow in root-finding functions

Root-finding functions like arkRootfind and cvRootfind use floating-point multiplication to check whether a sign change has occurred. This is prone to floating-point underflow (e.g. (-1e-166) * 1e-166 evaluates to 0) which makes the algorithm assume that the sign change was on the wrong sub-interval.

Here's a commit fixing this issue for cvode and arkode; feel free to pull it into sundials if you find it useful. The fix may need to be ported to other packages as well.

Thanks for maintaining sundials!

Missing check if preconditioner for matrix-free linear solver is set

Problem

I run into a problem with the matrix-free linear solvers like SUNLinSol_SPFGMR. Basically I had chosen the wrong preconditioner setting PREC_LEFT and didn't supply a preconditioner function with IDASetPreconditioner().
Since the error only showed while solving the linear system (in my case inside IDASolve()) I had to search for the problem for some time.

Suggested solution

So would it be a good idea to add a small check for NULL somewhere after the call to SUNLinSol_SPGMR(y, PREC_NONE, 5);?

Or alternatively add a small check in SUNLinSolSolve_SPGMR() in sunlinsol_spgmr.c to test if psolve is NULL and return an error flag.

For the other matrix-free linear solvers this applies as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.