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

3 次查看(过去 30 天)
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

采纳的回答

Yair Altman
Yair Altman 2020-7-14
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 个评论
Jinsu Kim
Jinsu Kim 2020-7-14
编辑:Jinsu Kim 2020-7-14
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by