octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #60525] Execution time of ode45, odeset and in


From: anonymous
Subject: [Octave-bug-tracker] [bug #60525] Execution time of ode45, odeset and inputParser
Date: Wed, 5 May 2021 00:50:54 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

URL:
  <https://savannah.gnu.org/bugs/?60525>

                 Summary: Execution time of ode45, odeset and inputParser
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Wed 05 May 2021 04:50:52 AM UTC
                Category: Performance
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Performance
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: octavecontrib@gmail.com
             Open/Closed: Open
                 Release: 6.2.0
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

*Code* : a loop repeatedly calling ode45 for _small_ time duration. The
integrated function is slightly modified in each iteration. So a single long
duration call doesn't seem possible.
*Observation* : Execution time is significantly longer than Matlab.
*OS* : Linux-Debian and Windows 7.
*Octave Version* : 5.2, 6.2
Discussed in detail at the discourse group
<https://octave.discourse.group/t/how-to-speedup-loop-with-ode45-inside-it>

== Summary ==
ode45 calls odeset (more times than what seems necessary). odeset then calls
inputParser which is where a significant portion of execution time is being
spent. With a suggested persistent storage of odeoptions inside odeset, and
avoidance of a call to odeset inside ode45, the execution time nearly halves
<https://octave.discourse.group/t/how-to-speedup-loop-with-ode45-inside-it/1099/9>.

== Example Code ==

clc;
clear;

endtime = 1000;
stepsize = 0.5; % the fixed step used by the controller

t = 0;
ii = 1;

% reserve space so that it doesn't slow down the program
tl = zeros(ceil(endtime/stepsize), 1);
yl = zeros(ceil(endtime/stepsize), 2);

ic = [1, 0];

control = 0.1;

profile clear;
profile on;

while(t < endtime)
% run the non linear time varying differential equation
% using a variable time step method.
[tt, yy] = ode45(@(t,x)[0,1; -1, control]*x/2, [0, stepsize], ic);

% collect results for plotting later
yl(ii, :) = yy(end, :);
tl(ii) = t + tt(end, :);

ic = yy(end, :);

if(norm(ic) > 5)
  % this is where the controller logic would have been written in the real
application
  control = -0.05;
end

ii = ii+1;

t = t+stepsize;
end

profile off;
profshow;


== Profiling Result ==

#                Function Attr          Time (s)   Time (%)        Calls
  20        @inputParser/parse             4.632      16.36         4000
  75     runge_kutta_45_dorpri             3.966      14.01        20000
  73        integrate_adaptive             3.607      12.74         2000
  28  @inputParser/add_missing             2.620       9.25         8000
  55   @inputParser/is_argname             2.058       7.27        46000
  56 @inputParser/validate_arg             1.295       4.57        46000
  76                     feval             1.173       4.14       122000
  57            anonymous@:0:0             1.107       3.91       172000
...





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60525>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]