[sundials-users] [LLNL/sundials] How to determine the number of times that the f function be called (Issue #179)

2 views
Skip to first unread message

Jianqi Xi

unread,
Jul 22, 2022, 6:50:45 PM7/22/22
to SUNDIAL...@listserv.llnl.gov

I have one quick question about how we could determine the number of times the code will call the f function. The f function could be the ODE function as shown in the example "cvRoberts_dns.c".

I have tested my code, I can get some general sense about the calling times: 1. The calling times will be related to the output time interval, like the tout, if the tout is larger, the number of calls will be larger; 2. The calling times will be reduced as the code process, for example, the number of calls could be 5000 at the first few output step, but then it could be reduced to 500, and even 50 as the output step increases.

But here my question is, how does the code determine the number of calls? Do we have some equation to calculate that or does it have some parameters that we can control the number of call in Sundials? Thank you


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <LLNL/sundials/issues/179@github.com>



To unsubscribe from the SUNDIALS-USERS list: write to: mailto:SUNDIALS-USERS-...@LISTSERV.LLNL.GOV

Jianqi Xi

unread,
Jul 25, 2022, 1:01:29 PM7/25/22
to SUNDIAL...@listserv.llnl.gov

You could count it yourself. int numfcalls=0; int my_f_func(...) { numfcalls++; ... } Maybe I'm not understanding your question?

-John Weeks
On Jul 22, 2022, at 8:57 AM, Jianqi Xi @.> wrote: I have one quick question about how we could determine the number of times the code will call the f function. The f function could be the ODE function as shown in the example "cvRoberts_dns.c". I have tested my code, I can get some general sense about the calling times: 1. The calling times will be related to the output time interval, like the tout, if the tout is larger, the number of calls will be larger; 2. The calling times will be reduced as the code process, for example, the number of calls could be 5000 at the first few output step, but then it could be reduced to 500, and even 50 as the output step increases. But here my question is, how does the code determine the number of calls? Do we have some equation to calculate that or does it have some parameters that we can control the number of call in Sundials? Thank you — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread. To unsubscribe from the SUNDIALS-USERS list: write to: @.

Thank you for your reply. Actually, I have used this way to count the number of calls, but I don't know why it gives those numbers, does it have one specific equation to determine the number of calls? Thank you


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <LLNL/sundials/issues/179/1193134499@github.com>

Mehmet Erol Sanliturk

unread,
Jul 25, 2022, 1:01:32 PM7/25/22
to SUNDIAL...@listserv.llnl.gov
Preliminary computation of "number of function computations calls"
depends on structure of encompassing computing algorithm :

(a) Algorithm uses  "fixed"  computations steps , i.e. , there are no
     any iterations based on a convergence criteria :
     The number of possible steps is used to compute the requested
     number by using "number of function calls per step" .

(b) Algorithm uses iterations based on a convergence criteria :
     My opinion is that there is no explicit formula covering
     all possible situations .

    In such cases , some programs requires an input value for
    "Maximum number of allowed iterations" to terminate
    computations if a convergence is not reached during iterations
    based on a given convergence criteria value , for example ,
    an "Epsilon" such as 1.0e-10 .
    Changing "Epsilon" value changes number of possible function
    computation calls .

(c) An algorithm having a mixture of fixed and iterative steps .


For SUNDIALS parts , please consider structure of computations
you want to use it with respect to input parameters , 'fixed" or
"iterative" or both  .


Mehmet Erol Sanliturk








 

David Gardner

unread,
Jul 25, 2022, 1:01:43 PM7/25/22
to SUNDIAL...@listserv.llnl.gov

The number of function evaluations will depend on several factors (e.g., tolerances, nonlinear/linear solver, etc.) and dynamics of the problem your are solving. What nonlinear/linear solver are you using? If using the dense or banded linear solver, are you supplying a Jacobian function? What is the evolution of the system like e.g., does the problem have an initial transient period followed by slow dynamics or tend toward a steady state?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <LLNL/sundials/issues/179/1193574613@github.com>

Jianqi Xi

unread,
Jul 25, 2022, 1:01:57 PM7/25/22
to SUNDIAL...@listserv.llnl.gov

@gardner48 Thank you for your response. Currently, I am using the Dense solver, and because the Jacobian function is too complex, I didn't supply the Jacobian function. For my system, it is used to describe the evolution of composition, and eventually, it will become a steady state. Thank you for your asking.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <LLNL/sundials/issues/179/1194136371@github.com>

Jianqi Xi

unread,
Jul 25, 2022, 1:02:02 PM7/25/22
to SUNDIAL...@listserv.llnl.gov

Thank you for your comments, in my case, I am using the iteration one based on some criteria, like Atol = 1e-10 and Rtol=1e-7. I see your point, it could be related to the specific equations that I used in my code, but I am wondering why the number of calls is pretty large at the first few step, and then become smaller and smaller as the step increases. Since my understanding is that each step should only depend on the initial values we provided, the number of the calls in each step could be independent. Maybe I am wrong, could you clarify it for me? Thank you,


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <LLNL/sundials/issues/179/1193136156@github.com>

Nguyen Ly

unread,
Jul 25, 2022, 4:42:54 PM7/25/22
to SUNDIAL...@listserv.llnl.gov
Hi Janqi,

If you are using Modified Newton Iteration for the nonlinear solver, SUNDIALS only updates the Jacobian once in a while based on whether a convergence failure occurs in the Newton solver and other heuristics. I think that’s why the number of function calls is only high in the first few iterations when transience is high and the Jacobian needs to be updated frequently. Once you approach the steady state, the old Jacobian can be reused for the Newton iteration.

Best,
Nguyen Ly

Cody Balos

unread,
Jul 26, 2022, 4:02:45 PM7/26/22
to SUNDIAL...@listserv.llnl.gov

@jianqixi In your case (with the dense linear solver), the number of function evaluations depends on the number of time steps (which depends on the time-step sizes), the number of nonlinear iterations, and the number of times the Jacobian is recomputed (internally, via difference quotients since you have not provided an analytical Jacobian).

If your solution has initial transients that go to a steady state, it makes sense that CVODE is calling the right-hand side function more frequently early on in the simulation. This is because CVODE is adapting the time-step size to resolve the solution to the requested tolerance. It is likely that the initial transients are requiring CVODE to use smaller time-steps than what it uses when the problem is at steady-state. In addition, at steady-state less nonlinear iterations are likely needed, and the Jacobian does not need to be updated as frequently.

You can output the number of time steps, number of nonlinear iterations, and number of jacobian evaluations throughout the simulation and see if this is all the case for your problem.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <LLNL/sundials/issues/179/1194635180@github.com>

Jianqi Xi

unread,
Jul 26, 2022, 4:03:32 PM7/26/22
to SUNDIAL...@listserv.llnl.gov

@balos1 Thank you for your clarification. I will try to output these values and check them. By the way, I know CVODE can automatically update the time-step size, but I wonder if we could control the time-step size by ourselves?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you commented.Message ID: <LLNL/sundials/issues/179/1195870002@github.com>

Reply all
Reply to author
Forward
0 new messages