From d9cfb6247a202377c1b137e1052b88787df1c15a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 23 Dec 2022 16:53:36 +0200 Subject: [PATCH] Update headers to 6.1.1 and add testing action --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 49 ++ DESCRIPTION | 2 +- README.md | 2 +- inst/include/cvode/cvode.h | 42 +- inst/include/cvode/cvode_bandpre.h | 2 +- inst/include/cvode/cvode_bbdpre.h | 2 +- inst/include/cvode/cvode_diag.h | 2 +- inst/include/cvode/cvode_direct.h | 27 +- inst/include/cvode/cvode_ls.h | 7 +- inst/include/cvode/cvode_proj.h | 2 +- inst/include/cvode/cvode_spils.h | 44 +- inst/include/cvodes/cvodes.h | 41 +- inst/include/cvodes/cvodes_bandpre.h | 2 +- inst/include/cvodes/cvodes_bbdpre.h | 2 +- inst/include/cvodes/cvodes_diag.h | 2 +- inst/include/cvodes/cvodes_direct.h | 38 +- inst/include/cvodes/cvodes_ls.h | 11 +- inst/include/cvodes/cvodes_spils.h | 62 ++- inst/include/ida/ida.h | 7 +- inst/include/ida/ida_bbdpre.h | 2 +- inst/include/ida/ida_direct.h | 27 +- inst/include/ida/ida_ls.h | 2 +- inst/include/ida/ida_spils.h | 51 +- inst/include/nvector/nvector_openmp.h | 30 +- inst/include/nvector/nvector_openmpdev.h | 33 +- inst/include/nvector/nvector_parallel.h | 42 +- inst/include/nvector/nvector_serial.h | 30 +- inst/include/sundials/sundials_band.h | 191 +++++--- inst/include/sundials/sundials_config.h | 62 ++- inst/include/sundials/sundials_config.in | 50 +- inst/include/sundials/sundials_context.h | 65 +++ inst/include/sundials/sundials_dense.h | 318 ++++++++----- inst/include/sundials/sundials_direct.h | 308 +++++++----- inst/include/sundials/sundials_fconfig.h | 47 -- inst/include/sundials/sundials_fconfig.in | 47 -- inst/include/sundials/sundials_futils.h | 2 +- inst/include/sundials/sundials_iterative.h | 353 +++++++++++--- inst/include/sundials/sundials_lapack.h | 4 +- inst/include/sundials/sundials_linearsolver.h | 13 +- inst/include/sundials/sundials_math.h | 2 +- inst/include/sundials/sundials_matrix.h | 6 +- inst/include/sundials/sundials_mpi_types.h | 6 +- .../sundials/sundials_nonlinearsolver.h | 11 +- inst/include/sundials/sundials_nvector.h | 64 ++- .../sundials/sundials_nvector_senswrapper.h | 4 +- inst/include/sundials/sundials_profiler.h | 117 +++++ inst/include/sundials/sundials_types.h | 77 +-- inst/include/sundials/sundials_version.h | 2 +- inst/include/sunlinsol/sunlinsol_band.h | 9 +- .../sunlinsol/sunlinsol_cusolversp_batchqr.h | 7 +- inst/include/sunlinsol/sunlinsol_dense.h | 9 +- inst/include/sunlinsol/sunlinsol_klu.h | 13 +- inst/include/sunlinsol/sunlinsol_lapackband.h | 21 +- .../include/sunlinsol/sunlinsol_lapackdense.h | 21 +- inst/include/sunlinsol/sunlinsol_pcg.h | 21 +- inst/include/sunlinsol/sunlinsol_spbcgs.h | 22 +- inst/include/sunlinsol/sunlinsol_spfgmr.h | 26 +- inst/include/sunlinsol/sunlinsol_spgmr.h | 42 +- inst/include/sunlinsol/sunlinsol_sptfqmr.h | 22 +- .../include/sunlinsol/sunlinsol_superludist.h | 5 +- inst/include/sunlinsol/sunlinsol_superlumt.h | 13 +- inst/include/sunmatrix/sunmatrix_band.h | 21 +- inst/include/sunmatrix/sunmatrix_dense.h | 14 +- inst/include/sunmatrix/sunmatrix_slunrloc.h | 4 +- inst/include/sunmatrix/sunmatrix_sparse.h | 17 +- .../sunnonlinsol/sunnonlinsol_fixedpoint.h | 20 +- .../sunnonlinsol/sunnonlinsol_newton.h | 10 +- .../sunnonlinsol/sunnonlinsol_petscsnes.h | 6 +- src/Makevars | 2 +- src/cvode.cpp | 13 +- src/cvodes.cpp | 13 +- src/cvsolve.cpp | 16 +- src/ida.cpp | 17 +- src/sundials/cvode/cvode.c | 83 +++- src/sundials/cvode/cvode_bandpre.c | 8 +- src/sundials/cvode/cvode_bandpre_impl.h | 2 +- src/sundials/cvode/cvode_bbdpre.c | 12 +- src/sundials/cvode/cvode_bbdpre_impl.h | 2 +- src/sundials/cvode/cvode_diag.c | 2 +- src/sundials/cvode/cvode_diag_impl.h | 2 +- src/sundials/cvode/cvode_direct.c | 2 +- src/sundials/cvode/cvode_impl.h | 8 +- src/sundials/cvode/cvode_io.c | 2 +- src/sundials/cvode/cvode_ls.c | 13 +- src/sundials/cvode/cvode_ls_impl.h | 2 +- src/sundials/cvode/cvode_nls.c | 2 +- src/sundials/cvode/cvode_proj.c | 2 +- src/sundials/cvode/cvode_spils.c | 2 +- src/sundials/cvodes/cvodea.c | 104 ++++- src/sundials/cvodes/cvodea_io.c | 2 +- src/sundials/cvodes/cvodes.c | 268 +++++++++-- src/sundials/cvodes/cvodes_bandpre.c | 8 +- src/sundials/cvodes/cvodes_bandpre_impl.h | 2 +- src/sundials/cvodes/cvodes_bbdpre.c | 12 +- src/sundials/cvodes/cvodes_bbdpre_impl.h | 2 +- src/sundials/cvodes/cvodes_diag.c | 2 +- src/sundials/cvodes/cvodes_diag_impl.h | 2 +- src/sundials/cvodes/cvodes_direct.c | 2 +- src/sundials/cvodes/cvodes_impl.h | 12 +- src/sundials/cvodes/cvodes_io.c | 60 ++- src/sundials/cvodes/cvodes_ls.c | 40 +- src/sundials/cvodes/cvodes_ls_impl.h | 2 +- src/sundials/cvodes/cvodes_nls.c | 2 +- src/sundials/cvodes/cvodes_nls_sim.c | 8 +- src/sundials/cvodes/cvodes_nls_stg.c | 8 +- src/sundials/cvodes/cvodes_nls_stg1.c | 2 +- src/sundials/cvodes/cvodes_spils.c | 2 +- src/sundials/ida/ida.c | 109 ++++- src/sundials/ida/ida_bbdpre.c | 10 +- src/sundials/ida/ida_bbdpre_impl.h | 2 +- src/sundials/ida/ida_direct.c | 2 +- src/sundials/ida/ida_ic.c | 73 +-- src/sundials/ida/ida_impl.h | 6 +- src/sundials/ida/ida_io.c | 2 +- src/sundials/ida/ida_ls.c | 6 +- src/sundials/ida/ida_ls_impl.h | 2 +- src/sundials/ida/ida_nls.c | 2 +- src/sundials/ida/ida_spils.c | 2 +- src/sundials/nvector/serial/nvector_serial.c | 87 ++-- src/sundials/sundials/sundials_band.c | 148 ++++-- src/sundials/sundials/sundials_context.c | 129 +++++ .../sundials/sundials/sundials_context_impl.h | 32 +- src/sundials/sundials/sundials_dense.c | 169 +++++-- src/sundials/sundials/sundials_direct.c | 150 ++++-- src/sundials/sundials/sundials_iterative.c | 405 ++++++++++++++-- .../sundials/sundials_iterative_impl.h | 35 ++ src/sundials/sundials/sundials_linearsolver.c | 90 +++- src/sundials/sundials/sundials_math.c | 2 +- src/sundials/sundials/sundials_matrix.c | 63 ++- .../sundials/sundials_nonlinearsolver.c | 40 +- src/sundials/sundials/sundials_nvector.c | 439 +++++++++++++----- .../sundials/sundials_nvector_senswrapper.c | 88 ++-- src/sundials/sundials/sundials_version.c | 6 +- src/sundials/sunlinsol/band/sunlinsol_band.c | 23 +- .../sunlinsol/dense/sunlinsol_dense.c | 22 +- src/sundials/sunmatrix/band/sunmatrix_band.c | 50 +- .../sunmatrix/dense/sunmatrix_dense.c | 24 +- .../sunnonlinsol/fixedpoint/sundials_debug.h | 2 +- .../fixedpoint/sunnonlinsol_fixedpoint.c | 12 +- .../sunnonlinsol/newton/sundials_debug.h | 2 +- .../sunnonlinsol/newton/sunnonlinsol_newton.c | 12 +- 143 files changed, 3957 insertions(+), 1671 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 inst/include/sundials/sundials_context.h delete mode 100644 inst/include/sundials/sundials_fconfig.h delete mode 100644 inst/include/sundials/sundials_fconfig.in create mode 100644 inst/include/sundials/sundials_profiler.h create mode 100644 src/sundials/sundials/sundials_context.c rename inst/include/sundials/sundials_fnvector.h => src/sundials/sundials/sundials_context_impl.h (54%) create mode 100644 src/sundials/sundials/sundials_iterative_impl.h diff --git a/.Rbuildignore b/.Rbuildignore index 49d53c9..3f54e59 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ cran-comments.md ^_pkgdown\.yml$ ^docs$ ^pkgdown$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..a3ac618 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/DESCRIPTION b/DESCRIPTION index 4db704c..e4a1b1a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Imports: Rcpp (>= 0.12.5) LinkingTo: Rcpp, RcppArmadillo -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Suggests: knitr, rmarkdown, diff --git a/README.md b/README.md index ffacd6a..5b0d344 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build status](https://ci.appveyor.com/api/projects/status/3mp1p26lpqp16t3d?svg=true)](https://ci.appveyor.com/project/sn248/sundialr) [![Travis-CI Build Status](https://travis-ci.org/sn248/sundialr.svg?branch=master)](https://travis-ci.org/sn248/sundialr) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/sundialr)](https://cran.r-project.org/package=sundialr) [![](https://cranlogs.r-pkg.org/badges/grand-total/sundialr)]( https://CRAN.R-project.org/package=sundialr) [![DOI](https://zenodo.org/badge/60889710.svg)](https://zenodo.org/badge/latestdoi/60889710) - +[![R-CMD-check](https://github.com/sn248/sundialr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sn248/sundialr/actions/workflows/R-CMD-check.yaml) ## sundialr diff --git a/inst/include/cvode/cvode.h b/inst/include/cvode/cvode.h index 64bcb88..f31fd4b 100644 --- a/inst/include/cvode/cvode.h +++ b/inst/include/cvode/cvode.h @@ -3,7 +3,7 @@ * and Dan Shumaker @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,6 +19,7 @@ #define _CVODE_H #include +#include #include #include #include @@ -81,6 +82,8 @@ extern "C" { #define CV_PROJFUNC_FAIL -30 #define CV_REPTD_PROJFUNC_ERR -31 +#define CV_CONTEXT_ERR -32 + #define CV_UNRECOGNIZED_ERR -99 @@ -107,7 +110,7 @@ typedef int (*CVMonitorFn)(void *cvode_mem, void *user_data); * ------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT void *CVodeCreate(int lmm); +SUNDIALS_EXPORT void *CVodeCreate(int lmm, SUNContext sunctx); SUNDIALS_EXPORT int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0); @@ -121,30 +124,29 @@ SUNDIALS_EXPORT int CVodeSVtolerances(void *cvode_mem, realtype reltol, SUNDIALS_EXPORT int CVodeWFtolerances(void *cvode_mem, CVEwtFn efun); /* Optional input functions */ -SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, - void *eh_data); + +SUNDIALS_EXPORT int CVodeSetConstraints(void *cvode_mem, N_Vector constraints); SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp); -SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data); -SUNDIALS_EXPORT int CVodeSetMonitorFn(void *cvode_mem, CVMonitorFn fn); -SUNDIALS_EXPORT int CVodeSetMonitorFrequency(void *cvode_mem, long int nst); -SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord); -SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps); -SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil); -SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet); +SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data); SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin); -SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin); -SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax); -SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop); +SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp); +SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf); SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef); +SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil); SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor); -SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf); -SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef); -SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp); -SUNDIALS_EXPORT int CVodeSetConstraints(void *cvode_mem, N_Vector constraints); -SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void *cvode_mem, - SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps); +SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord); +SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax); +SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin); +SUNDIALS_EXPORT int CVodeSetMonitorFn(void *cvode_mem, CVMonitorFn fn); +SUNDIALS_EXPORT int CVodeSetMonitorFrequency(void *cvode_mem, long int nst); SUNDIALS_EXPORT int CVodeSetNlsRhsFn(void *cvode_mem, CVRhsFn f); +SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef); +SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void *cvode_mem, SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet); +SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop); SUNDIALS_EXPORT int CVodeSetUseIntegratorFusedKernels(void *cvode_mem, booleantype onoff); +SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data); /* Rootfinding initialization function */ SUNDIALS_EXPORT int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g); diff --git a/inst/include/cvode/cvode_bandpre.h b/inst/include/cvode/cvode_bandpre.h index 90503e0..c7365e2 100644 --- a/inst/include/cvode/cvode_bandpre.h +++ b/inst/include/cvode/cvode_bandpre.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvode/cvode_bbdpre.h b/inst/include/cvode/cvode_bbdpre.h index aa7b2c0..7b7cea1 100644 --- a/inst/include/cvode/cvode_bbdpre.h +++ b/inst/include/cvode/cvode_bbdpre.h @@ -4,7 +4,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvode/cvode_diag.h b/inst/include/cvode/cvode_diag.h index 5ba13dd..8e22ba0 100644 --- a/inst/include/cvode/cvode_diag.h +++ b/inst/include/cvode/cvode_diag.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * --------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvode/cvode_direct.h b/inst/include/cvode/cvode_direct.h index 0fbe8a5..d360a23 100644 --- a/inst/include/cvode/cvode_direct.h +++ b/inst/include/cvode/cvode_direct.h @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -36,21 +36,28 @@ typedef CVLsJacFn CVDlsJacFn; Exported Functions (wrappers for equivalent routines in cvode_ls.h) ===================================================================*/ -SUNDIALS_EXPORT int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, - SUNMatrix A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetLinearSolver instead") +int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, + SUNMatrix A); -SUNDIALS_EXPORT int CVDlsSetJacFn(void *cvode_mem, CVDlsJacFn jac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacFn instead") +int CVDlsSetJacFn(void *cvode_mem, CVDlsJacFn jac); -SUNDIALS_EXPORT int CVDlsGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinWorkSpace instead") +int CVDlsGetWorkSpace(void *cvode_mem, long int *lenrwLS, + long int *leniwLS); -SUNDIALS_EXPORT int CVDlsGetNumJacEvals(void *cvode_mem, long int *njevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumJacEvals instead") +int CVDlsGetNumJacEvals(void *cvode_mem, long int *njevals); -SUNDIALS_EXPORT int CVDlsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumLinRhsEvals instead") +int CVDlsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); -SUNDIALS_EXPORT int CVDlsGetLastFlag(void *cvode_mem, long int *flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLastLinFlag instead") +int CVDlsGetLastFlag(void *cvode_mem, long int *flag); -SUNDIALS_EXPORT char *CVDlsGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinReturnFlagName instead") +char *CVDlsGetReturnFlagName(long int flag); #ifdef __cplusplus diff --git a/inst/include/cvode/cvode_ls.h b/inst/include/cvode/cvode_ls.h index bd8d8a0..8a0b733 100644 --- a/inst/include/cvode/cvode_ls.h +++ b/inst/include/cvode/cvode_ls.h @@ -4,7 +4,7 @@ * Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -135,11 +135,6 @@ SUNDIALS_EXPORT int CVodeGetLastLinFlag(void *cvode_mem, long int *flag); SUNDIALS_EXPORT char *CVodeGetLinReturnFlagName(long int flag); - -/* Deprecated functions */ -SUNDIALS_DEPRECATED_EXPORT -int CVodeSetMaxStepsBetweenJac(void *cvode_mem, long int msbj); - #ifdef __cplusplus } #endif diff --git a/inst/include/cvode/cvode_proj.h b/inst/include/cvode/cvode_proj.h index 1e21338..fb61de3 100644 --- a/inst/include/cvode/cvode_proj.h +++ b/inst/include/cvode/cvode_proj.h @@ -4,7 +4,7 @@ * Based on CPODES by Radu Serban @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvode/cvode_spils.h b/inst/include/cvode/cvode_spils.h index 59da0d7..0cba479 100644 --- a/inst/include/cvode/cvode_spils.h +++ b/inst/include/cvode/cvode_spils.h @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -39,36 +39,50 @@ typedef CVLsJacTimesVecFn CVSpilsJacTimesVecFn; Exported Functions (wrappers for equivalent routines in cvode_ls.h) ====================================================================*/ -SUNDIALS_EXPORT int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetLinearSolver instead") +int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS); -SUNDIALS_EXPORT int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetEpsLin instead") +int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac); -SUNDIALS_EXPORT int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn pset, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetPreconditioner instead") +int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn pset, CVSpilsPrecSolveFn psolve); -SUNDIALS_EXPORT int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacTimes instead") +int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, CVSpilsJacTimesVecFn jtimes); -SUNDIALS_EXPORT int CVSpilsGetWorkSpace(void *cvode_mem, long int *lenrwLS, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinWorkSpace instead") +int CVSpilsGetWorkSpace(void *cvode_mem, long int *lenrwLS, long int *leniwLS); -SUNDIALS_EXPORT int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumPrecEvals instead") +int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals); -SUNDIALS_EXPORT int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumPrecSolves instead") +int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves); -SUNDIALS_EXPORT int CVSpilsGetNumLinIters(void *cvode_mem, long int *nliters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumLinIters instead") +int CVSpilsGetNumLinIters(void *cvode_mem, long int *nliters); -SUNDIALS_EXPORT int CVSpilsGetNumConvFails(void *cvode_mem, long int *nlcfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumConvFails instead") +int CVSpilsGetNumConvFails(void *cvode_mem, long int *nlcfails); -SUNDIALS_EXPORT int CVSpilsGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumJTSetupEvals instead") +int CVSpilsGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups); -SUNDIALS_EXPORT int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumJtimesEvals instead") +int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals); -SUNDIALS_EXPORT int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumLinRhsEvals instead") +int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); -SUNDIALS_EXPORT int CVSpilsGetLastFlag(void *cvode_mem, long int *flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLastLinFlag instead") +int CVSpilsGetLastFlag(void *cvode_mem, long int *flag); -SUNDIALS_EXPORT char *CVSpilsGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinReturnFlagName instead") +char *CVSpilsGetReturnFlagName(long int flag); #ifdef __cplusplus diff --git a/inst/include/cvodes/cvodes.h b/inst/include/cvodes/cvodes.h index 58fdff6..5d52bf0 100644 --- a/inst/include/cvodes/cvodes.h +++ b/inst/include/cvodes/cvodes.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,6 +18,7 @@ #define _CVODES_H #include +#include #include #include #include @@ -107,6 +108,7 @@ extern "C" { #define CV_REPTD_QSRHSFUNC_ERR -53 #define CV_UNREC_QSRHSFUNC_ERR -54 +#define CV_CONTEXT_ERR -55 #define CV_UNRECOGNIZED_ERR -99 @@ -136,6 +138,8 @@ typedef void (*CVErrHandlerFn)(int error_code, const char *module, const char *function, char *msg, void *user_data); +typedef int (*CVMonitorFn)(void *cvode_mem, void *user_data); + typedef int (*CVQuadRhsFn)(realtype t, N_Vector y, N_Vector yQdot, void *user_data); @@ -176,7 +180,7 @@ typedef int (*CVQuadRhsFnBS)(realtype t, N_Vector y, N_Vector *yS, * --------------------------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT void *CVodeCreate(int lmm); +SUNDIALS_EXPORT void *CVodeCreate(int lmm, SUNContext sunctx); SUNDIALS_EXPORT int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0); @@ -190,27 +194,28 @@ SUNDIALS_EXPORT int CVodeSVtolerances(void *cvode_mem, realtype reltol, SUNDIALS_EXPORT int CVodeWFtolerances(void *cvode_mem, CVEwtFn efun); /* Optional input functions */ -SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, - void *eh_data); + +SUNDIALS_EXPORT int CVodeSetConstraints(void *cvode_mem, N_Vector constraints); SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp); -SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data); -SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord); -SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps); -SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil); -SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet); +SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data); SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin); -SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin); -SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax); -SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop); +SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp); +SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf); SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef); +SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil); SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor); -SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf); -SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef); -SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void *cvode_mem, long int msbp); -SUNDIALS_EXPORT int CVodeSetConstraints(void *cvode_mem, N_Vector constraints); -SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void *cvode_mem, - SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps); +SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord); +SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax); +SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin); +SUNDIALS_EXPORT int CVodeSetMonitorFn(void *cvode_mem, CVMonitorFn fn); +SUNDIALS_EXPORT int CVodeSetMonitorFrequency(void *cvode_mem, long int nst); SUNDIALS_EXPORT int CVodeSetNlsRhsFn(void *cvode_mem, CVRhsFn f); +SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef); +SUNDIALS_EXPORT int CVodeSetNonlinearSolver(void *cvode_mem, SUNNonlinearSolver NLS); +SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet); +SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop); +SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data); /* Rootfinding initialization function */ SUNDIALS_EXPORT int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g); diff --git a/inst/include/cvodes/cvodes_bandpre.h b/inst/include/cvodes/cvodes_bandpre.h index 7397dcf..32c8519 100644 --- a/inst/include/cvodes/cvodes_bandpre.h +++ b/inst/include/cvodes/cvodes_bandpre.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvodes/cvodes_bbdpre.h b/inst/include/cvodes/cvodes_bbdpre.h index 8f8b15f..194a65b 100644 --- a/inst/include/cvodes/cvodes_bbdpre.h +++ b/inst/include/cvodes/cvodes_bbdpre.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvodes/cvodes_diag.h b/inst/include/cvodes/cvodes_diag.h index d8bb65c..f7963d0 100644 --- a/inst/include/cvodes/cvodes_diag.h +++ b/inst/include/cvodes/cvodes_diag.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * --------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/cvodes/cvodes_direct.h b/inst/include/cvodes/cvodes_direct.h index cf1d3c9..378a049 100644 --- a/inst/include/cvodes/cvodes_direct.h +++ b/inst/include/cvodes/cvodes_direct.h @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -38,28 +38,38 @@ typedef CVLsJacFnBS CVDlsJacFnBS; Exported Functions (wrappers for equivalent routines in cvodes_ls.h) ====================================================================*/ -SUNDIALS_EXPORT int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, - SUNMatrix A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetLinearSolver instead") +int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, + SUNMatrix A); -SUNDIALS_EXPORT int CVDlsSetJacFn(void *cvode_mem, CVDlsJacFn jac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacFn instead") +int CVDlsSetJacFn(void *cvode_mem, CVDlsJacFn jac); -SUNDIALS_EXPORT int CVDlsGetWorkSpace(void *cvode_mem, long int *lenrwLS, - long int *leniwLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinWorkSpace instead") +int CVDlsGetWorkSpace(void *cvode_mem, long int *lenrwLS, + long int *leniwLS); -SUNDIALS_EXPORT int CVDlsGetNumJacEvals(void *cvode_mem, long int *njevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumJacEvals instead") +int CVDlsGetNumJacEvals(void *cvode_mem, long int *njevals); -SUNDIALS_EXPORT int CVDlsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumLinRhsEvals instead") +int CVDlsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); -SUNDIALS_EXPORT int CVDlsGetLastFlag(void *cvode_mem, long int *flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLastLinFlag instead") +int CVDlsGetLastFlag(void *cvode_mem, long int *flag); -SUNDIALS_EXPORT char *CVDlsGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinReturnFlagName instead") +char *CVDlsGetReturnFlagName(long int flag); -SUNDIALS_EXPORT int CVDlsSetLinearSolverB(void *cvode_mem, int which, - SUNLinearSolver LS, SUNMatrix A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetLinearSolverB instead") +int CVDlsSetLinearSolverB(void *cvode_mem, int which, + SUNLinearSolver LS, SUNMatrix A); -SUNDIALS_EXPORT int CVDlsSetJacFnB(void *cvode_mem, int which, CVDlsJacFnB jacB); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacFnB instead") +int CVDlsSetJacFnB(void *cvode_mem, int which, CVDlsJacFnB jacB); -SUNDIALS_EXPORT int CVDlsSetJacFnBS(void *cvode_mem, int which, CVDlsJacFnBS jacBS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacFnBS instead") +int CVDlsSetJacFnBS(void *cvode_mem, int which, CVDlsJacFnBS jacBS); #ifdef __cplusplus diff --git a/inst/include/cvodes/cvodes_ls.h b/inst/include/cvodes/cvodes_ls.h index b92a737..13a4aa3 100644 --- a/inst/include/cvodes/cvodes_ls.h +++ b/inst/include/cvodes/cvodes_ls.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -134,6 +134,11 @@ SUNDIALS_EXPORT int CVodeGetNumJtimesEvals(void *cvode_mem, long int *njvevals); SUNDIALS_EXPORT int CVodeGetNumLinRhsEvals(void *cvode_mem, long int *nfevalsLS); +SUNDIALS_EXPORT int CVodeGetLinSolveStats(void* cvode_mem, + long int* njevals, long int* nfevalsLS, + long int* nliters, long int* nlcfails, + long int* npevals, long int* npsolves, + long int* njtsetups, long int* njtimes); SUNDIALS_EXPORT int CVodeGetLastLinFlag(void *cvode_mem, long int *flag); SUNDIALS_EXPORT char *CVodeGetLinReturnFlagName(long int flag); @@ -256,10 +261,6 @@ SUNDIALS_EXPORT int CVodeSetLinSysFnB(void *cvode_mem, int which, SUNDIALS_EXPORT int CVodeSetLinSysFnBS(void *cvode_mem, int which, CVLsLinSysFnBS linsys); -/* Deprecated functions */ -SUNDIALS_DEPRECATED_EXPORT -int CVodeSetMaxStepsBetweenJac(void *cvode_mem, long int msbj); - #ifdef __cplusplus } #endif diff --git a/inst/include/cvodes/cvodes_spils.h b/inst/include/cvodes/cvodes_spils.h index 66a9b00..78f2179 100644 --- a/inst/include/cvodes/cvodes_spils.h +++ b/inst/include/cvodes/cvodes_spils.h @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -47,55 +47,75 @@ typedef CVLsJacTimesVecFnBS CVSpilsJacTimesVecFnBS; Exported Functions (wrappers for equivalent routines in cvodes_ls.h) ====================================================================*/ -SUNDIALS_EXPORT int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetLinearSolver instead") +int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS); -SUNDIALS_EXPORT int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetEpsLin instead") +int CVSpilsSetEpsLin(void *cvode_mem, realtype eplifac); -SUNDIALS_EXPORT int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn pset, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetPreconditioner instead") +int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn pset, CVSpilsPrecSolveFn psolve); -SUNDIALS_EXPORT int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacTimes instead") +int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, CVSpilsJacTimesVecFn jtimes); -SUNDIALS_EXPORT int CVSpilsGetWorkSpace(void *cvode_mem, long int *lenrwLS, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinWorkSpace instead") +int CVSpilsGetWorkSpace(void *cvode_mem, long int *lenrwLS, long int *leniwLS); -SUNDIALS_EXPORT int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumPrecEvals instead") +int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals); -SUNDIALS_EXPORT int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumPrecSolves instead") +int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves); -SUNDIALS_EXPORT int CVSpilsGetNumLinIters(void *cvode_mem, long int *nliters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumLinIters instead") +int CVSpilsGetNumLinIters(void *cvode_mem, long int *nliters); -SUNDIALS_EXPORT int CVSpilsGetNumConvFails(void *cvode_mem, long int *nlcfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumConvFails instead") +int CVSpilsGetNumConvFails(void *cvode_mem, long int *nlcfails); -SUNDIALS_EXPORT int CVSpilsGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumJTSetupEvals instead") +int CVSpilsGetNumJTSetupEvals(void *cvode_mem, long int *njtsetups); -SUNDIALS_EXPORT int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumJtimesEvals instead") +int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals); -SUNDIALS_EXPORT int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetNumLinRhsEvals instead") +int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS); -SUNDIALS_EXPORT int CVSpilsGetLastFlag(void *cvode_mem, long int *flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLastLinFlag instead") +int CVSpilsGetLastFlag(void *cvode_mem, long int *flag); -SUNDIALS_EXPORT char *CVSpilsGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeGetLinReturnFlagName instead") +char *CVSpilsGetReturnFlagName(long int flag); -SUNDIALS_EXPORT int CVSpilsSetLinearSolverB(void *cvode_mem, int which, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetLinearSolverB instead") +int CVSpilsSetLinearSolverB(void *cvode_mem, int which, SUNLinearSolver LS); -SUNDIALS_EXPORT int CVSpilsSetEpsLinB(void *cvode_mem, int which, realtype eplifacB); +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetEpsLinB instead") +int CVSpilsSetEpsLinB(void *cvode_mem, int which, realtype eplifacB); -SUNDIALS_EXPORT int CVSpilsSetPreconditionerB(void *cvode_mem, int which, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetPreconditionerB instead") +int CVSpilsSetPreconditionerB(void *cvode_mem, int which, CVSpilsPrecSetupFnB psetB, CVSpilsPrecSolveFnB psolveB); -SUNDIALS_EXPORT int CVSpilsSetPreconditionerBS(void *cvode_mem, int which, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetPreconditionerBS instead") +int CVSpilsSetPreconditionerBS(void *cvode_mem, int which, CVSpilsPrecSetupFnBS psetBS, CVSpilsPrecSolveFnBS psolveBS); -SUNDIALS_EXPORT int CVSpilsSetJacTimesB(void *cvode_mem, int which, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacTimesB instead") +int CVSpilsSetJacTimesB(void *cvode_mem, int which, CVSpilsJacTimesSetupFnB jtsetupB, CVSpilsJacTimesVecFnB jtimesB); -SUNDIALS_EXPORT int CVSpilsSetJacTimesBS(void *cvode_mem, int which, +SUNDIALS_DEPRECATED_EXPORT_MSG("use CVodeSetJacTimesBS instead") +int CVSpilsSetJacTimesBS(void *cvode_mem, int which, CVSpilsJacTimesSetupFnBS jtsetupBS, CVSpilsJacTimesVecFnBS jtimesBS); diff --git a/inst/include/ida/ida.h b/inst/include/ida/ida.h index d1c8849..07ee79e 100644 --- a/inst/include/ida/ida.h +++ b/inst/include/ida/ida.h @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,6 +19,7 @@ #define _IDA_H #include +#include #include #include #include @@ -77,6 +78,8 @@ extern "C" { #define IDA_BAD_DKY -27 #define IDA_VECTOROP_ERR -28 +#define IDA_CONTEXT_ERR -29 + #define IDA_UNRECOGNIZED_ERROR -99 @@ -101,7 +104,7 @@ typedef void (*IDAErrHandlerFn)(int error_code, * ------------------- */ /* Initialization functions */ -SUNDIALS_EXPORT void *IDACreate(void); +SUNDIALS_EXPORT void *IDACreate(SUNContext sunctx); SUNDIALS_EXPORT int IDAInit(void *ida_mem, IDAResFn res, realtype t0, N_Vector yy0, N_Vector yp0); diff --git a/inst/include/ida/ida_bbdpre.h b/inst/include/ida/ida_bbdpre.h index 37ec92a..3a75ff7 100644 --- a/inst/include/ida/ida_bbdpre.h +++ b/inst/include/ida/ida_bbdpre.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh, Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/ida/ida_direct.h b/inst/include/ida/ida_direct.h index cae882d..5c96bd8 100644 --- a/inst/include/ida/ida_direct.h +++ b/inst/include/ida/ida_direct.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -37,21 +37,28 @@ typedef IDALsJacFn IDADlsJacFn; Exported Functions (wrappers for equivalent routines in ida_ls.h) ===================================================================*/ -SUNDIALS_EXPORT int IDADlsSetLinearSolver(void *ida_mem, SUNLinearSolver LS, - SUNMatrix A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetLinearSolver instead") +int IDADlsSetLinearSolver(void *ida_mem, SUNLinearSolver LS, + SUNMatrix A); -SUNDIALS_EXPORT int IDADlsSetJacFn(void *ida_mem, IDADlsJacFn jac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetJacFn instead") +int IDADlsSetJacFn(void *ida_mem, IDADlsJacFn jac); -SUNDIALS_EXPORT int IDADlsGetWorkSpace(void *ida_mem, long int *lenrwLS, - long int *leniwLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetLinWorkSpace instead") +int IDADlsGetWorkSpace(void *ida_mem, long int *lenrwLS, + long int *leniwLS); -SUNDIALS_EXPORT int IDADlsGetNumJacEvals(void *ida_mem, long int *njevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumJacEvals instead") +int IDADlsGetNumJacEvals(void *ida_mem, long int *njevals); -SUNDIALS_EXPORT int IDADlsGetNumResEvals(void *ida_mem, long int *nrevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumLinResEvals instead") +int IDADlsGetNumResEvals(void *ida_mem, long int *nrevalsLS); -SUNDIALS_EXPORT int IDADlsGetLastFlag(void *ida_mem, long int *flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetLastLinFlag instead") +int IDADlsGetLastFlag(void *ida_mem, long int *flag); -SUNDIALS_EXPORT char *IDADlsGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetLinReturnFlagName instead") +char *IDADlsGetReturnFlagName(long int flag); #ifdef __cplusplus diff --git a/inst/include/ida/ida_ls.h b/inst/include/ida/ida_ls.h index 1c30b25..ce75180 100644 --- a/inst/include/ida/ida_ls.h +++ b/inst/include/ida/ida_ls.h @@ -4,7 +4,7 @@ * Aaron Collier @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/ida/ida_spils.h b/inst/include/ida/ida_spils.h index bc8c5d2..f878aa8 100644 --- a/inst/include/ida/ida_spils.h +++ b/inst/include/ida/ida_spils.h @@ -3,7 +3,7 @@ * Alan Hindmarsh, Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -40,37 +40,52 @@ typedef IDALsJacTimesVecFn IDASpilsJacTimesVecFn; Exported Functions (wrappers for equivalent routines in ida_ls.h) ====================================================================*/ -SUNDIALS_EXPORT int IDASpilsSetLinearSolver(void *ida_mem, SUNLinearSolver LS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetLinearSolver instead") +int IDASpilsSetLinearSolver(void *ida_mem, SUNLinearSolver LS); -SUNDIALS_EXPORT int IDASpilsSetPreconditioner(void *ida_mem, IDASpilsPrecSetupFn pset, - IDASpilsPrecSolveFn psolve); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetPreconditioner instead") +int IDASpilsSetPreconditioner(void *ida_mem, IDASpilsPrecSetupFn pset, + IDASpilsPrecSolveFn psolve); -SUNDIALS_EXPORT int IDASpilsSetJacTimes(void *ida_mem, IDASpilsJacTimesSetupFn jtsetup, - IDASpilsJacTimesVecFn jtimes); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetJacTimes instead") +int IDASpilsSetJacTimes(void *ida_mem, IDASpilsJacTimesSetupFn jtsetup, + IDASpilsJacTimesVecFn jtimes); -SUNDIALS_EXPORT int IDASpilsSetEpsLin(void *ida_mem, realtype eplifac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetEpsLin instead") +int IDASpilsSetEpsLin(void *ida_mem, realtype eplifac); -SUNDIALS_EXPORT int IDASpilsSetIncrementFactor(void *ida_mem, realtype dqincfac); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDASetIncrementFactor instead") +int IDASpilsSetIncrementFactor(void *ida_mem, realtype dqincfac); -SUNDIALS_EXPORT int IDASpilsGetWorkSpace(void *ida_mem, long int *lenrwLS, long int *leniwLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetLinWorkSpace instead") +int IDASpilsGetWorkSpace(void *ida_mem, long int *lenrwLS, long int *leniwLS); -SUNDIALS_EXPORT int IDASpilsGetNumPrecEvals(void *ida_mem, long int *npevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumPrecEvals instead") +int IDASpilsGetNumPrecEvals(void *ida_mem, long int *npevals); -SUNDIALS_EXPORT int IDASpilsGetNumPrecSolves(void *ida_mem, long int *npsolves); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumPrecSolves instead") +int IDASpilsGetNumPrecSolves(void *ida_mem, long int *npsolves); -SUNDIALS_EXPORT int IDASpilsGetNumLinIters(void *ida_mem, long int *nliters); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumLinIters instead") +int IDASpilsGetNumLinIters(void *ida_mem, long int *nliters); -SUNDIALS_EXPORT int IDASpilsGetNumConvFails(void *ida_mem, long int *nlcfails); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumLinConvFails instead") +int IDASpilsGetNumConvFails(void *ida_mem, long int *nlcfails); -SUNDIALS_EXPORT int IDASpilsGetNumJTSetupEvals(void *ida_mem, long int *njtsetups); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumJTSetupEvals instead") +int IDASpilsGetNumJTSetupEvals(void *ida_mem, long int *njtsetups); -SUNDIALS_EXPORT int IDASpilsGetNumJtimesEvals(void *ida_mem, long int *njvevals); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumJtimesEvals instead") +int IDASpilsGetNumJtimesEvals(void *ida_mem, long int *njvevals); -SUNDIALS_EXPORT int IDASpilsGetNumResEvals(void *ida_mem, long int *nrevalsLS); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetNumLinResEvals instead") +int IDASpilsGetNumResEvals(void *ida_mem, long int *nrevalsLS); -SUNDIALS_EXPORT int IDASpilsGetLastFlag(void *ida_mem, long int *flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetLastLinFlag instead") +int IDASpilsGetLastFlag(void *ida_mem, long int *flag); -SUNDIALS_EXPORT char *IDASpilsGetReturnFlagName(long int flag); +SUNDIALS_DEPRECATED_EXPORT_MSG("use IDAGetLinReturnFlagName instead") +char *IDASpilsGetReturnFlagName(long int flag); #ifdef __cplusplus diff --git a/inst/include/nvector/nvector_openmp.h b/inst/include/nvector/nvector_openmp.h index 8292b0a..e5b0138 100644 --- a/inst/include/nvector/nvector_openmp.h +++ b/inst/include/nvector/nvector_openmp.h @@ -7,7 +7,7 @@ * @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -89,18 +89,12 @@ typedef struct _N_VectorContent_OpenMP *N_VectorContent_OpenMP; * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector N_VNew_OpenMP(sunindextype vec_length, int num_threads); +SUNDIALS_EXPORT N_Vector N_VNew_OpenMP(sunindextype vec_length, int num_threads, SUNContext sunctx); -SUNDIALS_EXPORT N_Vector N_VNewEmpty_OpenMP(sunindextype vec_length, int num_threads); +SUNDIALS_EXPORT N_Vector N_VNewEmpty_OpenMP(sunindextype vec_length, int num_threads, SUNContext sunctx); SUNDIALS_EXPORT N_Vector N_VMake_OpenMP(sunindextype vec_length, realtype *v_data, - int num_threads); - -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArray_OpenMP(int count, N_Vector w); - -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArrayEmpty_OpenMP(int count, N_Vector w); - -SUNDIALS_EXPORT void N_VDestroyVectorArray_OpenMP(N_Vector* vs, int count); + int num_threads, SUNContext sunctx); SUNDIALS_EXPORT sunindextype N_VGetLength_OpenMP(N_Vector v); @@ -200,6 +194,22 @@ SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_OpenMP(N_Vector v, booleant SUNDIALS_EXPORT int N_VEnableScaleAddMultiVectorArray_OpenMP(N_Vector v, booleantype tf); SUNDIALS_EXPORT int N_VEnableLinearCombinationVectorArray_OpenMP(N_Vector v, booleantype tf); +/* + * ----------------------------------------------------------------- + * Deprecated functions + * ----------------------------------------------------------------- + */ + +/* use N_VCloneVectorArray */ +SUNDIALS_DEPRECATED_EXPORT N_Vector* N_VCloneVectorArray_OpenMP(int count, N_Vector w); + +/* use N_VCloneVectorArrayEmpty */ +SUNDIALS_DEPRECATED_EXPORT N_Vector* N_VCloneVectorArrayEmpty_OpenMP(int count, N_Vector w); + +/* use N_VDestroyVectorArray */ +SUNDIALS_DEPRECATED_EXPORT void N_VDestroyVectorArray_OpenMP(N_Vector* vs, int count); + + #ifdef __cplusplus } #endif diff --git a/inst/include/nvector/nvector_openmpdev.h b/inst/include/nvector/nvector_openmpdev.h index 81774ec..1ea6efe 100644 --- a/inst/include/nvector/nvector_openmpdev.h +++ b/inst/include/nvector/nvector_openmpdev.h @@ -7,7 +7,7 @@ * @ LLNL * ------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -87,19 +87,14 @@ typedef struct _N_VectorContent_OpenMPDEV *N_VectorContent_OpenMPDEV; * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector N_VNew_OpenMPDEV(sunindextype vec_length); +SUNDIALS_EXPORT N_Vector N_VNew_OpenMPDEV(sunindextype vec_length, SUNContext sunctx); -SUNDIALS_EXPORT N_Vector N_VNewEmpty_OpenMPDEV(sunindextype vec_length); +SUNDIALS_EXPORT N_Vector N_VNewEmpty_OpenMPDEV(sunindextype vec_length, SUNContext sunctx); SUNDIALS_EXPORT N_Vector N_VMake_OpenMPDEV(sunindextype vec_length, realtype *h_data, - realtype *v_data); - -SUNDIALS_EXPORT N_Vector *N_VCloneVectorArray_OpenMPDEV(int count, N_Vector w); - -SUNDIALS_EXPORT N_Vector *N_VCloneVectorArrayEmpty_OpenMPDEV(int count, N_Vector w); - -SUNDIALS_EXPORT void N_VDestroyVectorArray_OpenMPDEV(N_Vector *vs, int count); + realtype *v_data, + SUNContext sunctx); SUNDIALS_EXPORT sunindextype N_VGetLength_OpenMPDEV(N_Vector v); @@ -179,7 +174,7 @@ SUNDIALS_EXPORT realtype N_VWSqrSumLocal_OpenMPDEV(N_Vector x, N_Vector w); SUNDIALS_EXPORT realtype N_VWSqrSumMaskLocal_OpenMPDEV(N_Vector x, N_Vector w, N_Vector id); - + /* * ----------------------------------------------------------------- * Enable / disable fused vector operations @@ -200,6 +195,22 @@ SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_OpenMPDEV(N_Vector v, boole SUNDIALS_EXPORT int N_VEnableScaleAddMultiVectorArray_OpenMPDEV(N_Vector v, booleantype tf); SUNDIALS_EXPORT int N_VEnableLinearCombinationVectorArray_OpenMPDEV(N_Vector v, booleantype tf); +/* + * ----------------------------------------------------------------- + * Deprecated functions + * ----------------------------------------------------------------- + */ + +/* use N_VCloneVectorArray */ +SUNDIALS_DEPRECATED_EXPORT N_Vector *N_VCloneVectorArray_OpenMPDEV(int count, N_Vector w); + +/* use N_VCloneVectorArrayEmpty */ +SUNDIALS_DEPRECATED_EXPORT N_Vector *N_VCloneVectorArrayEmpty_OpenMPDEV(int count, N_Vector w); + +/* use N_VDestroyVectorArray */ +SUNDIALS_DEPRECATED_EXPORT void N_VDestroyVectorArray_OpenMPDEV(N_Vector *vs, int count); + + #ifdef __cplusplus } #endif diff --git a/inst/include/nvector/nvector_parallel.h b/inst/include/nvector/nvector_parallel.h index 3ceebd5..da28e32 100644 --- a/inst/include/nvector/nvector_parallel.h +++ b/inst/include/nvector/nvector_parallel.h @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -92,22 +92,19 @@ typedef struct _N_VectorContent_Parallel *N_VectorContent_Parallel; SUNDIALS_EXPORT N_Vector N_VNew_Parallel(MPI_Comm comm, sunindextype local_length, - sunindextype global_length); + sunindextype global_length, + SUNContext sunctx); SUNDIALS_EXPORT N_Vector N_VNewEmpty_Parallel(MPI_Comm comm, sunindextype local_length, - sunindextype global_length); + sunindextype global_length, + SUNContext sunctx); SUNDIALS_EXPORT N_Vector N_VMake_Parallel(MPI_Comm comm, sunindextype local_length, sunindextype global_length, - realtype *v_data); - -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArray_Parallel(int count, N_Vector w); - -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArrayEmpty_Parallel(int count, N_Vector w); - -SUNDIALS_EXPORT void N_VDestroyVectorArray_Parallel(N_Vector* vs, int count); + realtype *v_data, + SUNContext sunctx); SUNDIALS_EXPORT sunindextype N_VGetLength_Parallel(N_Vector v); @@ -194,6 +191,13 @@ SUNDIALS_EXPORT booleantype N_VConstrMaskLocal_Parallel(N_Vector c, N_Vector x, SUNDIALS_EXPORT realtype N_VMinQuotientLocal_Parallel(N_Vector num, N_Vector denom); +/* OPTIONAL single buffer reduction operations */ +SUNDIALS_EXPORT int N_VDotProdMultiLocal_Parallel(int nvec, N_Vector x, + N_Vector* Y, + realtype* dotprods); +SUNDIALS_EXPORT int N_VDotProdMultiAllReduce_Parallel(int nvec_total, N_Vector x, + realtype* dotprods); + /* OPTIONAL XBraid interface operations */ SUNDIALS_EXPORT int N_VBufSize_Parallel(N_Vector x, sunindextype *size); SUNDIALS_EXPORT int N_VBufPack_Parallel(N_Vector x, void *buf); @@ -219,6 +223,24 @@ SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_Parallel(N_Vector v, boolea SUNDIALS_EXPORT int N_VEnableScaleAddMultiVectorArray_Parallel(N_Vector v, booleantype tf); SUNDIALS_EXPORT int N_VEnableLinearCombinationVectorArray_Parallel(N_Vector v, booleantype tf); +SUNDIALS_EXPORT int N_VEnableDotProdMultiLocal_Parallel(N_Vector v, booleantype tf); + +/* + * ----------------------------------------------------------------- + * Deprecated functions + * ----------------------------------------------------------------- + */ + +/* use N_VCloneVectorArray */ +SUNDIALS_DEPRECATED_EXPORT N_Vector* N_VCloneVectorArray_Parallel(int count, N_Vector w); + +/* use N_VCloneVectorArrayEmpty */ +SUNDIALS_DEPRECATED_EXPORT N_Vector* N_VCloneVectorArrayEmpty_Parallel(int count, N_Vector w); + +/* use N_VDestroyVectorArray */ +SUNDIALS_DEPRECATED_EXPORT void N_VDestroyVectorArray_Parallel(N_Vector* vs, int count); + + #ifdef __cplusplus } #endif diff --git a/inst/include/nvector/nvector_serial.h b/inst/include/nvector/nvector_serial.h index 646bde1..95c6c3b 100644 --- a/inst/include/nvector/nvector_serial.h +++ b/inst/include/nvector/nvector_serial.h @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -82,17 +82,11 @@ typedef struct _N_VectorContent_Serial *N_VectorContent_Serial; * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector N_VNew_Serial(sunindextype vec_length); +SUNDIALS_EXPORT N_Vector N_VNew_Serial(sunindextype vec_length, SUNContext sunctx); -SUNDIALS_EXPORT N_Vector N_VNewEmpty_Serial(sunindextype vec_length); +SUNDIALS_EXPORT N_Vector N_VNewEmpty_Serial(sunindextype vec_length, SUNContext sunctx); -SUNDIALS_EXPORT N_Vector N_VMake_Serial(sunindextype vec_length, realtype *v_data); - -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArray_Serial(int count, N_Vector w); - -SUNDIALS_EXPORT N_Vector* N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w); - -SUNDIALS_EXPORT void N_VDestroyVectorArray_Serial(N_Vector* vs, int count); +SUNDIALS_EXPORT N_Vector N_VMake_Serial(sunindextype vec_length, realtype *v_data, SUNContext sunctx); SUNDIALS_EXPORT sunindextype N_VGetLength_Serial(N_Vector v); @@ -190,6 +184,22 @@ SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_Serial(N_Vector v, booleant SUNDIALS_EXPORT int N_VEnableScaleAddMultiVectorArray_Serial(N_Vector v, booleantype tf); SUNDIALS_EXPORT int N_VEnableLinearCombinationVectorArray_Serial(N_Vector v, booleantype tf); +/* + * ----------------------------------------------------------------- + * Deprecated functions + * ----------------------------------------------------------------- + */ + +/* use N_VCloneVectorArray */ +SUNDIALS_DEPRECATED_EXPORT N_Vector* N_VCloneVectorArray_Serial(int count, N_Vector w); + +/* use N_VCloneVectorArrayEmpty */ +SUNDIALS_DEPRECATED_EXPORT N_Vector* N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w); + +/* use N_VDestroyVectorArray */ +SUNDIALS_DEPRECATED_EXPORT void N_VDestroyVectorArray_Serial(N_Vector* vs, int count); + + #ifdef __cplusplus } #endif diff --git a/inst/include/sundials/sundials_band.h b/inst/include/sundials/sundials_band.h index 1d24445..2ba469a 100644 --- a/inst/include/sundials/sundials_band.h +++ b/inst/include/sundials/sundials_band.h @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -12,12 +12,12 @@ * SUNDIALS Copyright End * ----------------------------------------------------------------- * This is the header file for a generic BAND linear solver - * package, based on the DlsMat type defined in sundials_direct.h. + * package, based on the SUNDlsMat type defined in sundials_direct.h. * * There are two sets of band solver routines listed in - * this file: one set uses type DlsMat defined below and the + * this file: one set uses type SUNDlsMat defined below and the * other set uses the type realtype ** for band matrix arguments. - * Routines that work with the type DlsMat begin with "Band". + * Routines that work with the type SUNDlsMat begin with "Band". * Routines that work with realtype ** begin with "band". * -----------------------------------------------------------------*/ @@ -32,12 +32,12 @@ extern "C" { /* * ----------------------------------------------------------------- - * Function : BandGBTRF + * Function: SUNDlsMat_BandGBTRF * ----------------------------------------------------------------- - * Usage : ier = BandGBTRF(A, p); + * Usage : ier = SUNDlsMat_BandGBTRF(A, p); * if (ier != 0) ... A is singular * ----------------------------------------------------------------- - * BandGBTRF performs the LU factorization of the N by N band + * SUNDlsMat_BandGBTRF performs the LU factorization of the N by N band * matrix A. This is done using standard Gaussian elimination * with partial pivoting. * @@ -45,7 +45,7 @@ extern "C" { * pivot array p with the following information: * * (1) p[k] contains the row number of the pivot element chosen - * at the beginning of elimination step k, k=0, 1, ..., N-1. + * at the beginning of elimination step k, k = 0, 1, ..., N-1. * * (2) If the unique LU factorization of A is given by PA = LU, * where P is a permutation matrix, L is a lower triangular @@ -54,7 +54,7 @@ extern "C" { * (including its diagonal) contains U and the strictly lower * triangular part of A contains the multipliers, I-L. * - * BandGBTRF returns 0 if successful. Otherwise it encountered + * SUNDlsMat_BandGBTRF returns 0 if successful. Otherwise it encountered * a zero diagonal element during the factorization. In this case * it returns the column index (numbered from one) at which * it encountered the zero. @@ -68,111 +68,168 @@ extern "C" { * call A = BandAllocMat(N,mu,ml,smu), where mu, ml, and smu are * as defined above. The user does not have to zero the "extra" * storage allocated for the purpose of factorization. This will - * handled by the BandGBTRF routine. + * handled by the SUNDlsMat_BandGBTRF routine. * - * BandGBTRF is only a wrapper around bandGBTRF. All work is done - * in bandGBTRF, which works directly on the data in the DlsMat A - * (i.e. in the field A->cols). + * SUNDlsMat_BandGBTRF is only a wrapper around SUNDlsMat_bandGBTRF. + * All work is done in SUNDlsMat_bandGBTRF, which works directly on the + * data in the SUNDlsMat A (i.e. in the field A->cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype BandGBTRF(DlsMat A, sunindextype *p); -SUNDIALS_EXPORT sunindextype bandGBTRF(realtype **a, sunindextype n, - sunindextype mu, sunindextype ml, - sunindextype smu, sunindextype *p); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_BandGBTRF(SUNDlsMat A, sunindextype* p); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_BandGBTRF instead") +sunindextype BandGBTRF(DlsMat A, sunindextype *p); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_bandGBTRF(realtype **a, sunindextype n, + sunindextype mu, sunindextype ml, + sunindextype smu, sunindextype *p); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_bandGBTRF instead") +sunindextype bandGBTRF(realtype **a, sunindextype n, + sunindextype mu, sunindextype ml, + sunindextype smu, sunindextype *p); /* * ----------------------------------------------------------------- - * Function : BandGBTRS + * Function: SUNDlsMat_BandGBTRS * ----------------------------------------------------------------- - * Usage : BandGBTRS(A, p, b); + * Usage: SUNDlsMat_BandGBTRS(A, p, b); * ----------------------------------------------------------------- - * BandGBTRS solves the N-dimensional system A x = b using - * the LU factorization in A and the pivot information in p - * computed in BandGBTRF. The solution x is returned in b. This - * routine cannot fail if the corresponding call to BandGBTRF - * did not fail. + * SUNDlsMat_BandGBTRS solves the N-dimensional system A x = b using + * the LU factorization in A and the pivot information in p computed + * in SUNDlsMat_BandGBTRF. The solution x is returned in b. This + * routine cannot fail if the corresponding call to + * SUNDlsMat_BandGBTRF did not fail. * - * BandGBTRS is only a wrapper around bandGBTRS which does all the - * work directly on the data in the DlsMat A (i.e. in A->cols). + * SUNDlsMat_BandGBTRS is only a wrapper around SUNDlsMat_bandGBTRS + * which does all the work directly on the data in the DlsMat A (i.e. + * in A->cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandGBTRS(DlsMat A, sunindextype *p, realtype *b); -SUNDIALS_EXPORT void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, - sunindextype ml, sunindextype *p, realtype *b); +SUNDIALS_EXPORT +void SUNDlsMat_BandGBTRS(SUNDlsMat A, sunindextype *p, realtype *b); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_BandGBTRS instead") +void BandGBTRS(DlsMat A, sunindextype *p, realtype *b); + +SUNDIALS_EXPORT +void SUNDlsMat_bandGBTRS(realtype **a, sunindextype n, sunindextype smu, + sunindextype ml, sunindextype *p, realtype *b); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_bandGBTRS instead") +void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, + sunindextype ml, sunindextype *p, realtype *b); /* * ----------------------------------------------------------------- - * Function : BandCopy + * Function: SUNDlsMat_BandCopy * ----------------------------------------------------------------- - * Usage : BandCopy(A, B, copymu, copyml); + * Usage: SUNDlsMat_BandCopy(A, B, copymu, copyml); * ----------------------------------------------------------------- - * BandCopy copies the submatrix with upper and lower bandwidths - * copymu, copyml of the N by N band matrix A into the N by N - * band matrix B. + * SUNDlsMat_BandCopy copies the submatrix with upper and lower + * bandwidths copymu, copyml of the N by N band matrix A into the N by + * N band matrix B. * - * BandCopy is a wrapper around bandCopy which accesses the data - * in the DlsMat A and DlsMat B (i.e. the fields cols). + * SUNDlsMat_BandCopy is a wrapper around SUNDlsMat_bandCopy which + * accesses the data in the DlsMat A and DlsMat B (i.e. the fields + * cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandCopy(DlsMat A, DlsMat B, sunindextype copymu, - sunindextype copyml); -SUNDIALS_EXPORT void bandCopy(realtype **a, realtype **b, sunindextype n, - sunindextype a_smu, sunindextype b_smu, - sunindextype copymu, sunindextype copyml); +SUNDIALS_EXPORT +void SUNDlsMat_BandCopy(SUNDlsMat A, SUNDlsMat B, sunindextype copymu, + sunindextype copyml); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_BandCopy instead") +void BandCopy(DlsMat A, DlsMat B, sunindextype copymu, + sunindextype copyml); + +SUNDIALS_EXPORT +void SUNDlsMat_bandCopy(realtype **a, realtype **b, sunindextype n, + sunindextype a_smu, sunindextype b_smu, + sunindextype copymu, sunindextype copyml); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_bandCopy instead") +void bandCopy(realtype **a, realtype **b, sunindextype n, + sunindextype a_smu, sunindextype b_smu, + sunindextype copymu, sunindextype copyml); /* * ----------------------------------------------------------------- - * Function: BandScale + * Function: SUNDlsMat_BandScale * ----------------------------------------------------------------- - * Usage : BandScale(c, A); + * Usage: SUNDlsMat_BandScale(c, A); * ----------------------------------------------------------------- - * A(i,j) <- c*A(i,j), j-(A->mu) <= i <= j+(A->ml). + * A(i,j) <- c*A(i,j), j-(A->mu) < = i < = j+(A->ml). * - * BandScale is a wrapper around bandScale which performs the actual - * scaling by accessing the data in the DlsMat A (i.e. the field - * A->cols). + * SUNDlsMat_BandScale is a wrapper around SUNDlsMat_bandScale which + * performs the actual scaling by accessing the data in the + * SUNDlsMat A (i.e. the field A->cols). * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandScale(realtype c, DlsMat A); -SUNDIALS_EXPORT void bandScale(realtype c, realtype **a, sunindextype n, - sunindextype mu, sunindextype ml, - sunindextype smu); +void SUNDlsMat_BandScale(realtype c, SUNDlsMat A); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_BandScale instead") +void BandScale(realtype c, DlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_bandScale(realtype c, realtype **a, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_bandScale instead") +void bandScale(realtype c, realtype **a, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu); /* * ----------------------------------------------------------------- - * Function: bandAddIdentity + * Function: SUNDlsMat_bandAddIdentity * ----------------------------------------------------------------- - * bandAddIdentity adds the identity matrix to the n-by-n matrix - * stored in the realtype** arrays. + * SUNDlsMat_bandAddIdentity adds the identity matrix to the n-by-n + * matrix stored in the realtype** arrays. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void bandAddIdentity(realtype **a, sunindextype n, - sunindextype smu); +void SUNDlsMat_bandAddIdentity(realtype **a, sunindextype n, sunindextype smu); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_bandAddIdentity instead") +void bandAddIdentity(realtype **a, sunindextype n, sunindextype smu); /* * ----------------------------------------------------------------- - * Function: BandMatvec + * Function: SUNDlsMat_BandMatvec * ----------------------------------------------------------------- - * BandMatvec computes the matrix-vector product y = A*x, where A - * is an M-by-N band matrix, x is a vector of length N, and y is a - * vector of length M. No error checking is performed on the length - * of the arrays x and y. Only y is modified in this routine. + * SUNDlsMat_BandMatvec computes the matrix-vector product y = A*x, + * where A is an M-by-N band matrix, x is a vector of length N, and y + * is a vector of length M. No error checking is performed on the + * length of the arrays x and y. Only y is modified in this routine. * - * BandMatvec is a wrapper around bandMatvec which performs the - * actual product by accessing the data in the DlsMat A. + * SUNDlsMat_BandMatvec is a wrapper around SUNDlsMat_bandMatvec which + * performs the actual product by accessing the data in the SUNDlsMat + * A. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void BandMatvec(DlsMat A, realtype *x, realtype *y); -SUNDIALS_EXPORT void bandMatvec(realtype **a, realtype *x, realtype *y, - sunindextype n, sunindextype mu, - sunindextype ml, sunindextype smu); +SUNDIALS_EXPORT +void SUNDlsMat_BandMatvec(SUNDlsMat A, realtype *x, realtype *y); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_BandMatvec instead") +void BandMatvec(DlsMat A, realtype *x, realtype *y); + +SUNDIALS_EXPORT +void SUNDlsMat_bandMatvec(realtype **a, realtype *x, realtype *y, + sunindextype n, sunindextype mu, + sunindextype ml, sunindextype smu); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_bandMatvec instead") +void bandMatvec(realtype **a, realtype *x, realtype *y, + sunindextype n, sunindextype mu, + sunindextype ml, sunindextype smu); #ifdef __cplusplus } diff --git a/inst/include/sundials/sundials_config.h b/inst/include/sundials/sundials_config.h index a67f627..6f1b0e4 100644 --- a/inst/include/sundials/sundials_config.h +++ b/inst/include/sundials/sundials_config.h @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos, Aaron Collier and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,17 +14,32 @@ * SUNDIALS configuration header file. * -----------------------------------------------------------------*/ -#include "sundials_export.h" +#ifndef _SUNDIALS_CONFIG_H +#define _SUNDIALS_CONFIG_H + +#include "sundials/sundials_export.h" + +#ifndef SUNDIALS_DEPRECATED_MSG +# define SUNDIALS_DEPRECATED_MSG(msg) __attribute__ ((__deprecated__(msg))) +#endif + +#ifndef SUNDIALS_DEPRECATED_EXPORT_MSG +# define SUNDIALS_DEPRECATED_EXPORT_MSG(msg) SUNDIALS_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +#ifndef SUNDIALS_DEPRECATED_NO_EXPORT_MSG +# define SUNDIALS_DEPRECATED_NO_EXPORT_MSG(msg) SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif /* ------------------------------------------------------------------ * Define SUNDIALS version numbers * -----------------------------------------------------------------*/ -#define SUNDIALS_VERSION "5.8.0" -#define SUNDIALS_VERSION_MAJOR 5 -#define SUNDIALS_VERSION_MINOR 8 -#define SUNDIALS_VERSION_PATCH 0 +#define SUNDIALS_VERSION "6.1.1" +#define SUNDIALS_VERSION_MAJOR 6 +#define SUNDIALS_VERSION_MINOR 1 +#define SUNDIALS_VERSION_PATCH 1 #define SUNDIALS_VERSION_LABEL "" #define SUNDIALS_GIT_VERSION "" @@ -65,25 +80,23 @@ /* Use POSIX timers if available. * #define SUNDIALS_HAVE_POSIX_TIMERS */ -/* #undef SUNDIALS_HAVE_POSIX_TIMERS */ +#define SUNDIALS_HAVE_POSIX_TIMERS -/* CVODE should use fused kernels if utilizing - * the CUDA NVector. - */ +/* BUILD CVODE with fused kernel functionality */ /* #undef SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS */ - -/* BUILD SUNDIALS with monitoring functionalities - * the CUDA NVector. - */ +/* BUILD SUNDIALS with monitoring functionalities */ /* #undef SUNDIALS_BUILD_WITH_MONITORING */ +/* BUILD SUNDIALS with profiling functionalities */ +/* #undef SUNDIALS_BUILD_WITH_PROFILING */ + /* ------------------------------------------------------------------ * SUNDIALS TPL macros * -----------------------------------------------------------------*/ - - +/* Caliper */ +/* #undef SUNDIALS_CALIPER_ENABLED */ /* MAGMA backends */ #define SUNDIALS_MAGMA_BACKENDS_CUDA @@ -113,7 +126,6 @@ * SUNDIALS modules enabled * -----------------------------------------------------------------*/ - #define SUNDIALS_ARKODE 1 #define SUNDIALS_CVODE 1 #define SUNDIALS_CVODES 1 @@ -142,7 +154,7 @@ * -----------------------------------------------------------------*/ -/* FCMIX: Define Fortran name-mangling macro for C identifiers. +/* Define Fortran name-mangling macro for C identifiers. * Depending on the inferred scheme, one of the following six * macros will be defined: * #define SUNDIALS_F77_FUNC(name,NAME) name @@ -154,18 +166,18 @@ */ -/* FCMIX: Define Fortran name-mangling macro for C identifiers - * which contain underscores. +/* Define Fortran name-mangling macro for C identifiers + * which contain underscores. */ -/* FNVECTOR: Allow user to specify different MPI communicator +/* Allow user to specify different MPI communicator * If it was found that the MPI implementation supports MPI_Comm_f2c, then * #define SUNDIALS_MPI_COMM_F2C 1 * otherwise * #define SUNDIALS_MPI_COMM_F2C 0 */ -#define SUNDIALS_MPI_COMM_F2C 1 + /* ------------------------------------------------------------------ @@ -180,8 +192,12 @@ #endif #ifndef SUNDIALS_C_INLINE +#ifndef __STDC_VERSION__ /* must be c89 or c90 */ +#define SUNDIALS_C_INLINE +#else #define SUNDIALS_C_INLINE inline #endif +#endif #ifdef __cplusplus #define SUNDIALS_INLINE SUNDIALS_CXX_INLINE @@ -192,3 +208,5 @@ /* Mark SUNDIALS function as static inline. */ #define SUNDIALS_STATIC_INLINE static SUNDIALS_INLINE + +#endif /* _SUNDIALS_CONFIG_H */ diff --git a/inst/include/sundials/sundials_config.in b/inst/include/sundials/sundials_config.in index b7dde78..238200c 100644 --- a/inst/include/sundials/sundials_config.in +++ b/inst/include/sundials/sundials_config.in @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos, Aaron Collier and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,7 +14,22 @@ * SUNDIALS configuration header file. * -----------------------------------------------------------------*/ -#include "sundials_export.h" +#ifndef _SUNDIALS_CONFIG_H +#define _SUNDIALS_CONFIG_H + +#include "sundials/sundials_export.h" + +#ifndef SUNDIALS_DEPRECATED_MSG +# define SUNDIALS_DEPRECATED_MSG(msg) @SUNDIALS_DEPRECATED_MSG_MACRO@ +#endif + +#ifndef SUNDIALS_DEPRECATED_EXPORT_MSG +# define SUNDIALS_DEPRECATED_EXPORT_MSG(msg) SUNDIALS_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif + +#ifndef SUNDIALS_DEPRECATED_NO_EXPORT_MSG +# define SUNDIALS_DEPRECATED_NO_EXPORT_MSG(msg) SUNDIALS_NO_EXPORT SUNDIALS_DEPRECATED_MSG(msg) +#endif /* ------------------------------------------------------------------ * Define SUNDIALS version numbers @@ -67,23 +82,21 @@ */ #cmakedefine SUNDIALS_HAVE_POSIX_TIMERS -/* CVODE should use fused kernels if utilizing - * the CUDA NVector. - */ +/* BUILD CVODE with fused kernel functionality */ #cmakedefine SUNDIALS_BUILD_PACKAGE_FUSED_KERNELS - -/* BUILD SUNDIALS with monitoring functionalities - * the CUDA NVector. - */ +/* BUILD SUNDIALS with monitoring functionalities */ #cmakedefine SUNDIALS_BUILD_WITH_MONITORING +/* BUILD SUNDIALS with profiling functionalities */ +#cmakedefine SUNDIALS_BUILD_WITH_PROFILING + /* ------------------------------------------------------------------ * SUNDIALS TPL macros * -----------------------------------------------------------------*/ - -@SUNDIALS_CONFIGH_TPLS@ +/* Caliper */ +#cmakedefine SUNDIALS_CALIPER_ENABLED /* MAGMA backends */ #cmakedefine SUNDIALS_MAGMA_BACKENDS_CUDA @@ -113,7 +126,6 @@ * SUNDIALS modules enabled * -----------------------------------------------------------------*/ - @SUNDIALS_CONFIGH_BUILDS@ @@ -122,7 +134,7 @@ * -----------------------------------------------------------------*/ -/* FCMIX: Define Fortran name-mangling macro for C identifiers. +/* Define Fortran name-mangling macro for C identifiers. * Depending on the inferred scheme, one of the following six * macros will be defined: * #define SUNDIALS_F77_FUNC(name,NAME) name @@ -134,12 +146,12 @@ */ @F77_MANGLE_MACRO1@ -/* FCMIX: Define Fortran name-mangling macro for C identifiers - * which contain underscores. +/* Define Fortran name-mangling macro for C identifiers + * which contain underscores. */ @F77_MANGLE_MACRO2@ -/* FNVECTOR: Allow user to specify different MPI communicator +/* Allow user to specify different MPI communicator * If it was found that the MPI implementation supports MPI_Comm_f2c, then * #define SUNDIALS_MPI_COMM_F2C 1 * otherwise @@ -160,8 +172,12 @@ #endif #ifndef SUNDIALS_C_INLINE +#ifndef __STDC_VERSION__ /* must be c89 or c90 */ +#define SUNDIALS_C_INLINE +#else #define SUNDIALS_C_INLINE inline #endif +#endif #ifdef __cplusplus #define SUNDIALS_INLINE SUNDIALS_CXX_INLINE @@ -172,3 +188,5 @@ /* Mark SUNDIALS function as static inline. */ #define SUNDIALS_STATIC_INLINE static SUNDIALS_INLINE + +#endif /* _SUNDIALS_CONFIG_H */ diff --git a/inst/include/sundials/sundials_context.h b/inst/include/sundials/sundials_context.h new file mode 100644 index 0000000..c18e1b6 --- /dev/null +++ b/inst/include/sundials/sundials_context.h @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2022, 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 + * ----------------------------------------------------------------- + * SUNDIALS context class. A context object holds data that all + * SUNDIALS objects in a simulation share. It is thread-safe provided + * that each thread has its own context object. + * ----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_CONTEXT_H +#define _SUNDIALS_CONTEXT_H + +#include "sundials/sundials_types.h" +#include "sundials/sundials_profiler.h" + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef struct _SUNContext *SUNContext; + +SUNDIALS_EXPORT int SUNContext_Create(void* comm, SUNContext* ctx); +SUNDIALS_EXPORT int SUNContext_GetProfiler(SUNContext sunctx, SUNProfiler* profiler); +SUNDIALS_EXPORT int SUNContext_SetProfiler(SUNContext sunctx, SUNProfiler profiler); +SUNDIALS_EXPORT int SUNContext_Free(SUNContext* ctx); + +#ifdef __cplusplus +} + +namespace sundials +{ + +class Context +{ +public: + Context(void* comm = NULL) + { + SUNContext_Create(comm, &sunctx_); + } + + operator SUNContext() { return sunctx_; } + + ~Context() + { + SUNContext_Free(&sunctx_); + } + +private: + SUNContext sunctx_; + +}; + +} /* namespace sundials */ + +#endif +#endif diff --git a/inst/include/sundials/sundials_dense.h b/inst/include/sundials/sundials_dense.h index ae6ca8d..7296346 100644 --- a/inst/include/sundials/sundials_dense.h +++ b/inst/include/sundials/sundials_dense.h @@ -2,7 +2,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -31,178 +31,252 @@ extern "C" { #endif /* - * ----------------------------------------------------------------- - * Functions: DenseGETRF and DenseGETRS - * ----------------------------------------------------------------- - * DenseGETRF performs the LU factorization of the M by N dense - * matrix A. This is done using standard Gaussian elimination - * with partial (row) pivoting. Note that this applies only - * to matrices with M >= N and full column rank. - * - * A successful LU factorization leaves the matrix A and the - * pivot array p with the following information: - * - * (1) p[k] contains the row number of the pivot element chosen - * at the beginning of elimination step k, k=0, 1, ..., N-1. - * - * (2) If the unique LU factorization of A is given by PA = LU, - * where P is a permutation matrix, L is a lower trapezoidal - * matrix with all 1's on the diagonal, and U is an upper - * triangular matrix, then the upper triangular part of A - * (including its diagonal) contains U and the strictly lower + * ---------------------------------------------------------------------------- + * Functions: SUNDlsMat_DenseGETRF and SUNDlsMat_DenseGETRS + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseGETRF performs the LU factorization of the M by N dense matrix A. + * This is done using standard Gaussian elimination with partial (row) pivoting. + * Note that this applies only to matrices with M >= N and full column rank. + * + * A successful LU factorization leaves the matrix A and the pivot array p with + * the following information: + * + * (1) p[k] contains the row number of the pivot element chosen at the beginning + * of elimination step k, k=0, 1, ..., N-1. + * + * (2) If the unique LU factorization of A is given by PA = LU, where P is a + * permutation matrix, L is a lower trapezoidal matrix with all 1's on the + * diagonal, and U is an upper triangular matrix, then the upper triangular + * part of A (including its diagonal) contains U and the strictly lower * trapezoidal part of A contains the multipliers, I-L. * * For square matrices (M = N), L is unit lower triangular. * - * DenseGETRF returns 0 if successful. Otherwise it encountered - * a zero diagonal element during the factorization. In this case - * it returns the column index (numbered from one) at which - * it encountered the zero. + * SUNDlsMat_DenseGETRF returns 0 if successful. Otherwise it encountered a zero + * diagonal element during the factorization. In this case it returns the column + * index (numbered from one) at which it encountered the zero. * - * DenseGETRS solves the N-dimensional system A x = b using - * the LU factorization in A and the pivot information in p - * computed in DenseGETRF. The solution x is returned in b. This - * routine cannot fail if the corresponding call to DenseGETRF - * did not fail. - * DenseGETRS does NOT check for a square matrix! + * SUNDlsMat_DenseGETRS solves the N-dimensional system A x = b using the LU + * factorization in A and the pivot information in p computed in + * SUNDlsMat_DenseGETRF. The solution x is returned in b. This routine cannot fail + * if the corresponding call to SUNDlsMat_DenseGETRF did not fail. + * SUNDlsMat_DenseGETRS does NOT check for a square matrix! * - * ----------------------------------------------------------------- - * DenseGETRF and DenseGETRS are simply wrappers around denseGETRF - * and denseGETRS, respectively, which perform all the work by - * directly accessing the data in the DlsMat A (i.e. in A->cols). - * ----------------------------------------------------------------- + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseGETRF and SUNDlsMat_DenseGETRS are simply wrappers around + * SUNDlsMat_denseGETRF and SUNDlsMat_denseGETRS, respectively, which perform all the + * work by directly accessing the data in the SUNDlsMat A (i.e. in A->cols). + * ---------------------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype DenseGETRF(DlsMat A, sunindextype *p); -SUNDIALS_EXPORT void DenseGETRS(DlsMat A, sunindextype *p, realtype *b); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_DenseGETRF(SUNDlsMat A, sunindextype *p); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DenseGETRF instead") +sunindextype DenseGETRF(DlsMat A, sunindextype *p); + +SUNDIALS_EXPORT +void SUNDlsMat_DenseGETRS(SUNDlsMat A, sunindextype *p, realtype *b); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DenseGETRS instead") +void DenseGETRS(DlsMat A, sunindextype *p, realtype *b); -SUNDIALS_EXPORT sunindextype denseGETRF(realtype **a, sunindextype m, - sunindextype n, sunindextype *p); -SUNDIALS_EXPORT void denseGETRS(realtype **a, sunindextype n, sunindextype *p, - realtype *b); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_denseGETRF(realtype **a, sunindextype m, + sunindextype n, sunindextype *p); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseGETRF instead") +sunindextype denseGETRF(realtype **a, sunindextype m, + sunindextype n, sunindextype *p); + +SUNDIALS_EXPORT +void SUNDlsMat_denseGETRS(realtype **a, sunindextype n, sunindextype *p, + realtype *b); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseGETRS instead") +void denseGETRS(realtype **a, sunindextype n, sunindextype *p, + realtype *b); /* - * ----------------------------------------------------------------- - * Functions : DensePOTRF and DensePOTRS - * ----------------------------------------------------------------- - * DensePOTRF computes the Cholesky factorization of a real symmetric + * ---------------------------------------------------------------------------- + * Functions : SUNDlsMat_DensePOTRF and SUNDlsMat_DensePOTRS + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRF computes the Cholesky factorization of a real symmetric * positive definite matrix A. - * ----------------------------------------------------------------- - * DensePOTRS solves a system of linear equations A*X = B with a - * symmetric positive definite matrix A using the Cholesky factorization - * A = L*L**T computed by DensePOTRF. + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRS solves a system of linear equations A*X = B with a + * symmetric positive definite matrix A using the Cholesky factorization A = + * L*L**T computed by SUNDlsMat_DensePOTRF. * - * ----------------------------------------------------------------- - * DensePOTRF and DensePOTRS are simply wrappers around densePOTRF - * and densePOTRS, respectively, which perform all the work by - * directly accessing the data in the DlsMat A (i.e. the field cols) - * ----------------------------------------------------------------- + * ---------------------------------------------------------------------------- + * SUNDlsMat_DensePOTRF and SUNDlsMat_DensePOTRS are simply wrappers around + * SUNDlsMat_densePOTRF and SUNDlsMat_densePOTRS, respectively, which perform all the + * work by directly accessing the data in the DlsMat A (i.e. the field cols) + * ---------------------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype DensePOTRF(DlsMat A); -SUNDIALS_EXPORT void DensePOTRS(DlsMat A, realtype *b); -SUNDIALS_EXPORT sunindextype densePOTRF(realtype **a, sunindextype m); -SUNDIALS_EXPORT void densePOTRS(realtype **a, sunindextype m, realtype *b); +SUNDIALS_EXPORT +sunindextype SUNDlsMat_DensePOTRF(SUNDlsMat A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DensePOTRF instead") +sunindextype DensePOTRF(DlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_DensePOTRS(SUNDlsMat A, realtype *b); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DensePOTRS instead") +void DensePOTRS(DlsMat A, realtype *b); + +SUNDIALS_EXPORT +sunindextype SUNDlsMat_densePOTRF(realtype **a, sunindextype m); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_densePOTRF instead") +sunindextype densePOTRF(realtype **a, sunindextype m); + +SUNDIALS_EXPORT +void SUNDlsMat_densePOTRS(realtype **a, sunindextype m, realtype *b); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_densePOTRS instead") +void densePOTRS(realtype **a, sunindextype m, realtype *b); /* - * ----------------------------------------------------------------- - * Functions : DenseGEQRF and DenseORMQR - * ----------------------------------------------------------------- - * DenseGEQRF computes a QR factorization of a real M-by-N matrix A: - * A = Q * R (with M>= N). + * ----------------------------------------------------------------------------- + * Functions : SUNDlsMat_DenseGEQRF and SUNDlsMat_DenseORMQR + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseGEQRF computes a QR factorization of a real M-by-N matrix A: A = + * Q * R (with M>= N). * - * DenseGEQRF requires a temporary work vector wrk of length M. - * ----------------------------------------------------------------- - * DenseORMQR computes the product w = Q * v where Q is a real - * orthogonal matrix defined as the product of k elementary reflectors + * SUNDlsMat_DenseGEQRF requires a temporary work vector wrk of length M. + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseORMQR computes the product w = Q * v where Q is a real orthogonal + * matrix defined as the product of k elementary reflectors * * Q = H(1) H(2) . . . H(k) * - * as returned by DenseGEQRF. Q is an M-by-N matrix, v is a vector - * of length N and w is a vector of length M (with M >= N). + * as returned by SUNDlsMat_DenseGEQRF. Q is an M-by-N matrix, v is a vector of + * length N and w is a vector of length M (with M >= N). * - * DenseORMQR requires a temporary work vector wrk of length M. + * SUNDlsMat_DenseORMQR requires a temporary work vector wrk of length M. * - * ----------------------------------------------------------------- - * DenseGEQRF and DenseORMQR are simply wrappers around denseGEQRF - * and denseORMQR, respectively, which perform all the work by - * directly accessing the data in the DlsMat A (i.e. the field cols) - * ----------------------------------------------------------------- + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseGEQRF and SUNDlsMat_DenseORMQR are simply wrappers around + * SUNDlsMat_denseGEQRF and SUNDlsMat_denseORMQR, respectively, which perform all the + * work by directly accessing the data in the DlsMat A (i.e. the field cols) + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT int DenseGEQRF(DlsMat A, realtype *beta, realtype *wrk); -SUNDIALS_EXPORT int DenseORMQR(DlsMat A, realtype *beta, realtype *vn, - realtype *vm, realtype *wrk); +SUNDIALS_EXPORT +int SUNDlsMat_DenseGEQRF(SUNDlsMat A, realtype *beta, realtype *wrk); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DenseGEQRF instead") +int DenseGEQRF(DlsMat A, realtype *beta, realtype *wrk); + +SUNDIALS_EXPORT +int SUNDlsMat_DenseORMQR(SUNDlsMat A, realtype *beta, realtype *vn, + realtype *vm, realtype *wrk); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DenseORMQR instead") +int DenseORMQR(DlsMat A, realtype *beta, realtype *vn, + realtype *vm, realtype *wrk); + + +SUNDIALS_EXPORT +int SUNDlsMat_denseGEQRF(realtype **a, sunindextype m, sunindextype n, + realtype *beta, realtype *wrk); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseGEQRF instead") +int denseGEQRF(realtype **a, sunindextype m, sunindextype n, + realtype *beta, realtype *wrk); -SUNDIALS_EXPORT int denseGEQRF(realtype **a, sunindextype m, sunindextype n, - realtype *beta, realtype *wrk); -SUNDIALS_EXPORT int denseORMQR(realtype **a, sunindextype m, sunindextype n, - realtype *beta, realtype *v, realtype *w, - realtype *wrk); +SUNDIALS_EXPORT +int SUNDlsMat_denseORMQR(realtype **a, sunindextype m, sunindextype n, + realtype *beta, realtype *v, realtype *w, + realtype *wrk); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseORMQR instead") +int denseORMQR(realtype **a, sunindextype m, sunindextype n, + realtype *beta, realtype *v, realtype *w, + realtype *wrk); /* - * ----------------------------------------------------------------- - * Function : DenseCopy - * ----------------------------------------------------------------- - * DenseCopy copies the contents of the M-by-N matrix A into the + * ---------------------------------------------------------------------------- + * Function : SUNDlsMat_DenseCopy + * ---------------------------------------------------------------------------- + * SUNDlsMat_DenseCopy copies the contents of the M-by-N matrix A into the * M-by-N matrix B. * - * DenseCopy is a wrapper around denseCopy which accesses the data - * in the DlsMat A and DlsMat B (i.e. the fields cols) - * ----------------------------------------------------------------- + * SUNDlsMat_DenseCopy is a wrapper around SUNDlsMat_denseCopy which accesses + * the data in the SUNDlsMat A and SUNDlsMat B (i.e. the fields cols) + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void DenseCopy(DlsMat A, DlsMat B); -SUNDIALS_EXPORT void denseCopy(realtype **a, realtype **b, sunindextype m, - sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_DenseCopy(SUNDlsMat A, SUNDlsMat B); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DenseCopy instead") +void DenseCopy(DlsMat A, DlsMat B); + +SUNDIALS_EXPORT +void SUNDlsMat_denseCopy(realtype **a, realtype **b, sunindextype m, + sunindextype n); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseCopy instead") +void denseCopy(realtype **a, realtype **b, sunindextype m, + sunindextype n); /* - * ----------------------------------------------------------------- - * Function: DenseScale - * ----------------------------------------------------------------- - * DenseScale scales the elements of the M-by-N matrix A by the + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_DenseScale + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseScale scales the elements of the M-by-N matrix A by the * constant c and stores the result back in A. * - * DenseScale is a wrapper around denseScale which performs the actual - * scaling by accessing the data in the DlsMat A (i.e. in A->cols). - * ----------------------------------------------------------------- + * SUNDlsMat_DenseScale is a wrapper around SUNDlsMat_denseScale which performs + * the actual scaling by accessing the data in the SUNDlsMat A (i.e. in + * A->cols). + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void DenseScale(realtype c, DlsMat A); -SUNDIALS_EXPORT void denseScale(realtype c, realtype **a, sunindextype m, - sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_DenseScale(realtype c, SUNDlsMat A); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsSUNDlsMat_DenseScale_denseCopy instead") +void DenseScale(realtype c, DlsMat A); + +SUNDIALS_EXPORT +void SUNDlsMat_denseScale(realtype c, realtype **a, sunindextype m, + sunindextype n); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseScale instead") +void denseScale(realtype c, realtype **a, sunindextype m, + sunindextype n); /* - * ----------------------------------------------------------------- - * Function: denseAddIdentity - * ----------------------------------------------------------------- - * denseAddIdentity adds the identity matrix to the n-by-n matrix + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_denseAddIdentity + * ----------------------------------------------------------------------------- + * SUNDlsMat_denseAddIdentity adds the identity matrix to the n-by-n matrix * stored in a realtype** array. - * ----------------------------------------------------------------- + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void denseAddIdentity(realtype **a, sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_denseAddIdentity(realtype **a, sunindextype n); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseAddIdentity instead") +void denseAddIdentity(realtype **a, sunindextype n); /* - * ----------------------------------------------------------------- - * Function: DenseMatvec - * ----------------------------------------------------------------- - * DenseMatvec computes the matrix-vector product y = A*x, where A - * is an M-by-N matrix, x is a vector of length N, and y is a vector - * of length M. No error checking is performed on the length of the - * arrays x and y. Only y is modified in this routine. + * ----------------------------------------------------------------------------- + * Function: SUNDlsMat_DenseMatvec + * ----------------------------------------------------------------------------- + * SUNDlsMat_DenseMatvec computes the matrix-vector product y = A*x, where A is + * an M-by-N matrix, x is a vector of length N, and y is a vector of length M. + * No error checking is performed on the length of the arrays x and y. Only y + * is modified in this routine. * - * DenseMatvec is a wrapper around denseMatvec which performs the - * actual product by accessing the data in the DlsMat A. - * ----------------------------------------------------------------- + * SUNDlsMat_DenseMatvec is a wrapper around SUNDlsMat_denseMatvec which + * performs the actual product by accessing the data in the SUNDlsMat A. + * ----------------------------------------------------------------------------- */ -SUNDIALS_EXPORT void DenseMatvec(DlsMat A, realtype *x, realtype *y); -SUNDIALS_EXPORT void denseMatvec(realtype **a, realtype *x, realtype *y, - sunindextype m, sunindextype n); +SUNDIALS_EXPORT +void SUNDlsMat_DenseMatvec(SUNDlsMat A, realtype *x, realtype *y); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DenseMatvec instead") +void DenseMatvec(DlsMat A, realtype *x, realtype *y); + +SUNDIALS_EXPORT +void SUNDlsMat_denseMatvec(realtype **a, realtype *x, realtype *y, + sunindextype m, sunindextype n); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_denseMatvec instead") +void denseMatvec(realtype **a, realtype *x, realtype *y, + sunindextype m, sunindextype n); #ifdef __cplusplus diff --git a/inst/include/sundials/sundials_direct.h b/inst/include/sundials/sundials_direct.h index 0004e23..2a416a3 100644 --- a/inst/include/sundials/sundials_direct.h +++ b/inst/include/sundials/sundials_direct.h @@ -2,7 +2,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -48,9 +48,9 @@ extern "C" { /* * ----------------------------------------------------------------- - * Type : DlsMat + * Type : SUNDlsMat * ----------------------------------------------------------------- - * The type DlsMat is defined to be a pointer to a structure + * The type SUNDlsMat is defined to be a pointer to a structure * with various sizes, a data field, and an array of pointers to * the columns which defines a dense or band matrix for use in * direct linear solvers. The M and N fields indicates the number @@ -58,7 +58,7 @@ extern "C" { * dimensional array used for component storage. The cols field * stores the pointers in data for the beginning of each column. * ----------------------------------------------------------------- - * For DENSE matrices, the relevant fields in DlsMat are: + * For DENSE matrices, the relevant fields in SUNDlsMat are: * type = SUNDIALS_DENSE * M - number of rows * N - number of columns @@ -70,17 +70,18 @@ extern "C" { * * The elements of a dense matrix are stored columnwise (i.e. columns * are stored one on top of the other in memory). - * If A is of type DlsMat, then the (i,j)th element of A (with + * If A is of type SUNDlsMat, then the (i,j)th element of A (with * 0 <= i < M and 0 <= j < N) is given by (A->data)[j*n+i]. * - * The DENSE_COL and DENSE_ELEM macros below allow a user to access - * efficiently individual matrix elements without writing out explicit - * data structure references and without knowing too much about the - * underlying element storage. The only storage assumption needed is - * that elements are stored columnwise and that a pointer to the - * jth column of elements can be obtained via the DENSE_COL macro. - * ----------------------------------------------------------------- - * For BAND matrices, the relevant fields in DlsMat are: + * The SUNDLS_DENSE_COL and SUNDLS_DENSE_ELEM macros below allow a + * user to access efficiently individual matrix elements without + * writing out explicit data structure references and without knowing + * too much about the underlying element storage. The only storage + * assumption needed is that elements are stored columnwise and that a + * pointer to the jth column of elements can be obtained via the + * SUNDLS_DENSE_COL macro. + * ----------------------------------------------------------------- + * For BAND matrices, the relevant fields in SUNDlsMat are: * type = SUNDIALS_BAND * M - number of rows * N - number of columns @@ -98,17 +99,18 @@ extern "C" { * cols - array of pointers. cols[j] points to the first element * of the j-th column of the matrix in the array data. * - * The BAND_COL, BAND_COL_ELEM, and BAND_ELEM macros below allow a - * user to access individual matrix elements without writing out - * explicit data structure references and without knowing too much - * about the underlying element storage. The only storage assumption - * needed is that elements are stored columnwise and that a pointer - * into the jth column of elements can be obtained via the BAND_COL - * macro. The BAND_COL_ELEM macro selects an element from a column - * which has already been isolated via BAND_COL. The macro - * BAND_COL_ELEM allows the user to avoid the translation - * from the matrix location (i,j) to the index in the array returned - * by BAND_COL at which the (i,j)th element is stored. + * The SUNDLS_BAND_COL, SUNDLS_BAND_COL_ELEM, and SUNDLS_BAND_ELEM + * macros below allow a user to access individual matrix elements + * without writing out explicit data structure references and without + * knowing too much about the underlying element storage. The only + * storage assumption needed is that elements are stored columnwise + * and that a pointer into the jth column of elements can be obtained + * via the SUNDLS_BAND_COL macro. The SUNDLS_BAND_COL_ELEM macro + * selects an element from a column which has already been isolated + * via SUNDLS_BAND_COL. The macro SUNDLS_BAND_COL_ELEM allows the user + * to avoid the translation from the matrix location (i,j) to the + * index in the array returned by SUNDLS_BAND_COL at which the (i,j)th + * element is stored. * ----------------------------------------------------------------- */ @@ -123,7 +125,9 @@ typedef struct _DlsMat { realtype *data; sunindextype ldata; realtype **cols; -} *DlsMat; +} *SUNDlsMat; /* DEPRECATED DlsMat: use SUNDlsMat instead */ + +typedef SUNDlsMat DlsMat; /* * ================================================================== @@ -133,177 +137,230 @@ typedef struct _DlsMat { /* * ----------------------------------------------------------------- - * DENSE_COL and DENSE_ELEM + * SUNDLS_DENSE_COL and SUNDLS_DENSE_ELEM * ----------------------------------------------------------------- * - * DENSE_COL(A,j) references the jth column of the M-by-N dense - * matrix A, 0 <= j < N. The type of the expression DENSE_COL(A,j) - * is (realtype *). After the assignment col_j = DENSE_COL(A,j), - * col_j may be treated as an array indexed from 0 to M-1. - * The (i,j)-th element of A is thus referenced by col_j[i]. + * SUNDLS_DENSE_COL(A,j) references the jth column of the M-by-N dense + * matrix A, 0 <= j < N. The type of the expression SUNDLS_DENSE_COL(A,j) + * is (realtype *). After the assignment col_j = SUNDLS_DENSE_COL(A,j), + * col_j may be treated as an array indexed from 0 to M-1. The (i,j)-th + * element of A is thus referenced by * col_j[i]. * - * DENSE_ELEM(A,i,j) references the (i,j)th element of the dense + * SUNDLS_DENSE_ELEM(A,i,j) references the (i,j)th element of the dense * M-by-N matrix A, 0 <= i < M ; 0 <= j < N. * * ----------------------------------------------------------------- */ -#define DENSE_COL(A,j) ((A->cols)[j]) -#define DENSE_ELEM(A,i,j) ((A->cols)[j][i]) +#define SUNDLS_DENSE_COL(A,j) ((A->cols)[j]) +#define SUNDLS_DENSE_ELEM(A,i,j) ((A->cols)[j][i]) + +/* DEPRECATED DENSE_COL: use SUNDLS_DENSE_COL instead */ +#define DENSE_COL(A,j) SUNDLS_DENSE_COL(A,j) +/* DEPRECATED DENSE_ELEM: use SUNDLS_DENSE_ELEM instead */ +#define DENSE_ELEM(A,i,j) SUNDLS_DENSE_ELEM(A,i,j) /* * ----------------------------------------------------------------- - * BAND_COL, BAND_COL_ELEM, and BAND_ELEM + * SUNDLS_BAND_COL, SUNDLS_BAND_COL_ELEM, and SUNDLS_BAND_ELEM * ----------------------------------------------------------------- * - * BAND_COL(A,j) references the diagonal element of the jth column - * of the N by N band matrix A, 0 <= j <= N-1. The type of the - * expression BAND_COL(A,j) is realtype *. The pointer returned by - * the call BAND_COL(A,j) can be treated as an array which is - * indexed from -(A->mu) to (A->ml). + * SUNDLS_BAND_COL(A,j) references the diagonal element of the jth + * column of the N by N band matrix A, 0 <= j <= N-1. The type of the + * expression SUNDLS_BAND_COL(A,j) is realtype *. The pointer returned + * by the call SUNDLS_BAND_COL(A,j) can be treated as an array which + * is indexed from -(A->mu) to (A->ml). * - * BAND_COL_ELEM references the (i,j)th entry of the band matrix A - * when used in conjunction with BAND_COL. The index (i,j) should - * satisfy j-(A->mu) <= i <= j+(A->ml). + * SUNDLS_BAND_COL_ELEM references the (i,j)th entry of the band + * matrix A when used in conjunction with SUNDLS_BAND_COL. The index + * (i,j) should satisfy j-(A->mu) <= i <= j+(A->ml). * - * BAND_ELEM(A,i,j) references the (i,j)th element of the M-by-N - * band matrix A, where 0 <= i,j <= N-1. The location (i,j) should - * further satisfy j-(A->mu) <= i <= j+(A->ml). + * SUNDLS_BAND_ELEM(A,i,j) references the (i,j)th element of the + * M-by-N band matrix A, where 0 <= i,j <= N-1. The location (i,j) + * should further satisfy j-(A->mu) <= i <= j+(A->ml). * * ----------------------------------------------------------------- */ -#define BAND_COL(A,j) (((A->cols)[j])+(A->s_mu)) -#define BAND_COL_ELEM(col_j,i,j) (col_j[(i)-(j)]) -#define BAND_ELEM(A,i,j) ((A->cols)[j][(i)-(j)+(A->s_mu)]) +#define SUNDLS_BAND_COL(A,j) (((A->cols)[j])+(A->s_mu)) +#define SUNDLS_BAND_COL_ELEM(col_j,i,j) (col_j[(i)-(j)]) +#define SUNDLS_BAND_ELEM(A,i,j) ((A->cols)[j][(i)-(j)+(A->s_mu)]) + +/* DEPRECATED BAND_COL: use SUNDLS_BAND_COL */ +#define BAND_COL(A,j) SUNDLS_BAND_COL(A,j) +/* DEPRECATED BAND_COL_ELEM: use SUNDLS_BAND_COL_ELEM */ +#define BAND_COL_ELEM(col_j,i,j) SUNDLS_BAND_COL_ELEM(col_j,i,j) +/* DEPRECATED BAND_ELEM: use SUNDLS_BAND_ELEM */ +#define BAND_ELEM(A,i,j) SUNDLS_BAND_ELEM(A,i,j) /* * ================================================================== - * Exported function prototypes (functions working on dlsMat) + * Exported function prototypes (functions working on SUNDlsMat) * ================================================================== */ /* * ----------------------------------------------------------------- - * Function: NewDenseMat + * Function: SUNDlsMat_NewDenseMat * ----------------------------------------------------------------- - * NewDenseMat allocates memory for an M-by-N dense matrix and - * returns the storage allocated (type DlsMat). NewDenseMat - * returns NULL if the request for matrix storage cannot be - * satisfied. See the above documentation for the type DlsMat - * for matrix storage details. + * SUNDlsMat_NewDenseMat allocates memory for an M-by-N dense matrix + * and returns the storage allocated (type SUNDlsMat). + * SUNDlsMat_NewDenseMat returns NULL if the request for matrix + * storage cannot be satisfied. See the above documentation for the + * type SUNDlsMat for matrix storage details. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT DlsMat NewDenseMat(sunindextype M, sunindextype N); +SUNDIALS_EXPORT +SUNDlsMat SUNDlsMat_NewDenseMat(sunindextype M, sunindextype N); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_NewDenseMat instead") +DlsMat NewDenseMat(sunindextype M, sunindextype N); /* * ----------------------------------------------------------------- - * Function: NewBandMat + * Function: SUNDlsMat_NewBandMat * ----------------------------------------------------------------- - * NewBandMat allocates memory for an M-by-N band matrix + * SUNDlsMat_NewBandMat allocates memory for an M-by-N band matrix * with upper bandwidth mu, lower bandwidth ml, and storage upper - * bandwidth smu. Pass smu as follows depending on whether A will - * be LU factored: + * bandwidth smu. Pass smu as follows depending on whether A will be + * LU factored: * * (1) Pass smu = mu if A will not be factored. * * (2) Pass smu = MIN(N-1,mu+ml) if A will be factored. * - * NewBandMat returns the storage allocated (type DlsMat) or - * NULL if the request for matrix storage cannot be satisfied. - * See the documentation for the type DlsMat for matrix storage + * SUNDlsMat_NewBandMat returns the storage allocated (type SUNDlsMat) + * or NULL if the request for matrix storage cannot be satisfied. See + * the documentation for the type SUNDlsMat for matrix storage * details. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT DlsMat NewBandMat(sunindextype N, sunindextype mu, - sunindextype ml, sunindextype smu); +SUNDIALS_EXPORT +SUNDlsMat SUNDlsMat_NewBandMat(sunindextype N, sunindextype mu, + sunindextype ml, sunindextype smu); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_NewBandMat instead") +DlsMat NewBandMat(sunindextype N, sunindextype mu, + sunindextype ml, sunindextype smu); /* * ----------------------------------------------------------------- - * Functions: DestroyMat + * Functions: SUNDlsMat_DestroyMat * ----------------------------------------------------------------- - * DestroyMat frees the memory allocated by NewDenseMat or NewBandMat + * SUNDlsMat_DestroyMat frees the memory allocated by + * SUNDlsMat_NewDenseMat or SUNDlsMat_NewBandMat * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void DestroyMat(DlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_DestroyMat(DlsMat A); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DestroyMat instead") +void DestroyMat(DlsMat A); /* * ----------------------------------------------------------------- - * Function: NewIntArray + * Function: SUNDlsMat_NewIntArray * ----------------------------------------------------------------- - * NewIntArray allocates memory an array of N int's and returns - * the pointer to the memory it allocates. If the request for + * SUNDlsMat_NewIntArray allocates memory an array of N int's and + * returns the pointer to the memory it allocates. If the request for * memory storage cannot be satisfied, it returns NULL. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int *NewIntArray(int N); +SUNDIALS_EXPORT +int* SUNDlsMat_NewIntArray(int N); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_NewIntArray instead") +int* NewIntArray(int N); /* * ----------------------------------------------------------------- - * Function: NewIndexArray + * Function: SUNDlsMat_NewIndexArray * ----------------------------------------------------------------- - * NewIndexArray allocates memory an array of N sunindextype's and - * returns the pointer to the memory it allocates. If the request - * for memory storage cannot be satisfied, it returns NULL. + * SUNDlsMat_NewIndexArray allocates memory an array of N + * sunindextype's and returns the pointer to the memory it + * allocates. If the request for memory storage cannot be satisfied, + * it returns NULL. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT sunindextype *NewIndexArray(sunindextype N); +SUNDIALS_EXPORT +sunindextype* SUNDlsMat_NewIndexArray(sunindextype N); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_NewIndexArray instead") +sunindextype* NewIndexArray(sunindextype N); /* * ----------------------------------------------------------------- - * Function: NewRealArray + * Function: SUNDlsMat_NewRealArray * ----------------------------------------------------------------- - * NewRealArray allocates memory an array of N realtype and returns - * the pointer to the memory it allocates. If the request for + * SUNDlsMat_NewRealArray allocates memory an array of N realtype and + * returns the pointer to the memory it allocates. If the request for * memory storage cannot be satisfied, it returns NULL. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT realtype *NewRealArray(sunindextype N); +SUNDIALS_EXPORT +realtype* SUNDlsMat_NewRealArray(sunindextype N); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_NewRealArray instead") +realtype* NewRealArray(sunindextype N); /* * ----------------------------------------------------------------- - * Function: DestroyArray + * Function: SUNDlsMat_DestroyArray * ----------------------------------------------------------------- - * DestroyArray frees memory allocated by NewIntArray, NewIndexArray, - * or NewRealArray. + * SUNDlsMat_DestroyArray frees memory allocated by + * SUNDlsMat_NewIntArray, SUNDlsMat_NewIndexArray, or + * SUNDlsMat_NewRealArray. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void DestroyArray(void *p); +SUNDIALS_EXPORT +void SUNDlsMat_DestroyArray(void *p); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_DestroyArray instead") +void DestroyArray(void *p); /* * ----------------------------------------------------------------- - * Function : AddIdentity + * Function : SUNDlsMat_AddIdentity * ----------------------------------------------------------------- - * AddIdentity adds 1.0 to the main diagonal (A_ii, i=0,1,...,N-1) of - * the M-by-N matrix A (M>= N) and stores the result back in A. - * AddIdentity is typically used with square matrices. - * AddIdentity does not check for M >= N and therefore a segmentation - * fault will occur if M < N! + * SUNDlsMat_AddIdentity adds 1.0 to the main diagonal (A_ii, + * i=0,1,...,N-1) of the M-by-N matrix A (M>= N) and stores the result + * back in A. SUNDlsMat_AddIdentity is typically used with square + * matrices. SUNDlsMat_AddIdentity does not check for M >= N and + * therefore a segmentation fault will occur if M < N! * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void AddIdentity(DlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_AddIdentity(SUNDlsMat A); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_AddIdentity instead") +void AddIdentity(DlsMat A); /* * ----------------------------------------------------------------- - * Function : SetToZero + * Function : SUNDlsMat_SetToZero * ----------------------------------------------------------------- - * SetToZero sets all the elements of the M-by-N matrix A to 0.0. + * SUNDlsMat_SetToZero sets all the elements of the M-by-N matrix A + * to 0.0. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void SetToZero(DlsMat A); +SUNDIALS_EXPORT +void SUNDlsMat_SetToZero(SUNDlsMat A); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_SetToZero instead") +void SetToZero(DlsMat A); /* * ----------------------------------------------------------------- - * Functions: PrintMat + * Functions: SUNDlsMat_PrintMat * ----------------------------------------------------------------- * This function prints the M-by-N (dense or band) matrix A to * outfile as it would normally appear on paper. @@ -313,8 +370,11 @@ SUNDIALS_EXPORT void SetToZero(DlsMat A); * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT void PrintMat(DlsMat A, FILE *outfile); +SUNDIALS_EXPORT +void SUNDlsMat_PrintMat(SUNDlsMat A, FILE *outfile); +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_PrintMat") +void PrintMat(DlsMat A, FILE *outfile); /* * ================================================================== @@ -322,14 +382,50 @@ SUNDIALS_EXPORT void PrintMat(DlsMat A, FILE *outfile); * ================================================================== */ -SUNDIALS_EXPORT realtype **newDenseMat(sunindextype m, sunindextype n); -SUNDIALS_EXPORT realtype **newBandMat(sunindextype n, sunindextype smu, - sunindextype ml); -SUNDIALS_EXPORT void destroyMat(realtype **a); -SUNDIALS_EXPORT int *newIntArray(int n); -SUNDIALS_EXPORT sunindextype *newIndexArray(sunindextype n); -SUNDIALS_EXPORT realtype *newRealArray(sunindextype m); -SUNDIALS_EXPORT void destroyArray(void *v); +SUNDIALS_EXPORT +realtype** SUNDlsMat_newDenseMat(sunindextype m, sunindextype n); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_newDenseMat instead") +realtype** newDenseMat(sunindextype m, sunindextype n); + +SUNDIALS_EXPORT +realtype** SUNDlsMat_newBandMat(sunindextype n, sunindextype smu, + sunindextype ml); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_newBandMat instead") +realtype** newBandMat(sunindextype n, sunindextype smu, + sunindextype ml); + +SUNDIALS_EXPORT +void SUNDlsMat_destroyMat(realtype** a); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_destroyMat instead") +void destroyMat(realtype** a); + +SUNDIALS_EXPORT +int* SUNDlsMat_newIntArray(int n); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_newIntArray instead") +int* newIntArray(int n); + +SUNDIALS_EXPORT +sunindextype* SUNDlsMat_newIndexArray(sunindextype n); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_newIndexArray instead") +sunindextype* newIndexArray(sunindextype n); + +SUNDIALS_EXPORT +realtype* SUNDlsMat_newRealArray(sunindextype m); + +SUNDIALS_EXPORT +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_newRealArray instead") + realtype* newRealArray(sunindextype m); + +SUNDIALS_EXPORT +void SUNDlsMat_destroyArray(void* v); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNDlsMat_destroyArray instead") +void destroyArray(void* v); #ifdef __cplusplus diff --git a/inst/include/sundials/sundials_fconfig.h b/inst/include/sundials/sundials_fconfig.h deleted file mode 100644 index 1917ae9..0000000 --- a/inst/include/sundials/sundials_fconfig.h +++ /dev/null @@ -1,47 +0,0 @@ -! -! ----------------------------------------------------------------- -! Programmer(s): Daniel R. Reynolds @ SMU -!----------------------------------------------------------------- -! SUNDIALS Copyright Start -! Copyright (c) 2002-2021, 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 -! ------------------------------------------------------------------ -! SUNDIALS fortran configuration input -! ------------------------------------------------------------------ - -! Define precision of SUNDIALS data type 'realtype' as Fortran -! parameter "REALTYPE" -! -! Depending on the precision level, this value will be one of -! 4 (SUNDIALS_SINGLE_PRECISION) -! 8 (SUNDIALS_DOUBLE_PRECISION) -! 16 (SUNDIALS_EXTENDED_PRECISION) -! -integer REALTYPE -parameter (REALTYPE=8) - -! Define type of vector indices in SUNDIALS 'sunindextype' as -! the Fortran parameter "SUNINDEXTYPE" -! -! Depending on the user choice of indextype, this will be one of -! 4 (32BIT) -! 8 (64BIT) -! -integer SUNINDEXTYPE -parameter (SUNINDEXTYPE=8) - -! If building with MPI enabled, define the logical flag -! "SUNDIALS_MPI_COMM_F2C" indicating whether the user can specify -! a different MPI communicator than MPI_COMM_WORLD to FNVInitP -! -! .true. (communicator can differ from MPI_COMM_WORLD) -! .false. (communicator must be MPI_COMM_WORLD) -! -logical SUNDIALS_MPI_COMM_F2C -parameter (SUNDIALS_MPI_COMM_F2C=.true.) diff --git a/inst/include/sundials/sundials_fconfig.in b/inst/include/sundials/sundials_fconfig.in deleted file mode 100644 index ba09e3d..0000000 --- a/inst/include/sundials/sundials_fconfig.in +++ /dev/null @@ -1,47 +0,0 @@ -! -! ----------------------------------------------------------------- -! Programmer(s): Daniel R. Reynolds @ SMU -!----------------------------------------------------------------- -! SUNDIALS Copyright Start -! Copyright (c) 2002-2021, 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 -! ------------------------------------------------------------------ -! SUNDIALS fortran configuration input -! ------------------------------------------------------------------ - -! Define precision of SUNDIALS data type 'realtype' as Fortran -! parameter "REALTYPE" -! -! Depending on the precision level, this value will be one of -! 4 (SUNDIALS_SINGLE_PRECISION) -! 8 (SUNDIALS_DOUBLE_PRECISION) -! 16 (SUNDIALS_EXTENDED_PRECISION) -! -integer REALTYPE -parameter (REALTYPE=@FPRECISION_LEVEL@) - -! Define type of vector indices in SUNDIALS 'sunindextype' as -! the Fortran parameter "SUNINDEXTYPE" -! -! Depending on the user choice of indextype, this will be one of -! 4 (32BIT) -! 8 (64BIT) -! -integer SUNINDEXTYPE -parameter (SUNINDEXTYPE=@SUNDIALS_FINDEX_TYPE@) - -! If building with MPI enabled, define the logical flag -! "SUNDIALS_MPI_COMM_F2C" indicating whether the user can specify -! a different MPI communicator than MPI_COMM_WORLD to FNVInitP -! -! .true. (communicator can differ from MPI_COMM_WORLD) -! .false. (communicator must be MPI_COMM_WORLD) -! -logical SUNDIALS_MPI_COMM_F2C -parameter (SUNDIALS_MPI_COMM_F2C=@FMPI_COMM_F2C@) diff --git a/inst/include/sundials/sundials_futils.h b/inst/include/sundials/sundials_futils.h index 1ba352a..e37ec7b 100644 --- a/inst/include/sundials/sundials_futils.h +++ b/inst/include/sundials/sundials_futils.h @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/sundials/sundials_iterative.h b/inst/include/sundials/sundials_iterative.h index 0278ff5..071eb5a 100644 --- a/inst/include/sundials/sundials_iterative.h +++ b/inst/include/sundials/sundials_iterative.h @@ -1,8 +1,9 @@ /* ----------------------------------------------------------------- * Programmer(s): Scott D. Cohen and Alan C. Hindmarsh @ LLNL + * Shelby Lockhart @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -17,13 +18,13 @@ * The function type declarations give the prototypes for the * functions to be called within an iterative linear solver, that * are responsible for - * multiplying A by a given vector v (ATimesFn), - * setting up a preconditioner P (PSetupFn), and - * solving the preconditioner equation Pz = r (PSolveFn). + * multiplying A by a given vector v (SUNATimesFn), + * setting up a preconditioner P (SUNPSetupFn), and + * solving the preconditioner equation Pz = r (SUNPSolveFn). * -----------------------------------------------------------------*/ -#ifndef _ITERATIVE_H -#define _ITERATIVE_H +#ifndef _SUNDIALS_ITERATIVE_H +#define _SUNDIALS_ITERATIVE_H #include @@ -36,71 +37,82 @@ extern "C" { * ----------------------------------------------------------------- * enum : types of preconditioning * ----------------------------------------------------------------- - * PREC_NONE : The iterative linear solver should not use - * preconditioning. + * SUN_PREC_NONE : The iterative linear solver should not use + * preconditioning. * - * PREC_LEFT : The iterative linear solver uses preconditioning on - * the left only. + * SUN_PREC_LEFT : The iterative linear solver uses preconditioning + * on the left only. * - * PREC_RIGHT : The iterative linear solver uses preconditioning on - * the right only. + * SUN_PREC_RIGHT : The iterative linear solver uses preconditioning + * on the right only. * - * PREC_BOTH : The iterative linear solver uses preconditioning on - * both the left and the right. + * SUN_PREC_BOTH : The iterative linear solver uses preconditioning + * on both the left and the right. * ----------------------------------------------------------------- */ +/* DEPRECATED PREC_NONE: use SUN_PREC_NONE */ +/* DEPRECATED PREC_LEFT: use SUN_PREC_LEFT */ +/* DEPRECATED PREC_RIGHT: use SUN_PREC_RIGHT */ +/* DEPRECATED PREC_BOTH: use SUN_PREC_BOTH */ enum { PREC_NONE, PREC_LEFT, PREC_RIGHT, PREC_BOTH }; +enum { SUN_PREC_NONE, SUN_PREC_LEFT, SUN_PREC_RIGHT, SUN_PREC_BOTH }; /* * ----------------------------------------------------------------- * enum : types of Gram-Schmidt routines * ----------------------------------------------------------------- - * MODIFIED_GS : The iterative solver uses the modified - * Gram-Schmidt routine ModifiedGS listed in this - * file. + * SUN_MODIFIED_GS : The iterative solver uses the modified + * Gram-Schmidt routine SUNModifiedGS listed in + * this file. * - * CLASSICAL_GS : The iterative solver uses the classical - * Gram-Schmidt routine ClassicalGS listed in this - * file. + * SUN_CLASSICAL_GS : The iterative solver uses the classical + * Gram-Schmidt routine SUNClassicalGS listed in + * this file. * ----------------------------------------------------------------- */ +/* DEPRECATED MODIFIED_GS: use SUN_MODIFIED_GS */ +/* DEPRECATED CLASSICAL_GS: use SUN_CLASSICAL_GS */ enum { MODIFIED_GS = 1, CLASSICAL_GS = 2 }; +enum { SUN_MODIFIED_GS = 1, SUN_CLASSICAL_GS = 2 }; /* * ----------------------------------------------------------------- - * Type: ATimesFn + * Type: SUNATimesFn * ----------------------------------------------------------------- - * An ATimesFn multiplies Av and stores the result in z. The + * An SUNATimesFn multiplies Av and stores the result in z. The * caller is responsible for allocating memory for the z vector. * The parameter A_data is a pointer to any information about A * which the function needs in order to do its job. The vector v - * is unchanged. An ATimesFn returns 0 if successful and a + * is unchanged. An SUNATimesFn returns 0 if successful and a * non-zero value if unsuccessful. * ----------------------------------------------------------------- */ +/* DEPRECATED ATimesFn: use SUNATimesFn */ typedef int (*ATimesFn)(void *A_data, N_Vector v, N_Vector z); +typedef int (*SUNATimesFn)(void *A_data, N_Vector v, N_Vector z); /* * ----------------------------------------------------------------- - * Type: PSetupFn + * Type: SUNPSetupFn * ----------------------------------------------------------------- - * A PSetupFn is an integrator-supplied routine that accesses data - * stored in the integrator memory structure (P_data), and calls - * the user-supplied, integrator-specific preconditioner setup - * routine. + * A SUNPSetupFn is an integrator-supplied routine that accesses data + * stored in the integrator memory structure (P_data), and calls the + * user-supplied, integrator-specific preconditioner setup routine. * ----------------------------------------------------------------- */ +/* DEPRECATED PSetupFn: use SUNPSetupFn */ typedef int (*PSetupFn)(void *P_data); +typedef int (*SUNPSetupFn)(void *P_data); /* * ----------------------------------------------------------------- - * Type: PSolveFn + * Type: SUNPSolveFn * ----------------------------------------------------------------- - * A PSolveFn solves the preconditioner equation Pz = r for the + * A SUNPSolveFn solves the preconditioner equation Pz = r for the * vector z. The caller is responsible for allocating memory for * the z vector. The parameter P_data is a pointer to any * information about P which the function needs in order to do @@ -113,8 +125,8 @@ typedef int (*PSetupFn)(void *P_data); * || Pz - r ||_wrms < tol * where the weight vector for the WRMS norm may be accessed from * the main integrator memory structure. - * The vector r should not be modified by the PSolveFn. - * A PSolveFn returns 0 if successful and a non-zero value if + * The vector r should not be modified by the SUNPSolveFn. + * A SUNPSolveFn returns 0 if successful and a non-zero value if * unsuccessful. On a failure, a negative return value indicates * an unrecoverable condition, while a positive value indicates * a recoverable one, in which the calling routine may reattempt @@ -122,14 +134,44 @@ typedef int (*PSetupFn)(void *P_data); * ----------------------------------------------------------------- */ +/* DEPRECATED PSolveFn: use SUNPSolveFn */ typedef int (*PSolveFn)(void *P_data, N_Vector r, N_Vector z, realtype tol, int lr); +typedef int (*SUNPSolveFn)(void *P_data, N_Vector r, N_Vector z, + realtype tol, int lr); /* * ----------------------------------------------------------------- - * Function: ModifiedGS + * Type: SUNQRAddFn * ----------------------------------------------------------------- - * ModifiedGS performs a modified Gram-Schmidt orthogonalization + * A QRAddFn updates a given QR factorization defined by the input + * parameters: + * Q : N_Vector * + * R : realtype * + * with the input vector + * f : N_Vector + * + * Additional input parameters include: + * + * m : (int) the number of vectors already in the QR factorization + * + * mMax : (int) the maximum number of vectors to be in the QR + * factorization (the number of N_Vectors allocated to be in Q) + * + * SUNQR_data : (void *) a structure containing any additional inputs + * required for the execution of QRAddFn + * + * ----------------------------------------------------------------- +*/ + +typedef int (*SUNQRAddFn)(N_Vector *Q, realtype *R, N_Vector f, + int m, int mMax, void *QR_data); + +/* + * ----------------------------------------------------------------- + * Function: SUNModifiedGS + * ----------------------------------------------------------------- + * SUNModifiedGS performs a modified Gram-Schmidt orthogonalization * of the N_Vector v[k] against the p unit N_Vectors at * v[k-1], v[k-2], ..., v[k-p]. * @@ -152,47 +194,58 @@ typedef int (*PSolveFn)(void *P_data, N_Vector r, N_Vector z, * new_vk_norm is a pointer to memory allocated by the caller to * hold the Euclidean norm of the orthogonalized vector v[k]. * - * If (k-p) < 0, then ModifiedGS uses p=k. The orthogonalized + * If (k-p) < 0, then SUNModifiedGS uses p=k. The orthogonalized * v[k] is NOT normalized and is stored over the old v[k]. Once * the orthogonalization has been performed, the Euclidean norm * of v[k] is stored in (*new_vk_norm). * - * ModifiedGS returns 0 to indicate success. It cannot fail. + * SUNModifiedGS returns 0 to indicate success. It cannot fail. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int ModifiedGS(N_Vector* v, realtype **h, int k, int p, - realtype *new_vk_norm); +SUNDIALS_EXPORT +int SUNModifiedGS(N_Vector* v, realtype **h, int k, int p, + realtype *new_vk_norm); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNModifiedGS instead") +int ModifiedGS(N_Vector* v, realtype **h, int k, int p, + realtype *new_vk_norm); /* * ----------------------------------------------------------------- - * Function: ClassicalGS + * Function: SUNClassicalGS * ----------------------------------------------------------------- - * ClassicalGS performs a classical Gram-Schmidt + * SUNClassicalGS performs a classical Gram-Schmidt * orthogonalization of the N_Vector v[k] against the p unit * N_Vectors at v[k-1], v[k-2], ..., v[k-p]. The parameters v, h, * k, p, and new_vk_norm are as described in the documentation - * for ModifiedGS. + * for SUNModifiedGS. * * stemp is a length k+1 array of realtype which can be used as - * workspace by the ClassicalGS routine. + * workspace by the SUNClassicalGS routine. * * vtemp is an N_Vector array of k+1 vectors which can be used as - * workspace by the ClassicalGS routine. + * workspace by the SUNClassicalGS routine. * - * ClassicalGS returns 0 to indicate success. + * SUNClassicalGS returns 0 to indicate success. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int ClassicalGS(N_Vector* v, realtype **h, int k, int p, - realtype *new_vk_norm, realtype *stemp, - N_Vector* vtemp); +SUNDIALS_EXPORT +int SUNClassicalGS(N_Vector* v, realtype **h, int k, int p, + realtype *new_vk_norm, realtype *stemp, + N_Vector* vtemp); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNClassicalGS instead") +int ClassicalGS(N_Vector* v, realtype **h, int k, int p, + realtype *new_vk_norm, realtype *stemp, + N_Vector* vtemp); /* * ----------------------------------------------------------------- - * Function: QRfact + * Function: SUNQRfact * ----------------------------------------------------------------- - * QRfact performs a QR factorization of the Hessenberg matrix H. + * SUNQRfact performs a QR factorization of the Hessenberg matrix H. * * n is the problem size; the matrix H is (n+1) by n. * @@ -211,50 +264,226 @@ SUNDIALS_EXPORT int ClassicalGS(N_Vector* v, realtype **h, int k, int p, * n-1 columns of h have already been factored and only the last * column needs to be updated. * - * QRfact returns 0 if successful. If a zero is encountered on - * the diagonal of the triangular factor R, then QRfact returns + * SUNQRfact returns 0 if successful. If a zero is encountered on + * the diagonal of the triangular factor R, then SUNQRfact returns * the equation number of the zero entry, where the equations are - * numbered from 1, not 0. If QRsol is subsequently called in + * numbered from 1, not 0. If SUNQRsol is subsequently called in * this situation, it will return an error because it could not * divide by the zero diagonal entry. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int QRfact(int n, realtype **h, realtype *q, int job); +SUNDIALS_EXPORT +int SUNQRfact(int n, realtype **h, realtype *q, int job); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNQRFact instead") +int QRfact(int n, realtype **h, realtype *q, int job); /* * ----------------------------------------------------------------- - * Function: QRsol + * Function: SUNQRsol * ----------------------------------------------------------------- - * QRsol solves the linear least squares problem + * SUNQRsol solves the linear least squares problem * * min (b - H*x, b - H*x), x in R^n, * * where H is a Hessenberg matrix, and b is in R^(n+1). - * It uses the QR factors of H computed by QRfact. + * It uses the QR factors of H computed by SUNQRfact. * * n is the problem size; the matrix H is (n+1) by n. * - * h is a matrix (computed by QRfact) containing the upper + * h is a matrix (computed by SUNQRfact) containing the upper * triangular factor R of the original Hessenberg matrix H. * - * q is an array of length 2*n (computed by QRfact) containing + * q is an array of length 2*n (computed by SUNQRfact) containing * the Givens rotations used to factor H. * * b is the (n+1)-vector appearing in the least squares problem * above. * * On return, b contains the solution x of the least squares - * problem, if QRsol was successful. + * problem, if SUNQRsol was successful. * - * QRsol returns a 0 if successful. Otherwise, a zero was + * SUNQRsol returns a 0 if successful. Otherwise, a zero was * encountered on the diagonal of the triangular factor R. - * In this case, QRsol returns the equation number (numbered + * In this case, SUNQRsol returns the equation number (numbered * from 1, not 0) of the zero entry. * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT int QRsol(int n, realtype **h, realtype *q, realtype *b); +SUNDIALS_EXPORT +int SUNQRsol(int n, realtype **h, realtype *q, realtype *b); + +SUNDIALS_DEPRECATED_EXPORT_MSG("use SUNQRsol instead") +int QRsol(int n, realtype **h, realtype *q, realtype *b); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_MGS + * ----------------------------------------------------------------- + * SUNQRAdd_MGS uses Modified Gram Schmidt to update the QR factorization + * stored in user inputs + * - N_Vector *Q + * - realtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_MGS was successful. + * + * SUNQRAdd_MGS returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRAdd_MGS(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_ICWY + * ----------------------------------------------------------------- + * SUNQRAdd_ICWY uses the Inverse Compact WY Modified Gram Schmidt + * method to update the QR factorization stored in user inputs + * - N_Vector *Q + * - realtype *R + * - realtype *T (held within (void *) QRdata) + * to include the orthonormalized vector input by + * - N_Vector df. + * where the factorization to be updated is of the form + * Q * T * R + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, realtype *temp_array (this will be used for T) + * + * On return, Q, R, and T contain the updated Q T R factors, if + * SUNQRAdd_ICWY was successful. + * + * SUNQRAdd_ICWY returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRAdd_ICWY(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_ICWY_SB + * ----------------------------------------------------------------- + * The same function as SUNQRAdd_ICWY but using a single buffer + * for global reductions. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRAdd_ICWY_SB(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_CGS2 + * ----------------------------------------------------------------- + * SUNQRAdd_CGS2 uses a Classical Gram Schmidt with Reorthogonalization + * formulation to update the QR factorization stored in user inputs + * - N_Vector *Q + * - realtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, N_Vector vtemp2, realtype *temp_array + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_CGS2 was successful. + * + * SUNQRAdd_CGS2 returns a 0 if successful. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRAdd_CGS2(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_DCGS2 + * ----------------------------------------------------------------- + * SUNQRAdd_DCGS2 uses a Classical Gram Schmidt with Reorthogonalization + * formulation that delays reorthogonlization (for the purpose of + * reducing number of inner products) to update the QR factorization + * stored in user inputs + * - N_Vector *Q + * - realtype *R + * to include the orthonormalized vector input by + * - N_Vector df. + * + * Additional input parameters include: + * + * m : (int) current number of vectors in QR factorization + * + * mMax : (int) maximum number of vectors that will be in the QR + * factorization (the allocated number of N_Vectors in Q) + * + * QRdata : (void *) a struct containing any additional temporary + * vectors or arrays required for the QRAdd routine + * + * QRdata should contain : + * N_Vector vtemp, N_Vector vtemp2, realtype *temp_array + * + * On return, Q and R contain the updated Q R factors, if + * SUNQRAdd_DCGS2 was successful. + * + * SUNQRAdd_DCGS2 returns a 0 if successful. Otherwise,.... + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRAdd_DCGS2(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata); + +/* + * ----------------------------------------------------------------- + * Function: SUNQRAdd_DCGS2_SB + * ----------------------------------------------------------------- + * The same function as SUNQRAdd_DCGS2 but using a single buffer + * for global reductions. + * ----------------------------------------------------------------- + */ + +SUNDIALS_EXPORT +int SUNQRAdd_DCGS2_SB(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata); #ifdef __cplusplus } diff --git a/inst/include/sundials/sundials_lapack.h b/inst/include/sundials/sundials_lapack.h index 089625a..8d1b6da 100644 --- a/inst/include/sundials/sundials_lapack.h +++ b/inst/include/sundials/sundials_lapack.h @@ -3,7 +3,7 @@ * Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,6 +21,8 @@ #include +#warning "This header file is deprecated and will be removed in SUNDIALS v7.0.0" + #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif diff --git a/inst/include/sundials/sundials_linearsolver.h b/inst/include/sundials/sundials_linearsolver.h index ad3b051..ad2cd58 100644 --- a/inst/include/sundials/sundials_linearsolver.h +++ b/inst/include/sundials/sundials_linearsolver.h @@ -4,7 +4,7 @@ * Slaven Peles, Cody Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -108,9 +108,9 @@ typedef _SUNDIALS_STRUCT_ _generic_SUNLinearSolver *SUNLinearSolver; struct _generic_SUNLinearSolver_Ops { SUNLinearSolver_Type (*gettype)(SUNLinearSolver); SUNLinearSolver_ID (*getid)(SUNLinearSolver); - int (*setatimes)(SUNLinearSolver, void*, ATimesFn); + int (*setatimes)(SUNLinearSolver, void*, SUNATimesFn); int (*setpreconditioner)(SUNLinearSolver, void*, - PSetupFn, PSolveFn); + SUNPSetupFn, SUNPSolveFn); int (*setscalingvectors)(SUNLinearSolver, N_Vector, N_Vector); int (*setzeroguess)(SUNLinearSolver, booleantype); @@ -132,6 +132,7 @@ struct _generic_SUNLinearSolver_Ops { struct _generic_SUNLinearSolver { void *content; SUNLinearSolver_Ops ops; + SUNContext sunctx; }; @@ -139,7 +140,7 @@ struct _generic_SUNLinearSolver { * Functions exported by SUNLinearSolver module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSolNewEmpty(); +SUNDIALS_EXPORT SUNLinearSolver SUNLinSolNewEmpty(SUNContext sunctx); SUNDIALS_EXPORT void SUNLinSolFreeEmpty(SUNLinearSolver S); @@ -148,10 +149,10 @@ SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); + SUNATimesFn ATimes); SUNDIALS_EXPORT int SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, - PSetupFn Pset, PSolveFn Psol); + SUNPSetupFn Pset, SUNPSolveFn Psol); SUNDIALS_EXPORT int SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, N_Vector s2); diff --git a/inst/include/sundials/sundials_math.h b/inst/include/sundials/sundials_math.h index f79344e..0045016 100644 --- a/inst/include/sundials/sundials_math.h +++ b/inst/include/sundials/sundials_math.h @@ -4,7 +4,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/sundials/sundials_matrix.h b/inst/include/sundials/sundials_matrix.h index ebb73d5..56b2361 100644 --- a/inst/include/sundials/sundials_matrix.h +++ b/inst/include/sundials/sundials_matrix.h @@ -4,7 +4,7 @@ * Cody Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -44,6 +44,7 @@ #ifndef _SUNMATRIX_H #define _SUNMATRIX_H +#include #include #include @@ -98,6 +99,7 @@ struct _generic_SUNMatrix_Ops { struct _generic_SUNMatrix { void *content; SUNMatrix_Ops ops; + SUNContext sunctx; }; @@ -105,7 +107,7 @@ struct _generic_SUNMatrix { * Functions exported by SUNMatrix module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT SUNMatrix SUNMatNewEmpty(); +SUNDIALS_EXPORT SUNMatrix SUNMatNewEmpty(SUNContext sunctx); SUNDIALS_EXPORT void SUNMatFreeEmpty(SUNMatrix A); SUNDIALS_EXPORT int SUNMatCopyOps(SUNMatrix A, SUNMatrix B); SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID(SUNMatrix A); diff --git a/inst/include/sundials/sundials_mpi_types.h b/inst/include/sundials/sundials_mpi_types.h index 99ecd73..ac60e6c 100644 --- a/inst/include/sundials/sundials_mpi_types.h +++ b/inst/include/sundials/sundials_mpi_types.h @@ -3,7 +3,7 @@ * Aaron Collier, and Slaven Peles @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -33,7 +33,3 @@ #elif defined(SUNDIALS_INT32_T) #define MPI_SUNINDEXTYPE MPI_INT32_T #endif - -/* define legacy SUNDIALS MPI data types */ -#define PVEC_REAL_MPI_TYPE MPI_SUNREALTYPE -#define PVEC_INTEGER_MPI_TYPE MPI_SUNINDEXTYPE diff --git a/inst/include/sundials/sundials_nonlinearsolver.h b/inst/include/sundials/sundials_nonlinearsolver.h index 65e8a4c..eeb7699 100644 --- a/inst/include/sundials/sundials_nonlinearsolver.h +++ b/inst/include/sundials/sundials_nonlinearsolver.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner, and Cody J. Balos @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -47,6 +47,7 @@ #ifndef _SUNNONLINEARSOLVER_H #define _SUNNONLINEARSOLVER_H +#include #include #include @@ -120,6 +121,7 @@ struct _generic_SUNNonlinearSolver_Ops { struct _generic_SUNNonlinearSolver { void *content; SUNNonlinearSolver_Ops ops; + SUNContext sunctx; }; @@ -128,7 +130,7 @@ struct _generic_SUNNonlinearSolver { * ---------------------------------------------------------------------------*/ /* empty constructor/destructor */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSolNewEmpty(); +SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSolNewEmpty(SUNContext sunctx); SUNDIALS_EXPORT void SUNNonlinSolFreeEmpty(SUNNonlinearSolver NLS); /* core functions */ @@ -162,6 +164,7 @@ SUNDIALS_EXPORT int SUNNonlinSolSetConvTestFn(SUNNonlinearSolver NLS, SUNDIALS_EXPORT int SUNNonlinSolSetMaxIters(SUNNonlinearSolver NLS, int maxiters); + /* get functions */ SUNDIALS_EXPORT int SUNNonlinSolGetNumIters(SUNNonlinearSolver NLS, long int *niters); @@ -180,8 +183,8 @@ SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails(SUNNonlinearSolver NLS, #define SUN_NLS_SUCCESS 0 /* successful / converged */ /* Recoverable */ -#define SUN_NLS_CONTINUE +901 /* not converged, keep iterating */ -#define SUN_NLS_CONV_RECVR +902 /* convergece failure, try to recover */ +#define SUN_NLS_CONTINUE +901 /* not converged, keep iterating */ +#define SUN_NLS_CONV_RECVR +902 /* convergece failure, try to recover */ /* Unrecoverable */ #define SUN_NLS_MEM_NULL -901 /* memory argument is NULL */ diff --git a/inst/include/sundials/sundials_nvector.h b/inst/include/sundials/sundials_nvector.h index 7e5a60f..f96847f 100644 --- a/inst/include/sundials/sundials_nvector.h +++ b/inst/include/sundials/sundials_nvector.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -48,6 +48,7 @@ #include #include +#include #include #ifdef __cplusplus /* wrapper to enable C++ usage */ @@ -94,6 +95,14 @@ typedef N_Vector *N_Vector_S; /* Structure containing function pointers to vector operations */ struct _generic_N_Vector_Ops { + + /* + * REQUIRED operations. + * + * These must be implemented by derivations of the generic N_Vector. + */ + + /* constructors, destructors, and utility operations */ N_Vector_ID (*nvgetvectorid)(N_Vector); N_Vector (*nvclone)(N_Vector); N_Vector (*nvcloneempty)(N_Vector); @@ -126,12 +135,18 @@ struct _generic_N_Vector_Ops { booleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector); realtype (*nvminquotient)(N_Vector, N_Vector); - /* fused vector operations */ + /* + * OPTIONAL operations. + * + * These operations provide default implementations that may be overriden. + */ + + /* OPTIONAL fused vector operations */ int (*nvlinearcombination)(int, realtype*, N_Vector*, N_Vector); int (*nvscaleaddmulti)(int, realtype*, N_Vector, N_Vector*, N_Vector*); int (*nvdotprodmulti)(int, N_Vector, N_Vector*, realtype*); - /* vector array operations */ + /* OPTIONAL vector array operations */ int (*nvlinearsumvectorarray)(int, realtype, N_Vector*, realtype, N_Vector*, N_Vector*); int (*nvscalevectorarray)(int, realtype*, N_Vector*, N_Vector*); @@ -141,7 +156,11 @@ struct _generic_N_Vector_Ops { int (*nvscaleaddmultivectorarray)(int, int, realtype*, N_Vector*, N_Vector**, N_Vector**); int (*nvlinearcombinationvectorarray)(int, int, realtype*, N_Vector**, N_Vector*); - /* OPTIONAL local reduction kernels (no parallel communication) */ + /* + * OPTIONAL operations with no default implementation. + */ + + /* Local reduction kernels (no parallel communication) */ realtype (*nvdotprodlocal)(N_Vector, N_Vector); realtype (*nvmaxnormlocal)(N_Vector); realtype (*nvminlocal)(N_Vector); @@ -152,12 +171,16 @@ struct _generic_N_Vector_Ops { realtype (*nvwsqrsumlocal)(N_Vector, N_Vector); realtype (*nvwsqrsummasklocal)(N_Vector, N_Vector, N_Vector); - /* OPTIONAL XBraid interface operations */ + /* Single buffer reduction operations */ + int (*nvdotprodmultilocal)(int, N_Vector, N_Vector*, realtype*); + int (*nvdotprodmultiallreduce)(int, N_Vector, realtype*); + + /* XBraid interface operations */ int (*nvbufsize)(N_Vector, sunindextype*); int (*nvbufpack)(N_Vector, void*); int (*nvbufunpack)(N_Vector, void*); - /* debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined) */ + /* Debugging functions (called when SUNDIALS_DEBUG_PRINTVEC is defined). */ void (*nvprint)(N_Vector); void (*nvprintfile)(N_Vector, FILE*); }; @@ -168,6 +191,7 @@ struct _generic_N_Vector_Ops { struct _generic_N_Vector { void *content; N_Vector_Ops ops; + SUNContext sunctx; }; @@ -175,10 +199,14 @@ struct _generic_N_Vector { * Functions exported by NVECTOR module * ----------------------------------------------------------------- */ -SUNDIALS_EXPORT N_Vector N_VNewEmpty(); +SUNDIALS_EXPORT N_Vector N_VNewEmpty(SUNContext sunctx); SUNDIALS_EXPORT void N_VFreeEmpty(N_Vector v); SUNDIALS_EXPORT int N_VCopyOps(N_Vector w, N_Vector v); +/* + * Required operations. + */ + SUNDIALS_EXPORT N_Vector_ID N_VGetVectorID(N_Vector w); SUNDIALS_EXPORT N_Vector N_VClone(N_Vector w); SUNDIALS_EXPORT N_Vector N_VCloneEmpty(N_Vector w); @@ -212,7 +240,11 @@ SUNDIALS_EXPORT booleantype N_VInvTest(N_Vector x, N_Vector z); SUNDIALS_EXPORT booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); SUNDIALS_EXPORT realtype N_VMinQuotient(N_Vector num, N_Vector denom); -/* OPTIONAL fused vector operations */ +/* + * OPTIONAL operations with default implementations. + */ + +/* fused vector operations */ SUNDIALS_EXPORT int N_VLinearCombination(int nvec, realtype* c, N_Vector* X, N_Vector z); @@ -222,7 +254,7 @@ SUNDIALS_EXPORT int N_VScaleAddMulti(int nvec, realtype* a, N_Vector x, SUNDIALS_EXPORT int N_VDotProdMulti(int nvec, N_Vector x, N_Vector* Y, realtype* dotprods); -/* OPTIONAL vector array operations */ +/* vector array operations */ SUNDIALS_EXPORT int N_VLinearSumVectorArray(int nvec, realtype a, N_Vector* X, realtype b, N_Vector* Y, @@ -248,7 +280,11 @@ SUNDIALS_EXPORT int N_VLinearCombinationVectorArray(int nvec, int nsum, realtype* c, N_Vector** X, N_Vector* Z); -/* OPTIONAL local reduction kernels (no parallel communication) */ +/* + * OPTIONAL operations with no default implementation. + */ + +/* local reduction kernels (no parallel communication) */ SUNDIALS_EXPORT realtype N_VDotProdLocal(N_Vector x, N_Vector y); SUNDIALS_EXPORT realtype N_VMaxNormLocal(N_Vector x); SUNDIALS_EXPORT realtype N_VMinLocal(N_Vector x); @@ -259,7 +295,13 @@ SUNDIALS_EXPORT booleantype N_VInvTestLocal(N_Vector x, N_Vector z); SUNDIALS_EXPORT booleantype N_VConstrMaskLocal(N_Vector c, N_Vector x, N_Vector m); SUNDIALS_EXPORT realtype N_VMinQuotientLocal(N_Vector num, N_Vector denom); -/* OPTIONAL XBraid interface operations */ +/* single buffer reduction operations */ +SUNDIALS_EXPORT int N_VDotProdMultiLocal(int nvec, N_Vector x, N_Vector* Y, + realtype* dotprods); +SUNDIALS_EXPORT int N_VDotProdMultiAllReduce(int nvec_total, N_Vector x, + realtype* sum); + +/* XBraid interface operations */ SUNDIALS_EXPORT int N_VBufSize(N_Vector x, sunindextype *size); SUNDIALS_EXPORT int N_VBufPack(N_Vector x, void *buf); SUNDIALS_EXPORT int N_VBufUnpack(N_Vector x, void *buf); diff --git a/inst/include/sundials/sundials_nvector_senswrapper.h b/inst/include/sundials/sundials_nvector_senswrapper.h index 2dddbe6..7cd7898 100644 --- a/inst/include/sundials/sundials_nvector_senswrapper.h +++ b/inst/include/sundials/sundials_nvector_senswrapper.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -60,7 +60,7 @@ typedef struct _N_VectorContent_SensWrapper *N_VectorContent_SensWrapper; ============================================================================*/ /* constructor creates an empty vector wrapper */ -SUNDIALS_EXPORT N_Vector N_VNewEmpty_SensWrapper(int nvecs); +SUNDIALS_EXPORT N_Vector N_VNewEmpty_SensWrapper(int nvecs, SUNContext sunctx); SUNDIALS_EXPORT N_Vector N_VNew_SensWrapper(int count, N_Vector w); /* clone operations */ diff --git a/inst/include/sundials/sundials_profiler.h b/inst/include/sundials/sundials_profiler.h new file mode 100644 index 0000000..a99ca6b --- /dev/null +++ b/inst/include/sundials/sundials_profiler.h @@ -0,0 +1,117 @@ +/* ----------------------------------------------------------------- + * Programmer: Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2022, 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 + * -----------------------------------------------------------------*/ + +#ifndef _SUNDIALS_PROFILER_H +#define _SUNDIALS_PROFILER_H + +#include + +#include "sundials/sundials_config.h" + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) +#include "caliper/cali.h" +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +typedef struct _SUNProfiler *SUNProfiler; + +SUNDIALS_EXPORT int SUNProfiler_Create(void* comm, const char* title, SUNProfiler* p); +SUNDIALS_EXPORT int SUNProfiler_Free(SUNProfiler* p); +SUNDIALS_EXPORT int SUNProfiler_Begin(SUNProfiler p, const char* name); +SUNDIALS_EXPORT int SUNProfiler_End(SUNProfiler p, const char* name); +SUNDIALS_EXPORT int SUNProfiler_Print(SUNProfiler p, FILE* fp); + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && defined(SUNDIALS_CALIPER_ENABLED) + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) CALI_MARK_FUNCTION_BEGIN + +#define SUNDIALS_MARK_FUNCTION_END(profobj) CALI_MARK_FUNCTION_END + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) CALI_WRAP_STATEMENT(name, stmt) + +#define SUNDIALS_MARK_BEGIN(profobj, name) CALI_MARK_BEGIN(name) + +#define SUNDIALS_MARK_END(profobj, name) CALI_MARK_END(name) + +#ifdef __cplusplus +#define SUNDIALS_CXX_MARK_FUNCTION(projobj) CALI_CXX_MARK_FUNCTION +#endif + +#elif defined(SUNDIALS_BUILD_WITH_PROFILING) + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) SUNProfiler_Begin(profobj, __func__) + +#define SUNDIALS_MARK_FUNCTION_END(profobj) SUNProfiler_End(profobj, __func__) + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) \ + SUNProfiler_Begin(profobj, (name)); \ + stmt; \ + SUNProfiler_End(profobj, (name)); + +#define SUNDIALS_MARK_BEGIN(profobj, name) SUNProfiler_Begin(profobj, (name)) + +#define SUNDIALS_MARK_END(profobj, name) SUNProfiler_End(profobj, (name)) + +#ifdef __cplusplus +#define SUNDIALS_CXX_MARK_FUNCTION(profobj) sundials::ProfilerMarkScope __ProfilerMarkScope(profobj, __func__) +#endif + +#else + +#define SUNDIALS_MARK_FUNCTION_BEGIN(profobj) + +#define SUNDIALS_MARK_FUNCTION_END(profobj) + +#define SUNDIALS_WRAP_STATEMENT(profobj, name, stmt) + +#define SUNDIALS_MARK_BEGIN(profobj, name) + +#define SUNDIALS_MARK_END(profobj, name) + +#ifdef __cplusplus +#define SUNDIALS_CXX_MARK_FUNCTION(profobj) +#endif + +#endif + +#ifdef __cplusplus +} + +namespace sundials +{ +/* Convenience class for C++ codes. + Allows for simpler profiler statements using C++ scoping rules. */ +class ProfilerMarkScope +{ +public: + ProfilerMarkScope(SUNProfiler prof, const char* name) { + prof_ = prof; + name_ = name; + SUNProfiler_Begin(prof_, name_); + } + + ~ProfilerMarkScope() { + SUNProfiler_End(prof_, name_); + } +private: + SUNProfiler prof_; + const char* name_; +}; +} + +#endif +#endif /* SUNDIALS_PROFILER_H_ */ diff --git a/inst/include/sundials/sundials_types.h b/inst/include/sundials/sundials_types.h index ee304d9..fee4207 100644 --- a/inst/include/sundials/sundials_types.h +++ b/inst/include/sundials/sundials_types.h @@ -3,7 +3,7 @@ * Aaron Collier, and Slaven Peles @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -12,18 +12,18 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This header file exports three types: realtype, sunindextype and - * booleantype, as well as the constants SUNTRUE and SUNFALSE. + * This header file exports three types: sunrealtype, sunindextype, + * and sunbooleantype, as well as the constants SUNTRUE and SUNFALSE. * * Users should include the header file sundials_types.h in every - * program file and use the exported name realtype instead of + * program file and use the exported name sunrealtype instead of * float, double or long double. * * The constants SUNDIALS_SINGLE_PRECISION, SUNDIALS_DOUBLE_PRECISION * and SUNDIALS_LONG_DOUBLE_PRECISION indicate the underlying data - * type of realtype. + * type of sunrealtype. * - * The legal types for realtype are float, double and long double. + * The legal types for sunrealtype are float, double and long double. * * The constants SUNDIALS_INT64_T and SUNDIALS_INT32_T indicate * the underlying data type of sunindextype -- the integer data type @@ -31,27 +31,24 @@ * * Data types are set at the configuration stage. * - * The macro RCONST gives the user a convenient way to define + * The macro SUN_RCONST gives the user a convenient way to define * real-valued literal constants. To use the constant 1.0, for example, * the user should write the following: * - * #define ONE RCONST(1.0) + * #define ONE SUN_RCONST(1.0) * - * If realtype is defined as a double, then RCONST(1.0) expands - * to 1.0. If realtype is defined as a float, then RCONST(1.0) - * expands to 1.0F. If realtype is defined as a long double, - * then RCONST(1.0) expands to 1.0L. There is never a need to - * explicitly cast 1.0 to (realtype). The macro can be used for + * If sunrealtype is defined as a double, then SUN_RCONST(1.0) expands + * to 1.0. If sunrealtype is defined as a float, then SUN_RCONST(1.0) + * expands to 1.0F. If sunrealtype is defined as a long double, + * then SUN_RCONST(1.0) expands to 1.0L. There is never a need to + * explicitly cast 1.0 to (sunrealtype). The macro can be used for * literal constants only. It cannot be used for expressions. * -----------------------------------------------------------------*/ -#ifndef _SUNDIALSTYPES_H -#define _SUNDIALSTYPES_H +#ifndef _SUNDIALS_TYPES_H +#define _SUNDIALS_TYPES_H -#ifndef _SUNDIALS_CONFIG_H -#define _SUNDIALS_CONFIG_H #include -#endif #include #include @@ -67,7 +64,7 @@ extern "C" { * The _SUNDIALS_STRUCT_ macro is defined as a `struct` unless * generating the SWIG interfaces - in that case it is defined as * nothing. This is needed to work around a bug in SWIG which prevents - * it from properly parsing our generic module structures. + * it from properly parsing our generic module structures. *------------------------------------------------------------------ */ #ifdef SWIG @@ -78,36 +75,57 @@ extern "C" { /* *------------------------------------------------------------------ - * Type realtype - * Macro RCONST - * Constants BIG_REAL, SMALL_REAL, and UNIT_ROUNDOFF + * Type sunrealtype + * Macro SUN_RCONST + * Constants SUN_SMALL_REAL, SUN_BIG_REAL, and SUN_UNIT_ROUNDOFF *------------------------------------------------------------------ */ #if defined(SUNDIALS_SINGLE_PRECISION) +/* deprecated */ typedef float realtype; # define RCONST(x) x##F # define BIG_REAL FLT_MAX # define SMALL_REAL FLT_MIN # define UNIT_ROUNDOFF FLT_EPSILON +typedef float sunrealtype; +# define SUN_RCONST(x) x##F +# define SUN_BIG_REAL FLT_MAX +# define SUN_SMALL_REAL FLT_MIN +# define SUN_UNIT_ROUNDOFF FLT_EPSILON + #elif defined(SUNDIALS_DOUBLE_PRECISION) +/* deprecated */ typedef double realtype; # define RCONST(x) x # define BIG_REAL DBL_MAX # define SMALL_REAL DBL_MIN # define UNIT_ROUNDOFF DBL_EPSILON +typedef double sunrealtype; +# define SUN_RCONST(x) x +# define SUN_BIG_REAL DBL_MAX +# define SUN_SMALL_REAL DBL_MIN +# define SUN_UNIT_ROUNDOFF DBL_EPSILON + #elif defined(SUNDIALS_EXTENDED_PRECISION) +/* deprecated */ typedef long double realtype; # define RCONST(x) x##L # define BIG_REAL LDBL_MAX # define SMALL_REAL LDBL_MIN # define UNIT_ROUNDOFF LDBL_EPSILON +typedef long double sunrealtype; +# define SUN_RCONST(x) x##L +# define SUN_BIG_REAL LDBL_MAX +# define SUN_SMALL_REAL LDBL_MIN +# define SUN_UNIT_ROUNDOFF LDBL_EPSILON + #endif @@ -126,25 +144,30 @@ typedef SUNDIALS_INDEX_TYPE sunindextype; /* *------------------------------------------------------------------ - * Type : booleantype + * Type : sunbooleantype *------------------------------------------------------------------ * Constants : SUNFALSE and SUNTRUE *------------------------------------------------------------------ * ANSI C does not have a built-in boolean data type. Below is the - * definition for a new type called booleantype. The advantage of - * using the name booleantype (instead of int) is an increase in + * definition for a new type called sunbooleantype. The advantage of + * using the name sunbooleantype (instead of int) is an increase in * code readability. It also allows the programmer to make a * distinction between int and boolean data. Variables of type - * booleantype are intended to have only the two values SUNFALSE and + * sunbooleantype are intended to have only the two values SUNFALSE and * SUNTRUE which are defined below to be equal to 0 and 1, * respectively. *------------------------------------------------------------------ */ +/* deprecated */ #ifndef booleantype #define booleantype int #endif +#ifndef sunbooleantype +#define sunbooleantype int +#endif + #ifndef SUNFALSE #define SUNFALSE 0 #endif @@ -157,4 +180,4 @@ typedef SUNDIALS_INDEX_TYPE sunindextype; } #endif -#endif /* _SUNDIALSTYPES_H */ +#endif /* _SUNDIALS_TYPES_H */ diff --git a/inst/include/sundials/sundials_version.h b/inst/include/sundials/sundials_version.h index dd819c5..4805db3 100644 --- a/inst/include/sundials/sundials_version.h +++ b/inst/include/sundials/sundials_version.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/inst/include/sunlinsol/sunlinsol_band.h b/inst/include/sunlinsol/sunlinsol_band.h index 5b203a5..820309b 100644 --- a/inst/include/sunlinsol/sunlinsol_band.h +++ b/inst/include/sunlinsol/sunlinsol_band.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -51,12 +51,7 @@ typedef struct _SUNLinearSolverContent_Band *SUNLinearSolverContent_Band; * Exported Functions for SUNLINSOL_BAND * -------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNBandLinearSolver(N_Vector y, - SUNMatrix A); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_Band(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_Band(SUNLinearSolver S); diff --git a/inst/include/sunlinsol/sunlinsol_cusolversp_batchqr.h b/inst/include/sunlinsol/sunlinsol_cusolversp_batchqr.h index b4729f1..528f898 100644 --- a/inst/include/sunlinsol/sunlinsol_cusolversp_batchqr.h +++ b/inst/include/sunlinsol/sunlinsol_cusolversp_batchqr.h @@ -4,7 +4,7 @@ * Based on work by Donald Wilcox @ LBNL * ---------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -58,7 +58,8 @@ typedef struct _SUNLinearSolverContent_cuSolverSp_batchQR *SUNLinearSolverConten */ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_cuSolverSp_batchQR(N_Vector y, SUNMatrix A, - cusolverSpHandle_t cusol_handle); + cusolverSpHandle_t cusol_handle, + SUNContext sunctx); /* @@ -101,7 +102,7 @@ SUNDIALS_EXPORT void SUNLinSol_cuSolverSp_batchQR_SetDescription(SUNLinearSolver SUNDIALS_EXPORT void SUNLinSol_cuSolverSp_batchQR_GetDeviceSpace(SUNLinearSolver S, size_t* cuSolverInternal, - size_t* cuSolverWorkspace); + size_t* cuSolverWorkspace); #ifdef __cplusplus diff --git a/inst/include/sunlinsol/sunlinsol_dense.h b/inst/include/sunlinsol/sunlinsol_dense.h index c10eec8..17ba16b 100644 --- a/inst/include/sunlinsol/sunlinsol_dense.h +++ b/inst/include/sunlinsol/sunlinsol_dense.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -55,12 +55,7 @@ typedef struct _SUNLinearSolverContent_Dense *SUNLinearSolverContent_Dense; * Exported Functions for SUNLINSOL_DENSE * ---------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNDenseLinearSolver(N_Vector y, - SUNMatrix A); - +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_Dense(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_Dense(SUNLinearSolver S); diff --git a/inst/include/sunlinsol/sunlinsol_klu.h b/inst/include/sunlinsol/sunlinsol_klu.h index 482705e..b2d70e8 100644 --- a/inst/include/sunlinsol/sunlinsol_klu.h +++ b/inst/include/sunlinsol/sunlinsol_klu.h @@ -5,7 +5,7 @@ * code, written by Carol S. Woodward @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -104,21 +104,12 @@ typedef struct _SUNLinearSolverContent_KLU *SUNLinearSolverContent_KLU; * Exported Functions for SUNLINSOL_KLU * ------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_KLU(N_Vector y, SUNMatrix A); +SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_KLU(N_Vector y, SUNMatrix A, SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_KLUReInit(SUNLinearSolver S, SUNMatrix A, sunindextype nnz, int reinit_type); SUNDIALS_EXPORT int SUNLinSol_KLUSetOrdering(SUNLinearSolver S, int ordering_choice); -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNKLU(N_Vector y, SUNMatrix A); -/* deprecated */ -SUNDIALS_EXPORT int SUNKLUReInit(SUNLinearSolver S, SUNMatrix A, - sunindextype nnz, int reinit_type); -/* deprecated */ -SUNDIALS_EXPORT int SUNKLUSetOrdering(SUNLinearSolver S, - int ordering_choice); - /* -------------------- * Accessor functions * -------------------- */ diff --git a/inst/include/sunlinsol/sunlinsol_lapackband.h b/inst/include/sunlinsol/sunlinsol_lapackband.h index 6524a8d..e4d5317 100644 --- a/inst/include/sunlinsol/sunlinsol_lapackband.h +++ b/inst/include/sunlinsol/sunlinsol_lapackband.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -25,7 +25,6 @@ #define _SUNLINSOL_LAPBAND_H #include -#include #include #include #include @@ -34,17 +33,6 @@ extern "C" { #endif -/* Interfaces to match 'realtype' with the correct LAPACK functions */ -#if defined(SUNDIALS_DOUBLE_PRECISION) -#define xgbtrf_f77 dgbtrf_f77 -#define xgbtrs_f77 dgbtrs_f77 -#elif defined(SUNDIALS_SINGLE_PRECISION) -#define xgbtrf_f77 sgbtrf_f77 -#define xgbtrs_f77 sgbtrs_f77 -#else -#error Incompatible realtype for LAPACK; disable LAPACK and rebuild -#endif - /* ---------------------------------------------- * LAPACK band implementation of SUNLinearSolver * ---------------------------------------------- */ @@ -63,11 +51,8 @@ typedef struct _SUNLinearSolverContent_LapackBand *SUNLinearSolverContent_Lapack * -------------------------------------------- */ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackBand(N_Vector y, - SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNLapackBand(N_Vector y, SUNMatrix A); - + SUNMatrix A, + SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_LapackBand(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_LapackBand(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_LapackBand(SUNLinearSolver S); diff --git a/inst/include/sunlinsol/sunlinsol_lapackdense.h b/inst/include/sunlinsol/sunlinsol_lapackdense.h index 4c0899b..e456fe4 100644 --- a/inst/include/sunlinsol/sunlinsol_lapackdense.h +++ b/inst/include/sunlinsol/sunlinsol_lapackdense.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -25,7 +25,6 @@ #define _SUNLINSOL_LAPDENSE_H #include -#include #include #include #include @@ -34,17 +33,6 @@ extern "C" { #endif -/* Interfaces to match 'realtype' with the correct LAPACK functions */ -#if defined(SUNDIALS_DOUBLE_PRECISION) -#define xgetrf_f77 dgetrf_f77 -#define xgetrs_f77 dgetrs_f77 -#elif defined(SUNDIALS_SINGLE_PRECISION) -#define xgetrf_f77 sgetrf_f77 -#define xgetrs_f77 sgetrs_f77 -#else -#error Incompatible realtype for LAPACK; disable LAPACK and rebuild -#endif - /* ----------------------------------------------- * LAPACK dense implementation of SUNLinearSolver * ----------------------------------------------- */ @@ -63,11 +51,8 @@ typedef struct _SUNLinearSolverContent_LapackDense *SUNLinearSolverContent_Lapac * --------------------------------------------- */ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackDense(N_Vector y, - SUNMatrix A); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNLapackDense(N_Vector y, SUNMatrix A); - + SUNMatrix A, + SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_LapackDense(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_LapackDense(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_LapackDense(SUNLinearSolver S); diff --git a/inst/include/sunlinsol/sunlinsol_pcg.h b/inst/include/sunlinsol/sunlinsol_pcg.h index 549ed1c..454fd4a 100644 --- a/inst/include/sunlinsol/sunlinsol_pcg.h +++ b/inst/include/sunlinsol/sunlinsol_pcg.h @@ -3,7 +3,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -48,10 +48,10 @@ struct _SUNLinearSolverContent_PCG { realtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s; @@ -73,25 +73,22 @@ typedef struct _SUNLinearSolverContent_PCG *SUNLinearSolverContent_PCG; SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, - int maxl); + int maxl, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT int SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl); -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNPCG(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNPCGSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNPCGSetMaxl(SUNLinearSolver S, int maxl); - SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_PCG(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); + SUNATimesFn ATimes); SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, void* P_data, - PSetupFn Pset, - PSolveFn Psol); + SUNPSetupFn Pset, + SUNPSolveFn Psol); SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, N_Vector s, N_Vector nul); diff --git a/inst/include/sunlinsol/sunlinsol_spbcgs.h b/inst/include/sunlinsol/sunlinsol_spbcgs.h index 9f928a4..c1cbfcc 100644 --- a/inst/include/sunlinsol/sunlinsol_spbcgs.h +++ b/inst/include/sunlinsol/sunlinsol_spbcgs.h @@ -5,7 +5,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -52,10 +52,10 @@ struct _SUNLinearSolverContent_SPBCGS { realtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; @@ -81,25 +81,21 @@ typedef struct _SUNLinearSolverContent_SPBCGS *SUNLinearSolverContent_SPBCGS; SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, - int maxl); + int maxl, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT int SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPBCGS(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPBCGSSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPBCGSSetMaxl(SUNLinearSolver S, int maxl); - SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); + SUNATimesFn ATimes); SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, void* P_data, - PSetupFn Pset, - PSolveFn Psol); + SUNPSetupFn Pset, + SUNPSolveFn Psol); SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, N_Vector s1, N_Vector s2); diff --git a/inst/include/sunlinsol/sunlinsol_spfgmr.h b/inst/include/sunlinsol/sunlinsol_spfgmr.h index 6aec1d1..fc1833d 100644 --- a/inst/include/sunlinsol/sunlinsol_spfgmr.h +++ b/inst/include/sunlinsol/sunlinsol_spfgmr.h @@ -5,7 +5,7 @@ * Hilari C. Tiedeman @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -39,7 +39,7 @@ extern "C" { /* Default SPFGMR solver parameters */ #define SUNSPFGMR_MAXL_DEFAULT 5 #define SUNSPFGMR_MAXRS_DEFAULT 0 -#define SUNSPFGMR_GSTYPE_DEFAULT MODIFIED_GS +#define SUNSPFGMR_GSTYPE_DEFAULT SUN_MODIFIED_GS /* ----------------------------------------- * SPFGMR Implementation of SUNLinearSolver @@ -55,10 +55,10 @@ struct _SUNLinearSolverContent_SPFGMR { realtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; @@ -86,29 +86,23 @@ typedef struct _SUNLinearSolverContent_SPFGMR *SUNLinearSolverContent_SPFGMR; SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, - int maxl); + int maxl, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, int gstype); SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPFGMR(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPFGMRSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPFGMRSetGSType(SUNLinearSolver S, int gstype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); - - SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); + SUNATimesFn ATimes); SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, void* P_data, - PSetupFn Pset, - PSolveFn Psol); + SUNPSetupFn Pset, + SUNPSolveFn Psol); SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, N_Vector s1, N_Vector s2); diff --git a/inst/include/sunlinsol/sunlinsol_spgmr.h b/inst/include/sunlinsol/sunlinsol_spgmr.h index 6227c3e..6b7eec8 100644 --- a/inst/include/sunlinsol/sunlinsol_spgmr.h +++ b/inst/include/sunlinsol/sunlinsol_spgmr.h @@ -5,7 +5,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2020, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -28,6 +28,8 @@ #ifndef _SUNLINSOL_SPGMR_H #define _SUNLINSOL_SPGMR_H +#include + #include #include #include @@ -39,7 +41,7 @@ extern "C" { /* Default SPGMR solver parameters */ #define SUNSPGMR_MAXL_DEFAULT 5 #define SUNSPGMR_MAXRS_DEFAULT 0 -#define SUNSPGMR_GSTYPE_DEFAULT MODIFIED_GS +#define SUNSPGMR_GSTYPE_DEFAULT SUN_MODIFIED_GS /* ---------------------------------------- * SPGMR Implementation of SUNLinearSolver @@ -50,14 +52,15 @@ struct _SUNLinearSolverContent_SPGMR { int pretype; int gstype; int max_restarts; + booleantype zeroguess; int numiters; realtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; @@ -71,6 +74,9 @@ struct _SUNLinearSolverContent_SPGMR { realtype *cv; N_Vector *Xv; + + int print_level; + FILE* info_file; }; typedef struct _SUNLinearSolverContent_SPGMR *SUNLinearSolverContent_SPGMR; @@ -82,35 +88,28 @@ typedef struct _SUNLinearSolverContent_SPGMR *SUNLinearSolverContent_SPGMR; SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, - int maxl); + int maxl, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT int SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, int gstype); SUNDIALS_EXPORT int SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNSPGMR(N_Vector y, int pretype, int maxl); -/* deprecated */ -SUNDIALS_EXPORT int SUNSPGMRSetPrecType(SUNLinearSolver S, int pretype); -/* deprecated */ -SUNDIALS_EXPORT int SUNSPGMRSetGSType(SUNLinearSolver S, int gstype); -/* deprecated */ -SUNDIALS_EXPORT int SUNSPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); - SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); + SUNATimesFn ATimes); SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, void* P_data, - PSetupFn Pset, - PSolveFn Psol); + SUNPSetupFn Pset, + SUNPSolveFn Psol); SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, N_Vector s1, N_Vector s2); +SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, + booleantype onff); SUNDIALS_EXPORT int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, realtype tol); @@ -122,6 +121,11 @@ SUNDIALS_EXPORT int SUNLinSolSpace_SPGMR(SUNLinearSolver S, long int *lenrwLS, long int *leniwLS); SUNDIALS_EXPORT int SUNLinSolFree_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT int SUNLinSolSetInfoFile_SPGMR(SUNLinearSolver LS, + FILE* info_file); +SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_SPGMR(SUNLinearSolver LS, + int print_level); + #ifdef __cplusplus diff --git a/inst/include/sunlinsol/sunlinsol_sptfqmr.h b/inst/include/sunlinsol/sunlinsol_sptfqmr.h index bbdcd13..04153d5 100644 --- a/inst/include/sunlinsol/sunlinsol_sptfqmr.h +++ b/inst/include/sunlinsol/sunlinsol_sptfqmr.h @@ -4,7 +4,7 @@ * Based on code sundials_sptfqmr.h by: Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -50,10 +50,10 @@ struct _SUNLinearSolverContent_SPTFQMR { realtype resnorm; int last_flag; - ATimesFn ATimes; + SUNATimesFn ATimes; void* ATData; - PSetupFn Psetup; - PSolveFn Psolve; + SUNPSetupFn Psetup; + SUNPSolveFn Psolve; void* PData; N_Vector s1; @@ -81,25 +81,21 @@ typedef struct _SUNLinearSolverContent_SPTFQMR *SUNLinearSolverContent_SPTFQMR; SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, - int maxl); + int maxl, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT int SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl); - -SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPTFQMR(N_Vector y, int pretype, int maxl); -SUNDIALS_DEPRECATED_EXPORT int SUNSPTFQMRSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_DEPRECATED_EXPORT int SUNSPTFQMRSetMaxl(SUNLinearSolver S, int maxl); - SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, void* A_data, - ATimesFn ATimes); + SUNATimesFn ATimes); SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, void* P_data, - PSetupFn Pset, - PSolveFn Psol); + SUNPSetupFn Pset, + SUNPSolveFn Psol); SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, N_Vector s1, N_Vector s2); diff --git a/inst/include/sunlinsol/sunlinsol_superludist.h b/inst/include/sunlinsol/sunlinsol_superludist.h index 80c9b8c..e4c116d 100644 --- a/inst/include/sunlinsol/sunlinsol_superludist.h +++ b/inst/include/sunlinsol/sunlinsol_superludist.h @@ -3,7 +3,7 @@ * Programmer(s): Cody J. Balos @ LLNL * ---------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -100,7 +100,8 @@ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUDIST(N_Vector y, SUNMatrix A, xScalePermstruct_t *scaleperm, xSOLVEstruct_t *solve, SuperLUStat_t *stat, - superlu_dist_options_t *options); + superlu_dist_options_t *options, + SUNContext sunctx); /* * ---------------------------------------------------------------------------- diff --git a/inst/include/sunlinsol/sunlinsol_superlumt.h b/inst/include/sunlinsol/sunlinsol_superlumt.h index 79768da..b54c2d5 100644 --- a/inst/include/sunlinsol/sunlinsol_superlumt.h +++ b/inst/include/sunlinsol/sunlinsol_superlumt.h @@ -5,7 +5,7 @@ * written by Carol S. Woodward @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -95,17 +95,10 @@ typedef struct _SUNLinearSolverContent_SuperLUMT *SUNLinearSolverContent_SuperLU SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SuperLUMT(N_Vector y, SUNMatrix A, - int num_threads); + int num_threads, + SUNContext sunctx); SUNDIALS_EXPORT int SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, int ordering_choice); - -/* deprecated */ -SUNDIALS_EXPORT SUNLinearSolver SUNSuperLUMT(N_Vector y, SUNMatrix A, - int num_threads); -/* deprecated */ -SUNDIALS_EXPORT int SUNSuperLUMTSetOrdering(SUNLinearSolver S, - int ordering_choice); - SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SuperLUMT(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SuperLUMT(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S); diff --git a/inst/include/sunmatrix/sunmatrix_band.h b/inst/include/sunmatrix/sunmatrix_band.h index f6e16b9..4a4aafe 100644 --- a/inst/include/sunmatrix/sunmatrix_band.h +++ b/inst/include/sunmatrix/sunmatrix_band.h @@ -5,7 +5,7 @@ * Based on code sundials_direct.h by: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,15 +14,15 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the header file for the band implementation of the + * This is the header file for the band implementation of the * SUNMATRIX module, SUNMATRIX_BAND. * * Notes: * - The definition of the generic SUNMatrix structure can be found * in the header file sundials_matrix.h. * - The definition of the type 'realtype' can be found in the - * header file sundials_types.h, and it may be changed (at the - * configuration stage) according to the user's needs. + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition * for the type 'booleantype' and 'indextype'. * ----------------------------------------------------------------- @@ -41,7 +41,7 @@ extern "C" { /* --------------------------------- * Band implementation of SUNMatrix * --------------------------------- */ - + struct _SUNMatrixContent_Band { sunindextype M; sunindextype N; @@ -56,7 +56,7 @@ struct _SUNMatrixContent_Band { typedef struct _SUNMatrixContent_Band *SUNMatrixContent_Band; - + /* ------------------------------------ * Macros for access to SUNMATRIX_BAND * ------------------------------------ */ @@ -89,16 +89,17 @@ typedef struct _SUNMatrixContent_Band *SUNMatrixContent_Band; /* ---------------------------------------- - * Exported Functions for SUNMATRIX_BAND + * Exported Functions for SUNMATRIX_BAND * ---------------------------------------- */ SUNDIALS_EXPORT SUNMatrix SUNBandMatrix(sunindextype N, sunindextype mu, - sunindextype ml); + sunindextype ml, SUNContext sunctx); SUNDIALS_EXPORT SUNMatrix SUNBandMatrixStorage(sunindextype N, sunindextype mu, sunindextype ml, - sunindextype smu); + sunindextype smu, + SUNContext sunctx); SUNDIALS_EXPORT void SUNBandMatrix_Print(SUNMatrix A, FILE* outfile); @@ -121,7 +122,7 @@ SUNDIALS_EXPORT int SUNMatScaleAdd_Band(realtype c, SUNMatrix A, SUNMatrix B); SUNDIALS_EXPORT int SUNMatScaleAddI_Band(realtype c, SUNMatrix A); SUNDIALS_EXPORT int SUNMatMatvec_Band(SUNMatrix A, N_Vector x, N_Vector y); SUNDIALS_EXPORT int SUNMatSpace_Band(SUNMatrix A, long int *lenrw, long int *leniw); - + #ifdef __cplusplus } #endif diff --git a/inst/include/sunmatrix/sunmatrix_dense.h b/inst/include/sunmatrix/sunmatrix_dense.h index 9b23a3e..418d16d 100644 --- a/inst/include/sunmatrix/sunmatrix_dense.h +++ b/inst/include/sunmatrix/sunmatrix_dense.h @@ -5,7 +5,7 @@ * Based on code sundials_direct.h by: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -14,15 +14,15 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the header file for the dense implementation of the + * This is the header file for the dense implementation of the * SUNMATRIX module, SUNMATRIX_DENSE. * * Notes: * - The definition of the generic SUNMatrix structure can be found * in the header file sundials_matrix.h. * - The definition of the type 'realtype' can be found in the - * header file sundials_types.h, and it may be changed (at the - * configuration stage) according to the user's needs. + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition * for the type 'booleantype' and 'indextype'. * ----------------------------------------------------------------- @@ -41,7 +41,7 @@ extern "C" { /* ---------------------------------- * Dense implementation of SUNMatrix * ---------------------------------- */ - + struct _SUNMatrixContent_Dense { sunindextype M; sunindextype N; @@ -76,7 +76,7 @@ typedef struct _SUNMatrixContent_Dense *SUNMatrixContent_Dense; * Exported Functions for SUNMATRIX_DENSE * --------------------------------------- */ -SUNDIALS_EXPORT SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N); +SUNDIALS_EXPORT SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N, SUNContext sunctx); SUNDIALS_EXPORT void SUNDenseMatrix_Print(SUNMatrix A, FILE* outfile); @@ -97,7 +97,7 @@ SUNDIALS_EXPORT int SUNMatScaleAddI_Dense(realtype c, SUNMatrix A); SUNDIALS_EXPORT int SUNMatMatvec_Dense(SUNMatrix A, N_Vector x, N_Vector y); SUNDIALS_EXPORT int SUNMatSpace_Dense(SUNMatrix A, long int *lenrw, long int *leniw); - + #ifdef __cplusplus } #endif diff --git a/inst/include/sunmatrix/sunmatrix_slunrloc.h b/inst/include/sunmatrix/sunmatrix_slunrloc.h index 63ea673..6e18920 100644 --- a/inst/include/sunmatrix/sunmatrix_slunrloc.h +++ b/inst/include/sunmatrix/sunmatrix_slunrloc.h @@ -3,7 +3,7 @@ * Programmer(s): Cody Balos @ LLNL * ---------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -53,7 +53,7 @@ typedef struct _SUNMatrixContent_SLUNRloc *SUNMatrixContent_SLUNRloc; * --------------------------------------------------------------------------*/ -SUNDIALS_EXPORT SUNMatrix SUNMatrix_SLUNRloc(SuperMatrix *A_super, gridinfo_t *grid); +SUNDIALS_EXPORT SUNMatrix SUNMatrix_SLUNRloc(SuperMatrix *A_super, gridinfo_t *grid, SUNContext sunctx); SUNDIALS_EXPORT void SUNMatrix_SLUNRloc_Print(SUNMatrix A, FILE *fp); /* ---------------------------------------------------------------------------- diff --git a/inst/include/sunmatrix/sunmatrix_sparse.h b/inst/include/sunmatrix/sunmatrix_sparse.h index 102c78a..4a6b0a4 100644 --- a/inst/include/sunmatrix/sunmatrix_sparse.h +++ b/inst/include/sunmatrix/sunmatrix_sparse.h @@ -2,11 +2,11 @@ * ----------------------------------------------------------------- * Programmer(s): Daniel Reynolds @ SMU * David Gardner @ LLNL - * Based on code sundials_sparse.h by: Carol Woodward and + * Based on code sundials_sparse.h by: Carol Woodward and * Slaven Peles @ LLNL, and Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -15,15 +15,15 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the header file for the sparse implementation of the + * This is the header file for the sparse implementation of the * SUNMATRIX module, SUNMATRIX_SPARSE. * * Notes: * - The definition of the generic SUNMatrix structure can be found * in the header file sundials_matrix.h. * - The definition of the type 'realtype' can be found in the - * header file sundials_types.h, and it may be changed (at the - * configuration stage) according to the user's needs. + * header file sundials_types.h, and it may be changed (at the + * configuration stage) according to the user's needs. * The sundials_types.h file also contains the definition * for the type 'booleantype' and 'indextype'. * ----------------------------------------------------------------- @@ -48,11 +48,11 @@ extern "C" { #define CSC_MAT 0 #define CSR_MAT 1 - + /* ------------------------------------------ * Sparse Implementation of SUNMATRIX_SPARSE * ------------------------------------------ */ - + struct _SUNMatrixContent_Sparse { sunindextype M; sunindextype N; @@ -100,7 +100,8 @@ typedef struct _SUNMatrixContent_Sparse *SUNMatrixContent_Sparse; * ---------------------------------------- */ SUNDIALS_EXPORT SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, - sunindextype NNZ, int sparsetype); + sunindextype NNZ, int sparsetype, + SUNContext sunctx); SUNDIALS_EXPORT SUNMatrix SUNSparseFromDenseMatrix(SUNMatrix A, realtype droptol, diff --git a/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h b/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h index 22be29b..1b12670 100644 --- a/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h +++ b/inst/include/sunnonlinsol/sunnonlinsol_fixedpoint.h @@ -1,8 +1,8 @@ -/*----------------------------------------------------------------------------- +/* --------------------------------------------------------------------------- * Programmer(s): Daniel R. Reynolds @ SMU - *----------------------------------------------------------------------------- + * --------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -10,14 +10,14 @@ * * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End - *----------------------------------------------------------------------------- + * --------------------------------------------------------------------------- * This is the header file for the SUNNonlinearSolver module implementation of * the Anderson-accelerated fixed-point method. * * Part I defines the solver-specific content structure. * * Part II contains prototypes for the solver constructor and operations. - *---------------------------------------------------------------------------*/ + * ---------------------------------------------------------------------------*/ #ifndef _SUNNONLINSOL_FIXEDPOINT_H #define _SUNNONLINSOL_FIXEDPOINT_H @@ -76,8 +76,12 @@ typedef struct _SUNNonlinearSolverContent_FixedPoint *SUNNonlinearSolverContent_ ---------------------------------------------------------------------------*/ /* Constructor to create solver and allocates memory */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m); -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m); +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m, + SUNContext sunctx); /* core functions */ SUNDIALS_EXPORT SUNNonlinearSolver_Type SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS); @@ -122,7 +126,7 @@ SUNDIALS_EXPORT int SUNNonlinSolSetInfoFile_FixedPoint(SUNNonlinearSolver NLS, FILE* info_file); SUNDIALS_EXPORT int SUNNonlinSolSetPrintLevel_FixedPoint(SUNNonlinearSolver NLS, - int print_level); + int print_level); #ifdef __cplusplus diff --git a/inst/include/sunnonlinsol/sunnonlinsol_newton.h b/inst/include/sunnonlinsol/sunnonlinsol_newton.h index db2624b..147b65f 100644 --- a/inst/include/sunnonlinsol/sunnonlinsol_newton.h +++ b/inst/include/sunnonlinsol/sunnonlinsol_newton.h @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -64,8 +64,12 @@ typedef struct _SUNNonlinearSolverContent_Newton *SUNNonlinearSolverContent_Newt * ---------------------------------------------------------------------------*/ /* Constructor to create solver and allocates memory */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y); -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y); +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y, + SUNContext sunctx); /* core functions */ SUNDIALS_EXPORT SUNNonlinearSolver_Type SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS); diff --git a/inst/include/sunnonlinsol/sunnonlinsol_petscsnes.h b/inst/include/sunnonlinsol/sunnonlinsol_petscsnes.h index 551188b..ede0731 100644 --- a/inst/include/sunnonlinsol/sunnonlinsol_petscsnes.h +++ b/inst/include/sunnonlinsol/sunnonlinsol_petscsnes.h @@ -2,7 +2,7 @@ * Programmer(s): Cody J. Balos @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -56,7 +56,9 @@ typedef struct _SUNNonlinearSolverContent_PetscSNES *SUNNonlinearSolverContent_P /* Constructor to create solver and allocates memory */ -SUNDIALS_EXPORT SUNNonlinearSolver SUNNonlinSol_PetscSNES(N_Vector y, SNES snes); +SUNDIALS_EXPORT +SUNNonlinearSolver SUNNonlinSol_PetscSNES(N_Vector y, SNES snes, + SUNContext sunctx); /* SUNNonlinearSolver API functions */ diff --git a/src/Makevars b/src/Makevars index 6cdd4c3..606e3e8 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1,5 +1,5 @@ CXX=clang++ -PKG_CPPFLAGS= -I../inst/include/ -I./inst/ -DHAVE_CONFIG_H -DARMA_USE_CXX11 +PKG_CPPFLAGS= -I../inst/include/ -I./inst/ -DHAVE_CONFIG_H -DARMA_USE_CXX11 -I./sundials/sundials CXX_STD = CXX11 PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L../inst/ -lsundials_all LIBS=-L./ -L../inst/ diff --git a/src/cvode.cpp b/src/cvode.cpp index 06b12ec..e86982f 100644 --- a/src/cvode.cpp +++ b/src/cvode.cpp @@ -63,6 +63,8 @@ NumericMatrix cvode(NumericVector time_vector, NumericVector IC, SEXP input_func int time_vec_len = time_vector.length(); int y_len = IC.length(); int abstol_len = abstolerance.length(); + SUNContext sunctx; + SUNContext_Create(NULL, &sunctx); int flag; realtype reltol = reltolerance; @@ -74,7 +76,7 @@ NumericMatrix cvode(NumericVector time_vector, NumericVector IC, SEXP input_func // Set the vector absolute tolerance ----------------------------------------- // abstol must be same length as IC - N_Vector abstol = N_VNew_Serial(abstol_len); + N_Vector abstol = N_VNew_Serial(abstol_len, sunctx); realtype *abstol_ptr = N_VGetArrayPointer(abstol); if(abstol_len == 1){ // if a scalar is provided - use it to make a vector with same values @@ -92,7 +94,7 @@ NumericMatrix cvode(NumericVector time_vector, NumericVector IC, SEXP input_func } // Set the initial conditions------------------------------------------------- - N_Vector y0 = N_VNew_Serial(y_len); + N_Vector y0 = N_VNew_Serial(y_len, sunctx); realtype *y0_ptr = N_VGetArrayPointer(y0); for (int i = 0; icv_sunctx->profiler /*=================================================================*/ /* Private Helper Functions Prototypes */ @@ -305,7 +310,7 @@ static int cvRootfind(CVodeMem cv_mem); * message to standard err and returns NULL. */ -void *CVodeCreate(int lmm) +void *CVodeCreate(int lmm, SUNContext sunctx) { int maxord; CVodeMem cv_mem; @@ -317,6 +322,11 @@ void *CVodeCreate(int lmm) return(NULL); } + if (sunctx == NULL) { + cvProcessError(NULL, 0, "CVODE", "CVodeCreate", MSGCV_NULL_SUNCTX); + return(NULL); + } + cv_mem = NULL; cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec)); if (cv_mem == NULL) { @@ -329,7 +339,8 @@ void *CVodeCreate(int lmm) maxord = (lmm == CV_ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; - /* copy input parameters into cv_mem */ + /* Copy input parameters into cv_mem */ + cv_mem->cv_sunctx = sunctx; cv_mem->cv_lmm = lmm; /* Set uround */ @@ -435,15 +446,19 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Check for legal input parameters */ if (y0==NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeInit", MSGCV_NULL_Y0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } if (f == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeInit", MSGCV_NULL_F); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -453,6 +468,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) if(!nvectorOK) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeInit", MSGCV_BAD_NVECTOR); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -472,6 +488,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) allocOK = cvAllocVectors(cv_mem, y0); if (!allocOK) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODE", "CVodeInit", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -485,12 +502,13 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) N_VScale(ONE, y0, cv_mem->cv_zn[0]); /* create a Newton nonlinear solver object by default */ - NLS = SUNNonlinSol_Newton(y0); + NLS = SUNNonlinSol_Newton(y0, cv_mem->cv_sunctx); /* check that nonlinear solver is non-NULL */ if (NLS == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODE", "CVodeInit", MSGCV_MEM_FAIL); cvFreeVectors(cv_mem); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -503,6 +521,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) "Setting the nonlinear solver failed"); cvFreeVectors(cv_mem); SUNNonlinSolFree(NLS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -566,6 +585,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) cv_mem->cv_MallocDone = SUNTRUE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -596,11 +616,14 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Check if cvode_mem was allocated */ if (cv_mem->cv_MallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_MALLOC, "CVODE", "CVodeReInit", MSGCV_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_MALLOC); } @@ -609,6 +632,7 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) if (y0 == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeReInit", MSGCV_NULL_Y0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -661,6 +685,7 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) /* Problem has been successfully re-initialized */ + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1026,27 +1051,33 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Check if cvode_mem was allocated */ if (cv_mem->cv_MallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_MALLOC, "CVODE", "CVode", MSGCV_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_MALLOC); } /* Check for yout != NULL */ if ((cv_mem->cv_y = yout) == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_YOUT_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } /* Check for tret != NULL */ if (tret == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } /* Check for valid itask */ if ( (itask != CV_NORMAL) && (itask != CV_ONE_STEP) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1072,7 +1103,10 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, /* Check inputs for corectness */ ier = cvInitialSetup(cv_mem); - if (ier!= CV_SUCCESS) return(ier); + if (ier!= CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(ier); + } /* Call f at (t0,y0), set zn[1] = y'(t0). */ @@ -1082,11 +1116,13 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval < 0) { cvProcessError(cv_mem, CV_RHSFUNC_FAIL, "CVODE", "CVode", MSGCV_RHSFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RHSFUNC_FAIL); } if (retval > 0) { cvProcessError(cv_mem, CV_FIRST_RHSFUNC_ERR, "CVODE", "CVode", MSGCV_RHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_FIRST_RHSFUNC_ERR); } @@ -1096,6 +1132,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if ( (cv_mem->cv_tstop - cv_mem->cv_tn)*(tout - cv_mem->cv_tn) <= ZERO ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } } @@ -1105,6 +1142,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, cv_mem->cv_h = cv_mem->cv_hin; if ( (cv_mem->cv_h != ZERO) && ((tout-cv_mem->cv_tn)*cv_mem->cv_h < ZERO) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_BAD_H0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } if (cv_mem->cv_h == ZERO) { @@ -1115,6 +1153,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, hflag = cvHin(cv_mem, tout_hin); if (hflag != CV_SUCCESS) { istate = cvHandleFailure(cv_mem, hflag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(istate); } } @@ -1147,6 +1186,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval == CV_RTFUNC_FAIL) { cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODE", "cvRcheck1", MSGCV_RTFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RTFUNC_FAIL); } @@ -1186,13 +1226,16 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval == CLOSERT) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "cvRcheck2", MSGCV_CLOSE_ROOTS, cv_mem->cv_tlo); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } else if (retval == CV_RTFUNC_FAIL) { cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODE", "cvRcheck2", MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RTFUNC_FAIL); } else if (retval == RTFOUND) { cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ROOT_RETURN); } @@ -1207,15 +1250,18 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if ((irfndp == 1) && (itask == CV_ONE_STEP)) { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } } else if (retval == RTFOUND) { /* a new root was found */ cv_mem->cv_irfnd = 1; cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ROOT_RETURN); } else if (retval == CV_RTFUNC_FAIL) { /* g failed */ cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODE", "cvRcheck3", MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RTFUNC_FAIL); } @@ -1230,8 +1276,10 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (ier != CV_SUCCESS) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_BAD_TOUT, tout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1240,6 +1288,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, SUNRabs(cv_mem->cv_tn - cv_mem->cv_tretlast) > troundoff ) { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1251,10 +1300,12 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (ier != CV_SUCCESS) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVode", MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } cv_mem->cv_tretlast = *tret = cv_mem->cv_tstop; cv_mem->cv_tstopset = SUNFALSE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_TSTOP_RETURN); } @@ -1447,6 +1498,8 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, } /* end looping for internal steps */ + + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(istate); } @@ -1487,13 +1540,17 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if (dky == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODE", "CVodeGetDky", MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } if ((k < 0) || (k > cv_mem->cv_q)) { cvProcessError(cv_mem, CV_BAD_K, "CVODE", "CVodeGetDky", MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_K); } @@ -1506,6 +1563,7 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) if ((t-tp)*(t-tn1) > ZERO) { cvProcessError(cv_mem, CV_BAD_T, "CVODE", "CVodeGetDky", MSGCV_BAD_T, t, cv_mem->cv_tn-cv_mem->cv_hu, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_T); } @@ -1523,11 +1581,19 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dky); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return (CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dky, dky); + + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1549,8 +1615,11 @@ int CVodeComputeState(void *cvode_mem, N_Vector ycor, N_Vector y) cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, y); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } diff --git a/src/sundials/cvode/cvode_bandpre.c b/src/sundials/cvode/cvode_bandpre.c index 898f8eb..d48ba5c 100644 --- a/src/sundials/cvode/cvode_bandpre.c +++ b/src/sundials/cvode/cvode_bandpre.c @@ -5,7 +5,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -109,7 +109,7 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, /* Allocate memory for saved banded Jacobian approximation. */ pdata->savedJ = NULL; - pdata->savedJ = SUNBandMatrixStorage(N, mup, mlp, mup); + pdata->savedJ = SUNBandMatrixStorage(N, mup, mlp, mup, cv_mem->cv_sunctx); if (pdata->savedJ == NULL) { free(pdata); pdata = NULL; cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVBANDPRE", @@ -120,7 +120,7 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, /* Allocate memory for banded preconditioner. */ storagemu = SUNMIN(N-1, mup+mlp); pdata->savedP = NULL; - pdata->savedP = SUNBandMatrixStorage(N, mup, mlp, storagemu); + pdata->savedP = SUNBandMatrixStorage(N, mup, mlp, storagemu, cv_mem->cv_sunctx); if (pdata->savedP == NULL) { SUNMatDestroy(pdata->savedJ); free(pdata); pdata = NULL; @@ -131,7 +131,7 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(cv_mem->cv_tempv, pdata->savedP); + pdata->LS = SUNLinSol_Band(cv_mem->cv_tempv, pdata->savedP, cv_mem->cv_sunctx); if (pdata->LS == NULL) { SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); diff --git a/src/sundials/cvode/cvode_bandpre_impl.h b/src/sundials/cvode/cvode_bandpre_impl.h index 31ec6b8..1104f8f 100644 --- a/src/sundials/cvode/cvode_bandpre_impl.h +++ b/src/sundials/cvode/cvode_bandpre_impl.h @@ -5,7 +5,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_bbdpre.c b/src/sundials/cvode/cvode_bbdpre.c index 20bc9ad..f376fe6 100644 --- a/src/sundials/cvode/cvode_bbdpre.c +++ b/src/sundials/cvode/cvode_bbdpre.c @@ -5,7 +5,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -110,7 +110,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, pdata->mlkeep = mlk; /* Allocate memory for saved Jacobian */ - pdata->savedJ = SUNBandMatrixStorage(Nlocal, muk, mlk, muk); + pdata->savedJ = SUNBandMatrixStorage(Nlocal, muk, mlk, muk, cv_mem->cv_sunctx); if (pdata->savedJ == NULL) { free(pdata); pdata = NULL; cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVBBDPRE", @@ -121,7 +121,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Allocate memory for preconditioner matrix */ storage_mu = SUNMIN(Nlocal-1, muk + mlk); pdata->savedP = NULL; - pdata->savedP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu); + pdata->savedP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu, cv_mem->cv_sunctx); if (pdata->savedP == NULL) { SUNMatDestroy(pdata->savedJ); free(pdata); pdata = NULL; @@ -132,7 +132,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Allocate memory for temporary N_Vectors */ pdata->zlocal = NULL; - pdata->zlocal = N_VNewEmpty_Serial(Nlocal); + pdata->zlocal = N_VNewEmpty_Serial(Nlocal, cv_mem->cv_sunctx); if (pdata->zlocal == NULL) { SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); @@ -142,7 +142,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, return(CVLS_MEM_FAIL); } pdata->rlocal = NULL; - pdata->rlocal = N_VNewEmpty_Serial(Nlocal); + pdata->rlocal = N_VNewEmpty_Serial(Nlocal, cv_mem->cv_sunctx); if (pdata->rlocal == NULL) { N_VDestroy(pdata->zlocal); SUNMatDestroy(pdata->savedP); @@ -194,7 +194,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->savedP); + pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->savedP, cv_mem->cv_sunctx); if (pdata->LS == NULL) { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); diff --git a/src/sundials/cvode/cvode_bbdpre_impl.h b/src/sundials/cvode/cvode_bbdpre_impl.h index 0217437..bf0a843 100644 --- a/src/sundials/cvode/cvode_bbdpre_impl.h +++ b/src/sundials/cvode/cvode_bbdpre_impl.h @@ -4,7 +4,7 @@ * Michael Wittman, Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_diag.c b/src/sundials/cvode/cvode_diag.c index e26be37..8f9c124 100644 --- a/src/sundials/cvode/cvode_diag.c +++ b/src/sundials/cvode/cvode_diag.c @@ -4,7 +4,7 @@ * Radu Serban, Cody J. Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_diag_impl.h b/src/sundials/cvode/cvode_diag_impl.h index c402daf..7a5e643 100644 --- a/src/sundials/cvode/cvode_diag_impl.h +++ b/src/sundials/cvode/cvode_diag_impl.h @@ -4,7 +4,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_direct.c b/src/sundials/cvode/cvode_direct.c index c86a864..0d773d4 100644 --- a/src/sundials/cvode/cvode_direct.c +++ b/src/sundials/cvode/cvode_direct.c @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_impl.h b/src/sundials/cvode/cvode_impl.h index 746060e..3f5cc97 100644 --- a/src/sundials/cvode/cvode_impl.h +++ b/src/sundials/cvode/cvode_impl.h @@ -4,7 +4,7 @@ * Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,8 +21,9 @@ #include -#include "cvode/cvode.h" +#include #include "cvode_proj_impl.h" +#include "sundials_context_impl.h" #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { @@ -120,6 +121,8 @@ extern "C" { typedef struct CVodeMemRec { + SUNContext cv_sunctx; + realtype cv_uround; /* machine unit roundoff */ /*-------------------------- @@ -588,6 +591,7 @@ void cvRescale(CVodeMem cv_mem); #define MSGCV_CVMEM_FAIL "Allocation of cvode_mem failed." #define MSGCV_MEM_FAIL "A memory request failed." #define MSGCV_BAD_LMM "Illegal value for lmm. The legal values are CV_ADAMS and CV_BDF." +#define MSGCV_NULL_SUNCTX "sunctx = NULL illegal." #define MSGCV_NO_MALLOC "Attempt to call before CVodeInit." #define MSGCV_NEG_MAXORD "maxord <= 0 illegal." #define MSGCV_BAD_MAXORD "Illegal attempt to increase maximum method order." diff --git a/src/sundials/cvode/cvode_io.c b/src/sundials/cvode/cvode_io.c index 26aab22..913309c 100644 --- a/src/sundials/cvode/cvode_io.c +++ b/src/sundials/cvode/cvode_io.c @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_ls.c b/src/sundials/cvode/cvode_ls.c index 54caffb..c40d9fa 100644 --- a/src/sundials/cvode/cvode_ls.c +++ b/src/sundials/cvode/cvode_ls.c @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -384,13 +384,6 @@ int CVodeSetJacEvalFrequency(void *cvode_mem, long int msbj) return(CVLS_SUCCESS); } -/* Deprecated */ -int CVodeSetMaxStepsBetweenJac(void *cvode_mem, long int msbj) -{ - return(CVodeSetJacEvalFrequency(cvode_mem, msbj)); -} - - /* CVodeSetLinearSolutionScaling enables or disables scaling the linear solver solution to account for changes in gamma. */ int CVodeSetLinearSolutionScaling(void *cvode_mem, booleantype onoff) @@ -422,8 +415,8 @@ int CVodeSetPreconditioner(void *cvode_mem, CVLsPrecSetupFn psetup, { CVodeMem cv_mem; CVLsMem cvls_mem; - PSetupFn cvls_psetup; - PSolveFn cvls_psolve; + SUNPSetupFn cvls_psetup; + SUNPSolveFn cvls_psolve; int retval; /* access CVLsMem structure */ diff --git a/src/sundials/cvode/cvode_ls_impl.h b/src/sundials/cvode/cvode_ls_impl.h index 8c47ec2..b5c8705 100644 --- a/src/sundials/cvode/cvode_ls_impl.h +++ b/src/sundials/cvode/cvode_ls_impl.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_nls.c b/src/sundials/cvode/cvode_nls.c index 59d816f..6f5ea04 100644 --- a/src/sundials/cvode/cvode_nls.c +++ b/src/sundials/cvode/cvode_nls.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_proj.c b/src/sundials/cvode/cvode_proj.c index 7d5e277..11ed32a 100644 --- a/src/sundials/cvode/cvode_proj.c +++ b/src/sundials/cvode/cvode_proj.c @@ -4,7 +4,7 @@ * Based on CPODES by Radu Serban @ LLNL * --------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvode/cvode_spils.c b/src/sundials/cvode/cvode_spils.c index d5feb07..216aeee 100644 --- a/src/sundials/cvode/cvode_spils.c +++ b/src/sundials/cvode/cvode_spils.c @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodea.c b/src/sundials/cvodes/cvodea.c index 7f97d69..30e03e7 100644 --- a/src/sundials/cvodes/cvodea.c +++ b/src/sundials/cvodes/cvodea.c @@ -3,7 +3,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -42,6 +42,12 @@ #define HUNDRED RCONST(100.0) /* real 100.0 */ #define FUZZ_FACTOR RCONST(1000000.0) /* fuzz factor for IMget */ +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define CV_PROFILER cv_mem->cv_sunctx->profiler + /* * ================================================================= * PRIVATE FUNCTION PROTOTYPES @@ -107,13 +113,17 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) } cv_mem = (CVodeMem)cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if (steps <= 0) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeAdjInit", MSGCV_BAD_STEPS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } if ( (interp != CV_HERMITE) && (interp != CV_POLYNOMIAL) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeAdjInit", MSGCV_BAD_INTERP); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -125,6 +135,7 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) ca_mem = (CVadjMem) malloc(sizeof(struct CVadjMemRec)); if (ca_mem == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeAdjInit", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -167,6 +178,7 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) if (ca_mem->dt_mem == NULL) { free(ca_mem); ca_mem = NULL; cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeAdjInit", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -178,6 +190,7 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) free(ca_mem->dt_mem); ca_mem->dt_mem = NULL; free(ca_mem); ca_mem = NULL; cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeAdjInit", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } } @@ -245,6 +258,7 @@ int CVodeAdjInit(void *cvode_mem, long int steps, int interp) cv_mem->cv_adj = SUNTRUE; cv_mem->cv_adjMallocDone = SUNTRUE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -275,9 +289,12 @@ int CVodeAdjReInit(void *cvode_mem) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeAdjReInit", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } @@ -299,6 +316,7 @@ int CVodeAdjReInit(void *cvode_mem) ca_mem->ca_tstopCVodeFcall = SUNFALSE; ca_mem->ca_firstCVodeBcall = SUNTRUE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -376,9 +394,12 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeF", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } @@ -387,18 +408,21 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, /* Check for yout != NULL */ if (yout == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeF", MSGCV_YOUT_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } /* Check for tret != NULL */ if (tret == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeF", MSGCV_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } /* Check for valid itask */ if ( (itask != CV_NORMAL) && (itask != CV_ONE_STEP) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeF", MSGCV_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -426,6 +450,7 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, ca_mem->ck_mem = CVAckpntInit(cv_mem); if (ca_mem->ck_mem == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeF", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -438,6 +463,7 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, allocOK = ca_mem->ca_IMmalloc(cv_mem); if (!allocOK) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeF", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -489,6 +515,7 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, ca_mem->ca_IMnewData = SUNTRUE; ca_mem->ca_ckpntData = ca_mem->ck_mem; ca_mem->ca_np = cv_mem->cv_nst % ca_mem->ca_nsteps + 1; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -590,6 +617,7 @@ int CVodeF(void *cvode_mem, realtype tout, N_Vector yout, ca_mem->ca_ckpntData = ca_mem->ck_mem; ca_mem->ca_np = cv_mem->cv_nst % ca_mem->ca_nsteps + 1; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -634,7 +662,7 @@ int CVodeCreateB(void *cvode_mem, int lmmB, int *which) /* Create and set a new CVODES object for the backward problem */ - cvodeB_mem = CVodeCreate(lmmB); + cvodeB_mem = CVodeCreate(lmmB, cv_mem->cv_sunctx); if (cvodeB_mem == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODEA", "CVodeCreateB", MSGCV_MEM_FAIL); return(CV_MEM_FAIL); @@ -705,10 +733,13 @@ int CVodeInitB(void *cvode_mem, int which, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeInitB", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -717,6 +748,7 @@ int CVodeInitB(void *cvode_mem, int which, if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeInitB", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -734,7 +766,10 @@ int CVodeInitB(void *cvode_mem, int which, flag = CVodeInit(cvodeB_mem, CVArhs, tB0, yB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(flag); + } /* Copy fB function in cvB_mem */ @@ -747,6 +782,7 @@ int CVodeInitB(void *cvode_mem, int which, cvB_mem->cv_y = N_VClone(yB0); N_VScale(ONE, yB0, cvB_mem->cv_y); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -768,10 +804,13 @@ int CVodeInitBS(void *cvode_mem, int which, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeInitBS", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -780,6 +819,7 @@ int CVodeInitBS(void *cvode_mem, int which, if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeInitBS", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -797,7 +837,10 @@ int CVodeInitBS(void *cvode_mem, int which, flag = CVodeInit(cvodeB_mem, CVArhs, tB0, yB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(flag); + } /* Copy fBs function in cvB_mem */ @@ -810,6 +853,7 @@ int CVodeInitBS(void *cvode_mem, int which, cvB_mem->cv_y = N_VClone(yB0); N_VScale(ONE, yB0, cvB_mem->cv_y); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -830,9 +874,12 @@ int CVodeReInitB(void *cvode_mem, int which, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeReInitB", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -840,6 +887,7 @@ int CVodeReInitB(void *cvode_mem, int which, /* Check the value of which */ if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeReInitB", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -856,6 +904,7 @@ int CVodeReInitB(void *cvode_mem, int which, flag = CVodeReInit(cvodeB_mem, tB0, yB0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -974,9 +1023,12 @@ int CVodeQuadInitB(void *cvode_mem, int which, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadInitB", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -984,6 +1036,7 @@ int CVodeQuadInitB(void *cvode_mem, int which, /* Check which */ if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadInitB", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -997,11 +1050,15 @@ int CVodeQuadInitB(void *cvode_mem, int which, cvodeB_mem = (void *) (cvB_mem->cv_mem); flag = CVodeQuadInit(cvodeB_mem, CVArhsQ, yQB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(flag); + } cvB_mem->cv_fQ_withSensi = SUNFALSE; cvB_mem->cv_fQ = fQB; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1021,9 +1078,12 @@ int CVodeQuadInitBS(void *cvode_mem, int which, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadInitBS", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -1031,6 +1091,7 @@ int CVodeQuadInitBS(void *cvode_mem, int which, /* Check which */ if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadInitBS", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1044,11 +1105,15 @@ int CVodeQuadInitBS(void *cvode_mem, int which, cvodeB_mem = (void *) (cvB_mem->cv_mem); flag = CVodeQuadInit(cvodeB_mem, CVArhsQ, yQB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(flag); + } cvB_mem->cv_fQ_withSensi = SUNTRUE; cvB_mem->cv_fQs = fQBs; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1067,9 +1132,12 @@ int CVodeQuadReInitB(void *cvode_mem, int which, N_Vector yQB0) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadReInitB", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -1077,6 +1145,7 @@ int CVodeQuadReInitB(void *cvode_mem, int which, N_Vector yQB0) /* Check the value of which */ if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadReInitB", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1090,8 +1159,12 @@ int CVodeQuadReInitB(void *cvode_mem, int which, N_Vector yQB0) cvodeB_mem = (void *) (cvB_mem->cv_mem); flag = CVodeQuadReInit(cvodeB_mem, yQB0); - if (flag != CV_SUCCESS) return(flag); + if (flag != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(flag); + } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1110,9 +1183,12 @@ int CVodeQuadSStolerancesB(void *cvode_mem, int which, realtype reltolQB, realty } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -1120,6 +1196,7 @@ int CVodeQuadSStolerancesB(void *cvode_mem, int which, realtype reltolQB, realty /* Check which */ if ( which >= ca_mem->ca_nbckpbs ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeQuadSStolerancesB", MSGCV_BAD_WHICH); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1134,6 +1211,7 @@ int CVodeQuadSStolerancesB(void *cvode_mem, int which, realtype reltolQB, realty flag = CVodeQuadSStolerances(cvodeB_mem, reltolQB, abstolQB); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -1216,10 +1294,13 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Was ASA initialized? */ if (cv_mem->cv_adjMallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_ADJ, "CVODEA", "CVodeB", MSGCV_NO_ADJ); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_ADJ); } ca_mem = cv_mem->cv_adj_mem; @@ -1228,6 +1309,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) if ( ca_mem->ca_nbckpbs == 0 ) { cvProcessError(cv_mem, CV_NO_BCK, "CVODEA", "CVodeB", MSGCV_NO_BCK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_BCK); } cvB_mem = ca_mem->cvB_mem; @@ -1236,6 +1318,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) if ( ca_mem->ca_firstCVodeFcall ) { cvProcessError(cv_mem, CV_NO_FWD, "CVODEA", "CVodeB", MSGCV_NO_FWD); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_FWD); } sign = (ca_mem->ca_tfinal - ca_mem->ca_tinitial > ZERO) ? 1 : -1; @@ -1257,12 +1340,14 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) if ( (sign*(tBn-ca_mem->ca_tinitial) < ZERO) || (sign*(ca_mem->ca_tfinal-tBn) < ZERO) ) { cvProcessError(cv_mem, CV_BAD_TB0, "CVODEA", "CVodeB", MSGCV_BAD_TB0, tmp_cvB_mem->cv_index); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_TB0); } if (sign*(tBn-tBout) <= ZERO) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_TBOUT, tmp_cvB_mem->cv_index); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1275,6 +1360,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) if ( ca_mem->ca_IMinterpSensi && !ca_mem->ca_IMstoreSensi) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_SENSI); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1285,6 +1371,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) if ( (itaskB != CV_NORMAL) && (itaskB != CV_ONE_STEP) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_ITASKB); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1296,6 +1383,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) tBout = ca_mem->ca_tinitial; } else { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODEA", "CVodeB", MSGCV_BAD_TBOUT); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } } @@ -1395,6 +1483,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) if (flag <0) { cvProcessError(cv_mem, flag, "CVODEA", "CVodeB", MSGCV_BACK_ERROR, tmp_cvB_mem->cv_index); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -1423,6 +1512,7 @@ int CVodeB(void *cvode_mem, realtype tBout, int itaskB) } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } diff --git a/src/sundials/cvodes/cvodea_io.c b/src/sundials/cvodes/cvodea_io.c index 69b3642..ebd6142 100644 --- a/src/sundials/cvodes/cvodea_io.c +++ b/src/sundials/cvodes/cvodea_io.c @@ -6,7 +6,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes.c b/src/sundials/cvodes/cvodes.c index a0d8a16..d4c64e2 100644 --- a/src/sundials/cvodes/cvodes.c +++ b/src/sundials/cvodes/cvodes.c @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -407,6 +407,11 @@ #define DGMAX RCONST(0.3) +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define CV_PROFILER cv_mem->cv_sunctx->profiler /*=================================================================*/ /* Private Helper Functions Prototypes */ @@ -571,7 +576,7 @@ static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, realtype t, * message to standard err and returns NULL. */ -void *CVodeCreate(int lmm) +void *CVodeCreate(int lmm, SUNContext sunctx) { int maxord; CVodeMem cv_mem; @@ -583,6 +588,11 @@ void *CVodeCreate(int lmm) return(NULL); } + if (sunctx == NULL) { + cvProcessError(NULL, 0, "CVODES", "CVodeCreate", MSGCV_NULL_SUNCTX); + return(NULL); + } + cv_mem = NULL; cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec)); if (cv_mem == NULL) { @@ -596,37 +606,40 @@ void *CVodeCreate(int lmm) maxord = (lmm == CV_ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; /* copy input parameters into cv_mem */ + cv_mem->cv_sunctx = sunctx; cv_mem->cv_lmm = lmm; /* Set uround */ cv_mem->cv_uround = UNIT_ROUNDOFF; /* Set default values for integrator optional inputs */ - cv_mem->cv_f = NULL; - cv_mem->cv_user_data = NULL; - cv_mem->cv_itol = CV_NN; - cv_mem->cv_atolmin0 = SUNTRUE; - cv_mem->cv_user_efun = SUNFALSE; - cv_mem->cv_efun = NULL; - cv_mem->cv_e_data = NULL; - cv_mem->cv_ehfun = cvErrHandler; - cv_mem->cv_eh_data = cv_mem; - cv_mem->cv_errfp = stderr; - cv_mem->cv_qmax = maxord; - cv_mem->cv_mxstep = MXSTEP_DEFAULT; - cv_mem->cv_mxhnil = MXHNIL_DEFAULT; - cv_mem->cv_sldeton = SUNFALSE; - cv_mem->cv_hin = ZERO; - cv_mem->cv_hmin = HMIN_DEFAULT; - cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT; - cv_mem->cv_tstopset = SUNFALSE; - cv_mem->cv_maxnef = MXNEF; - cv_mem->cv_maxncf = MXNCF; - cv_mem->cv_nlscoef = CORTES; - cv_mem->cv_msbp = MSBP; - cv_mem->convfail = CV_NO_FAILURES; - cv_mem->cv_constraints = NULL; - cv_mem->cv_constraintsSet = SUNFALSE; + cv_mem->cv_f = NULL; + cv_mem->cv_user_data = NULL; + cv_mem->cv_itol = CV_NN; + cv_mem->cv_atolmin0 = SUNTRUE; + cv_mem->cv_user_efun = SUNFALSE; + cv_mem->cv_efun = NULL; + cv_mem->cv_e_data = NULL; + cv_mem->cv_ehfun = cvErrHandler; + cv_mem->cv_eh_data = cv_mem; + cv_mem->cv_monitorfun = NULL; + cv_mem->cv_monitor_interval = 0; + cv_mem->cv_errfp = stderr; + cv_mem->cv_qmax = maxord; + cv_mem->cv_mxstep = MXSTEP_DEFAULT; + cv_mem->cv_mxhnil = MXHNIL_DEFAULT; + cv_mem->cv_sldeton = SUNFALSE; + cv_mem->cv_hin = ZERO; + cv_mem->cv_hmin = HMIN_DEFAULT; + cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT; + cv_mem->cv_tstopset = SUNFALSE; + cv_mem->cv_maxnef = MXNEF; + cv_mem->cv_maxncf = MXNCF; + cv_mem->cv_nlscoef = CORTES; + cv_mem->cv_msbp = MSBP; + cv_mem->convfail = CV_NO_FAILURES; + cv_mem->cv_constraints = NULL; + cv_mem->cv_constraintsSet = SUNFALSE; /* Initialize root finding variables */ @@ -769,15 +782,19 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Check for legal input parameters */ if (y0==NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeInit", MSGCV_NULL_Y0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } if (f == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeInit", MSGCV_NULL_F); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -787,6 +804,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) if(!nvectorOK) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeInit", MSGCV_BAD_NVECTOR); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -806,6 +824,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) allocOK = cvAllocVectors(cv_mem, y0); if (!allocOK) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeInit", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -825,6 +844,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) cvFreeVectors(cv_mem); cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeInit", MSGCV_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -838,12 +858,13 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) N_VScale(ONE, y0, cv_mem->cv_zn[0]); /* create a Newton nonlinear solver object by default */ - NLS = SUNNonlinSol_Newton(y0); + NLS = SUNNonlinSol_Newton(y0, cv_mem->cv_sunctx); /* check that nonlinear solver is non-NULL */ if (NLS == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeInit", MSGCV_MEM_FAIL); cvFreeVectors(cv_mem); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -856,6 +877,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) "Setting the nonlinear solver failed"); cvFreeVectors(cv_mem); SUNNonlinSolFree(NLS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_MEM_FAIL); } @@ -923,6 +945,7 @@ int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0) cv_mem->cv_MallocDone = SUNTRUE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -953,11 +976,14 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Check if cvode_mem was allocated */ if (cv_mem->cv_MallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVodeReInit", MSGCV_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_MALLOC); } @@ -966,6 +992,7 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) if (y0 == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeReInit", MSGCV_NULL_Y0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -1022,6 +1049,7 @@ int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0) /* Problem has been successfully re-initialized */ + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -1569,9 +1597,9 @@ int CVodeSensInit(void *cvode_mem, int Ns, int ism, CVSensRhsFn fS, N_Vector *yS /* create a Newton nonlinear solver object by default */ if (ism == CV_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(Ns+1, cv_mem->cv_acor); + NLS = SUNNonlinSol_NewtonSens(Ns+1, cv_mem->cv_acor, cv_mem->cv_sunctx); else - NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor); + NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor, cv_mem->cv_sunctx); /* check that the nonlinear solver is non-NULL */ if (NLS == NULL) { @@ -1786,11 +1814,11 @@ int CVodeSensInit1(void *cvode_mem, int Ns, int ism, CVSensRhs1Fn fS1, N_Vector /* create a Newton nonlinear solver object by default */ if (ism == CV_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(Ns+1, cv_mem->cv_acor); + NLS = SUNNonlinSol_NewtonSens(Ns+1, cv_mem->cv_acor, cv_mem->cv_sunctx); else if (ism == CV_STAGGERED) - NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor); + NLS = SUNNonlinSol_NewtonSens(Ns, cv_mem->cv_acor, cv_mem->cv_sunctx); else - NLS = SUNNonlinSol_Newton(cv_mem->cv_acor); + NLS = SUNNonlinSol_Newton(cv_mem->cv_acor, cv_mem->cv_sunctx); /* check that the nonlinear solver is non-NULL */ if (NLS == NULL) { @@ -1951,11 +1979,13 @@ int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0) /* create a Newton nonlinear solver object by default */ if (ism == CV_SIMULTANEOUS) - NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns+1, cv_mem->cv_acor); + NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns+1, cv_mem->cv_acor, + cv_mem->cv_sunctx); else if (ism == CV_STAGGERED) - NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns, cv_mem->cv_acor); + NLS = SUNNonlinSol_NewtonSens(cv_mem->cv_Ns, cv_mem->cv_acor, + cv_mem->cv_sunctx); else - NLS = SUNNonlinSol_Newton(cv_mem->cv_acor); + NLS = SUNNonlinSol_Newton(cv_mem->cv_acor, cv_mem->cv_sunctx); /* check that the nonlinear solver is non-NULL */ if (NLS == NULL) { @@ -2790,27 +2820,33 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + /* Check if cvode_mem was allocated */ if (cv_mem->cv_MallocDone == SUNFALSE) { cvProcessError(cv_mem, CV_NO_MALLOC, "CVODES", "CVode", MSGCV_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_MALLOC); } /* Check for yout != NULL */ if ((cv_mem->cv_y = yout) == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_YOUT_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } /* Check for tret != NULL */ if (tret == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } /* Check for valid itask */ if ( (itask != CV_NORMAL) && (itask != CV_ONE_STEP) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } @@ -2836,7 +2872,10 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, /* Check inputs for corectness */ ier = cvInitialSetup(cv_mem); - if (ier!= CV_SUCCESS) return(ier); + if (ier != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(ier); + } /* * Call f at (t0,y0), set zn[1] = y'(t0). @@ -2851,11 +2890,13 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval < 0) { cvProcessError(cv_mem, CV_RHSFUNC_FAIL, "CVODES", "CVode", MSGCV_RHSFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RHSFUNC_FAIL); } if (retval > 0) { cvProcessError(cv_mem, CV_FIRST_RHSFUNC_ERR, "CVODES", "CVode", MSGCV_RHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_FIRST_RHSFUNC_ERR); } @@ -2866,11 +2907,13 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval < 0) { cvProcessError(cv_mem, CV_QRHSFUNC_FAIL, "CVODES", "CVode", MSGCV_QRHSFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_QRHSFUNC_FAIL); } if (retval > 0) { cvProcessError(cv_mem, CV_FIRST_QRHSFUNC_ERR, "CVODES", "CVode", MSGCV_QRHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_FIRST_QRHSFUNC_ERR); } } @@ -2883,11 +2926,13 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval < 0) { cvProcessError(cv_mem, CV_SRHSFUNC_FAIL, "CVODES", "CVode", MSGCV_SRHSFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SRHSFUNC_FAIL); } if (retval > 0) { cvProcessError(cv_mem, CV_FIRST_SRHSFUNC_ERR, "CVODES", "CVode", MSGCV_SRHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_FIRST_SRHSFUNC_ERR); } } @@ -2901,11 +2946,13 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval < 0) { cvProcessError(cv_mem, CV_QSRHSFUNC_FAIL, "CVODES", "CVode", MSGCV_QSRHSFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_QSRHSFUNC_FAIL); } if (retval > 0) { cvProcessError(cv_mem, CV_FIRST_QSRHSFUNC_ERR, "CVODES", "CVode", MSGCV_QSRHSFUNC_FIRST); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_FIRST_QSRHSFUNC_ERR); } } @@ -2916,6 +2963,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if ( (cv_mem->cv_tstop - cv_mem->cv_tn)*(tout - cv_mem->cv_tn) <= ZERO ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } } @@ -2925,6 +2973,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, cv_mem->cv_h = cv_mem->cv_hin; if ( (cv_mem->cv_h != ZERO) && ((tout-cv_mem->cv_tn)*cv_mem->cv_h < ZERO) ) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_H0); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } if (cv_mem->cv_h == ZERO) { @@ -2935,6 +2984,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, hflag = cvHin(cv_mem, tout_hin); if (hflag != CV_SUCCESS) { istate = cvHandleFailure(cv_mem, hflag); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(istate); } } @@ -2972,7 +3022,10 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znS[1], cv_mem->cv_znS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } } if (cv_mem->cv_quadr_sensi) { @@ -2981,7 +3034,10 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, retval = N_VScaleVectorArray(cv_mem->cv_Ns, cv_mem->cv_cvals, cv_mem->cv_znQS[1], cv_mem->cv_znQS[1]); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } } /* Check for zeros of root function g at and near t0. */ @@ -2993,6 +3049,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval == CV_RTFUNC_FAIL) { cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck1", MSGCV_RTFUNC_FAILED, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RTFUNC_FAIL); } @@ -3032,13 +3089,16 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (retval == CLOSERT) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "cvRcheck2", MSGCV_CLOSE_ROOTS, cv_mem->cv_tlo); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } else if (retval == CV_RTFUNC_FAIL) { cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck2", MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RTFUNC_FAIL); } else if (retval == RTFOUND) { cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ROOT_RETURN); } @@ -3053,15 +3113,18 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if ((irfndp == 1) && (itask == CV_ONE_STEP)) { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } } else if (retval == RTFOUND) { /* a new root was found */ cv_mem->cv_irfnd = 1; cv_mem->cv_tretlast = *tret = cv_mem->cv_tlo; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ROOT_RETURN); } else if (retval == CV_RTFUNC_FAIL) { /* g failed */ cvProcessError(cv_mem, CV_RTFUNC_FAIL, "CVODES", "cvRcheck3", MSGCV_RTFUNC_FAILED, cv_mem->cv_tlo); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_RTFUNC_FAIL); } @@ -3076,8 +3139,10 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (ier != CV_SUCCESS) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_TOUT, tout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -3086,6 +3151,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, SUNRabs(cv_mem->cv_tn - cv_mem->cv_tretlast) > troundoff ) { cv_mem->cv_tretlast = *tret = cv_mem->cv_tn; N_VScale(ONE, cv_mem->cv_zn[0], yout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -3097,10 +3163,12 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, if (ier != CV_SUCCESS) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVode", MSGCV_BAD_TSTOP, cv_mem->cv_tstop, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_ILL_INPUT); } cv_mem->cv_tretlast = *tret = cv_mem->cv_tstop; cv_mem->cv_tstopset = SUNFALSE; + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_TSTOP_RETURN); } @@ -3347,6 +3415,7 @@ int CVode(void *cvode_mem, realtype tout, N_Vector yout, } } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(istate); } @@ -3367,8 +3436,11 @@ int CVodeComputeState(void *cvode_mem, N_Vector ycor, N_Vector y) cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + N_VLinearSum(ONE, cv_mem->cv_zn[0], ONE, ycor, y); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -3390,11 +3462,17 @@ int CVodeComputeStateSens(void *cvode_mem, N_Vector *ycorS, N_Vector *yS) cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + retval = N_VLinearSumVectorArray(cv_mem->cv_Ns, ONE, cv_mem->cv_znS[0], ONE, ycorS, yS); - if (retval != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (retval != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -3416,8 +3494,11 @@ int CVodeComputeStateSens1(void *cvode_mem, int idx, N_Vector ycorS1, cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + N_VLinearSum(ONE, cv_mem->cv_znS[0][idx], ONE, ycorS1, yS1); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -3459,13 +3540,17 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if (dky == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetDky", MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } if ((k < 0) || (k > cv_mem->cv_q)) { cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetDky", MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_K); } @@ -3478,6 +3563,7 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) if ((t-tp)*(t-tn1) > ZERO) { cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetDky", MSGCV_BAD_T, t, cv_mem->cv_tn-cv_mem->cv_hu, cv_mem->cv_tn); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_T); } @@ -3495,11 +3581,19 @@ int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky) nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dky); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dky, dky); + + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_SUCCESS); } @@ -3522,10 +3616,13 @@ int CVodeGetQuad(void *cvode_mem, realtype *tret, N_Vector yQout) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + *tret = cv_mem->cv_tretlast; flag = CVodeGetQuadDky(cvode_mem,cv_mem->cv_tretlast,0,yQout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -3558,18 +3655,23 @@ int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, N_Vector dkyQ) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if(cv_mem->cv_quadr != SUNTRUE) { cvProcessError(cv_mem, CV_NO_QUAD, "CVODES", "CVodeGetQuadDky", MSGCV_NO_QUAD); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_QUAD); } if (dkyQ == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetQuadDky", MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } if ((k < 0) || (k > cv_mem->cv_q)) { cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetQuadDky", MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_K); } @@ -3581,6 +3683,7 @@ int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, N_Vector dkyQ) tn1 = cv_mem->cv_tn + tfuzz; if ((t-tp)*(t-tn1) > ZERO) { cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetQuadDky", MSGCV_BAD_T); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_T); } @@ -3598,13 +3701,20 @@ int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, N_Vector dkyQ) nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dkyQ); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dkyQ, dkyQ); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); } /* @@ -3626,10 +3736,13 @@ int CVodeGetSens(void *cvode_mem, realtype *tret, N_Vector *ySout) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + *tret = cv_mem->cv_tretlast; flag = CVodeGetSensDky(cvode_mem,cv_mem->cv_tretlast,0,ySout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -3652,10 +3765,13 @@ int CVodeGetSens1(void *cvode_mem, realtype *tret, int is, N_Vector ySout) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + *tret = cv_mem->cv_tretlast; flag = CVodeGetSensDky1(cvode_mem,cv_mem->cv_tretlast,0,is,ySout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -3680,9 +3796,12 @@ int CVodeGetSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyS) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if (dkyS == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetSensDky", MSGCV_NULL_DKYA); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } @@ -3691,6 +3810,7 @@ int CVodeGetSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyS) if (ier!=CV_SUCCESS) break; } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(ier); } @@ -3724,27 +3844,33 @@ int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dkyS) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if(cv_mem->cv_sensi != SUNTRUE) { cvProcessError(cv_mem, CV_NO_SENS, "CVODES", "CVodeGetSensDky1", MSGCV_NO_SENSI); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_SENS); } if (dkyS == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetSensDky1", MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } if ((k < 0) || (k > cv_mem->cv_q)) { cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetSensDky1", MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_K); } if ((is < 0) || (is > cv_mem->cv_Ns-1)) { cvProcessError(cv_mem, CV_BAD_IS, "CVODES", "CVodeGetSensDky1", MSGCV_BAD_IS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_IS); } @@ -3757,6 +3883,7 @@ int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dkyS) if ((t-tp)*(t-tn1) > ZERO) { cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetSensDky1", MSGCV_BAD_T); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_T); } @@ -3774,13 +3901,20 @@ int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dkyS) nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dkyS); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dkyS, dkyS); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); } /* @@ -3802,10 +3936,13 @@ int CVodeGetQuadSens(void *cvode_mem, realtype *tret, N_Vector *yQSout) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + *tret = cv_mem->cv_tretlast; flag = CVodeGetQuadSensDky(cvode_mem,cv_mem->cv_tretlast,0,yQSout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -3821,10 +3958,13 @@ int CVodeGetQuadSens1(void *cvode_mem, realtype *tret, int is, N_Vector yQSout) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + *tret = cv_mem->cv_tretlast; flag = CVodeGetQuadSensDky1(cvode_mem,cv_mem->cv_tretlast,0,is,yQSout); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(flag); } @@ -3848,9 +3988,12 @@ int CVodeGetQuadSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyQS_all) } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if (dkyQS_all == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetSensDky", MSGCV_NULL_DKYA); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } @@ -3859,6 +4002,7 @@ int CVodeGetQuadSensDky(void *cvode_mem, realtype t, int k, N_Vector *dkyQS_all) if (ier!=CV_SUCCESS) break; } + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(ier); } @@ -3878,27 +4022,33 @@ int CVodeGetQuadSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dk } cv_mem = (CVodeMem) cvode_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(CV_PROFILER); + if(cv_mem->cv_quadr_sensi != SUNTRUE) { cvProcessError(cv_mem, CV_NO_QUADSENS, "CVODES", "CVodeGetQuadSensDky1", MSGCV_NO_QUADSENSI); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_NO_QUADSENS); } if (dkyQS == NULL) { cvProcessError(cv_mem, CV_BAD_DKY, "CVODES", "CVodeGetQuadSensDky1", MSGCV_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_DKY); } if ((k < 0) || (k > cv_mem->cv_q)) { cvProcessError(cv_mem, CV_BAD_K, "CVODES", "CVodeGetQuadSensDky1", MSGCV_BAD_K); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_K); } if ((is < 0) || (is > cv_mem->cv_Ns-1)) { cvProcessError(cv_mem, CV_BAD_IS, "CVODES", "CVodeGetQuadSensDky1", MSGCV_BAD_IS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_IS); } @@ -3911,6 +4061,7 @@ int CVodeGetQuadSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dk if ((t-tp)*(t-tn1) > ZERO) { cvProcessError(cv_mem, CV_BAD_T, "CVODES", "CVodeGetQuadSensDky1", MSGCV_BAD_T); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); return(CV_BAD_T); } @@ -3928,13 +4079,20 @@ int CVodeGetQuadSensDky1(void *cvode_mem, realtype t, int k, int is, N_Vector dk nvec += 1; } ier = N_VLinearCombination(nvec, cv_mem->cv_cvals, cv_mem->cv_Xvecs, dkyQS); - if (ier != CV_SUCCESS) return (CV_VECTOROP_ERR); + if (ier != CV_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_VECTOROP_ERR); + } - if (k == 0) return(CV_SUCCESS); + if (k == 0) { + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); + } r = SUNRpowerI(cv_mem->cv_h, -k); N_VScale(r, dkyQS, dkyQS); - return(CV_SUCCESS); + SUNDIALS_MARK_FUNCTION_END(CV_PROFILER); + return(CV_SUCCESS); } /* @@ -6908,6 +7066,14 @@ static void cvCompleteStep(CVodeMem cv_mem) cv_mem->cv_saved_tq5 = cv_mem->cv_tq[5]; cv_mem->cv_indx_acor = cv_mem->cv_qmax; } + +#ifdef SUNDIALS_BUILD_WITH_MONITORING + /* If user access function was provided, call it now */ + if (cv_mem->cv_monitorfun != NULL && + !(cv_mem->cv_nst % cv_mem->cv_monitor_interval)) { + cv_mem->cv_monitorfun((void*) cv_mem, cv_mem->cv_user_data); + } +#endif } /* diff --git a/src/sundials/cvodes/cvodes_bandpre.c b/src/sundials/cvodes/cvodes_bandpre.c index d8e6a28..d60a357 100644 --- a/src/sundials/cvodes/cvodes_bandpre.c +++ b/src/sundials/cvodes/cvodes_bandpre.c @@ -4,7 +4,7 @@ * Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -112,7 +112,7 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, /* Allocate memory for saved banded Jacobian approximation. */ pdata->savedJ = NULL; - pdata->savedJ = SUNBandMatrixStorage(N, mup, mlp, mup); + pdata->savedJ = SUNBandMatrixStorage(N, mup, mlp, mup, cv_mem->cv_sunctx); if (pdata->savedJ == NULL) { free(pdata); pdata = NULL; cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", @@ -123,7 +123,7 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, /* Allocate memory for banded preconditioner. */ storagemu = SUNMIN(N-1, mup+mlp); pdata->savedP = NULL; - pdata->savedP = SUNBandMatrixStorage(N, mup, mlp, storagemu); + pdata->savedP = SUNBandMatrixStorage(N, mup, mlp, storagemu, cv_mem->cv_sunctx); if (pdata->savedP == NULL) { SUNMatDestroy(pdata->savedJ); free(pdata); pdata = NULL; @@ -134,7 +134,7 @@ int CVBandPrecInit(void *cvode_mem, sunindextype N, /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(cv_mem->cv_tempv, pdata->savedP); + pdata->LS = SUNLinSol_Band(cv_mem->cv_tempv, pdata->savedP, cv_mem->cv_sunctx); if (pdata->LS == NULL) { SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); diff --git a/src/sundials/cvodes/cvodes_bandpre_impl.h b/src/sundials/cvodes/cvodes_bandpre_impl.h index c7cd866..6afa1ab 100644 --- a/src/sundials/cvodes/cvodes_bandpre_impl.h +++ b/src/sundials/cvodes/cvodes_bandpre_impl.h @@ -4,7 +4,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_bbdpre.c b/src/sundials/cvodes/cvodes_bbdpre.c index 710c5c4..b2af393 100644 --- a/src/sundials/cvodes/cvodes_bbdpre.c +++ b/src/sundials/cvodes/cvodes_bbdpre.c @@ -4,7 +4,7 @@ * Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -124,7 +124,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, pdata->mlkeep = mlk; /* Allocate memory for saved Jacobian */ - pdata->savedJ = SUNBandMatrixStorage(Nlocal, muk, mlk, muk); + pdata->savedJ = SUNBandMatrixStorage(Nlocal, muk, mlk, muk, cv_mem->cv_sunctx); if (pdata->savedJ == NULL) { free(pdata); pdata = NULL; cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBBDPRE", @@ -135,7 +135,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Allocate memory for preconditioner matrix */ storage_mu = SUNMIN(Nlocal-1, muk + mlk); pdata->savedP = NULL; - pdata->savedP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu); + pdata->savedP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu, cv_mem->cv_sunctx); if (pdata->savedP == NULL) { SUNMatDestroy(pdata->savedJ); free(pdata); pdata = NULL; @@ -146,7 +146,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Allocate memory for temporary N_Vectors */ pdata->zlocal = NULL; - pdata->zlocal = N_VNewEmpty_Serial(Nlocal); + pdata->zlocal = N_VNewEmpty_Serial(Nlocal, cv_mem->cv_sunctx); if (pdata->zlocal == NULL) { SUNMatDestroy(pdata->savedP); SUNMatDestroy(pdata->savedJ); @@ -156,7 +156,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, return(CVLS_MEM_FAIL); } pdata->rlocal = NULL; - pdata->rlocal = N_VNewEmpty_Serial(Nlocal); + pdata->rlocal = N_VNewEmpty_Serial(Nlocal, cv_mem->cv_sunctx); if (pdata->rlocal == NULL) { N_VDestroy(pdata->zlocal); SUNMatDestroy(pdata->savedP); @@ -208,7 +208,7 @@ int CVBBDPrecInit(void *cvode_mem, sunindextype Nlocal, /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->savedP); + pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->savedP, cv_mem->cv_sunctx); if (pdata->LS == NULL) { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); diff --git a/src/sundials/cvodes/cvodes_bbdpre_impl.h b/src/sundials/cvodes/cvodes_bbdpre_impl.h index 924b175..c5efeaa 100644 --- a/src/sundials/cvodes/cvodes_bbdpre_impl.h +++ b/src/sundials/cvodes/cvodes_bbdpre_impl.h @@ -4,7 +4,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_diag.c b/src/sundials/cvodes/cvodes_diag.c index 49ee7e9..d8529f8 100644 --- a/src/sundials/cvodes/cvodes_diag.c +++ b/src/sundials/cvodes/cvodes_diag.c @@ -3,7 +3,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_diag_impl.h b/src/sundials/cvodes/cvodes_diag_impl.h index beb90d4..2dcb117 100644 --- a/src/sundials/cvodes/cvodes_diag_impl.h +++ b/src/sundials/cvodes/cvodes_diag_impl.h @@ -3,7 +3,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_direct.c b/src/sundials/cvodes/cvodes_direct.c index bc18925..d21192d 100644 --- a/src/sundials/cvodes/cvodes_direct.c +++ b/src/sundials/cvodes/cvodes_direct.c @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_impl.h b/src/sundials/cvodes/cvodes_impl.h index aa24dd6..241277f 100644 --- a/src/sundials/cvodes/cvodes_impl.h +++ b/src/sundials/cvodes/cvodes_impl.h @@ -2,7 +2,7 @@ * Programmer(s): Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,6 +20,7 @@ #include #include "cvodes/cvodes.h" +#include "sundials_context_impl.h" #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { @@ -91,6 +92,8 @@ typedef struct CVodeBMemRec *CVodeBMem; typedef struct CVodeMemRec { + SUNContext cv_sunctx; + realtype cv_uround; /* machine unit roundoff */ /*-------------------------- @@ -473,6 +476,12 @@ typedef struct CVodeMemRec { void *cv_eh_data; /* data pointer passed to ehfun */ FILE *cv_errfp; /* CVODE error messages are sent to errfp */ + /*------------------------------------------- + User access function + -------------------------------------------*/ + CVMonitorFn cv_monitorfun; /* func called with CVODE mem and user data */ + long int cv_monitor_interval; /* step interval to call cv_monitorfun */ + /*------------------------- Stability Limit Detection -------------------------*/ @@ -1049,6 +1058,7 @@ int cvSensRhs1InternalDQ(int Ns, realtype t, #define MSGCV_CVMEM_FAIL "Allocation of cvode_mem failed." #define MSGCV_MEM_FAIL "A memory request failed." #define MSGCV_BAD_LMM "Illegal value for lmm. The legal values are CV_ADAMS and CV_BDF." +#define MSGCV_NULL_SUNCTX "sunctx = NULL illegal." #define MSGCV_NO_MALLOC "Attempt to call before CVodeInit." #define MSGCV_NEG_MAXORD "maxord <= 0 illegal." #define MSGCV_BAD_MAXORD "Illegal attempt to increase maximum method order." diff --git a/src/sundials/cvodes/cvodes_io.c b/src/sundials/cvodes/cvodes_io.c index 602a413..e53df77 100644 --- a/src/sundials/cvodes/cvodes_io.c +++ b/src/sundials/cvodes/cvodes_io.c @@ -2,7 +2,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -78,6 +78,64 @@ int CVodeSetErrFile(void *cvode_mem, FILE *errfp) return(CV_SUCCESS); } +/* + * CVodeSetMonitorFn + * + * Specifies the user function to call for monitoring + * the solution and/or integrator statistics. + */ + +int CVodeSetMonitorFn(void *cvode_mem, CVMonitorFn fn) +{ + CVodeMem cv_mem; + + if (cvode_mem==NULL) { + cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMonitorFn", MSGCV_NO_MEM); + return(CV_MEM_NULL); + } + + cv_mem = (CVodeMem) cvode_mem; + +#ifdef SUNDIALS_BUILD_WITH_MONITORING + cv_mem->cv_monitorfun = fn; + return(CV_SUCCESS); +#else + cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMonitorFn", "SUNDIALS was not built with monitoring enabled."); + return(CV_ILL_INPUT); +#endif +} + +/* + * CVodeSetMonitorFrequency + * + * Specifies the frequency with which to call the user function. + */ + +int CVodeSetMonitorFrequency(void *cvode_mem, long int nst) +{ + CVodeMem cv_mem; + + if (cvode_mem==NULL) { + cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVodeSetMonitorFrequency", MSGCV_NO_MEM); + return(CV_MEM_NULL); + } + + if (nst < 0) { + cvProcessError(NULL, CV_ILL_INPUT, "CVODES", "CVodeSetMonitorFrequency", "step interval must be >= 0\n"); + return(CV_ILL_INPUT); + } + + cv_mem = (CVodeMem) cvode_mem; + +#ifdef SUNDIALS_BUILD_WITH_MONITORING + cv_mem->cv_monitor_interval = nst; + return(CV_SUCCESS); +#else + cvProcessError(cv_mem, CV_ILL_INPUT, "CVODES", "CVodeSetMonitorFrequency", "SUNDIALS was not built with monitoring enabled."); + return(CV_ILL_INPUT); +#endif +} + /* * CVodeSetUserData * diff --git a/src/sundials/cvodes/cvodes_ls.c b/src/sundials/cvodes/cvodes_ls.c index ef368e1..ce285dd 100644 --- a/src/sundials/cvodes/cvodes_ls.c +++ b/src/sundials/cvodes/cvodes_ls.c @@ -3,7 +3,7 @@ * Radu Serban @ LLNL * ---------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -465,13 +465,6 @@ int CVodeSetJacEvalFrequency(void *cvode_mem, long int msbj) return(CVLS_SUCCESS); } -/* Deprecated */ -int CVodeSetMaxStepsBetweenJac(void *cvode_mem, long int msbj) -{ - return(CVodeSetJacEvalFrequency(cvode_mem, msbj)); -} - - /* CVodeSetLinearSolutionScaling enables or disables scaling the linear solver solution to account for changes in gamma. */ int CVodeSetLinearSolutionScaling(void *cvode_mem, booleantype onoff) @@ -503,8 +496,8 @@ int CVodeSetPreconditioner(void *cvode_mem, CVLsPrecSetupFn psetup, { CVodeMem cv_mem; CVLsMem cvls_mem; - PSetupFn cvls_psetup; - PSolveFn cvls_psolve; + SUNPSetupFn cvls_psetup; + SUNPSolveFn cvls_psolve; int retval; /* access CVLsMem structure */ @@ -832,6 +825,33 @@ int CVodeGetNumJtimesEvals(void *cvode_mem, long int *njvevals) } +/* CVodeGetLinSolveStats returns statistics related to the linear solve. */ +int CVodeGetLinSolveStats(void* cvode_mem, long int* njevals, long int* nfevalsLS, + long int* nliters, long int* nlcfails, long int* npevals, + long int* npsolves, long int* njtsetups, long int* njtimes) +{ + CVodeMem cv_mem; + CVLsMem cvls_mem; + int retval; + + /* access CVLsMem structure; set output value and return */ + retval = cvLs_AccessLMem(cvode_mem, "CVodeGetLinSolveStats", + &cv_mem, &cvls_mem); + if (retval != CVLS_SUCCESS) return(retval); + + *njevals = cvls_mem->nje; + *nfevalsLS = cvls_mem->nfeDQ; + *nliters = cvls_mem->nli; + *nlcfails = cvls_mem->ncfl; + *npevals = cvls_mem->npe; + *npsolves = cvls_mem->nps; + *njtsetups = cvls_mem->njtsetup; + *njtimes = cvls_mem->njtimes; + + return(CVLS_SUCCESS); +} + + /* CVodeGetLastLinFlag returns the last flag set in a CVLS function */ int CVodeGetLastLinFlag(void *cvode_mem, long int *flag) { diff --git a/src/sundials/cvodes/cvodes_ls_impl.h b/src/sundials/cvodes/cvodes_ls_impl.h index 0f3e74f..553c918 100644 --- a/src/sundials/cvodes/cvodes_ls_impl.h +++ b/src/sundials/cvodes/cvodes_ls_impl.h @@ -3,7 +3,7 @@ * Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_nls.c b/src/sundials/cvodes/cvodes_nls.c index 0d1ccca..a903a78 100644 --- a/src/sundials/cvodes/cvodes_nls.c +++ b/src/sundials/cvodes/cvodes_nls.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_nls_sim.c b/src/sundials/cvodes/cvodes_nls_sim.c index 706124b..e570fd4 100644 --- a/src/sundials/cvodes/cvodes_nls_sim.c +++ b/src/sundials/cvodes/cvodes_nls_sim.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -146,14 +146,14 @@ int CVodeSetNonlinearSolverSensSim(void *cvode_mem, SUNNonlinearSolver NLS) /* create vector wrappers if necessary */ if (cv_mem->simMallocDone == SUNFALSE) { - cv_mem->zn0Sim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1); + cv_mem->zn0Sim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1, cv_mem->cv_sunctx); if (cv_mem->zn0Sim == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSetNonlinearSolverSensSim", MSGCV_MEM_FAIL); return(CV_MEM_FAIL); } - cv_mem->ycorSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1); + cv_mem->ycorSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1, cv_mem->cv_sunctx); if (cv_mem->ycorSim == NULL) { N_VDestroy(cv_mem->zn0Sim); cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", @@ -161,7 +161,7 @@ int CVodeSetNonlinearSolverSensSim(void *cvode_mem, SUNNonlinearSolver NLS) return(CV_MEM_FAIL); } - cv_mem->ewtSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1); + cv_mem->ewtSim = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns+1, cv_mem->cv_sunctx); if (cv_mem->ewtSim == NULL) { N_VDestroy(cv_mem->zn0Sim); N_VDestroy(cv_mem->ycorSim); diff --git a/src/sundials/cvodes/cvodes_nls_stg.c b/src/sundials/cvodes/cvodes_nls_stg.c index fba4c6b..eb50136 100644 --- a/src/sundials/cvodes/cvodes_nls_stg.c +++ b/src/sundials/cvodes/cvodes_nls_stg.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -137,14 +137,14 @@ int CVodeSetNonlinearSolverSensStg(void *cvode_mem, SUNNonlinearSolver NLS) /* create vector wrappers if necessary */ if (cv_mem->stgMallocDone == SUNFALSE) { - cv_mem->zn0Stg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns); + cv_mem->zn0Stg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns, cv_mem->cv_sunctx); if (cv_mem->zn0Stg == NULL) { cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", "CVodeSetNonlinearSolverSensStg", MSGCV_MEM_FAIL); return(CV_MEM_FAIL); } - cv_mem->ycorStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns); + cv_mem->ycorStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns, cv_mem->cv_sunctx); if (cv_mem->ycorStg == NULL) { N_VDestroy(cv_mem->zn0Stg); cvProcessError(cv_mem, CV_MEM_FAIL, "CVODES", @@ -152,7 +152,7 @@ int CVodeSetNonlinearSolverSensStg(void *cvode_mem, SUNNonlinearSolver NLS) return(CV_MEM_FAIL); } - cv_mem->ewtStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns); + cv_mem->ewtStg = N_VNewEmpty_SensWrapper(cv_mem->cv_Ns, cv_mem->cv_sunctx); if (cv_mem->ewtStg == NULL) { N_VDestroy(cv_mem->zn0Stg); N_VDestroy(cv_mem->ycorStg); diff --git a/src/sundials/cvodes/cvodes_nls_stg1.c b/src/sundials/cvodes/cvodes_nls_stg1.c index 3673749..8ab17e6 100644 --- a/src/sundials/cvodes/cvodes_nls_stg1.c +++ b/src/sundials/cvodes/cvodes_nls_stg1.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/cvodes/cvodes_spils.c b/src/sundials/cvodes/cvodes_spils.c index 0103eef..1ae7e7e 100644 --- a/src/sundials/cvodes/cvodes_spils.c +++ b/src/sundials/cvodes/cvodes_spils.c @@ -2,7 +2,7 @@ * Programmer(s): Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/ida/ida.c b/src/sundials/ida/ida.c index 2623356..76221de 100644 --- a/src/sundials/ida/ida.c +++ b/src/sundials/ida/ida.c @@ -2,7 +2,7 @@ * Programmer(s): Alan Hindmarsh, Radu Serban and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -176,6 +176,13 @@ #define MAXBACKS 100 /* max backtracks per Newton step in IDACalcIC */ #define XRATE RCONST(0.25) /* constant for updating Jacobian/preconditioner */ +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define IDA_PROFILER IDA_mem->ida_sunctx->profiler + + /* * ================================================================= * PRIVATE FUNCTION PROTOTYPES @@ -267,10 +274,16 @@ static int IDARootfind(IDAMem IDA_mem); * message to standard err and returns NULL. */ -void *IDACreate(void) +void *IDACreate(SUNContext sunctx) { IDAMem IDA_mem; + /* Test inputs */ + if (sunctx == NULL) { + IDAProcessError(NULL, 0, "IDA", "IDACreate", MSG_NULL_SUNCTX); + return(NULL); + } + IDA_mem = NULL; IDA_mem = (IDAMem) malloc(sizeof(struct IDAMemRec)); if (IDA_mem == NULL) { @@ -281,6 +294,8 @@ void *IDACreate(void) /* Zero out ida_mem */ memset(IDA_mem, 0, sizeof(struct IDAMemRec)); + IDA_mem->ida_sunctx = sunctx; + /* Set unit roundoff in IDA_mem */ IDA_mem->ida_uround = UNIT_ROUNDOFF; @@ -366,20 +381,25 @@ int IDAInit(void *ida_mem, IDAResFn res, } IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + /* Check for legal input parameters */ if (yy0 == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDAInit", MSG_Y0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } if (yp0 == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDAInit", MSG_YP0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } if (res == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDAInit", MSG_RES_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -388,6 +408,7 @@ int IDAInit(void *ida_mem, IDAResFn res, nvectorOK = IDACheckNvector(yy0); if (!nvectorOK) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDAInit", MSG_BAD_NVECTOR); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -407,6 +428,7 @@ int IDAInit(void *ida_mem, IDAResFn res, allocOK = IDAAllocVectors(IDA_mem, yy0); if (!allocOK) { IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDAInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -421,12 +443,13 @@ int IDAInit(void *ida_mem, IDAResFn res, N_VScale(ONE, yp0, IDA_mem->ida_phi[1]); /* create a Newton nonlinear solver object by default */ - NLS = SUNNonlinSol_Newton(yy0); + NLS = SUNNonlinSol_Newton(yy0, IDA_mem->ida_sunctx); /* check that nonlinear solver is non-NULL */ if (NLS == NULL) { IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDAInit", MSG_MEM_FAIL); IDAFreeVectors(IDA_mem); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -439,6 +462,7 @@ int IDAInit(void *ida_mem, IDAResFn res, "Setting the nonlinear solver failed"); IDAFreeVectors(IDA_mem); SUNNonlinSolFree(NLS); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -493,6 +517,7 @@ int IDAInit(void *ida_mem, IDAResFn res, IDA_mem->ida_MallocDone = SUNTRUE; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } @@ -525,10 +550,13 @@ int IDAReInit(void *ida_mem, } IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + /* Check if problem was malloc'ed */ if (IDA_mem->ida_MallocDone == SUNFALSE) { IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDA", "IDAReInit", MSG_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_NO_MALLOC); } @@ -536,11 +564,13 @@ int IDAReInit(void *ida_mem, if (yy0 == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDAReInit", MSG_Y0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } if (yp0 == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDAReInit", MSG_YP0_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -576,6 +606,7 @@ int IDAReInit(void *ida_mem, /* Problem has been successfully re-initialized */ + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } @@ -740,6 +771,8 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) } IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + nrt = (nrtfn < 0) ? 0 : nrtfn; /* If rerunning IDARootInit() with a different number of root @@ -764,6 +797,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) if (nrt == 0) { IDA_mem->ida_nrtfn = nrt; IDA_mem->ida_gfun = NULL; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } @@ -775,10 +809,10 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) if (nrt == IDA_mem->ida_nrtfn) { if (g != IDA_mem->ida_gfun) { if (g == NULL) { - free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; - free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; - free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; - free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; + free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; + free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; + free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; + free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; free(IDA_mem->ida_rootdir); IDA_mem->ida_rootdir = NULL; free(IDA_mem->ida_gactive); IDA_mem->ida_gactive = NULL; @@ -786,20 +820,26 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) IDA_mem->ida_liw -= 3*nrt; IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDARootInit", MSG_ROOT_FUNC_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } else { IDA_mem->ida_gfun = g; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } } - else return(IDA_SUCCESS); + else { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return(IDA_SUCCESS); + } } /* Set variable values in IDA memory block */ IDA_mem->ida_nrtfn = nrt; if (g == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDARootInit", MSG_ROOT_FUNC_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } else IDA_mem->ida_gfun = g; @@ -809,6 +849,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) IDA_mem->ida_glo = (realtype *) malloc(nrt*sizeof(realtype)); if (IDA_mem->ida_glo == NULL) { IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -817,6 +858,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) if (IDA_mem->ida_ghi == NULL) { free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -826,6 +868,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) free(IDA_mem->ida_glo); IDA_mem->ida_glo = NULL; free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -836,6 +879,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) free(IDA_mem->ida_ghi); IDA_mem->ida_ghi = NULL; free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -847,6 +891,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) free(IDA_mem->ida_grout); IDA_mem->ida_grout = NULL; free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -859,6 +904,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) free(IDA_mem->ida_iroots); IDA_mem->ida_iroots = NULL; free(IDA_mem->ida_rootdir); IDA_mem->ida_rootdir = NULL; IDAProcessError(IDA_mem, IDA_MEM_FAIL, "IDA", "IDARootInit", MSG_MEM_FAIL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_MEM_FAIL); } @@ -871,6 +917,7 @@ int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g) IDA_mem->ida_lrw += 3*nrt; IDA_mem->ida_liw += 3*nrt; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } @@ -936,10 +983,13 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, } IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + /* Check if problem was malloc'ed */ if (IDA_mem->ida_MallocDone == SUNFALSE) { IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDA", "IDASolve", MSG_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_NO_MALLOC); } @@ -947,23 +997,27 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, if (yret == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_YRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } IDA_mem->ida_yy = yret; if (ypret == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_YPRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } IDA_mem->ida_yp = ypret; if (tret == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_TRET_NULL); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } if ((itask != IDA_NORMAL) && (itask != IDA_ONE_STEP)) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_BAD_ITASK); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -976,7 +1030,10 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, if (IDA_mem->ida_SetupDone == SUNFALSE) { ier = IDAInitialSetup(IDA_mem); - if (ier != IDA_SUCCESS) return(ier); + if (ier != IDA_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return(ier); + } IDA_mem->ida_SetupDone = SUNTRUE; } @@ -987,17 +1044,20 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, tdist = SUNRabs(tout - IDA_mem->ida_tn); if (tdist == ZERO) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_TOO_CLOSE); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } troundoff = TWO * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(tout)); if (tdist < troundoff) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_TOO_CLOSE); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } IDA_mem->ida_hh = IDA_mem->ida_hin; if ( (IDA_mem->ida_hh != ZERO) && ((tout-IDA_mem->ida_tn)*IDA_mem->ida_hh < ZERO) ) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_BAD_HINIT); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -1016,6 +1076,7 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, if ( (IDA_mem->ida_tstop - IDA_mem->ida_tn)*IDA_mem->ida_hh <= ZERO) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASolve", MSG_BAD_TSTOP, IDA_mem->ida_tstop, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } if ( (IDA_mem->ida_tn + IDA_mem->ida_hh - IDA_mem->ida_tstop)*IDA_mem->ida_hh > ZERO) @@ -1032,6 +1093,7 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, if (ier == IDA_RTFUNC_FAIL) { IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDA", "IDARcheck1", MSG_RTFUNC_FAILED, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_RTFUNC_FAIL); } } @@ -1068,13 +1130,16 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, if (ier == CLOSERT) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDARcheck2", MSG_CLOSE_ROOTS, IDA_mem->ida_tlo); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } else if (ier == IDA_RTFUNC_FAIL) { IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDA", "IDARcheck2", MSG_RTFUNC_FAILED, IDA_mem->ida_tlo); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_RTFUNC_FAIL); } else if (ier == RTFOUND) { IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tlo; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ROOT_RETURN); } @@ -1088,15 +1153,18 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, if ((irfndp == 1) && (itask == IDA_ONE_STEP)) { IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tn; ier = IDAGetSolution(IDA_mem, IDA_mem->ida_tn, yret, ypret); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } } else if (ier == RTFOUND) { /* a new root was found */ IDA_mem->ida_irfnd = 1; IDA_mem->ida_tretlast = *tret = IDA_mem->ida_tlo; + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ROOT_RETURN); } else if (ier == IDA_RTFUNC_FAIL) { /* g failed */ IDAProcessError(IDA_mem, IDA_RTFUNC_FAIL, "IDA", "IDARcheck3", MSG_RTFUNC_FAILED, IDA_mem->ida_tlo); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_RTFUNC_FAIL); } } @@ -1107,7 +1175,10 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, /* Now test for all other stop conditions. */ istate = IDAStopTest1(IDA_mem, tout, tret, yret, ypret, itask); - if (istate != CONTINUE_STEPS) return(istate); + if (istate != CONTINUE_STEPS) { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return(istate); + } } /* Looping point for internal steps. */ @@ -1239,6 +1310,7 @@ int IDASolve(void *ida_mem, realtype tout, realtype *tret, } /* End of step loop */ + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(istate); } @@ -1280,13 +1352,17 @@ int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky) } IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + if (dky == NULL) { IDAProcessError(IDA_mem, IDA_BAD_DKY, "IDA", "IDAGetDky", MSG_NULL_DKY); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_BAD_DKY); } if ((k < 0) || (k > IDA_mem->ida_kused)) { IDAProcessError(IDA_mem, IDA_BAD_K, "IDA", "IDAGetDky", MSG_BAD_K); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_BAD_K); } @@ -1298,6 +1374,7 @@ int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky) if ((t - tp)*IDA_mem->ida_hh < ZERO) { IDAProcessError(IDA_mem, IDA_BAD_T, "IDA", "IDAGetDky", MSG_BAD_T, t, IDA_mem->ida_tn-IDA_mem->ida_hused, IDA_mem->ida_tn); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_BAD_T); } @@ -1356,8 +1433,12 @@ int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky) /* Sum j=k to j<=IDA_mem->ida_kused */ retval = N_VLinearCombination(IDA_mem->ida_kused-k+1, cjk+k, IDA_mem->ida_phi+k, dky); - if (retval != IDA_SUCCESS) return(IDA_VECTOROP_ERR); + if (retval != IDA_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return(IDA_VECTOROP_ERR); + } + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } @@ -1377,8 +1458,11 @@ int IDAComputeY(void *ida_mem, N_Vector ycor, N_Vector y) IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, ycor, y); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } @@ -1398,8 +1482,11 @@ int IDAComputeYp(void *ida_mem, N_Vector ycor, N_Vector yp) IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + N_VLinearSum(ONE, IDA_mem->ida_yppredict, IDA_mem->ida_cj, ycor, yp); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); } diff --git a/src/sundials/ida/ida_bbdpre.c b/src/sundials/ida/ida_bbdpre.c index 1574230..dafc069 100644 --- a/src/sundials/ida/ida_bbdpre.c +++ b/src/sundials/ida/ida_bbdpre.c @@ -4,7 +4,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -116,7 +116,7 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, /* Allocate memory for preconditioner matrix. */ pdata->PP = NULL; - pdata->PP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu); + pdata->PP = SUNBandMatrixStorage(Nlocal, muk, mlk, storage_mu, IDA_mem->ida_sunctx); if (pdata->PP == NULL) { free(pdata); pdata = NULL; IDAProcessError(IDA_mem, IDALS_MEM_FAIL, "IDABBDPRE", @@ -126,7 +126,7 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, /* Allocate memory for temporary N_Vectors */ pdata->zlocal = NULL; - pdata->zlocal = N_VNewEmpty_Serial(Nlocal); + pdata->zlocal = N_VNewEmpty_Serial(Nlocal, IDA_mem->ida_sunctx); if (pdata->zlocal == NULL) { SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; @@ -135,7 +135,7 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, return(IDALS_MEM_FAIL); } pdata->rlocal = NULL; - pdata->rlocal = N_VNewEmpty_Serial(Nlocal); + pdata->rlocal = N_VNewEmpty_Serial(Nlocal, IDA_mem->ida_sunctx); if (pdata->rlocal == NULL) { N_VDestroy(pdata->zlocal); SUNMatDestroy(pdata->PP); @@ -197,7 +197,7 @@ int IDABBDPrecInit(void *ida_mem, sunindextype Nlocal, /* Allocate memory for banded linear solver */ pdata->LS = NULL; - pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->PP); + pdata->LS = SUNLinSol_Band(pdata->rlocal, pdata->PP, IDA_mem->ida_sunctx); if (pdata->LS == NULL) { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); diff --git a/src/sundials/ida/ida_bbdpre_impl.h b/src/sundials/ida/ida_bbdpre_impl.h index 88364af..2a4daac 100644 --- a/src/sundials/ida/ida_bbdpre_impl.h +++ b/src/sundials/ida/ida_bbdpre_impl.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/ida/ida_direct.c b/src/sundials/ida/ida_direct.c index ec30491..0a9c86e 100644 --- a/src/sundials/ida/ida_direct.c +++ b/src/sundials/ida/ida_direct.c @@ -3,7 +3,7 @@ * Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/ida/ida_ic.c b/src/sundials/ida/ida_ic.c index fcc9123..cb40d88 100644 --- a/src/sundials/ida/ida_ic.c +++ b/src/sundials/ida/ida_ic.c @@ -2,11 +2,11 @@ * ----------------------------------------------------------------- * $Revision$ * $Date$ - * ----------------------------------------------------------------- + * ----------------------------------------------------------------- * Programmers: Alan C. Hindmarsh, and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -16,7 +16,7 @@ * SUNDIALS Copyright End * ----------------------------------------------------------------- * This is the implementation file for the IC calculation for IDA. - * It is independent of the linear solver in use. + * It is independent of the linear solver in use. * ----------------------------------------------------------------- */ @@ -28,7 +28,7 @@ /* * ================================================================= - * IDA Constants + * IDA Constants * ================================================================= */ @@ -52,9 +52,15 @@ #define IC_FAIL_RECOV 1 #define IC_CONSTR_FAILED 2 #define IC_LINESRCH_FAILED 3 -#define IC_CONV_FAIL 4 +#define IC_CONV_FAIL 4 #define IC_SLOW_CONVRG 5 +/*=================================================================*/ +/* Shortcuts */ +/*=================================================================*/ + +#define IDA_PROFILER IDA_mem->ida_sunctx->profiler + /* * ================================================================= * Private Helper Functions Prototypes @@ -62,7 +68,7 @@ */ extern int IDAInitialSetup(IDAMem IDA_mem); -extern realtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, +extern realtype IDAWrmsNorm(IDAMem IDA_mem, N_Vector x, N_Vector w, booleantype mask); static int IDAnlsIC(IDAMem IDA_mem); @@ -83,7 +89,7 @@ static int IDAICFailFlag(IDAMem IDA_mem, int retval); * ----------------------------------------------------------------- * IDACalcIC * ----------------------------------------------------------------- - * IDACalcIC computes consistent initial conditions, given the + * IDACalcIC computes consistent initial conditions, given the * user's initial guess for unknown components of yy0 and/or yp0. * * The return value is IDA_SUCCESS = 0 if no error occurred. @@ -122,29 +128,37 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) } IDA_mem = (IDAMem) ida_mem; + SUNDIALS_MARK_FUNCTION_BEGIN(IDA_PROFILER); + /* Check if problem was malloc'ed */ - + if(IDA_mem->ida_MallocDone == SUNFALSE) { IDAProcessError(IDA_mem, IDA_NO_MALLOC, "IDA", "IDACalcIC", MSG_NO_MALLOC); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_NO_MALLOC); } /* Check inputs to IDA for correctness and consistency */ ier = IDAInitialSetup(IDA_mem); - if(ier != IDA_SUCCESS) return(IDA_ILL_INPUT); + if(ier != IDA_SUCCESS) { + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); + return(IDA_ILL_INPUT); + } IDA_mem->ida_SetupDone = SUNTRUE; /* Check legality of input arguments, and set IDA memory copies. */ if(icopt != IDA_YA_YDP_INIT && icopt != IDA_Y_INIT) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDACalcIC", MSG_IC_BAD_ICOPT); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } IDA_mem->ida_icopt = icopt; if(icopt == IDA_YA_YDP_INIT && (IDA_mem->ida_id == NULL)) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDACalcIC", MSG_IC_MISSING_ID); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -152,6 +166,7 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) troundoff = TWO * IDA_mem->ida_uround * (SUNRabs(IDA_mem->ida_tn) + SUNRabs(tout1)); if(tdist < troundoff) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDACalcIC", MSG_IC_TOO_CLOSE); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } @@ -171,6 +186,7 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) minid = N_VMin(IDA_mem->ida_id); if(minid < ZERO) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDACalcIC", MSG_IC_BAD_ID); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_ILL_INPUT); } if(minid > HALF) IDA_mem->ida_sysindex = 0; @@ -180,8 +196,8 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) IDA_mem->ida_epsNewt = IDA_mem->ida_epiccon; - /* Initializations: - cjratio = 1 (for use in direct linear solvers); + /* Initializations: + cjratio = 1 (for use in direct linear solvers); set nbacktr = 0; */ IDA_mem->ida_cjratio = ONE; @@ -207,7 +223,7 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) /* Loop over nwt = number of evaluations of ewt vector. */ for(nwt = 1; nwt <= 2; nwt++) { - + /* Loop over nh = number of h values. */ for(nh = 1; nh <= mxnh; nh++) { @@ -233,9 +249,9 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) if(retval != IDA_SUCCESS) break; ewtsetOK = IDA_mem->ida_efun(IDA_mem->ida_yy0, IDA_mem->ida_ewt, IDA_mem->ida_edata); - if(ewtsetOK != 0) { - retval = IDA_BAD_EWT; - break; + if(ewtsetOK != 0) { + retval = IDA_BAD_EWT; + break; } N_VScale(ONE, IDA_mem->ida_yy0, IDA_mem->ida_phi[0]); N_VScale(ONE, IDA_mem->ida_yp0, IDA_mem->ida_phi[1]); @@ -255,13 +271,14 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) if(retval != IDA_SUCCESS) { icret = IDAICFailFlag(IDA_mem, retval); + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(icret); } /* Otherwise return success flag. */ + SUNDIALS_MARK_FUNCTION_END(IDA_PROFILER); return(IDA_SUCCESS); - } /* @@ -274,7 +291,7 @@ int IDACalcIC(void *ida_mem, int icopt, realtype tout1) * ----------------------------------------------------------------- * IDAnlsIC * ----------------------------------------------------------------- - * IDAnlsIC solves a nonlinear system for consistent initial + * IDAnlsIC solves a nonlinear system for consistent initial * conditions. It calls IDANewtonIC to do most of the work. * * The return value is IDA_SUCCESS = 0 if no error occurred. @@ -362,7 +379,7 @@ static int IDAnlsIC (IDAMem IDA_mem) * or on maxbacks test) * IC_CONV_FAIL if the Newton iterations failed to converge * IC_SLOW_CONVRG if the iterations appear to be converging slowly. - * They failed the convergence test, but showed + * They failed the convergence test, but showed * an overall norm reduction (by a factor of < 0.1) * or a convergence rate <= ICRATEMAX). * The error return values (negative) considered non-recoverable are: @@ -429,15 +446,15 @@ static int IDANewtonIC(IDAMem IDA_mem) * ----------------------------------------------------------------- * IDALineSrch * ----------------------------------------------------------------- - * IDALineSrch performs the Linesearch algorithm with the + * IDALineSrch performs the Linesearch algorithm with the * calculation of consistent initial conditions. * - * On entry, yy0 and yp0 are the current values of y and y', the + * On entry, yy0 and yp0 are the current values of y and y', the * Newton step is delta, the current residual vector F is savres, * delnorm is WRMS-norm(delta), and fnorm is the norm of the vector * J-inverse F. * - * On a successful return, yy0, yp0, and savres have been updated, + * On a successful return, yy0, yp0, and savres have been updated, * delnew contains the current value of J-inverse F, and fnorm is * WRMS-norm(delnew). * @@ -532,7 +549,7 @@ static int IDALineSrch(IDAMem IDA_mem, realtype *delnorm, realtype *fnorm) * IDAfnorm * ----------------------------------------------------------------- * IDAfnorm computes the norm of the current function value, by - * evaluating the DAE residual function, calling the linear + * evaluating the DAE residual function, calling the linear * system solver, and computing a WRMS-norm. * * On return, savres contains the current residual vector F, and @@ -590,7 +607,7 @@ static int IDAfnorm(IDAMem IDA_mem, realtype *fnorm) static int IDANewyyp(IDAMem IDA_mem, realtype lambda) { - + /* IDA_YA_YDP_INIT case: ynew = yy0 - lambda*delta where id_i = 0 ypnew = yp0 - cj*lambda*delta where id_i = 1. */ if(IDA_mem->ida_icopt == IDA_YA_YDP_INIT) { @@ -625,7 +642,7 @@ static int IDANewyyp(IDAMem IDA_mem, realtype lambda) static int IDANewy(IDAMem IDA_mem) { - + /* IDA_YA_YDP_INIT case: ynew = yy0 - delta where id_i = 0. */ if(IDA_mem->ida_icopt == IDA_YA_YDP_INIT) { N_VProd(IDA_mem->ida_id, IDA_mem->ida_delta, IDA_mem->ida_dtemp); @@ -670,7 +687,7 @@ static int IDAICFailFlag(IDAMem IDA_mem, int retval) IDAProcessError(IDA_mem, IDA_LSETUP_FAIL, "IDA", "IDACalcIC", MSG_IC_SETUP_FAIL); return(IDA_LSETUP_FAIL); - case IDA_LSOLVE_FAIL: + case IDA_LSOLVE_FAIL: IDAProcessError(IDA_mem, IDA_LSOLVE_FAIL, "IDA", "IDACalcIC", MSG_IC_SOLVE_FAIL); return(IDA_LSOLVE_FAIL); @@ -678,11 +695,11 @@ static int IDAICFailFlag(IDAMem IDA_mem, int retval) IDAProcessError(IDA_mem, IDA_NO_RECOVERY, "IDA", "IDACalcIC", MSG_IC_NO_RECOVERY); return(IDA_NO_RECOVERY); - case IC_CONSTR_FAILED: + case IC_CONSTR_FAILED: IDAProcessError(IDA_mem, IDA_CONSTR_FAIL, "IDA", "IDACalcIC", MSG_IC_FAIL_CONSTR); return(IDA_CONSTR_FAIL); - case IC_LINESRCH_FAILED: + case IC_LINESRCH_FAILED: IDAProcessError(IDA_mem, IDA_LINESEARCH_FAIL, "IDA", "IDACalcIC", MSG_IC_FAILED_LINS); return(IDA_LINESEARCH_FAIL); @@ -690,7 +707,7 @@ static int IDAICFailFlag(IDAMem IDA_mem, int retval) IDAProcessError(IDA_mem, IDA_CONV_FAIL, "IDA", "IDACalcIC", MSG_IC_CONV_FAILED); return(IDA_CONV_FAIL); - case IC_SLOW_CONVRG: + case IC_SLOW_CONVRG: IDAProcessError(IDA_mem, IDA_CONV_FAIL, "IDA", "IDACalcIC", MSG_IC_CONV_FAILED); return(IDA_CONV_FAIL); diff --git a/src/sundials/ida/ida_impl.h b/src/sundials/ida/ida_impl.h index fdbc5d7..baa15cc 100644 --- a/src/sundials/ida/ida_impl.h +++ b/src/sundials/ida/ida_impl.h @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,6 +22,7 @@ #include #include "ida/ida.h" +#include "sundials_context_impl.h" #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { @@ -61,6 +62,8 @@ extern "C" { typedef struct IDAMemRec { + SUNContext ida_sunctx; + realtype ida_uround; /* machine unit roundoff */ /*-------------------------- @@ -451,6 +454,7 @@ int idaNlsInit(IDAMem IDA_mem); /* General errors */ #define MSG_MEM_FAIL "A memory request failed." +#define MSG_NULL_SUNCTX "sunctx = NULL illegal." #define MSG_NO_MEM "ida_mem = NULL illegal." #define MSG_NO_MALLOC "Attempt to call before IDAMalloc." #define MSG_BAD_NVECTOR "A required vector operation is not implemented." diff --git a/src/sundials/ida/ida_io.c b/src/sundials/ida/ida_io.c index c8e8e74..f8f847a 100644 --- a/src/sundials/ida/ida_io.c +++ b/src/sundials/ida/ida_io.c @@ -3,7 +3,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/ida/ida_ls.c b/src/sundials/ida/ida_ls.c index 448e332..33390f8 100644 --- a/src/sundials/ida/ida_ls.c +++ b/src/sundials/ida/ida_ls.c @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -412,8 +412,8 @@ int IDASetPreconditioner(void *ida_mem, { IDAMem IDA_mem; IDALsMem idals_mem; - PSetupFn idals_psetup; - PSolveFn idals_psolve; + SUNPSetupFn idals_psetup; + SUNPSolveFn idals_psolve; int retval; /* access IDALsMem structure */ diff --git a/src/sundials/ida/ida_ls_impl.h b/src/sundials/ida/ida_ls_impl.h index ec7d9c9..378791f 100644 --- a/src/sundials/ida/ida_ls_impl.h +++ b/src/sundials/ida/ida_ls_impl.h @@ -3,7 +3,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/ida/ida_nls.c b/src/sundials/ida/ida_nls.c index bd2834d..d8f408c 100644 --- a/src/sundials/ida/ida_nls.c +++ b/src/sundials/ida/ida_nls.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/ida/ida_spils.c b/src/sundials/ida/ida_spils.c index 626d862..6df80c8 100644 --- a/src/sundials/ida/ida_spils.c +++ b/src/sundials/ida/ida_spils.c @@ -3,7 +3,7 @@ * Alan Hindmarsh, Radu Serban and Aaron Collier @ LLNL *----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/nvector/serial/nvector_serial.c b/src/sundials/nvector/serial/nvector_serial.c index 0e42f24..958ea2c 100644 --- a/src/sundials/nvector/serial/nvector_serial.c +++ b/src/sundials/nvector/serial/nvector_serial.c @@ -3,7 +3,7 @@ * and Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -67,14 +67,14 @@ N_Vector_ID N_VGetVectorID_Serial(N_Vector v) * Function to create a new empty serial vector */ -N_Vector N_VNewEmpty_Serial(sunindextype length) +N_Vector N_VNewEmpty_Serial(sunindextype length, SUNContext sunctx) { N_Vector v; N_VectorContent_Serial content; /* Create an empty vector object */ v = NULL; - v = N_VNewEmpty(); + v = N_VNewEmpty(sunctx); if (v == NULL) return(NULL); /* Attach operations */ @@ -123,6 +123,9 @@ N_Vector N_VNewEmpty_Serial(sunindextype length) v->ops->nvwsqrsumlocal = N_VWSqrSumLocal_Serial; v->ops->nvwsqrsummasklocal = N_VWSqrSumMaskLocal_Serial; + /* single buffer reduction operations */ + v->ops->nvdotprodmultilocal = N_VDotProdMulti_Serial; + /* XBraid interface operations */ v->ops->nvbufsize = N_VBufSize_Serial; v->ops->nvbufpack = N_VBufPack_Serial; @@ -152,13 +155,13 @@ N_Vector N_VNewEmpty_Serial(sunindextype length) * Function to create a new serial vector */ -N_Vector N_VNew_Serial(sunindextype length) +N_Vector N_VNew_Serial(sunindextype length, SUNContext sunctx) { N_Vector v; realtype *data; v = NULL; - v = N_VNewEmpty_Serial(length); + v = N_VNewEmpty_Serial(length, sunctx); if (v == NULL) return(NULL); /* Create data */ @@ -182,12 +185,12 @@ N_Vector N_VNew_Serial(sunindextype length) * Function to create a serial N_Vector with user data component */ -N_Vector N_VMake_Serial(sunindextype length, realtype *v_data) +N_Vector N_VMake_Serial(sunindextype length, realtype *v_data, SUNContext sunctx) { N_Vector v; v = NULL; - v = N_VNewEmpty_Serial(length); + v = N_VNewEmpty_Serial(length, sunctx); if (v == NULL) return(NULL); if (length > 0) { @@ -205,25 +208,7 @@ N_Vector N_VMake_Serial(sunindextype length, realtype *v_data) N_Vector* N_VCloneVectorArray_Serial(int count, N_Vector w) { - N_Vector* vs; - int j; - - if (count <= 0) return(NULL); - - vs = NULL; - vs = (N_Vector*) malloc(count * sizeof(N_Vector)); - if(vs == NULL) return(NULL); - - for (j = 0; j < count; j++) { - vs[j] = NULL; - vs[j] = N_VClone_Serial(w); - if (vs[j] == NULL) { - N_VDestroyVectorArray_Serial(vs, j-1); - return(NULL); - } - } - - return(vs); + return(N_VCloneVectorArray(count, w)); } /* ---------------------------------------------------------------------------- @@ -232,25 +217,7 @@ N_Vector* N_VCloneVectorArray_Serial(int count, N_Vector w) N_Vector* N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w) { - N_Vector* vs; - int j; - - if (count <= 0) return(NULL); - - vs = NULL; - vs = (N_Vector*) malloc(count * sizeof(N_Vector)); - if(vs == NULL) return(NULL); - - for (j = 0; j < count; j++) { - vs[j] = NULL; - vs[j] = N_VCloneEmpty_Serial(w); - if (vs[j] == NULL) { - N_VDestroyVectorArray_Serial(vs, j-1); - return(NULL); - } - } - - return(vs); + return(N_VCloneEmptyVectorArray(count, w)); } /* ---------------------------------------------------------------------------- @@ -259,12 +226,7 @@ N_Vector* N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w) void N_VDestroyVectorArray_Serial(N_Vector* vs, int count) { - int j; - - for (j = 0; j < count; j++) N_VDestroy_Serial(vs[j]); - - free(vs); vs = NULL; - + N_VDestroyVectorArray(vs, count); return; } @@ -301,11 +263,11 @@ void N_VPrintFile_Serial(N_Vector x, FILE* outfile) for (i = 0; i < N; i++) { #if defined(SUNDIALS_EXTENDED_PRECISION) - fprintf(outfile, "%35.32Lg\n", xd[i]); + fprintf(outfile, "%35.32Le\n", xd[i]); #elif defined(SUNDIALS_DOUBLE_PRECISION) - fprintf(outfile, "%19.16g\n", xd[i]); + fprintf(outfile, "%19.16e\n", xd[i]); #else - fprintf(outfile, "%11.8g\n", xd[i]); + fprintf(outfile, "%11.8e\n", xd[i]); #endif } fprintf(outfile, "\n"); @@ -328,7 +290,7 @@ N_Vector N_VCloneEmpty_Serial(N_Vector w) /* Create vector */ v = NULL; - v = N_VNewEmpty(); + v = N_VNewEmpty(w->sunctx); if (v == NULL) return(NULL); /* Attach operations */ @@ -1978,6 +1940,8 @@ int N_VEnableFusedOps_Serial(N_Vector v, booleantype tf) v->ops->nvwrmsnormmaskvectorarray = N_VWrmsNormMaskVectorArray_Serial; v->ops->nvscaleaddmultivectorarray = N_VScaleAddMultiVectorArray_Serial; v->ops->nvlinearcombinationvectorarray = N_VLinearCombinationVectorArray_Serial; + /* enable single buffer reduction operations */ + v->ops->nvdotprodmultilocal = N_VDotProdMulti_Serial; } else { /* disable all fused vector operations */ v->ops->nvlinearcombination = NULL; @@ -1991,6 +1955,8 @@ int N_VEnableFusedOps_Serial(N_Vector v, booleantype tf) v->ops->nvwrmsnormmaskvectorarray = NULL; v->ops->nvscaleaddmultivectorarray = NULL; v->ops->nvlinearcombinationvectorarray = NULL; + /* disable single buffer reduction operations */ + v->ops->nvdotprodmultilocal = NULL; } /* return success */ @@ -2043,10 +2009,13 @@ int N_VEnableDotProdMulti_Serial(N_Vector v, booleantype tf) if (v->ops == NULL) return(-1); /* enable/disable operation */ - if (tf) - v->ops->nvdotprodmulti = N_VDotProdMulti_Serial; - else - v->ops->nvdotprodmulti = NULL; + if (tf) { + v->ops->nvdotprodmulti = N_VDotProdMulti_Serial; + v->ops->nvdotprodmultilocal = N_VDotProdMulti_Serial; + } else { + v->ops->nvdotprodmulti = NULL; + v->ops->nvdotprodmultilocal = NULL; + } /* return success */ return(0); diff --git a/src/sundials/sundials/sundials_band.c b/src/sundials/sundials/sundials_band.c index 66da9f9..1b675af 100644 --- a/src/sundials/sundials/sundials_band.c +++ b/src/sundials/sundials/sundials_band.c @@ -6,7 +6,7 @@ * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -33,33 +33,58 @@ /* * ----------------------------------------------------- - * Functions working on DlsMat + * Functions working on SUNDlsMat * ----------------------------------------------------- */ -sunindextype BandGBTRF(DlsMat A, sunindextype *p) +sunindextype SUNDlsMat_BandGBTRF(SUNDlsMat A, sunindextype* p) { - return(bandGBTRF(A->cols, A->M, A->mu, A->ml, A->s_mu, p)); + return(SUNDlsMat_bandGBTRF(A->cols, A->M, A->mu, A->ml, A->s_mu, p)); } -void BandGBTRS(DlsMat A, sunindextype *p, realtype *b) +sunindextype BandGBTRF(SUNDlsMat A, sunindextype *p) { - bandGBTRS(A->cols, A->M, A->s_mu, A->ml, p, b); + return(SUNDlsMat_bandGBTRF(A->cols, A->M, A->mu, A->ml, A->s_mu, p)); } -void BandCopy(DlsMat A, DlsMat B, sunindextype copymu, sunindextype copyml) +void SUNDlsMat_BandGBTRS(SUNDlsMat A, sunindextype *p, realtype *b) { - bandCopy(A->cols, B->cols, A->M, A->s_mu, B->s_mu, copymu, copyml); + SUNDlsMat_bandGBTRS(A->cols, A->M, A->s_mu, A->ml, p, b); } -void BandScale(realtype c, DlsMat A) +void BandGBTRS(SUNDlsMat A, sunindextype *p, realtype *b) { - bandScale(c, A->cols, A->M, A->mu, A->ml, A->s_mu); + SUNDlsMat_bandGBTRS(A->cols, A->M, A->s_mu, A->ml, p, b); } -void BandMatvec(DlsMat A, realtype *x, realtype *y) +void SUNDlsMat_BandCopy(SUNDlsMat A, SUNDlsMat B, sunindextype copymu, sunindextype copyml) { - bandMatvec(A->cols, x, y, A->M, A->mu, A->ml, A->s_mu); + SUNDlsMat_bandCopy(A->cols, B->cols, A->M, A->s_mu, B->s_mu, copymu, copyml); +} + +void BandCopy(SUNDlsMat A, SUNDlsMat B, sunindextype copymu, sunindextype copyml) +{ + SUNDlsMat_bandCopy(A->cols, B->cols, A->M, A->s_mu, B->s_mu, copymu, copyml); +} + +void SUNDlsMat_BandScale(realtype c, SUNDlsMat A) +{ + SUNDlsMat_bandScale(c, A->cols, A->M, A->mu, A->ml, A->s_mu); +} + +void BandScale(realtype c, SUNDlsMat A) +{ + SUNDlsMat_bandScale(c, A->cols, A->M, A->mu, A->ml, A->s_mu); +} + +void SUNDlsMat_BandMatvec(SUNDlsMat A, realtype *x, realtype *y) +{ + SUNDlsMat_bandMatvec(A->cols, x, y, A->M, A->mu, A->ml, A->s_mu); +} + +void BandMatvec(SUNDlsMat A, realtype *x, realtype *y) +{ + SUNDlsMat_bandMatvec(A->cols, x, y, A->M, A->mu, A->ml, A->s_mu); } /* @@ -69,6 +94,11 @@ void BandMatvec(DlsMat A, realtype *x, realtype *y) */ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindextype ml, sunindextype smu, sunindextype *p) +{ + return(SUNDlsMat_bandGBTRF(a, n, mu, ml, smu, p)); +} + +sunindextype SUNDlsMat_bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindextype ml, sunindextype smu, sunindextype *p) { sunindextype c, r, num_rows; sunindextype i, j, k, l, storage_l, storage_k, last_col_k, last_row_k; @@ -83,7 +113,7 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty for (c=0; c < n; c++) { a_c = a[c]; for (r=0; r < num_rows; r++) { - a_c[r] = ZERO; + a_c[r] = ZERO; } } } @@ -91,7 +121,7 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty /* k = elimination step number */ for (k=0; k < n-1; k++, p++) { - + col_k = a[k]; diag_k = col_k + smu; sub_diag_k = diag_k + 1; @@ -101,21 +131,21 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty l=k; max = SUNRabs(*diag_k); - for (i=k+1, kptr=sub_diag_k; i <= last_row_k; i++, kptr++) { + for (i=k+1, kptr=sub_diag_k; i <= last_row_k; i++, kptr++) { if (SUNRabs(*kptr) > max) { - l=i; - max = SUNRabs(*kptr); + l=i; + max = SUNRabs(*kptr); } } storage_l = ROW(l, k, smu); *p = l; - + /* check for zero pivot element */ if (col_k[storage_l] == ZERO) return(k+1); - + /* swap a(l,k) and a(k,k) if necessary */ - + if ( (swap = (l != k) )) { temp = col_k[storage_l]; col_k[storage_l] = *diag_k; @@ -127,7 +157,7 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty /* a(k,k) holds the pivot element. This scaling */ /* stores the pivot row multipliers -a(i,k)/a(k,k) */ /* in a(i,k), i=k+1, ..., SUNMIN(n-1,k+ml). */ - + mult = -ONE / (*diag_k); for (i=k+1, kptr = sub_diag_k; i <= last_row_k; i++, kptr++) (*kptr) *= mult; @@ -136,37 +166,37 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty /* row k is the pivot row after swapping with row l. */ /* The computation is done one column at a time, */ /* column j=k+1, ..., SUNMIN(k+smu,n-1). */ - + last_col_k = SUNMIN(k+smu,n-1); for (j=k+1; j <= last_col_k; j++) { - + col_j = a[j]; - storage_l = ROW(l,j,smu); - storage_k = ROW(k,j,smu); + storage_l = ROW(l,j,smu); + storage_k = ROW(k,j,smu); a_kj = col_j[storage_l]; /* Swap the elements a(k,j) and a(k,l) if l!=k. */ - + if (swap) { - col_j[storage_l] = col_j[storage_k]; - col_j[storage_k] = a_kj; + col_j[storage_l] = col_j[storage_k]; + col_j[storage_k] = a_kj; } /* a(i,j) = a(i,j) - [a(i,k)/a(k,k)]*a(k,j) */ /* a_kj = a(k,j), *kptr = - a(i,k)/a(k,k), *jptr = a(i,j) */ if (a_kj != ZERO) { - for (i=k+1, kptr=sub_diag_k, jptr=col_j+ROW(k+1,j,smu); - i <= last_row_k; - i++, kptr++, jptr++) - (*jptr) += a_kj * (*kptr); + for (i=k+1, kptr=sub_diag_k, jptr=col_j+ROW(k+1,j,smu); + i <= last_row_k; + i++, kptr++, jptr++) + (*jptr) += a_kj * (*kptr); } - } + } } - + /* set the last pivot row to be n-1 and check for a zero pivot */ - *p = n-1; + *p = n-1; if (a[n-1][smu] == ZERO) return(n); /* return 0 to indicate success */ @@ -174,13 +204,19 @@ sunindextype bandGBTRF(realtype **a, sunindextype n, sunindextype mu, sunindexty return(0); } -void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, sunindextype ml, sunindextype *p, realtype *b) +void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, + sunindextype ml, sunindextype *p, realtype *b) +{ + SUNDlsMat_bandGBTRS(a, n, smu, ml, p, b); +} + +void SUNDlsMat_bandGBTRS(realtype **a, sunindextype n, sunindextype smu, sunindextype ml, sunindextype *p, realtype *b) { sunindextype k, l, i, first_row_k, last_row_k; realtype mult, *diag_k; - + /* Solve Ly = Pb, store solution y in b */ - + for (k=0; k < n-1; k++) { l = p[k]; mult = b[l]; @@ -193,9 +229,9 @@ void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, sunindextype ml, for (i=k+1; i <= last_row_k; i++) b[i] += mult * diag_k[i-k]; } - + /* Solve Ux = y, store solution x in b */ - + for (k=n-1; k >= 0; k--) { diag_k = a[k]+smu; first_row_k = SUNMAX(0,k-smu); @@ -206,14 +242,20 @@ void bandGBTRS(realtype **a, sunindextype n, sunindextype smu, sunindextype ml, } } -void bandCopy(realtype **a, realtype **b, sunindextype n, sunindextype a_smu, sunindextype b_smu, +void bandCopy(realtype **a, realtype **b, sunindextype n, sunindextype a_smu, sunindextype b_smu, sunindextype copymu, sunindextype copyml) +{ + SUNDlsMat_bandCopy(a, b, n, a_smu, b_smu, copymu, copyml); +} + +void SUNDlsMat_bandCopy(realtype **a, realtype **b, sunindextype n, sunindextype a_smu, sunindextype b_smu, + sunindextype copymu, sunindextype copyml) { sunindextype i, j, copySize; realtype *a_col_j, *b_col_j; copySize = copymu + copyml + 1; - + for (j=0; j < n; j++) { a_col_j = a[j]+a_smu-copymu; b_col_j = b[j]+b_smu-copymu; @@ -223,6 +265,11 @@ void bandCopy(realtype **a, realtype **b, sunindextype n, sunindextype a_smu, su } void bandScale(realtype c, realtype **a, sunindextype n, sunindextype mu, sunindextype ml, sunindextype smu) +{ + SUNDlsMat_bandScale(c, a, n, mu, ml, smu); +} + +void SUNDlsMat_bandScale(realtype c, realtype **a, sunindextype n, sunindextype mu, sunindextype ml, sunindextype smu) { sunindextype i, j, colSize; realtype *col_j; @@ -237,15 +284,26 @@ void bandScale(realtype c, realtype **a, sunindextype n, sunindextype mu, sunind } void bandAddIdentity(realtype **a, sunindextype n, sunindextype smu) +{ + SUNDlsMat_bandAddIdentity(a, n, smu); +} + +void SUNDlsMat_bandAddIdentity(realtype **a, sunindextype n, sunindextype smu) { sunindextype j; - + for(j=0; j < n; j++) a[j][smu] += ONE; } -void bandMatvec(realtype **a, realtype *x, realtype *y, sunindextype n, - sunindextype mu, sunindextype ml, sunindextype smu) +void bandMatvec(realtype **a, realtype *x, realtype *y, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu) +{ + SUNDlsMat_bandMatvec(a, x, y, n, mu, ml, smu); +} + +void SUNDlsMat_bandMatvec(realtype **a, realtype *x, realtype *y, sunindextype n, + sunindextype mu, sunindextype ml, sunindextype smu) { sunindextype i, j, is, ie; realtype *col_j; diff --git a/src/sundials/sundials/sundials_context.c b/src/sundials/sundials/sundials_context.c new file mode 100644 index 0000000..c5a6f57 --- /dev/null +++ b/src/sundials/sundials/sundials_context.c @@ -0,0 +1,129 @@ +/* ----------------------------------------------------------------- + * Programmer(s): Cody J. Balos @ LLNL + * ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2022, 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 + * ----------------------------------------------------------------- + * SUNDIALS context class. A context object holds data that all + * SUNDIALS objects in a simulation share. + * ----------------------------------------------------------------*/ + +#include +#include +#include + +#include +#include +#include "sundials_context_impl.h" +#include "sundials_debug.h" + + +int SUNContext_Create(void* comm, SUNContext* sunctx) +{ + SUNProfiler profiler = NULL; + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + if (SUNProfiler_Create(comm, "SUNContext Default", &profiler)) + return(-1); +#endif + + *sunctx = NULL; + *sunctx = (SUNContext) malloc(sizeof(struct _SUNContext)); + + if (*sunctx == NULL) + { +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + SUNProfiler_Free(&profiler); +#endif + return(-1); + } + + (*sunctx)->profiler = profiler; + (*sunctx)->own_profiler = SUNTRUE; + + return(0); +} + +int SUNContext_GetProfiler(SUNContext sunctx, SUNProfiler* profiler) +{ + if (sunctx == NULL) return(-1); + +#ifdef SUNDIALS_BUILD_WITH_PROFILING + /* get profiler */ + *profiler = sunctx->profiler; +#else + *profiler = NULL; +#endif + + return(0); +} + +int SUNContext_SetProfiler(SUNContext sunctx, SUNProfiler profiler) +{ + if (sunctx == NULL) return(-1); + +#ifdef SUNDIALS_BUILD_WITH_PROFILING + /* free any existing profiler */ + if (sunctx->profiler && sunctx->own_profiler) { + if (SUNProfiler_Free(&(sunctx->profiler))) + return(-1); + sunctx->profiler = NULL; + } + + /* set profiler */ + sunctx->profiler = profiler; + sunctx->own_profiler = SUNFALSE; +#endif + + return(0); +} + +int SUNContext_Free(SUNContext* sunctx) +{ +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + FILE *fp; + char* sunprofiler_print_env; +#endif + + if (!sunctx) return(0); + if (!(*sunctx)) return(0); + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) && !defined(SUNDIALS_CALIPER_ENABLED) + /* Find out where we are printing to */ + sunprofiler_print_env = getenv("SUNPROFILER_PRINT"); + fp = NULL; + if (sunprofiler_print_env) + { + if (!strcmp(sunprofiler_print_env, "0")) + fp = NULL; + else if (!strcmp(sunprofiler_print_env, "1") || + !strcmp(sunprofiler_print_env, "TRUE") || + !strcmp(sunprofiler_print_env, "stdout")) + fp = stdout; + else + fp = fopen(sunprofiler_print_env, "a"); + } + + /* Enforce that the profiler is freed before finalizing, + if it is not owned by the sunctx. */ + if ((*sunctx)->profiler) + { + if (fp) SUNProfiler_Print((*sunctx)->profiler, fp); + if (fp) fclose(fp); + if ((*sunctx)->own_profiler && SUNProfiler_Free(&(*sunctx)->profiler)) + return(-1); + } +#endif + + free(*sunctx); + *sunctx = NULL; + + return(0); +} diff --git a/inst/include/sundials/sundials_fnvector.h b/src/sundials/sundials/sundials_context_impl.h similarity index 54% rename from inst/include/sundials/sundials_fnvector.h rename to src/sundials/sundials/sundials_context_impl.h index e1f3980..2a5f2bb 100644 --- a/inst/include/sundials/sundials_fnvector.h +++ b/src/sundials/sundials/sundials_context_impl.h @@ -1,8 +1,8 @@ /* ----------------------------------------------------------------- - * Programmer(s): Radu Serban and Aaron Collier @ LLNL + * Programmer(s): Cody J. Balos @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -11,32 +11,26 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This file (companion of nvector.h) contains definitions - * needed for the initialization of vector operations in Fortran. - * -----------------------------------------------------------------*/ + * SUNDIALS context class implementation. + * ----------------------------------------------------------------*/ +#ifndef _SUNDIALS_CONTEXT_IMPL_H +#define _SUNDIALS_CONTEXT_IMPL_H -#ifndef _FNVECTOR_H -#define _FNVECTOR_H - -#ifndef _SUNDIALS_CONFIG_H -#define _SUNDIALS_CONFIG_H -#include -#endif +#include +#include +#include #ifdef __cplusplus /* wrapper to enable C++ usage */ extern "C" { #endif -/* SUNDIALS solver IDs */ - -#define FCMIX_CVODE 1 -#define FCMIX_IDA 2 -#define FCMIX_KINSOL 3 -#define FCMIX_ARKODE 4 +struct _SUNContext { + SUNProfiler profiler; + booleantype own_profiler; +}; #ifdef __cplusplus } #endif - #endif diff --git a/src/sundials/sundials/sundials_dense.c b/src/sundials/sundials/sundials_dense.c index 108c670..aa11085 100644 --- a/src/sundials/sundials/sundials_dense.c +++ b/src/sundials/sundials/sundials_dense.c @@ -7,7 +7,7 @@ * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,7 +19,7 @@ * This is the implementation file for a generic package of dense * matrix operations. * ----------------------------------------------------------------- - */ + */ #include #include @@ -33,56 +33,106 @@ /* * ----------------------------------------------------- - * Functions working on DlsMat + * Functions working on SUNDlsMat * ----------------------------------------------------- */ -sunindextype DenseGETRF(DlsMat A, sunindextype *p) +sunindextype SUNDlsMat_DenseGETRF(SUNDlsMat A, sunindextype *p) { - return(denseGETRF(A->cols, A->M, A->N, p)); + return(SUNDlsMat_denseGETRF(A->cols, A->M, A->N, p)); } -void DenseGETRS(DlsMat A, sunindextype *p, realtype *b) +sunindextype DenseGETRF(SUNDlsMat A, sunindextype *p) { - denseGETRS(A->cols, A->N, p, b); + return(SUNDlsMat_denseGETRF(A->cols, A->M, A->N, p)); } -sunindextype DensePOTRF(DlsMat A) +void SUNDlsMat_DenseGETRS(SUNDlsMat A, sunindextype *p, realtype *b) { - return(densePOTRF(A->cols, A->M)); + SUNDlsMat_denseGETRS(A->cols, A->N, p, b); } -void DensePOTRS(DlsMat A, realtype *b) +void DenseGETRS(SUNDlsMat A, sunindextype *p, realtype *b) { - densePOTRS(A->cols, A->M, b); + SUNDlsMat_denseGETRS(A->cols, A->N, p, b); } -int DenseGEQRF(DlsMat A, realtype *beta, realtype *wrk) +sunindextype SUNDlsMat_DensePOTRF(SUNDlsMat A) { - return(denseGEQRF(A->cols, A->M, A->N, beta, wrk)); + return(SUNDlsMat_densePOTRF(A->cols, A->M)); } -int DenseORMQR(DlsMat A, realtype *beta, realtype *vn, realtype *vm, realtype *wrk) +sunindextype DensePOTRF(SUNDlsMat A) { - return(denseORMQR(A->cols, A->M, A->N, beta, vn, vm, wrk)); + return(SUNDlsMat_densePOTRF(A->cols, A->M)); } -void DenseCopy(DlsMat A, DlsMat B) +void SUNDlsMat_DensePOTRS(SUNDlsMat A, realtype *b) { - denseCopy(A->cols, B->cols, A->M, A->N); + SUNDlsMat_densePOTRS(A->cols, A->M, b); } -void DenseScale(realtype c, DlsMat A) +void DensePOTRS(SUNDlsMat A, realtype *b) { - denseScale(c, A->cols, A->M, A->N); + SUNDlsMat_densePOTRS(A->cols, A->M, b); } -void DenseMatvec(DlsMat A, realtype *x, realtype *y) +int SUNDlsMat_DenseGEQRF(SUNDlsMat A, realtype *beta, realtype *wrk) { - denseMatvec(A->cols, x, y, A->M, A->N); + return(SUNDlsMat_denseGEQRF(A->cols, A->M, A->N, beta, wrk)); +} + +int DenseGEQRF(SUNDlsMat A, realtype *beta, realtype *wrk) +{ + return(SUNDlsMat_denseGEQRF(A->cols, A->M, A->N, beta, wrk)); +} + +int SUNDlsMat_DenseORMQR(SUNDlsMat A, realtype *beta, realtype *vn, realtype *vm, realtype *wrk) +{ + return(SUNDlsMat_denseORMQR(A->cols, A->M, A->N, beta, vn, vm, wrk)); +} + +int DenseORMQR(SUNDlsMat A, realtype *beta, realtype *vn, realtype *vm, realtype *wrk) +{ + return(SUNDlsMat_denseORMQR(A->cols, A->M, A->N, beta, vn, vm, wrk)); +} + +void SUNDlsMat_DenseCopy(SUNDlsMat A, SUNDlsMat B) +{ + SUNDlsMat_denseCopy(A->cols, B->cols, A->M, A->N); +} + +void DenseCopy(SUNDlsMat A, SUNDlsMat B) +{ + SUNDlsMat_denseCopy(A->cols, B->cols, A->M, A->N); +} + +void SUNDlsMat_DenseScale(realtype c, SUNDlsMat A) +{ + SUNDlsMat_denseScale(c, A->cols, A->M, A->N); +} + +void DenseScale(realtype c, SUNDlsMat A) +{ + SUNDlsMat_denseScale(c, A->cols, A->M, A->N); +} + +void SUNDlsMat_DenseMatvec(SUNDlsMat A, realtype *x, realtype *y) +{ + SUNDlsMat_denseMatvec(A->cols, x, y, A->M, A->N); +} + +void DenseMatvec(SUNDlsMat A, realtype *x, realtype *y) +{ + SUNDlsMat_denseMatvec(A->cols, x, y, A->M, A->N); } sunindextype denseGETRF(realtype **a, sunindextype m, sunindextype n, sunindextype *p) +{ + return(SUNDlsMat_denseGETRF(a, m, n, p)); +} + +sunindextype SUNDlsMat_denseGETRF(realtype **a, sunindextype m, sunindextype n, sunindextype *p) { sunindextype i, j, k, l; realtype *col_j, *col_k; @@ -101,8 +151,8 @@ sunindextype denseGETRF(realtype **a, sunindextype m, sunindextype n, sunindexty /* check for zero pivot element */ if (col_k[l] == ZERO) return(k+1); - - /* swap a(k,1:n) and a(l,1:n) if necessary */ + + /* swap a(k,1:n) and a(l,1:n) if necessary */ if ( l!= k ) { for (i=0; i0) { for(i=j; i=0; i--) { col_i = a[i]; - for (j=i+1; j= n) * using Householder reflections. * - * On exit, the elements on and above the diagonal of A contain the n by n - * upper triangular matrix R; the elements below the diagonal, with the array beta, + * On exit, the elements on and above the diagonal of A contain the n by n + * upper triangular matrix R; the elements below the diagonal, with the array beta, * represent the orthogonal matrix Q as a product of elementary reflectors . * * v (of length m) must be provided as workspace. @@ -259,6 +326,11 @@ void densePOTRS(realtype **a, sunindextype m, realtype *b) */ int denseGEQRF(realtype **a, sunindextype m, sunindextype n, realtype *beta, realtype *v) +{ + return(SUNDlsMat_denseGEQRF(a, m, n, beta, v)); +} + +int SUNDlsMat_denseGEQRF(realtype **a, sunindextype m, sunindextype n, realtype *beta, realtype *v) { realtype ajj, s, mu, v1, v1_2; realtype *col_j, *col_k; @@ -270,7 +342,7 @@ int denseGEQRF(realtype **a, sunindextype m, sunindextype n, realtype *beta, rea col_j = a[j]; ajj = col_j[j]; - + /* Compute the j-th Householder vector (of length m-j) */ v[0] = ONE; s = ZERO; @@ -286,7 +358,7 @@ int denseGEQRF(realtype **a, sunindextype m, sunindextype n, realtype *beta, rea beta[j] = TWO * v1_2 / (s + v1_2); for(i=1; i= n. * * v (of length m) must be provided as workspace. */ + int denseORMQR(realtype **a, sunindextype m, sunindextype n, realtype *beta, realtype *vn, realtype *vm, realtype *v) +{ + return(SUNDlsMat_denseORMQR(a, m, n, beta, vn, vm, v)); +} + +int SUNDlsMat_denseORMQR(realtype **a, sunindextype m, sunindextype n, realtype *beta, + realtype *vn, realtype *vm, realtype *v) { realtype *col_j, s; sunindextype i, j; @@ -350,6 +429,11 @@ int denseORMQR(realtype **a, sunindextype m, sunindextype n, realtype *beta, } void denseCopy(realtype **a, realtype **b, sunindextype m, sunindextype n) +{ + SUNDlsMat_denseCopy(a, b, m, n); +} + +void SUNDlsMat_denseCopy(realtype **a, realtype **b, sunindextype m, sunindextype n) { sunindextype i, j; realtype *a_col_j, *b_col_j; @@ -364,6 +448,11 @@ void denseCopy(realtype **a, realtype **b, sunindextype m, sunindextype n) } void denseScale(realtype c, realtype **a, sunindextype m, sunindextype n) +{ + SUNDlsMat_denseScale(c, a, m, n); +} + +void SUNDlsMat_denseScale(realtype c, realtype **a, sunindextype m, sunindextype n) { sunindextype i, j; realtype *col_j; @@ -376,13 +465,23 @@ void denseScale(realtype c, realtype **a, sunindextype m, sunindextype n) } void denseAddIdentity(realtype **a, sunindextype n) +{ + SUNDlsMat_denseAddIdentity(a, n); +} + +void SUNDlsMat_denseAddIdentity(realtype **a, sunindextype n) { sunindextype i; - + for (i=0; i < n; i++) a[i][i] += ONE; } void denseMatvec(realtype **a, realtype *x, realtype *y, sunindextype m, sunindextype n) +{ + SUNDlsMat_denseMatvec(a, x, y, m, n); +} + +void SUNDlsMat_denseMatvec(realtype **a, realtype *x, realtype *y, sunindextype m, sunindextype n) { sunindextype i, j; realtype *col_j; diff --git a/src/sundials/sundials/sundials_direct.c b/src/sundials/sundials/sundials_direct.c index 612378d..eb5eba5 100644 --- a/src/sundials/sundials/sundials_direct.c +++ b/src/sundials/sundials/sundials_direct.c @@ -2,7 +2,7 @@ * Programmer: Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -13,7 +13,7 @@ * ----------------------------------------------------------------- * This is the implementation file for operations to be used by a * generic direct linear solver. - * -----------------------------------------------------------------*/ + * -----------------------------------------------------------------*/ #include #include @@ -24,17 +24,22 @@ #define ZERO RCONST(0.0) #define ONE RCONST(1.0) -DlsMat NewDenseMat(sunindextype M, sunindextype N) +SUNDlsMat NewDenseMat(sunindextype M, sunindextype N) { - DlsMat A; + return(SUNDlsMat_NewDenseMat(M, N)); +} + +SUNDlsMat SUNDlsMat_NewDenseMat(sunindextype M, sunindextype N) +{ + SUNDlsMat A; sunindextype j; if ( (M <= 0) || (N <= 0) ) return(NULL); A = NULL; - A = (DlsMat) malloc(sizeof *A); + A = (SUNDlsMat) malloc(sizeof *A); if (A==NULL) return (NULL); - + A->data = (realtype *) malloc(M * N * sizeof(realtype)); if (A->data == NULL) { free(A); A = NULL; @@ -59,7 +64,12 @@ DlsMat NewDenseMat(sunindextype M, sunindextype N) return(A); } -realtype **newDenseMat(sunindextype m, sunindextype n) +realtype** newDenseMat(sunindextype m, sunindextype n) +{ + return(SUNDlsMat_newDenseMat(m, n)); +} + +realtype** SUNDlsMat_newDenseMat(sunindextype m, sunindextype n) { sunindextype j; realtype **a; @@ -83,15 +93,20 @@ realtype **newDenseMat(sunindextype m, sunindextype n) } -DlsMat NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, sunindextype smu) +SUNDlsMat NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, sunindextype smu) { - DlsMat A; + return(SUNDlsMat_NewBandMat(N, mu, ml, smu)); +} + +SUNDlsMat SUNDlsMat_NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, sunindextype smu) +{ + SUNDlsMat A; sunindextype j, colSize; if (N <= 0) return(NULL); - + A = NULL; - A = (DlsMat) malloc(sizeof *A); + A = (SUNDlsMat) malloc(sizeof *A); if (A == NULL) return (NULL); colSize = smu + ml + 1; @@ -125,7 +140,12 @@ DlsMat NewBandMat(sunindextype N, sunindextype mu, sunindextype ml, sunindextype return(A); } -realtype **newBandMat(sunindextype n, sunindextype smu, sunindextype ml) +realtype** newBandMat(sunindextype n, sunindextype smu, sunindextype ml) +{ + return(SUNDlsMat_newBandMat(n, smu, ml)); +} + +realtype** SUNDlsMat_newBandMat(sunindextype n, sunindextype smu, sunindextype ml) { realtype **a; sunindextype j, colSize; @@ -149,7 +169,12 @@ realtype **newBandMat(sunindextype n, sunindextype smu, sunindextype ml) return(a); } -void DestroyMat(DlsMat A) +void DestroyMat(SUNDlsMat A) +{ + SUNDlsMat_DestroyMat(A); +} + +void SUNDlsMat_DestroyMat(SUNDlsMat A) { free(A->data); A->data = NULL; free(A->cols); @@ -157,12 +182,22 @@ void DestroyMat(DlsMat A) } void destroyMat(realtype **a) +{ + SUNDlsMat_destroyMat(a); +} + +void SUNDlsMat_destroyMat(realtype **a) { free(a[0]); a[0] = NULL; free(a); a = NULL; } -int *NewIntArray(int N) +int* NewIntArray(int N) +{ + return(SUNDlsMat_NewIntArray(N)); +} + +int* SUNDlsMat_NewIntArray(int N) { int *vec; @@ -174,7 +209,12 @@ int *NewIntArray(int N) return(vec); } -int *newIntArray(int n) +int* newIntArray(int N) +{ + return(SUNDlsMat_newIntArray(N)); +} + +int* SUNDlsMat_newIntArray(int n) { int *v; @@ -186,7 +226,12 @@ int *newIntArray(int n) return(v); } -sunindextype *NewIndexArray(sunindextype N) +sunindextype* NewIndexArray(sunindextype N) +{ + return(SUNDlsMat_NewIndexArray(N)); +} + +sunindextype* SUNDlsMat_NewIndexArray(sunindextype N) { sunindextype *vec; @@ -198,7 +243,12 @@ sunindextype *NewIndexArray(sunindextype N) return(vec); } -sunindextype *newIndexArray(sunindextype n) +sunindextype* newIndexArray(sunindextype n) +{ + return(SUNDlsMat_newIndexArray(n)); +} + +sunindextype* SUNDlsMat_newIndexArray(sunindextype n) { sunindextype *v; @@ -210,7 +260,12 @@ sunindextype *newIndexArray(sunindextype n) return(v); } -realtype *NewRealArray(sunindextype N) +realtype* NewRealArray(sunindextype N) +{ + return(SUNDlsMat_NewRealArray(N)); +} + +realtype* SUNDlsMat_NewRealArray(sunindextype N) { realtype *vec; @@ -222,7 +277,12 @@ realtype *NewRealArray(sunindextype N) return(vec); } -realtype *newRealArray(sunindextype m) +realtype* newRealArray(sunindextype N) +{ + return(SUNDlsMat_newRealArray(N)); +} + +realtype* SUNDlsMat_newRealArray(sunindextype m) { realtype *v; @@ -234,20 +294,34 @@ realtype *newRealArray(sunindextype m) return(v); } -void DestroyArray(void *V) -{ - free(V); +void DestroyArray(void *p) +{ + SUNDlsMat_DestroyArray(p); +} + +void SUNDlsMat_DestroyArray(void *V) +{ + free(V); V = NULL; } -void destroyArray(void *v) +void destroyArray(void *p) { - free(v); + SUNDlsMat_destroyArray(p); +} + +void SUNDlsMat_destroyArray(void *v) +{ + free(v); v = NULL; } +void AddIdentity(SUNDlsMat A) +{ + SUNDlsMat_AddIdentity(A); +} -void AddIdentity(DlsMat A) +void SUNDlsMat_AddIdentity(SUNDlsMat A) { sunindextype i; @@ -265,8 +339,12 @@ void AddIdentity(DlsMat A) } +void SetToZero(SUNDlsMat A) +{ + SUNDlsMat_SetToZero(A); +} -void SetToZero(DlsMat A) +void SUNDlsMat_SetToZero(SUNDlsMat A) { sunindextype i, j, colSize; realtype *col_j; @@ -274,7 +352,7 @@ void SetToZero(DlsMat A) switch (A->type) { case SUNDIALS_DENSE: - + for (j=0; jN; j++) { col_j = A->cols[j]; for (i=0; iM; i++) @@ -298,8 +376,12 @@ void SetToZero(DlsMat A) } +void PrintMat(SUNDlsMat A, FILE *outfile) +{ + SUNDlsMat_PrintMat(A, outfile); +} -void PrintMat(DlsMat A, FILE *outfile) +void SUNDlsMat_PrintMat(SUNDlsMat A, FILE *outfile) { sunindextype i, j, start, finish; realtype **a; @@ -312,17 +394,17 @@ void PrintMat(DlsMat A, FILE *outfile) for (i=0; i < A->M; i++) { for (j=0; j < A->N; j++) { #if defined(SUNDIALS_EXTENDED_PRECISION) - fprintf(outfile, "%12Lg ", DENSE_ELEM(A,i,j)); + fprintf(outfile, "%12Lg ", SUNDLS_DENSE_ELEM(A,i,j)); #elif defined(SUNDIALS_DOUBLE_PRECISION) - fprintf(outfile, "%12g ", DENSE_ELEM(A,i,j)); + fprintf(outfile, "%12g ", SUNDLS_DENSE_ELEM(A,i,j)); #else - fprintf(outfile, "%12g ", DENSE_ELEM(A,i,j)); + fprintf(outfile, "%12g ", SUNDLS_DENSE_ELEM(A,i,j)); #endif } fprintf(outfile, "\n"); } fprintf(outfile, "\n"); - + break; case SUNDIALS_BAND: @@ -345,11 +427,9 @@ void PrintMat(DlsMat A, FILE *outfile) fprintf(outfile, "\n"); } fprintf(outfile, "\n"); - + break; } } - - diff --git a/src/sundials/sundials/sundials_iterative.c b/src/sundials/sundials/sundials_iterative.c index 6b1055c..76a0259 100644 --- a/src/sundials/sundials/sundials_iterative.c +++ b/src/sundials/sundials/sundials_iterative.c @@ -1,13 +1,10 @@ -/* - * ----------------------------------------------------------------- - * $Revision$ - * $Date$ - * ----------------------------------------------------------------- +/* ----------------------------------------------------------------- * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh and * Radu Serban @ LLNL + * Shelby Lockhart @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,12 +16,11 @@ * This is the implementation file for the iterative.h header * file. It contains the implementation of functions that may be * useful for many different iterative solvers of A x = b. - * ----------------------------------------------------------------- - */ + * -----------------------------------------------------------------*/ #include -#include +#include "sundials_iterative_impl.h" #include #define FACTOR RCONST(1000.0) @@ -33,26 +29,32 @@ /* * ----------------------------------------------------------------- - * Function : ModifiedGS + * Function : SUNModifiedGS * ----------------------------------------------------------------- - * This implementation of ModifiedGS is a slight modification of a - * previous modified Gram-Schmidt routine (called mgs) written by + * This implementation of SUNModifiedGS is a slight modification of + * a previous modified Gram-Schmidt routine (called mgs) written by * Milo Dorr. * ----------------------------------------------------------------- */ - -int ModifiedGS(N_Vector *v, realtype **h, int k, int p, + +int ModifiedGS(N_Vector *v, realtype **h, int k, int p, realtype *new_vk_norm) +{ + return(SUNModifiedGS(v, h, k, p, new_vk_norm)); +} + +int SUNModifiedGS(N_Vector *v, realtype **h, int k, int p, + realtype *new_vk_norm) { int i, k_minus_1, i0; realtype new_norm_2, new_product, vk_norm, temp; - + vk_norm = SUNRsqrt(N_VDotProd(v[k],v[k])); k_minus_1 = k - 1; i0 = SUNMAX(k-p, 0); - + /* Perform modified Gram-Schmidt */ - + for (i=i0; i < k; i++) { h[i][k_minus_1] = N_VDotProd(v[i], v[k]); N_VLinearSum(ONE, v[k], -h[i][k_minus_1], v[i], v[k]); @@ -70,7 +72,7 @@ int ModifiedGS(N_Vector *v, realtype **h, int k, int p, temp = FACTOR * vk_norm; if ((temp + (*new_vk_norm)) != temp) return(0); - + new_norm_2 = ZERO; for (i=i0; i < k; i++) { @@ -92,15 +94,21 @@ int ModifiedGS(N_Vector *v, realtype **h, int k, int p, /* * ----------------------------------------------------------------- - * Function : ClassicalGS + * Function : SUNClassicalGS * ----------------------------------------------------------------- - * This implementation of ClassicalGS was contributed by Homer Walker - * and Peter Brown. + * This implementation of SUNClassicalGS was contributed by Homer + * Walker and Peter Brown. * ----------------------------------------------------------------- */ int ClassicalGS(N_Vector *v, realtype **h, int k, int p, realtype *new_vk_norm, realtype *stemp, N_Vector *vtemp) +{ + return(SUNClassicalGS(v, h, k, p, new_vk_norm, stemp, vtemp)); +} + +int SUNClassicalGS(N_Vector *v, realtype **h, int k, int p, realtype *new_vk_norm, + realtype *stemp, N_Vector *vtemp) { int i, i0, k_minus_1, retval; realtype vk_norm; @@ -155,14 +163,19 @@ int ClassicalGS(N_Vector *v, realtype **h, int k, int p, realtype *new_vk_norm, /* * ----------------------------------------------------------------- - * Function : QRfact + * Function : SUNQRfact * ----------------------------------------------------------------- - * This implementation of QRfact is a slight modification of a + * This implementation of SUNQRfact is a slight modification of a * previous routine (called qrfact) written by Milo Dorr. * ----------------------------------------------------------------- */ int QRfact(int n, realtype **h, realtype *q, int job) +{ + return(SUNQRfact(n, h, q, job)); +} + +int SUNQRfact(int n, realtype **h, realtype *q, int job) { realtype c, s, temp1, temp2, temp3; int i, j, k, q_ptr, n_minus_1, code=0; @@ -174,35 +187,35 @@ int QRfact(int n, realtype **h, realtype *q, int job) code = 0; for (k=0; k < n; k++) { - + /* Multiply column k by the previous k-1 Givens rotations */ for (j=0; j < k-1; j++) { - i = 2*j; - temp1 = h[j][k]; - temp2 = h[j+1][k]; - c = q[i]; - s = q[i+1]; - h[j][k] = c*temp1 - s*temp2; - h[j+1][k] = s*temp1 + c*temp2; + i = 2*j; + temp1 = h[j][k]; + temp2 = h[j+1][k]; + c = q[i]; + s = q[i+1]; + h[j][k] = c*temp1 - s*temp2; + h[j+1][k] = s*temp1 + c*temp2; } - + /* Compute the Givens rotation components c and s */ q_ptr = 2*k; temp1 = h[k][k]; temp2 = h[k+1][k]; if( temp2 == ZERO) { - c = ONE; - s = ZERO; + c = ONE; + s = ZERO; } else if (SUNRabs(temp2) >= SUNRabs(temp1)) { - temp3 = temp1/temp2; - s = -ONE/SUNRsqrt(ONE+SUNSQR(temp3)); - c = -s*temp3; + temp3 = temp1/temp2; + s = -ONE/SUNRsqrt(ONE+SUNSQR(temp3)); + c = -s*temp3; } else { - temp3 = temp2/temp1; - c = ONE/SUNRsqrt(ONE+SUNSQR(temp3)); - s = -c*temp3; + temp3 = temp2/temp1; + c = ONE/SUNRsqrt(ONE+SUNSQR(temp3)); + s = -c*temp3; } q[q_ptr] = c; q[q_ptr+1] = s; @@ -216,7 +229,7 @@ int QRfact(int n, realtype **h, realtype *q, int job) n_minus_1 = n - 1; code = 0; - + /* Multiply the new column by the previous n-1 Givens rotations */ for (k=0; k < n_minus_1; k++) { @@ -228,9 +241,9 @@ int QRfact(int n, realtype **h, realtype *q, int job) h[k][n_minus_1] = c*temp1 - s*temp2; h[k+1][n_minus_1] = s*temp1 + c*temp2; } - + /* Compute new Givens rotation and multiply it times the last two - entries in the new column of H. Note that the second entry of + entries in the new column of H. Note that the second entry of this product will be 0, so it is not necessary to compute it. */ temp1 = h[n_minus_1][n_minus_1]; @@ -253,26 +266,31 @@ int QRfact(int n, realtype **h, realtype *q, int job) if ((h[n_minus_1][n_minus_1] = c*temp1 - s*temp2) == ZERO) code = n; } - + return (code); } /* * ----------------------------------------------------------------- - * Function : QRsol + * Function : SUNQRsol * ----------------------------------------------------------------- - * This implementation of QRsol is a slight modification of a + * This implementation of SUNQRsol is a slight modification of a * previous routine (called qrsol) written by Milo Dorr. * ----------------------------------------------------------------- */ int QRsol(int n, realtype **h, realtype *q, realtype *b) +{ + return(SUNQRsol(n, h, q, b)); +} + +int SUNQRsol(int n, realtype **h, realtype *q, realtype *b) { realtype c, s, temp1, temp2; int i, k, q_ptr, code=0; /* Compute Q*b */ - + for (k=0; k < n; k++) { q_ptr = 2*k; c = q[q_ptr]; @@ -293,6 +311,297 @@ int QRsol(int n, realtype **h, realtype *q, realtype *b) b[k] /= h[k][k]; for (i=0; i < k; i++) b[i] -= b[k]*h[i][k]; } - + return (code); } + + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_MGS + * ----------------------------------------------------------------- + * Implementation of QRAdd to be called in Anderson Acceleration + * ----------------------------------------------------------------- + */ + +int SUNQRAdd_MGS(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata) +{ + sunindextype j; + SUNQRData qrdata = (SUNQRData) QRdata; + + N_VScale(ONE, df, qrdata->vtemp); + for (j=0; j < m; j++) { + R[m * mMax + j] = N_VDotProd(Q[j], qrdata->vtemp); + N_VLinearSum(ONE, qrdata->vtemp, -R[m * mMax + j], Q[j], qrdata->vtemp); + } + R[m * mMax + m] = SUNRsqrt(N_VDotProd(qrdata->vtemp, qrdata->vtemp)); + N_VScale((1/R[m * mMax + m]), qrdata->vtemp, Q[m]); + + /* Return success */ + return 0; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_ICWY + * ----------------------------------------------------------------- + * Low synchronous implementation of QRAdd to be called in + * Anderson Acceleration. + * ----------------------------------------------------------------- + */ + +int SUNQRAdd_ICWY(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata) +{ + sunindextype j, k; + SUNQRData qrdata = (SUNQRData) QRdata; + + N_VScale(ONE, df, qrdata->vtemp); /* stores d_fi in temp */ + + if (m > 0) { + /* T(1:k-1,k-1)^T = Q(:,1:k-1)^T * Q(:,k-1) */ + N_VDotProdMulti(m, Q[m-1], Q, qrdata->temp_array + (m-1) * mMax); + + /* T(k-1,k-1) = 1.0 */ + qrdata->temp_array[(m-1) * mMax + (m-1)] = ONE; + + /* R(1:k-1,k) = Q_k-1^T * df */ + N_VDotProdMulti(m, qrdata->vtemp, Q, R + m * mMax ); + + /* Solve T^T * R(1:k-1,k) = R(1:k-1,k) */ + for (k = 0; k < m; k++) { + /* Skip setting the diagonal element because it doesn't change */ + for (j = k+1; j < m; j++) { + R[m * mMax + j] -= R[m * mMax + k] * qrdata->temp_array[j * mMax + k]; + } + } + /* end */ + + /* Q(:,k-1) = df - Q_k-1 R(1:k-1,k) */ + N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = SUNRsqrt(N_VDotProd(qrdata->vtemp, qrdata->vtemp)); + /* Q(:,k) = df / \| df \| */ + N_VScale((1/R[m * mMax + m]), qrdata->vtemp, Q[m]); + + /* Return success */ + return 0; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_ICWY_SB + * ----------------------------------------------------------------- + * Low synchronous implementation of QRAdd to be called in + * Anderson Acceleration which utilizes a single buffer reduction. + * ----------------------------------------------------------------- + */ + +int SUNQRAdd_ICWY_SB(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata) +{ + sunindextype j, k; + SUNQRData qrdata = (SUNQRData) QRdata; + + N_VScale(ONE, df, qrdata->vtemp); /* stores d_fi in temp */ + + if (m > 0) { + /* T(1:k-1,k-1)^T = Q(:,1:k-1)^T * Q(:,k-1) */ + N_VDotProdMultiLocal(m, Q[m-1], Q, qrdata->temp_array + (m-1) * mMax); + + /* R(1:k-1,k) = Q_k-1^T * df */ + /* Put R values at end of temp_array */ + N_VDotProdMultiLocal(m, qrdata->vtemp, Q, qrdata->temp_array + (m-1) * mMax + m ); + N_VDotProdMultiAllReduce(m+m, qrdata->vtemp, qrdata->temp_array + (m-1) * mMax); + + /* Move the last values from temp array into R */ + for (k = 0; k < m; k++) { + R[m*mMax + k] = qrdata->temp_array[(m-1)*mMax + m + k]; + } + + /* T(k-1,k-1) = 1.0 */ + qrdata->temp_array[(m-1) * mMax + (m-1)] = ONE; + + /* Solve T^T * R(1:k-1,k) = R(1:k-1,k) */ + for (k = 0; k < m; k++) { + /* Skip setting the diagonal element because it doesn't change */ + for (j = k+1; j < m; j++) { + R[m * mMax + j] -= R[m * mMax + k] * qrdata->temp_array[j * mMax + k]; + } + } + /* end */ + + /* Q(:,k-1) = df - Q_k-1 R(1:k-1,k) */ + N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = SUNRsqrt(N_VDotProd(qrdata->vtemp, qrdata->vtemp)); + /* Q(:,k) = df / \| df \| */ + N_VScale((1/R[m * mMax + m]), qrdata->vtemp, Q[m]); + + /* Return success */ + return 0; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_CGS2 + * ----------------------------------------------------------------- + * Low synchronous Implementation of QRAdd to be called in + * Anderson Acceleration. + * ----------------------------------------------------------------- + */ + +int SUNQRAdd_CGS2(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata) +{ + sunindextype j; + SUNQRData qrdata = (SUNQRData) QRdata; + + N_VScale(ONE, df, qrdata->vtemp); /* temp = df */ + + if (m > 0) { + /* s_k = Q_k-1^T df_aa -- update with sdata as a realtype* array */ + N_VDotProdMulti(m, qrdata->vtemp, Q, R + m * mMax); + + /* y = df - Q_k-1 s_k */ + N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp2); + + /* z_k = Q_k-1^T y */ + N_VDotProdMulti(m, qrdata->vtemp2, Q, qrdata->temp_array); + + /* df = y - Q_k-1 z_k -- update using N_VLinearCombination */ + N_VLinearCombination(m, qrdata->temp_array, Q, Q[m]); + N_VLinearSum(ONE, qrdata->vtemp2, -ONE, Q[m], qrdata->vtemp); + + /* R(1:k-1,k) = s_k + z_k */ + for (j = 0; j < m; j++) { + R[m * mMax + j] = R[m * mMax + j] + qrdata->temp_array[j]; + } + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = SUNRsqrt(N_VDotProd(qrdata->vtemp, qrdata->vtemp)); + /* Q(:,k) = df / R(k,k) */ + N_VScale((1/R[m * mMax + m]), qrdata->vtemp, Q[m]); + + /* Return success */ + return 0; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_DCGS2 + * ----------------------------------------------------------------- + * Low synchronous Implementation of QRAdd to be called in + * Anderson Acceleration. + * ----------------------------------------------------------------- + */ + +int SUNQRAdd_DCGS2(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata) +{ + sunindextype j; + SUNQRData qrdata = (SUNQRData) QRdata; + + N_VScale(ONE, df, qrdata->vtemp); /* temp = df */ + + if (m > 0) { + /* R(1:k-1,k) = Q_k-1^T df_aa */ + N_VDotProdMulti(m, qrdata->vtemp, Q, R + m*mMax); + /* Delayed reorthogonalization */ + if (m > 1) { + /* s = Q_k-2^T Q(:,k-1) */ + N_VDotProdMulti(m-1, Q[m-1], Q, qrdata->temp_array); + + /* Q(:,k-1) = Q(:,k-1) - Q_k-2 s */ + N_VLinearCombination(m-1, qrdata->temp_array, Q, qrdata->vtemp2); + N_VLinearSum(ONE, Q[m-1], -ONE, qrdata->vtemp2, Q[m-1]); + + /* R(1:k-2,k-1) = R(1:k-2,k-1) + s */ + for (j = 0; j < m-1; j++) { + R[(m-1) * mMax + j] = R[(m-1) * mMax + j] + qrdata->temp_array[j]; + } + } + + /* df = df - Q(:,k-1) R(1:k-1,k) */ + N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = SUNRsqrt(N_VDotProd(qrdata->vtemp, qrdata->vtemp)); + /* Q(:,k) = df / R(k,k) */ + N_VScale((1/R[m * mMax + m]), qrdata->vtemp, Q[m]); + + /* Return success */ + return 0; +} + +/* + * ----------------------------------------------------------------- + * Function : SUNQRAdd_DCGS2_SB + * ----------------------------------------------------------------- + * Low synchronous Implementation of QRAdd to be called in + * Anderson Acceleration which utilizes a single buffer reduction. + * ----------------------------------------------------------------- + */ + +int SUNQRAdd_DCGS2_SB(N_Vector *Q, realtype *R, N_Vector df, + int m, int mMax, void *QRdata) +{ + sunindextype j; + SUNQRData qrdata = (SUNQRData) QRdata; + + N_VScale(ONE, df, qrdata->vtemp); /* temp = df */ + + if (m > 0) { + if (m == 1) { + /* R(1:k-1,k) = Q_k-1^T df_aa */ + N_VDotProdMulti(m, qrdata->vtemp, Q, R + m*mMax); + } + /* Delayed reorthogonalization */ + else if (m > 1) { + /* R(1:k-1,k) = Q_k-1^T df_aa */ + /* Put R values at beginning of temp array */ + N_VDotProdMultiLocal(m, qrdata->vtemp, Q, qrdata->temp_array); + + /* s = Q_k-2^T Q(:,k-1) */ + N_VDotProdMultiLocal(m-1, Q[m-1], Q, qrdata->temp_array + m); + N_VDotProdMultiAllReduce(m + m-1, qrdata->vtemp, qrdata->temp_array); + + /* Move R values to R */ + for (j = 0; j < m; j++) { + R[m*mMax + j] = qrdata->temp_array[j]; + } + + /* Q(:,k-1) = Q(:,k-1) - Q_k-2 s */ + N_VLinearCombination(m-1, qrdata->temp_array + m, Q, qrdata->vtemp2); + N_VLinearSum(ONE, Q[m-1], -ONE, qrdata->vtemp2, Q[m-1]); + + /* R(1:k-2,k-1) = R(1:k-2,k-1) + s */ + for (j = 0; j < m-1; j++) { + R[(m-1) * mMax + j] = R[(m-1) * mMax + j] + qrdata->temp_array[m + j]; + } + } + + /* df = df - Q(:,k-1) R(1:k-1,k) */ + N_VLinearCombination(m, R + m * mMax, Q, qrdata->vtemp2); + N_VLinearSum(ONE, qrdata->vtemp, -ONE, qrdata->vtemp2, qrdata->vtemp); + } + + /* R(k,k) = \| df \| */ + R[m * mMax + m] = SUNRsqrt(N_VDotProd(qrdata->vtemp, qrdata->vtemp)); + /* Q(:,k) = df / R(k,k) */ + N_VScale((1/R[m * mMax + m]), qrdata->vtemp, Q[m]); + + /* Return success */ + return 0; +} diff --git a/src/sundials/sundials/sundials_iterative_impl.h b/src/sundials/sundials/sundials_iterative_impl.h new file mode 100644 index 0000000..fed1c72 --- /dev/null +++ b/src/sundials/sundials/sundials_iterative_impl.h @@ -0,0 +1,35 @@ +/* ----------------------------------------------------------------------------- + * Programmer(s): David J. Gardner and Shelby Lockhart @ LLNL + * ----------------------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2022, 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 + * ----------------------------------------------------------------------------- + * This is the implementation header file for SUNDIALS functions used by + * different iterative solvers. + * ---------------------------------------------------------------------------*/ + +#include + +/* ----------------------------------------------------------------------------- + * Type: SUNQRData + * ----------------------------------------------------------------------------- + * A SUNQRData struct holds temporary workspace vectors and realtype arrays for + * a SUNQRAddFn. The N_Vectors and realtype arrays it contains are created by + * the routine calling a SUNQRAdd function. + * ---------------------------------------------------------------------------*/ + +typedef struct _SUNQRData *SUNQRData; + +struct _SUNQRData +{ + N_Vector vtemp; + N_Vector vtemp2; + realtype *temp_array; +}; diff --git a/src/sundials/sundials/sundials_linearsolver.c b/src/sundials/sundials/sundials_linearsolver.c index 28f5e48..7a2a62e 100644 --- a/src/sundials/sundials/sundials_linearsolver.c +++ b/src/sundials/sundials/sundials_linearsolver.c @@ -4,7 +4,7 @@ * Slaven Peles @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -20,16 +20,27 @@ #include #include +#include "sundials_context_impl.h" + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) +static SUNProfiler getSUNProfiler(SUNLinearSolver S) +{ + return(S->sunctx->profiler); +} +#endif /* ----------------------------------------------------------------- * Create a new empty SUNLinearSolver object * ----------------------------------------------------------------- */ -SUNLinearSolver SUNLinSolNewEmpty() +SUNLinearSolver SUNLinSolNewEmpty(SUNContext sunctx) { SUNLinearSolver LS; SUNLinearSolver_Ops ops; + /* a context is required */ + if (sunctx == NULL) return(NULL); + /* create linear solver object */ LS = NULL; LS = (SUNLinearSolver) malloc(sizeof *LS); @@ -57,9 +68,10 @@ SUNLinearSolver SUNLinSolNewEmpty() ops->space = NULL; ops->free = NULL; - /* attach ops and initialize content to NULL */ + /* attach ops and initialize content and context to NULL */ LS->ops = ops; LS->content = NULL; + LS->sunctx = sunctx; return(LS); } @@ -99,31 +111,43 @@ SUNLinearSolver_ID SUNLinSolGetID(SUNLinearSolver S) } int SUNLinSolSetATimes(SUNLinearSolver S, void* A_data, - ATimesFn ATimes) + SUNATimesFn ATimes) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->setatimes) - return ((int) S->ops->setatimes(S, A_data, ATimes)); + ier = S->ops->setatimes(S, A_data, ATimes); else - return SUNLS_SUCCESS; + ier = SUNLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(ier); } int SUNLinSolSetPreconditioner(SUNLinearSolver S, void* P_data, - PSetupFn Pset, PSolveFn Psol) + SUNPSetupFn Pset, SUNPSolveFn Psol) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->setpreconditioner) - return ((int) S->ops->setpreconditioner(S, P_data, Pset, Psol)); + ier = S->ops->setpreconditioner(S, P_data, Pset, Psol); else - return SUNLS_SUCCESS; + ier = SUNLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(ier); } int SUNLinSolSetScalingVectors(SUNLinearSolver S, N_Vector s1, N_Vector s2) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->setscalingvectors) - return ((int) S->ops->setscalingvectors(S, s1, s2)); + ier = S->ops->setscalingvectors(S, s1, s2); else - return SUNLS_SUCCESS; + ier = SUNLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(ier); } int SUNLinSolSetZeroGuess(SUNLinearSolver S, booleantype onoff) @@ -136,48 +160,70 @@ int SUNLinSolSetZeroGuess(SUNLinearSolver S, booleantype onoff) int SUNLinSolInitialize(SUNLinearSolver S) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->initialize) - return ((int) S->ops->initialize(S)); + ier = S->ops->initialize(S); else - return SUNLS_SUCCESS; + ier = SUNLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(ier); } int SUNLinSolSetup(SUNLinearSolver S, SUNMatrix A) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->setup) - return ((int) S->ops->setup(S, A)); + ier = S->ops->setup(S, A); else - return SUNLS_SUCCESS; + ier = SUNLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(ier); } int SUNLinSolSolve(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, realtype tol) { - return ((int) S->ops->solve(S, A, x, b, tol)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); + ier = S->ops->solve(S, A, x, b, tol); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(ier); } int SUNLinSolNumIters(SUNLinearSolver S) { + int ier; if (S->ops->numiters) - return ((int) S->ops->numiters(S)); + ier = S->ops->numiters(S); else - return 0; + ier = 0; + return(ier); } realtype SUNLinSolResNorm(SUNLinearSolver S) { + double result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->resnorm) - return ((realtype) S->ops->resnorm(S)); + result = S->ops->resnorm(S); else - return RCONST(0.0); + result = RCONST(0.0); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(result); } N_Vector SUNLinSolResid(SUNLinearSolver S) { + N_Vector resid; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->resid) - return ((N_Vector) S->ops->resid(S)); + resid = S->ops->resid(S); else - return NULL; + resid = NULL; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); + return(resid); } sunindextype SUNLinSolLastFlag(SUNLinearSolver S) diff --git a/src/sundials/sundials/sundials_math.c b/src/sundials/sundials/sundials_math.c index e7db5ed..bafeff6 100644 --- a/src/sundials/sundials/sundials_math.c +++ b/src/sundials/sundials/sundials_math.c @@ -3,7 +3,7 @@ * Aaron Collier @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * diff --git a/src/sundials/sundials/sundials_matrix.c b/src/sundials/sundials/sundials_matrix.c index 0ffa67f..0fa0e1a 100644 --- a/src/sundials/sundials/sundials_matrix.c +++ b/src/sundials/sundials/sundials_matrix.c @@ -4,7 +4,7 @@ * Slaven Peles @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -21,16 +21,27 @@ #include #include #include +#include "sundials_context_impl.h" + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) +static SUNProfiler getSUNProfiler(SUNMatrix A) +{ + return(A->sunctx->profiler); +} +#endif /* ----------------------------------------------------------------- * Create a new empty SUNMatrix object * ----------------------------------------------------------------- */ -SUNMatrix SUNMatNewEmpty() +SUNMatrix SUNMatNewEmpty(SUNContext sunctx) { SUNMatrix A; SUNMatrix_Ops ops; + /* a context is required */ + if (sunctx == NULL) return(NULL); + /* create matrix object */ A = NULL; A = (SUNMatrix) malloc(sizeof *A); @@ -56,6 +67,7 @@ SUNMatrix SUNMatNewEmpty() /* attach ops and initialize content to NULL */ A->ops = ops; A->content = NULL; + A->sunctx = sunctx; return(A); } @@ -119,7 +131,10 @@ SUNMatrix_ID SUNMatGetID(SUNMatrix A) SUNMatrix SUNMatClone(SUNMatrix A) { SUNMatrix B = NULL; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); B = A->ops->clone(A); + B->sunctx = A->sunctx; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); return(B); } @@ -142,38 +157,64 @@ void SUNMatDestroy(SUNMatrix A) int SUNMatZero(SUNMatrix A) { - return((int) A->ops->zero(A)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); + ier = A->ops->zero(A); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } int SUNMatCopy(SUNMatrix A, SUNMatrix B) { - return((int) A->ops->copy(A, B)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); + ier = A->ops->copy(A, B); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } int SUNMatScaleAdd(realtype c, SUNMatrix A, SUNMatrix B) { - return((int) A->ops->scaleadd(c, A, B)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); + ier = A->ops->scaleadd(c, A, B); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } int SUNMatScaleAddI(realtype c, SUNMatrix A) { - return((int) A->ops->scaleaddi(c, A)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); + ier = A->ops->scaleaddi(c, A); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } int SUNMatMatvecSetup(SUNMatrix A) { + int ier = 0; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); if (A->ops->matvecsetup) - return((int) A->ops->matvecsetup(A)); - else - return(0); + ier = A->ops->matvecsetup(A); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } int SUNMatMatvec(SUNMatrix A, N_Vector x, N_Vector y) { - return((int) A->ops->matvec(A, x, y)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); + ier = A->ops->matvec(A, x, y); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } int SUNMatSpace(SUNMatrix A, long int *lenrw, long int *leniw) { - return((int) A->ops->space(A, lenrw, leniw)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(A)); + ier = A->ops->space(A, lenrw, leniw); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(A)); + return(ier); } diff --git a/src/sundials/sundials/sundials_nonlinearsolver.c b/src/sundials/sundials/sundials_nonlinearsolver.c index 85fa2f2..87c0a1e 100644 --- a/src/sundials/sundials/sundials_nonlinearsolver.c +++ b/src/sundials/sundials/sundials_nonlinearsolver.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -18,16 +18,27 @@ #include #include +#include "sundials_context_impl.h" + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) +static SUNProfiler getSUNProfiler(SUNNonlinearSolver NLS) +{ + return(NLS->sunctx->profiler); +} +#endif /* ----------------------------------------------------------------------------- * Create a new empty SUNLinearSolver object * ---------------------------------------------------------------------------*/ -SUNNonlinearSolver SUNNonlinSolNewEmpty() +SUNNonlinearSolver SUNNonlinSolNewEmpty(SUNContext sunctx) { SUNNonlinearSolver NLS; SUNNonlinearSolver_Ops ops; + /* check input */ + if (!sunctx) return(NULL); + /* create nonlinear solver object */ NLS = NULL; NLS = (SUNNonlinearSolver) malloc(sizeof *NLS); @@ -53,7 +64,8 @@ SUNNonlinearSolver SUNNonlinSolNewEmpty() ops->getcuriter = NULL; ops->getnumconvfails = NULL; - /* attach ops and initialize content to NULL */ + /* attach context and ops, initialize content to NULL */ + NLS->sunctx = sunctx; NLS->ops = ops; NLS->content = NULL; @@ -88,18 +100,26 @@ SUNNonlinearSolver_Type SUNNonlinSolGetType(SUNNonlinearSolver NLS) int SUNNonlinSolInitialize(SUNNonlinearSolver NLS) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(NLS)); if (NLS->ops->initialize) - return((int) NLS->ops->initialize(NLS)); + ier = NLS->ops->initialize(NLS); else - return(SUN_NLS_SUCCESS); + ier = SUN_NLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(NLS)); + return(ier); } int SUNNonlinSolSetup(SUNNonlinearSolver NLS, N_Vector y, void* mem) { + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(NLS)); if (NLS->ops->setup) - return((int) NLS->ops->setup(NLS, y, mem)); + ier = NLS->ops->setup(NLS, y, mem); else - return(SUN_NLS_SUCCESS); + ier = SUN_NLS_SUCCESS; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(NLS)); + return(ier); } int SUNNonlinSolSolve(SUNNonlinearSolver NLS, @@ -107,7 +127,11 @@ int SUNNonlinSolSolve(SUNNonlinearSolver NLS, N_Vector w, realtype tol, booleantype callLSetup, void* mem) { - return((int) NLS->ops->solve(NLS, y0, y, w, tol, callLSetup, mem)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(NLS)); + ier = NLS->ops->solve(NLS, y0, y, w, tol, callLSetup, mem); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(NLS)); + return(ier); } int SUNNonlinSolFree(SUNNonlinearSolver NLS) diff --git a/src/sundials/sundials/sundials_nvector.c b/src/sundials/sundials/sundials_nvector.c index d204425..e7998ee 100644 --- a/src/sundials/sundials/sundials_nvector.c +++ b/src/sundials/sundials/sundials_nvector.c @@ -4,7 +4,7 @@ * Daniel R. Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -22,16 +22,27 @@ #include #include +#include "sundials_context_impl.h" + +#if defined(SUNDIALS_BUILD_WITH_PROFILING) +static SUNProfiler getSUNProfiler(N_Vector v) +{ + return(v->sunctx->profiler); +} +#endif /* ----------------------------------------------------------------- - * Create an empty NVector object + * Methods that are not ops (i.e., non-virtual and not overridable). * -----------------------------------------------------------------*/ -N_Vector N_VNewEmpty() +/* Create an empty NVector object */ +N_Vector N_VNewEmpty(SUNContext sunctx) { N_Vector v; N_Vector_Ops ops; + if (sunctx == NULL) return(NULL); + /* create vector object */ v = NULL; v = (N_Vector) malloc(sizeof *v); @@ -44,6 +55,12 @@ N_Vector N_VNewEmpty() /* initialize operations to NULL */ + /* + * REQUIRED operations. + * + * These must be implemented by derivations of the generic N_Vector. + */ + /* constructors, destructors, and utility operations */ ops->nvgetvectorid = NULL; ops->nvclone = NULL; @@ -67,8 +84,8 @@ N_Vector N_VNewEmpty() ops->nvaddconst = NULL; ops->nvdotprod = NULL; ops->nvmaxnorm = NULL; - ops->nvwrmsnormmask = NULL; ops->nvwrmsnorm = NULL; + ops->nvwrmsnormmask = NULL; ops->nvmin = NULL; ops->nvwl2norm = NULL; ops->nvl1norm = NULL; @@ -77,6 +94,12 @@ N_Vector N_VNewEmpty() ops->nvconstrmask = NULL; ops->nvminquotient = NULL; + /* + * OPTIONAL operations. + * + * These operations provide default implementations that may be overriden. + */ + /* fused vector operations (optional) */ ops->nvlinearcombination = NULL; ops->nvscaleaddmulti = NULL; @@ -91,16 +114,24 @@ N_Vector N_VNewEmpty() ops->nvscaleaddmultivectorarray = NULL; ops->nvlinearcombinationvectorarray = NULL; + /* + * OPTIONAL operations with no default implementation. + */ + /* local reduction operations (optional) */ - ops->nvdotprodlocal = NULL; - ops->nvmaxnormlocal = NULL; - ops->nvminlocal = NULL; - ops->nvl1normlocal = NULL; - ops->nvinvtestlocal = NULL; - ops->nvconstrmasklocal = NULL; - ops->nvminquotientlocal = NULL; - ops->nvwsqrsumlocal = NULL; - ops->nvwsqrsummasklocal = NULL; + ops->nvdotprodlocal = NULL; + ops->nvmaxnormlocal = NULL; + ops->nvminlocal = NULL; + ops->nvl1normlocal = NULL; + ops->nvinvtestlocal = NULL; + ops->nvconstrmasklocal = NULL; + ops->nvminquotientlocal = NULL; + ops->nvwsqrsumlocal = NULL; + ops->nvwsqrsummasklocal = NULL; + + /* single buffer reduction operations */ + ops->nvdotprodmultilocal = NULL; + ops->nvdotprodmultiallreduce = NULL; /* XBraid interface operations */ ops->nvbufsize = NULL; @@ -111,18 +142,17 @@ N_Vector N_VNewEmpty() ops->nvprint = NULL; ops->nvprintfile = NULL; - /* attach ops and initialize content to NULL */ - v->ops = ops; + /* attach ops */ + v->ops = ops; + + /* initialize content and sunctx to NULL */ v->content = NULL; + v->sunctx = sunctx; return(v); } - -/* ----------------------------------------------------------------- - * Free a generic N_Vector (assumes content is already empty) - * -----------------------------------------------------------------*/ - +/* Free a generic N_Vector (assumes content is already empty) */ void N_VFreeEmpty(N_Vector v) { if (v == NULL) return; @@ -136,11 +166,7 @@ void N_VFreeEmpty(N_Vector v) return; } - -/* ----------------------------------------------------------------- - * Copy a vector 'ops' structure - * -----------------------------------------------------------------*/ - +/* Copy a vector 'ops' structure */ int N_VCopyOps(N_Vector w, N_Vector v) { /* Check that ops structures exist */ @@ -149,6 +175,12 @@ int N_VCopyOps(N_Vector w, N_Vector v) /* Copy ops from w to v */ + /* + * REQUIRED operations. + * + * These must be implemented by derivations of the generic N_Vector. + */ + /* constructors, destructors, and utility operations */ v->ops->nvgetvectorid = w->ops->nvgetvectorid; v->ops->nvclone = w->ops->nvclone; @@ -172,8 +204,8 @@ int N_VCopyOps(N_Vector w, N_Vector v) v->ops->nvaddconst = w->ops->nvaddconst; v->ops->nvdotprod = w->ops->nvdotprod; v->ops->nvmaxnorm = w->ops->nvmaxnorm; - v->ops->nvwrmsnormmask = w->ops->nvwrmsnormmask; v->ops->nvwrmsnorm = w->ops->nvwrmsnorm; + v->ops->nvwrmsnormmask = w->ops->nvwrmsnormmask; v->ops->nvmin = w->ops->nvmin; v->ops->nvwl2norm = w->ops->nvwl2norm; v->ops->nvl1norm = w->ops->nvl1norm; @@ -182,6 +214,12 @@ int N_VCopyOps(N_Vector w, N_Vector v) v->ops->nvconstrmask = w->ops->nvconstrmask; v->ops->nvminquotient = w->ops->nvminquotient; + /* + * OPTIONAL operations. + * + * These operations provide default implementations that may be overriden. + */ + /* fused vector operations */ v->ops->nvlinearcombination = w->ops->nvlinearcombination; v->ops->nvscaleaddmulti = w->ops->nvscaleaddmulti; @@ -196,16 +234,24 @@ int N_VCopyOps(N_Vector w, N_Vector v) v->ops->nvscaleaddmultivectorarray = w->ops->nvscaleaddmultivectorarray; v->ops->nvlinearcombinationvectorarray = w->ops->nvlinearcombinationvectorarray; + /* + * OPTIONAL operations with no default implementation. + */ + /* local reduction operations */ - v->ops->nvdotprodlocal = w->ops->nvdotprodlocal; - v->ops->nvmaxnormlocal = w->ops->nvmaxnormlocal; - v->ops->nvminlocal = w->ops->nvminlocal; - v->ops->nvl1normlocal = w->ops->nvl1normlocal; - v->ops->nvinvtestlocal = w->ops->nvinvtestlocal; - v->ops->nvconstrmasklocal = w->ops->nvconstrmasklocal; - v->ops->nvminquotientlocal = w->ops->nvminquotientlocal; - v->ops->nvwsqrsumlocal = w->ops->nvwsqrsumlocal; - v->ops->nvwsqrsummasklocal = w->ops->nvwsqrsummasklocal; + v->ops->nvdotprodlocal = w->ops->nvdotprodlocal; + v->ops->nvmaxnormlocal = w->ops->nvmaxnormlocal; + v->ops->nvminlocal = w->ops->nvminlocal; + v->ops->nvl1normlocal = w->ops->nvl1normlocal; + v->ops->nvinvtestlocal = w->ops->nvinvtestlocal; + v->ops->nvconstrmasklocal = w->ops->nvconstrmasklocal; + v->ops->nvminquotientlocal = w->ops->nvminquotientlocal; + v->ops->nvwsqrsumlocal = w->ops->nvwsqrsumlocal; + v->ops->nvwsqrsummasklocal = w->ops->nvwsqrsummasklocal; + + /* single buffer reduction operations */ + v->ops->nvdotprodmultilocal = w->ops->nvdotprodmultilocal; + v->ops->nvdotprodmultiallreduce = w->ops->nvdotprodmultiallreduce; /* XBraid interface operations */ v->ops->nvbufsize = w->ops->nvbufsize; @@ -230,12 +276,22 @@ N_Vector_ID N_VGetVectorID(N_Vector w) N_Vector N_VClone(N_Vector w) { - return(w->ops->nvclone(w)); + N_Vector result = NULL; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(w)); + result = w->ops->nvclone(w); + result->sunctx = w->sunctx; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(w)); + return result; } N_Vector N_VCloneEmpty(N_Vector w) { - return(w->ops->nvcloneempty(w)); + N_Vector result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(w)); + result = w->ops->nvcloneempty(w); + result->sunctx = w->sunctx; + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(w)); + return result; } void N_VDestroy(N_Vector v) @@ -299,167 +355,237 @@ sunindextype N_VGetLength(N_Vector v) void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvlinearsum(a, x, b, y, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } void N_VConst(realtype c, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(z)); z->ops->nvconst(c, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(z)); return; } void N_VProd(N_Vector x, N_Vector y, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvprod(x, y, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } void N_VDiv(N_Vector x, N_Vector y, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvdiv(x, y, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } void N_VScale(realtype c, N_Vector x, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvscale(c, x, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } void N_VAbs(N_Vector x, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvabs(x, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } void N_VInv(N_Vector x, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvinv(x, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } void N_VAddConst(N_Vector x, realtype b, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvaddconst(x, b, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } realtype N_VDotProd(N_Vector x, N_Vector y) { - return((realtype) y->ops->nvdotprod(x, y)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) y->ops->nvdotprod(x, y)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VMaxNorm(N_Vector x) { - return((realtype) x->ops->nvmaxnorm(x)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvmaxnorm(x)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VWrmsNorm(N_Vector x, N_Vector w) { - return((realtype) x->ops->nvwrmsnorm(x, w)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvwrmsnorm(x, w)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VWrmsNormMask(N_Vector x, N_Vector w, N_Vector id) { - return((realtype) x->ops->nvwrmsnormmask(x, w, id)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvwrmsnormmask(x, w, id)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VMin(N_Vector x) { - return((realtype) x->ops->nvmin(x)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvmin(x)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VWL2Norm(N_Vector x, N_Vector w) { - return((realtype) x->ops->nvwl2norm(x, w)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvwl2norm(x, w)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VL1Norm(N_Vector x) { - return((realtype) x->ops->nvl1norm(x)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvl1norm(x)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } void N_VCompare(realtype c, N_Vector x, N_Vector z) { + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); z->ops->nvcompare(c, x, z); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); return; } booleantype N_VInvTest(N_Vector x, N_Vector z) { - return((booleantype) z->ops->nvinvtest(x, z)); + booleantype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((booleantype) z->ops->nvinvtest(x, z)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m) { - return((booleantype) x->ops->nvconstrmask(c, x, m)); + booleantype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(c)); + result = ((booleantype) x->ops->nvconstrmask(c, x, m)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(c)); + return(result); } realtype N_VMinQuotient(N_Vector num, N_Vector denom) { - return((realtype) num->ops->nvminquotient(num, denom)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(num)); + result = ((realtype) num->ops->nvminquotient(num, denom)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(num)); + return(result); } + + /* ----------------------------------------------------------------- * OPTIONAL fused vector operations * -----------------------------------------------------------------*/ int N_VLinearCombination(int nvec, realtype* c, N_Vector* X, N_Vector z) { - int i; - realtype ONE=RCONST(1.0); + int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0])); if (z->ops->nvlinearcombination != NULL) { - return(z->ops->nvlinearcombination(nvec, c, X, z)); + ier = z->ops->nvlinearcombination(nvec, c, X, z); } else { z->ops->nvscale(c[0], X[0], z); for (i=1; iops->nvlinearsum(c[i], X[i], ONE, z, z); + z->ops->nvlinearsum(c[i], X[i], RCONST(1.0), z, z); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0])); + return(ier); } int N_VScaleAddMulti(int nvec, realtype* a, N_Vector x, N_Vector* Y, N_Vector* Z) { - int i; - realtype ONE=RCONST(1.0); + int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); if (x->ops->nvscaleaddmulti != NULL) { - return(x->ops->nvscaleaddmulti(nvec, a, x, Y, Z)); + ier = x->ops->nvscaleaddmulti(nvec, a, x, Y, Z); } else { for (i=0; iops->nvlinearsum(a[i], x, ONE, Y[i], Z[i]); + x->ops->nvlinearsum(a[i], x, RCONST(1.0), Y[i], Z[i]); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(ier); } int N_VDotProdMulti(int nvec, N_Vector x, N_Vector* Y, realtype* dotprods) { - int i; + int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); if (x->ops->nvdotprodmulti != NULL) { - return(x->ops->nvdotprodmulti(nvec, x, Y, dotprods)); + ier = x->ops->nvdotprodmulti(nvec, x, Y, dotprods); } else { for (i=0; iops->nvdotprod(x, Y[i]); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(ier); } /* ----------------------------------------------------------------- @@ -469,111 +595,126 @@ int N_VDotProdMulti(int nvec, N_Vector x, N_Vector* Y, realtype* dotprods) int N_VLinearSumVectorArray(int nvec, realtype a, N_Vector* X, realtype b, N_Vector* Y, N_Vector* Z) { - int i; + int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0])); if (Z[0]->ops->nvlinearsumvectorarray != NULL) { - return(Z[0]->ops->nvlinearsumvectorarray(nvec, a, X, b, Y, Z)); + ier = Z[0]->ops->nvlinearsumvectorarray(nvec, a, X, b, Y, Z); } else { for (i=0; iops->nvlinearsum(a, X[i], b, Y[i], Z[i]); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0])); + return(ier); } int N_VScaleVectorArray(int nvec, realtype* c, N_Vector* X, N_Vector* Z) { - int i; + int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0])); if (Z[0]->ops->nvscalevectorarray != NULL) { - return(Z[0]->ops->nvscalevectorarray(nvec, c, X, Z)); + ier = Z[0]->ops->nvscalevectorarray(nvec, c, X, Z); } else { for (i=0; iops->nvscale(c[i], X[i], Z[i]); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0])); + return(ier); } int N_VConstVectorArray(int nvec, realtype c, N_Vector* Z) { int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(Z[0])); if (Z[0]->ops->nvconstvectorarray != NULL) { ier = Z[0]->ops->nvconstvectorarray(nvec, c, Z); - return(ier); } else { for (i=0; iops->nvconst(c, Z[i]); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(Z[0])); + return(ier); } int N_VWrmsNormVectorArray(int nvec, N_Vector* X, N_Vector* W, realtype* nrm) { int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0])); if (X[0]->ops->nvwrmsnormvectorarray != NULL) { ier = X[0]->ops->nvwrmsnormvectorarray(nvec, X, W, nrm); - return(ier); } else { for (i=0; iops->nvwrmsnorm(X[i], W[i]); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0])); + return(ier); } int N_VWrmsNormMaskVectorArray(int nvec, N_Vector* X, N_Vector* W, N_Vector id, realtype* nrm) { int i, ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0])); if (id->ops->nvwrmsnormmaskvectorarray != NULL) { ier = id->ops->nvwrmsnormmaskvectorarray(nvec, X, W, id, nrm); - return(ier); } else { for (i=0; iops->nvwrmsnormmask(X[i], W[i], id); } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0])); + return(ier); } int N_VScaleAddMultiVectorArray(int nvec, int nsum, realtype* a, N_Vector* X, N_Vector** Y, N_Vector** Z) { - int i, j; - int ier=0; - realtype ONE=RCONST(1.0); - N_Vector* YY=NULL; - N_Vector* ZZ=NULL; + int i, j, ier; + N_Vector* YY = NULL; + N_Vector* ZZ = NULL; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0])); if (X[0]->ops->nvscaleaddmultivectorarray != NULL) { ier = X[0]->ops->nvscaleaddmultivectorarray(nvec, nsum, a, X, Y, Z); - return(ier); } else if (X[0]->ops->nvscaleaddmulti != NULL ) { @@ -596,31 +737,30 @@ int N_VScaleAddMultiVectorArray(int nvec, int nsum, realtype* a, N_Vector* X, free(YY); free(ZZ); - return(ier); - } else { for (i=0; iops->nvlinearsum(a[j], X[i], ONE, Y[j][i], Z[j][i]); + X[0]->ops->nvlinearsum(a[j], X[i], RCONST(1.0), Y[j][i], Z[j][i]); } } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0])); + return(ier); } int N_VLinearCombinationVectorArray(int nvec, int nsum, realtype* c, N_Vector** X, N_Vector* Z) { - int i, j; - int ier=0; - realtype ONE=RCONST(1.0); - N_Vector* Y=NULL; + int i, j, ier; + N_Vector* Y = NULL; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(X[0][0])); if (Z[0]->ops->nvlinearcombinationvectorarray != NULL) { ier = Z[0]->ops->nvlinearcombinationvectorarray(nvec, nsum, c, X, Z); - return(ier); } else if (Z[0]->ops->nvlinearcombination != NULL ) { @@ -640,18 +780,19 @@ int N_VLinearCombinationVectorArray(int nvec, int nsum, realtype* c, /* free array of vectors */ free(Y); - return(ier); - } else { for (i=0; iops->nvscale(c[0], X[0][i], Z[i]); for (j=1; jops->nvlinearsum(c[j], X[j][i], ONE, Z[i], Z[i]); + Z[0]->ops->nvlinearsum(c[j], X[j][i], RCONST(1.0), Z[i], Z[i]); } } - return(0); + ier = 0; } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(X[0][0])); + return(ier); } /* ----------------------------------------------------------------- @@ -660,47 +801,115 @@ int N_VLinearCombinationVectorArray(int nvec, int nsum, realtype* c, realtype N_VDotProdLocal(N_Vector x, N_Vector y) { - return((realtype) y->ops->nvdotprodlocal(x, y)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) y->ops->nvdotprodlocal(x, y)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VMaxNormLocal(N_Vector x) { - return((realtype) x->ops->nvmaxnormlocal(x)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvmaxnormlocal(x)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VMinLocal(N_Vector x) { - return((realtype) x->ops->nvminlocal(x)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvminlocal(x)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VL1NormLocal(N_Vector x) { - return((realtype) x->ops->nvl1normlocal(x)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvl1normlocal(x)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VWSqrSumLocal(N_Vector x, N_Vector w) { - return((realtype) x->ops->nvwsqrsumlocal(x,w)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvwsqrsumlocal(x,w)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VWSqrSumMaskLocal(N_Vector x, N_Vector w, N_Vector id) { - return((realtype) x->ops->nvwsqrsummasklocal(x,w,id)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((realtype) x->ops->nvwsqrsummasklocal(x,w,id)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } booleantype N_VInvTestLocal(N_Vector x, N_Vector z) { - return((booleantype) z->ops->nvinvtestlocal(x,z)); + booleantype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((booleantype) z->ops->nvinvtestlocal(x,z)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } booleantype N_VConstrMaskLocal(N_Vector c, N_Vector x, N_Vector m) { - return((booleantype) x->ops->nvconstrmasklocal(c,x,m)); + booleantype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + result = ((booleantype) x->ops->nvconstrmasklocal(c,x,m)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(result); } realtype N_VMinQuotientLocal(N_Vector num, N_Vector denom) { - return((realtype) num->ops->nvminquotientlocal(num,denom)); + realtype result; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(num)); + result = ((realtype) num->ops->nvminquotientlocal(num,denom)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(num)); + return(result); +} + +/* ------------------------------------------- + * OPTIONAL single buffer reduction operations + * -------------------------------------------*/ + +int N_VDotProdMultiLocal(int nvec, N_Vector x, N_Vector* Y, realtype* dotprods) +{ + int i; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + + if (x->ops->nvdotprodmultilocal) + return((int) x->ops->nvdotprodmultilocal(nvec, x, Y, dotprods)); + + if (x->ops->nvdotprodlocal) { + for (i = 0; i < nvec; i++) { + dotprods[i] = x->ops->nvdotprodlocal(x, Y[i]); + } + return(0); + } + + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(-1); +} + +int N_VDotProdMultiAllReduce(int nvec, N_Vector x, realtype* sum) +{ + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + if (x->ops->nvdotprodmultiallreduce) + return(x->ops->nvdotprodmultiallreduce(nvec, x, sum)); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(-1); } /* ------------------------------------ @@ -709,20 +918,38 @@ realtype N_VMinQuotientLocal(N_Vector num, N_Vector denom) int N_VBufSize(N_Vector x, sunindextype *size) { - if (x->ops->nvbufsize == NULL) return(-1); - return(x->ops->nvbufsize(x, size)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + if (x->ops->nvbufsize == NULL) + ier = -1; + else + ier = x->ops->nvbufsize(x, size); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(ier); } int N_VBufPack(N_Vector x, void *buf) { - if (x->ops->nvbufpack == NULL) return(-1); - return(x->ops->nvbufpack(x, buf)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + if (x->ops->nvbufpack == NULL) + ier = -1; + else + ier = x->ops->nvbufpack(x, buf); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(ier); } int N_VBufUnpack(N_Vector x, void *buf) { - if (x->ops->nvbufunpack == NULL) return(-1); - return(x->ops->nvbufunpack(x, buf)); + int ier; + SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(x)); + if (x->ops->nvbufunpack == NULL) + ier = -1; + else + ier = x->ops->nvbufunpack(x, buf); + SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(x)); + return(ier); } /* ----------------------------------------------------------------- diff --git a/src/sundials/sundials/sundials_nvector_senswrapper.c b/src/sundials/sundials/sundials_nvector_senswrapper.c index 5d56921..8cdb6b9 100644 --- a/src/sundials/sundials/sundials_nvector_senswrapper.c +++ b/src/sundials/sundials/sundials_nvector_senswrapper.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -32,87 +32,64 @@ /*------------------------------------------------------------------------------ create a new empty vector wrapper with space for vectors ----------------------------------------------------------------------------*/ -N_Vector N_VNewEmpty_SensWrapper(int nvecs) +N_Vector N_VNewEmpty_SensWrapper(int nvecs, SUNContext sunctx) { int i; N_Vector v; - N_Vector_Ops ops; N_VectorContent_SensWrapper content; /* return if wrapper is empty */ if (nvecs < 1) return(NULL); - /* create vector */ + /* Create an empty vector object */ v = NULL; - v = (N_Vector) malloc(sizeof *v); + v = N_VNewEmpty(sunctx); if (v == NULL) return(NULL); - /* create vector operation structure */ - ops = NULL; - ops = (N_Vector_Ops) malloc(sizeof *ops); - if (ops == NULL) {free(v); return(NULL);} + /* Attach operations */ - ops->nvgetvectorid = NULL; - ops->nvclone = N_VClone_SensWrapper; - ops->nvcloneempty = N_VCloneEmpty_SensWrapper; - ops->nvdestroy = N_VDestroy_SensWrapper; - ops->nvspace = NULL; - ops->nvgetarraypointer = NULL; - ops->nvsetarraypointer = NULL; + v->ops->nvclone = N_VClone_SensWrapper; + v->ops->nvcloneempty = N_VCloneEmpty_SensWrapper; + v->ops->nvdestroy = N_VDestroy_SensWrapper; /* standard vector operations */ - ops->nvlinearsum = N_VLinearSum_SensWrapper; - ops->nvconst = N_VConst_SensWrapper; - ops->nvprod = N_VProd_SensWrapper; - ops->nvdiv = N_VDiv_SensWrapper; - ops->nvscale = N_VScale_SensWrapper; - ops->nvabs = N_VAbs_SensWrapper; - ops->nvinv = N_VInv_SensWrapper; - ops->nvaddconst = N_VAddConst_SensWrapper; - ops->nvdotprod = N_VDotProd_SensWrapper; - ops->nvmaxnorm = N_VMaxNorm_SensWrapper; - ops->nvwrmsnormmask = N_VWrmsNormMask_SensWrapper; - ops->nvwrmsnorm = N_VWrmsNorm_SensWrapper; - ops->nvmin = N_VMin_SensWrapper; - ops->nvwl2norm = N_VWL2Norm_SensWrapper; - ops->nvl1norm = N_VL1Norm_SensWrapper; - ops->nvcompare = N_VCompare_SensWrapper; - ops->nvinvtest = N_VInvTest_SensWrapper; - ops->nvconstrmask = N_VConstrMask_SensWrapper; - ops->nvminquotient = N_VMinQuotient_SensWrapper; - - /* fused vector operations */ - ops->nvlinearcombination = NULL; - ops->nvscaleaddmulti = NULL; - ops->nvdotprodmulti = NULL; - - /* vector array operations */ - ops->nvlinearsumvectorarray = NULL; - ops->nvscalevectorarray = NULL; - ops->nvconstvectorarray = NULL; - ops->nvwrmsnormvectorarray = NULL; - ops->nvwrmsnormmaskvectorarray = NULL; - ops->nvscaleaddmultivectorarray = NULL; - ops->nvlinearcombinationvectorarray = NULL; + v->ops->nvlinearsum = N_VLinearSum_SensWrapper; + v->ops->nvconst = N_VConst_SensWrapper; + v->ops->nvprod = N_VProd_SensWrapper; + v->ops->nvdiv = N_VDiv_SensWrapper; + v->ops->nvscale = N_VScale_SensWrapper; + v->ops->nvabs = N_VAbs_SensWrapper; + v->ops->nvinv = N_VInv_SensWrapper; + v->ops->nvaddconst = N_VAddConst_SensWrapper; + v->ops->nvdotprod = N_VDotProd_SensWrapper; + v->ops->nvmaxnorm = N_VMaxNorm_SensWrapper; + v->ops->nvwrmsnormmask = N_VWrmsNormMask_SensWrapper; + v->ops->nvwrmsnorm = N_VWrmsNorm_SensWrapper; + v->ops->nvmin = N_VMin_SensWrapper; + v->ops->nvwl2norm = N_VWL2Norm_SensWrapper; + v->ops->nvl1norm = N_VL1Norm_SensWrapper; + v->ops->nvcompare = N_VCompare_SensWrapper; + v->ops->nvinvtest = N_VInvTest_SensWrapper; + v->ops->nvconstrmask = N_VConstrMask_SensWrapper; + v->ops->nvminquotient = N_VMinQuotient_SensWrapper; /* create content */ content = NULL; content = (N_VectorContent_SensWrapper) malloc(sizeof *content); - if (content == NULL) {free(ops); free(v); return(NULL);} + if (content == NULL) { N_VFreeEmpty(v); return(NULL); } content->nvecs = nvecs; content->own_vecs = SUNFALSE; content->vecs = NULL; content->vecs = (N_Vector*) malloc(nvecs * sizeof(N_Vector)); - if (content->vecs == NULL) {free(ops); free(v); free(content); return(NULL);} + if (content->vecs == NULL) { free(content); N_VFreeEmpty(v); return(NULL); } /* initialize vector array to null */ for (i=0; i < nvecs; i++) content->vecs[i] = NULL; - /* attach content and ops */ + /* attach content */ v->content = content; - v->ops = ops; return(v); } @@ -124,7 +101,7 @@ N_Vector N_VNew_SensWrapper(int count, N_Vector w) int i; v = NULL; - v = N_VNewEmpty_SensWrapper(count); + v = N_VNewEmpty_SensWrapper(count, w->sunctx); if (v == NULL) return(NULL); for (i=0; i < NV_NVECS_SW(v); i++) { @@ -135,6 +112,9 @@ N_Vector N_VNew_SensWrapper(int count, N_Vector w) /* update own vectors status */ NV_OWN_VECS_SW(v) = SUNTRUE; + /* set context */ + v->sunctx = w->sunctx; + return(v); } diff --git a/src/sundials/sundials/sundials_version.c b/src/sundials/sundials/sundials_version.c index e8804d0..e77b895 100644 --- a/src/sundials/sundials/sundials_version.c +++ b/src/sundials/sundials/sundials_version.c @@ -2,7 +2,7 @@ * Programmer(s): David J. Gardner @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -19,6 +19,10 @@ #include +/* note strlen does not include terminating null character hence the + use of >= when checking len below and strncpy copies up to len + characters including the terminating null character */ + /* fill string with SUNDIALS version information */ int SUNDIALSGetVersion(char *version, int len) { diff --git a/src/sundials/sunlinsol/band/sunlinsol_band.c b/src/sundials/sunlinsol/band/sunlinsol_band.c index 04e39fd..f570587 100644 --- a/src/sundials/sunlinsol/band/sunlinsol_band.c +++ b/src/sundials/sunlinsol/band/sunlinsol_band.c @@ -2,7 +2,7 @@ * Programmer(s): Daniel Reynolds @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -35,15 +35,6 @@ #define PIVOTS(S) ( BAND_CONTENT(S)->pivots ) #define LASTFLAG(S) ( BAND_CONTENT(S)->last_flag ) -/* - * ----------------------------------------------------------------- - * deprecated wrapper functions - * ----------------------------------------------------------------- - */ - -SUNLinearSolver SUNBandLinearSolver(N_Vector y, SUNMatrix A) -{ return(SUNLinSol_Band(y, A)); } - /* * ----------------------------------------------------------------- * exported functions @@ -54,7 +45,7 @@ SUNLinearSolver SUNBandLinearSolver(N_Vector y, SUNMatrix A) * Function to create a new band linear solver */ -SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A) +SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx) { SUNLinearSolver S; SUNLinearSolverContent_Band content; @@ -82,7 +73,7 @@ SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A) /* Create an empty linear solver */ S = NULL; - S = SUNLinSolNewEmpty(); + S = SUNLinSolNewEmpty(sunctx); if (S == NULL) return(NULL); /* Attach operations */ @@ -170,8 +161,8 @@ int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A) } /* perform LU factorization of input matrix */ - LASTFLAG(S) = bandGBTRF(A_cols, SM_COLUMNS_B(A), SM_UBAND_B(A), - SM_LBAND_B(A), SM_SUBAND_B(A), pivots); + LASTFLAG(S) = SUNDlsMat_bandGBTRF(A_cols, SM_COLUMNS_B(A), SM_UBAND_B(A), + SM_LBAND_B(A), SM_SUBAND_B(A), pivots); /* store error flag (if nonzero, that row encountered zero-valued pivod) */ if (LASTFLAG(S) > 0) @@ -205,8 +196,8 @@ int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, N_Vector x, } /* solve using LU factors */ - bandGBTRS(A_cols, SM_COLUMNS_B(A), SM_SUBAND_B(A), - SM_LBAND_B(A), pivots, xdata); + SUNDlsMat_bandGBTRS(A_cols, SM_COLUMNS_B(A), SM_SUBAND_B(A), + SM_LBAND_B(A), pivots, xdata); LASTFLAG(S) = SUNLS_SUCCESS; return(SUNLS_SUCCESS); } diff --git a/src/sundials/sunlinsol/dense/sunlinsol_dense.c b/src/sundials/sunlinsol/dense/sunlinsol_dense.c index 12a1b8c..efd37af 100644 --- a/src/sundials/sunlinsol/dense/sunlinsol_dense.c +++ b/src/sundials/sunlinsol/dense/sunlinsol_dense.c @@ -2,7 +2,7 @@ * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -33,16 +33,6 @@ #define PIVOTS(S) ( DENSE_CONTENT(S)->pivots ) #define LASTFLAG(S) ( DENSE_CONTENT(S)->last_flag ) - -/* - * ----------------------------------------------------------------- - * deprecated wrapper functions - * ----------------------------------------------------------------- - */ - -SUNLinearSolver SUNDenseLinearSolver(N_Vector y, SUNMatrix A) -{ return(SUNLinSol_Dense(y, A)); } - /* * ----------------------------------------------------------------- * exported functions @@ -53,7 +43,7 @@ SUNLinearSolver SUNDenseLinearSolver(N_Vector y, SUNMatrix A) * Function to create a new dense linear solver */ -SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A) +SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx) { SUNLinearSolver S; SUNLinearSolverContent_Dense content; @@ -74,7 +64,7 @@ SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A) /* Create an empty linear solver */ S = NULL; - S = SUNLinSolNewEmpty(); + S = SUNLinSolNewEmpty(sunctx); if (S == NULL) return(NULL); /* Attach operations */ @@ -156,8 +146,8 @@ int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A) } /* perform LU factorization of input matrix */ - LASTFLAG(S) = denseGETRF(A_cols, SUNDenseMatrix_Rows(A), - SUNDenseMatrix_Columns(A), pivots); + LASTFLAG(S) = SUNDlsMat_denseGETRF(A_cols, SUNDenseMatrix_Rows(A), + SUNDenseMatrix_Columns(A), pivots); /* store error flag (if nonzero, this row encountered zero-valued pivod) */ if (LASTFLAG(S) > 0) @@ -190,7 +180,7 @@ int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, N_Vector x, } /* solve using LU factors */ - denseGETRS(A_cols, SUNDenseMatrix_Rows(A), pivots, xdata); + SUNDlsMat_denseGETRS(A_cols, SUNDenseMatrix_Rows(A), pivots, xdata); LASTFLAG(S) = SUNLS_SUCCESS; return(SUNLS_SUCCESS); } diff --git a/src/sundials/sunmatrix/band/sunmatrix_band.c b/src/sundials/sunmatrix/band/sunmatrix_band.c index 6f1da1d..fb68605 100644 --- a/src/sundials/sunmatrix/band/sunmatrix_band.c +++ b/src/sundials/sunmatrix/band/sunmatrix_band.c @@ -2,11 +2,11 @@ * ----------------------------------------------------------------- * Programmer(s): Daniel Reynolds @ SMU * David Gardner @ LLNL - * Based on code sundials_band.c by: Alan C. Hindmarsh and + * Based on code sundials_band.c by: Alan C. Hindmarsh and * Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -15,10 +15,10 @@ * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- - * This is the implementation file for the band implementation of + * This is the implementation file for the band implementation of * the SUNMATRIX package. * ----------------------------------------------------------------- - */ + */ #include #include @@ -43,12 +43,13 @@ static int SMScaleAddNew_Band(realtype c, SUNMatrix A, SUNMatrix B); */ /* ---------------------------------------------------------------------------- - * Function to create a new band matrix with default storage upper bandwidth + * Function to create a new band matrix with default storage upper bandwidth */ -SUNMatrix SUNBandMatrix(sunindextype N, sunindextype mu, sunindextype ml) +SUNMatrix SUNBandMatrix(sunindextype N, sunindextype mu, + sunindextype ml, SUNContext sunctx) { - return (SUNBandMatrixStorage(N, mu, ml, mu+ml)); + return (SUNBandMatrixStorage(N, mu, ml, mu+ml, sunctx)); } /* ---------------------------------------------------------------------------- @@ -56,7 +57,8 @@ SUNMatrix SUNBandMatrix(sunindextype N, sunindextype mu, sunindextype ml) */ SUNMatrix SUNBandMatrixStorage(sunindextype N, sunindextype mu, - sunindextype ml, sunindextype smu) + sunindextype ml, sunindextype smu, + SUNContext sunctx) { SUNMatrix A; SUNMatrixContent_Band content; @@ -67,7 +69,7 @@ SUNMatrix SUNBandMatrixStorage(sunindextype N, sunindextype mu, /* Create an empty matrix object */ A = NULL; - A = SUNMatNewEmpty(); + A = SUNMatNewEmpty(sunctx); if (A == NULL) return(NULL); /* Attach operations */ @@ -113,14 +115,14 @@ SUNMatrix SUNBandMatrixStorage(sunindextype N, sunindextype mu, } /* ---------------------------------------------------------------------------- - * Function to print the band matrix + * Function to print the band matrix */ - + void SUNBandMatrix_Print(SUNMatrix A, FILE* outfile) { sunindextype i, j, start, finish; - /* should not be called unless A is a band matrix; + /* should not be called unless A is a band matrix; otherwise return immediately */ if (SUNMatGetID(A) != SUNMATRIX_BAND) return; @@ -237,7 +239,7 @@ SUNMatrix_ID SUNMatGetID_Band(SUNMatrix A) SUNMatrix SUNMatClone_Band(SUNMatrix A) { SUNMatrix B = SUNBandMatrixStorage(SM_COLUMNS_B(A), SM_UBAND_B(A), - SM_LBAND_B(A), SM_SUBAND_B(A)); + SM_LBAND_B(A), SM_SUBAND_B(A), A->sunctx); return(B); } @@ -309,9 +311,9 @@ int SUNMatCopy_Band(SUNMatrix A, SUNMatrix B) SM_CONTENT_B(B)->data = (realtype *) realloc(SM_CONTENT_B(B)->data, SM_COLUMNS_B(B) * colSize*sizeof(realtype)); for (j=0; jcols[j] = SM_CONTENT_B(B)->data + j * colSize; + SM_CONTENT_B(B)->cols[j] = SM_CONTENT_B(B)->data + j * colSize; } - + /* Perform operation */ if (SUNMatZero_Band(B) != SUNMAT_SUCCESS) return SUNMAT_OPERATION_FAIL; @@ -328,7 +330,7 @@ int SUNMatScaleAddI_Band(realtype c, SUNMatrix A) { sunindextype i, j; realtype *A_colj; - + /* Verify that A is a band matrix */ if (SUNMatGetID(A) != SUNMATRIX_BAND) return SUNMAT_ILL_INPUT; @@ -357,7 +359,7 @@ int SUNMatScaleAdd_Band(realtype c, SUNMatrix A, SUNMatrix B) (SM_LBAND_B(B) > SM_LBAND_B(A)) ) { return SMScaleAddNew_Band(c,A,B); } - + /* Otherwise, perform operation in-place */ for (j=0; jsunctx); /* scale/add c*A into new matrix */ for (j=0; jcontent = C->content; C->content = NULL; SUNMatDestroy_Band(C); - + return SUNMAT_SUCCESS; } diff --git a/src/sundials/sunmatrix/dense/sunmatrix_dense.c b/src/sundials/sunmatrix/dense/sunmatrix_dense.c index 9775dfc..3770d6e 100644 --- a/src/sundials/sunmatrix/dense/sunmatrix_dense.c +++ b/src/sundials/sunmatrix/dense/sunmatrix_dense.c @@ -5,7 +5,7 @@ * Alan C. Hindmarsh and Radu Serban @ LLNL * ----------------------------------------------------------------- * SUNDIALS Copyright Start - * Copyright (c) 2002-2021, Lawrence Livermore National Security + * Copyright (c) 2002-2022, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * @@ -43,7 +43,7 @@ static booleantype SMCompatible2_Dense(SUNMatrix A, N_Vector x, N_Vector y); * Function to create a new dense matrix */ -SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N) +SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N, SUNContext sunctx) { SUNMatrix A; SUNMatrixContent_Dense content; @@ -54,7 +54,7 @@ SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N) /* Create an empty matrix object */ A = NULL; - A = SUNMatNewEmpty(); + A = SUNMatNewEmpty(sunctx); if (A == NULL) return(NULL); /* Attach operations */ @@ -96,14 +96,14 @@ SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N) /* ---------------------------------------------------------------------------- - * Function to print the dense matrix + * Function to print the dense matrix */ - + void SUNDenseMatrix_Print(SUNMatrix A, FILE* outfile) { sunindextype i, j; - - /* should not be called unless A is a dense matrix; + + /* should not be called unless A is a dense matrix; otherwise return immediately */ if (SUNMatGetID(A) != SUNMATRIX_DENSE) return; @@ -193,7 +193,7 @@ SUNMatrix_ID SUNMatGetID_Dense(SUNMatrix A) SUNMatrix SUNMatClone_Dense(SUNMatrix A) { - SUNMatrix B = SUNDenseMatrix(SM_ROWS_D(A), SM_COLUMNS_D(A)); + SUNMatrix B = SUNDenseMatrix(SM_ROWS_D(A), SM_COLUMNS_D(A), A->sunctx); return(B); } @@ -260,7 +260,7 @@ int SUNMatScaleAddI_Dense(realtype c, SUNMatrix A) for (j=0; j