Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handling in cvode #382

Merged
merged 32 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2d59639
error handling in cvode
balos1 Dec 6, 2023
631660a
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 6, 2023
fdd7d02
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
055fc4f
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
e6f4902
Apply suggestions from code review
balos1 Dec 7, 2023
eff4012
Merge remote-tracking branch 'origin/feature/error-handling-cvode' in…
balos1 Dec 7, 2023
6ae4831
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
d5757fc
fix cvode.c changes
balos1 Dec 7, 2023
5c5d3c3
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 7, 2023
3ef61b1
add cvode error handling unit test
balos1 Dec 7, 2023
4e2d8dd
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 7, 2023
7174507
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
f4e361e
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
7a0ec4d
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 7, 2023
eec60e6
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 7, 2023
2f46396
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
dd35902
remove cvode error handler function
balos1 Dec 8, 2023
bbf6ff7
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
7c6ba5a
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
8aeede6
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
574d9c1
format after merge
balos1 Dec 8, 2023
f26a776
ensure sundials_mpi_errors.h is included when MPI is enabled
balos1 Dec 8, 2023
3c1635c
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
741b58f
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 11, 2023
03a3033
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 11, 2023
5cf67b9
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 11, 2023
5670a7a
make requested changes
balos1 Dec 11, 2023
329fccb
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 12, 2023
81bf98f
fix cmake for unit test
balos1 Dec 12, 2023
74da510
call GetLastError in ProcessError
balos1 Dec 12, 2023
2871a5a
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 12, 2023
fc3920d
address comments
balos1 Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/cvode/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ Users now need to link to ``sundials_core`` in addition to the libraries already
This will be picked up automatically in projects that use the SUNDIALS CMake target. The library ``sundials_generic`` has been superceded by ``sundials_core`` and is no longer available.
This fixes some duplicate symbol errors on Windows when linking to multiple SUNDIALS libraries.

**Breaking change**
The functions ``CVodeSetErrFile`` and ``CVodeSetHandlerErrFn`` have been removed.
Users of these functions can use the functions :c:func:`SUNContext_PushErrHandler`,
and :c:func:`SUNLogger_SetErrorFilename` instead. For further details see
Sections :numref:`SUNDIALS.Errors` and :numref:`SUNDIALS.Logging`.

Changes in v6.6.2
-----------------

Expand Down
77 changes: 3 additions & 74 deletions doc/cvode/guide/source/Usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,9 @@ error message to the error handler function. All error return values are
negative, so the test ``flag < 0`` will catch all errors.

The optional input calls can, unless otherwise noted, be executed in any order.
However, if the user's program calls either :c:func:`CVodeSetErrFile` or
:c:func:`CVodeSetErrHandlerFn`, then that call should appear first, in order to
take effect for any later error message. Finally, a call to an ``CVodeSet***``
function can, unless otherwise noted, be made at any time from the user's
calling program and, if successful, takes effect immediately.

A call to an ``CVodeSet***`` function can, unless otherwise noted, be made
at any time from the user's calling program and, if successful, takes effect
immediately.

.. _CVODE.Usage.CC.optional_input.optin_main:

Expand All @@ -826,10 +823,6 @@ Main solver optional input functions
+-------------------------------+---------------------------------------------+----------------+
| **Optional input** | **Function name** | **Default** |
+===============================+=============================================+================+
| Pointer to an error file | :c:func:`CVodeSetErrFile` | ``stderr`` |
+-------------------------------+---------------------------------------------+----------------+
| Error handler function | :c:func:`CVodeSetErrHandlerFn` | internal fn. |
+-------------------------------+---------------------------------------------+----------------+
| User data | :c:func:`CVodeSetUserData` | ``NULL`` |
+-------------------------------+---------------------------------------------+----------------+
| Maximum order for BDF method | :c:func:`CVodeSetMaxOrd` | 5 |
Expand Down Expand Up @@ -870,41 +863,6 @@ Main solver optional input functions
+-------------------------------+---------------------------------------------+----------------+


.. c:function:: int CVodeSetErrFile(void* cvode_mem, FILE * errfp)
balos1 marked this conversation as resolved.
Show resolved Hide resolved

The function ``CVodeSetErrFile`` specifies a pointer to the file where all CVODE messages should be directed when the default CVODE error handler function is used.

**Arguments:**
* ``cvode_mem`` -- pointer to the CVODE memory block.
* ``errfp`` -- pointer to output file.

