Why does my script takes longer time to execute than expected?
4 次查看(过去 30 天)
显示 更早的评论
Hi, I tried to run my matlab script. In the attached file: MBBA5CBPAA_Result.m, I tried to run only the second section:Active dissipation. The computation is supposed to take 11 hours 36 minutes but is still running even after 12 hours. Please is there any way to speed up the running time. The Non_linear1_differentu_MBBA_func1.m and dissipative_elastic_energy_MBBA_fun.m are subroutines (functions), while the MBBA5CBPAA_Result.m is where the run the code.
Your assistance is highly appreciated. Thank you.
14 个评论
University Glasgow
2023-2-27
Hi Walter,
I did a rough calculation. For 11 by 11 array it took 1.32 minutes and I increased the mesh size to 250 by 250, which i think should be approx. 11.32 hours.
Walter Roberson
2023-2-27
11 x 11 appears to be length(u) by length(xi) . Your last commented-out u and xi are 11 elements each, suggesting that those are what you calculated with. Your current u and xi are 251 elements each (not 250); perhaps you had an off-by one in making that remark.
On the other hand there is an N inside of dissipative_elastic_energy_MBBA_func and that N is exactly 250, so the amount of work done is proporational to length(u) by length(xi) by N .
Did you possibly increase N ?
Walter Roberson
2023-2-27
You are running an ode for tspan = 0:20000 for each combination of u and xi. Although it is possible to combine independent ode into a single ode45 call, it is often not advised to do so as the points at which ode45() needs to internally refine the system might be at different locations for the different odes so it can be inefficient and a source of numeric roundoff problems to combine independent odes.
Your ode45 with 20001 is probably taking the bulk of your computation time.
The Non_linear1_differentu_MBBA_func1 is already designed to run through combinations of u and xi, so you could reduce the calling overhead by calling it once over the full xi and u, instead of calling it once for each individual combination of xi and u. I doubt that will make significant difference, though.
University Glasgow
2023-2-27
Thank you so much Walter for your expalanation. Is actually making sense now. I did not increase N. Please how do I call over Non_linear1_differentu_MBBA_func1 once for the full xi and u?
Walter Roberson
2023-2-27
I do not understand why you say "2*11" and "2*250" rather than 11^2 and 250^2 ?
dissipative_elastic_energy_MBBA_func has
for iu=1:length(u)
for ixi=1:length(xi)
so operations are being done proporational to the product of the lengths of u and xi -- each of which used to be length 11
% xi = -0.2:0.04:0.2;
% u = 0:0.2:2;
but are now 251
xi = -0.2:0.0016:0.2;
u = 0:0.008:2;
Walter Roberson
2023-2-27
Your current code in dissipative_elastic_energy_MBBA_func has
for iu=1:length(u)
for ixi=1:length(xi)
[nt,tspan,THETA, V, z, t]= Non_linear1_differentu_MBBA_func1(u(iu), xi(ixi), d, N);
so you are passing in individual u and individual xi values to Non_linear1_differentu_MBBA_func1
But that function has
Xix = xi;
Ui = u;
for Xidx = 1:length(Xix)
xi = Xix(Xidx);
for Uidx = 1:length(Ui)
u = Ui(Uidx);
so that function is already looping over each xi and u value. You do not need to pass in individual u and xi pairs into Non_linear1_differentu_MBBA_func1 -- you could call
[all_nt, tspan, all_THETA, all_V, all_z, all_t] = Non_linear1_differentu_MBBA_func1(u, xi, d, N);
0r something similar to that, knowing that Non_linear1_differentu_MBBA_func1 is already designed to return data for all of the u xi combinations. You would have to look more carefully at the output values for Non_linear1_differentu_MBBA_func1 to see how it puts the values together.
Perhaps you would want to still loop over individual u elements but process all of the xi elements at the same time.
I would expect that the overhead of calling Non_linear1_differentu_MBBA_func1 length(u) by length(xi) times instead of just once would be only a small portion of the cost of the code. It looks to me as if your major cost is the ode45 call with the timespan that is 20001 elements. It is not obvious to me why you are asking for so many output times.
University Glasgow
2023-2-27
编辑:University Glasgow
2023-2-27
I tried to restructure my code by calling my function: dissipative_elastic_energy_MBBA_func in a for loop. For 11 by 11 mesh, I got 1.06 [min]. I tried for 51 by 51 mesh, I got 26.7 [min].
Walter Roberson
2023-2-28
1.06 * 60 / (11*11)
ans = 0.5256
26.7 * 60 / (51*51)
ans = 0.6159
so it is a little slower per iteration as you increase the mesh size, but not greatly so. 20%-ish ?
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)