bugGNU Octave - Bugs: bug #60525, Execution time of ode45, odeset...

 
 

bug #60525: Execution time of ode45, odeset and inputParser

Submitter:  None
Submitted:  Wed 05 May 2021 04:50:52 AM UTC
   
 
Category:  Performance Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Performance
Status:  Need Info Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 6.2.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 05 May 2021 07:57:10 AM UTC, comment #2: 

Yes, the diffs are reversed.

I can provide a patch for ode45,
I think it should be applied also to at least ode23.

I am not sure whether the odeset patch is needed, though.
Probably we could just document that passing an option
struct is more efficient than letting the solver create
the defaults itself when running in a loop ...


Carlo de Falco <cdf>
Group Member
Wed 05 May 2021 06:41:54 AM UTC, comment #1: 

I'm not sure I correctly read the diffs in the thread you linked to. Were they created with reverse source and destination?

Could you or cdf please provide a patch that applies on the default branch of Octave?

Markus Mützel <mmuetzel>
Group administrator
Wed 05 May 2021 04:50:52 AM UTC, original submission:  

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

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.

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
...


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by cdf (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by mmuetzel
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-05-05 mmuetzel StatusNone Need Info
        Carbon-Copy- Added cdf

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code