**Return value:**
* ``CV_SUCCESS`` -- The optional value has been successfully set.
* ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`.

**Notes:**
The default value for ``errfp`` is ``stderr``. Passing a value of ``NULL`` disables all future error message output (except for the case in which the CVODE memory pointer is ``NULL``). This use of ``CVodeSetErrFile`` is strongly discouraged.

.. warning::

If ``CVodeSetErrFile`` is to be called, it should be called before any other optional input functions, in order to take effect for any later error message.

.. c:function:: int CVodeSetErrHandlerFn(void* cvode_mem, CVErrHandlerFn ehfun, void * eh_data)

The function ``CVodeSetErrHandlerFn`` specifies the optional user-defined function to be used in handling error messages.

**Arguments:**
* ``cvode_mem`` -- pointer to the CVODE memory block.
* ``ehfun`` -- is the C error handler function of type :c:type:`CVErrHandlerFn`.
* ``eh_data`` -- pointer to user data passed to ``ehfun`` every time it is called.

**Return value:**
* ``CV_SUCCESS`` -- The function ``ehfun`` and data pointer ``eh_data`` have been successfully set.
* ``CV_MEM_NULL`` -- The CVODE memory block was not initialized through a previous call to :c:func:`CVodeCreate`.

**Notes:**
Error messages indicating that the CVODE solver memory is ``NULL`` will always be directed to ``stderr``.

.. c:function:: int CVodeSetUserData(void* cvode_mem, void * user_data)

The function ``CVodeSetUserData`` specifies the user data block ``user_data`` and attaches it to the main CVODE memory block.
Expand Down Expand Up @@ -3342,35 +3300,6 @@ The user must provide a function of type defined as follows:
equal to 1 (in which case CVODE returns ``CV_UNREC_RHSFUNC_ERR``).


.. _CVODE.Usage.CC.user_fct_sim.ehFn:

Error message handler function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As an alternative to the default behavior of directing error and warning
messages to the file pointed to by ``errfp`` (see :c:func:`CVodeSetErrFile`), the user may provide a
function of type ``CVErrHandlerFn`` to process any such messages. The function type
:c:type:`CVErrHandlerFn` is defined as follows:

.. c:type:: void (*CVErrHandlerFn)(int error_code, const char *module, const char *function, char *msg, void *eh_data);

This function processes error and warning message from CVODE and it sub-modules.

**Arguments:**
* ``error_code`` is the error code.
* ``module`` is the name of the CVODE module reporting the error.
* ``function`` is the name of the function in which the error occurred.
* ``msg`` is the error message.
* ``eh_data`` is a pointer to user data, the same as the ``eh_data`` parameter passed to :c:func:`CVodeSetErrHandlerFn`.

**Return value:**
* void

**Notes:**
``error_code`` is negative for errors and positive (``CV_WARNING``) for warnings.
If a function that returns a pointer to memory encounters an error, it sets ``error_code`` to 0.


.. _CVODE.Usage.CC.user_fct_sim.monitorfn:

Monitor function
Expand Down
9 changes: 1 addition & 8 deletions examples/cvode/parallel/cvAdvDiff_diag_p.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
#include <nvector/nvector_parallel.h> /* access to MPI-parallel N_Vector */
#include <stdio.h>
#include <stdlib.h>
#include <sundials/sundials_logger.h>
#include <sundials/sundials_mpi_errors.h>
#include <sundials/sundials_types.h> /* definition of type realtype */
#include <sundials/sundials_core.h>

/* Problem Constants */

Expand Down Expand Up @@ -131,11 +129,6 @@ int main(int argc, char* argv[])
SUNContext_PushErrHandler(sunctx, SUNMPIAbortErrHandlerFn, NULL);
SUNContext_PushErrHandler(sunctx, SUNLogErrHandlerFn, NULL);

/* Setup different error handler stack so that we abort after logging */
SUNContext_PopErrHandler(sunctx);
SUNContext_PushErrHandler(sunctx, SUNMPIAbortErrHandlerFn, NULL);
SUNContext_PushErrHandler(sunctx, SUNLogErrHandlerFn, NULL);

/* This requires that SUNDIALS was configured with the CMake options
SUNDIALS_LOGGING_LEVEL=n
where n is one of:
Expand Down
6 changes: 0 additions & 6 deletions include/cvode/cvode.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ typedef int (*CVRootFn)(sunrealtype t, N_Vector y, sunrealtype* gout,

typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void* user_data);

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);

/* -------------------
Expand All @@ -122,9 +119,6 @@ SUNDIALS_EXPORT int CVodeWFtolerances(void* cvode_mem, CVEwtFn efun);
SUNDIALS_EXPORT int CVodeSetConstraints(void* cvode_mem, N_Vector constraints);
SUNDIALS_EXPORT int CVodeSetDeltaGammaMaxLSetup(void* cvode_mem,
sunrealtype dgmax_lsetup);
SUNDIALS_EXPORT int CVodeSetErrFile(void* cvode_mem, FILE* errfp);
SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void* cvode_mem, CVErrHandlerFn ehfun,
void* eh_data);
SUNDIALS_EXPORT int CVodeSetInitStep(void* cvode_mem, sunrealtype hin);
SUNDIALS_EXPORT int CVodeSetLSetupFrequency(void* cvode_mem, long int msbp);
SUNDIALS_EXPORT int CVodeSetMaxConvFails(void* cvode_mem, int maxncf);
Expand Down
4 changes: 4 additions & 0 deletions include/sundials/sundials_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
#include <sundials/sundials_types.h>
#include <sundials/sundials_version.h>

#if SUNDIALS_MPI_ENABLED
#include <sundials/sundials_mpi_errors.h>
#endif

#endif /* _SUNDIALS_CORE_H */
Loading
Loading