LLNL / sundials

Official development repository for SUNDIALS - a SUite of Nonlinear and DIfferential/ALgebraic equation Solvers. Pull requests are welcome for bug fixes and minor changes.
https://computing.llnl.gov/projects/sundials
BSD 3-Clause "New" or "Revised" License
515 stars 125 forks source link

Feature: Logging Updates #501

Open gardner48 opened 3 months ago

gardner48 commented 3 months ago

Follow on to utilities added in #499

balos1 commented 3 months ago

Checkout https://github.com/LLNL/sundials/blob/feature/nls-switching-v7-gs/src/sundials/sundials_logger_impl.h#L35. Now that we have C99 we can change all the logging statements in the code to use a variadic macro and it makes the logging statements much cleaner and gets rid of the repetitive preprocessor checks. My intent was to bring this over from that branch. I can do that here if you think it looks good.

gardner48 commented 3 months ago

Checkout https://github.com/LLNL/sundials/blob/feature/nls-switching-v7-gs/src/sundials/sundials_logger_impl.h#L35. Now that we have C99 we can change all the logging statements in the code to use a variadic macro and it makes the logging statements much cleaner and gets rid of the repetitive preprocessor checks. My intent was to bring this over from that branch. I can do that here if you think it looks good.

I was going to ask if you still had the variadic macros from the original logging implementation on another branch. I think switching over to those would be great.

It would also be nice to have an "If" version of the macros i.e., something like SUNLogInfoIf that takes an additional boolean input to change cases like

#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO
      if (kflag != ARK_SUCCESS)
      {
        SUNLogInfo(ARK_LOGGER, __func__, "end-step-attempt", "status = failed solve, kflag = %i", kflag);
      }
#endif

into something like

SUNLogInfoIf(kflag != ARK_SUCCESS, ARK_LOGGER __func__, "end-step-attempt", "status = failed solve, kflag = %i", kflag);
balos1 commented 3 months ago

@gardner48 The "if" version sounds like a nice addition as well.

gardner48 commented 2 days ago
1. Add the integer values that correspond with each logging level (`SUN_LOGLEVEL_ALL`, `SUN_LOGLEVEL_NONE`, ...).  Currently, users are asked for a numerical logging level value by CMake, which can only be found hidden inside `include/sundials/sundials_logger.h`.

The logging documentation directs users to the documentation for the CMake option here which lists the numeric values and associated logging level.

2. The end of this file has an incredibly brief section on "Example Usage" for the logger.  Could you add a few step-by-step "case studies" showing how a user could

   * configure SUNDIALS with an "appropriate" logging level
   * set environment variables to hold the "relevant" log file(s)
   * run an existing SUNDIALS example
   * use one of `tools/log_example.py` or `tools/log_example_mri.py`, e.g., to plot the step size history as a function of time.

I'll update that section with additional information shortly.