How to speed up a code from the Code Profiler Results ?

1 view (last 30 days)
I want to imrpove my code speed, so I did code profiling analysis.
Below is the result of code profiler but I have no idea how to start with these results.
I used ode15s solver, and results seems that bottleneck contained in ode15s solver which means I did not manually write these codes.
The most time consuming lines are:
line 131: Fdel(:,j) = feval(F,Fargs{1:diffvar-1},ydel(:,j),Fargs{diffvar+1:end})
line 148: dFdy = Fdiff * diag(1 ./ del);
line 126 : ydel = y(:,ones(1,ny)) + diag(del);
It accounts on the total computing time 77.1 %, 19.3 % respectively.
Tolerance option change in ode15s solver was not the answer..
In this case, is there any troubleshooting method to enhance the code speed?
Thanks in advances :D

Accepted Answer

Yair Altman
Yair Altman on 14 Jul 2020
Try to set the "Vectorized" property using the odeset function, before running ode45. Also, specifying the Jacobian in advance (if you know it) can speed up the calculation - set the "Jacobian" and optionally "JPattern" properties of odeset, Take a look at the other options to see if you can give the solver more information about your function - the more information that the solver has, the more likely it is to use an optimized computation.
  1 Comment
Jinsu Kim
Jinsu Kim on 14 Jul 2020
Edited: Jinsu Kim on 14 Jul 2020
Thanks for your reply :)
Unfortunately, I don't know my Jacobian matrix. Anyway, now I'm trying to convert m.file to Cmex file. I hope it works.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!