Code Slows Down if I Preallocate Larger Variables?

Hello, I am using Matlab to explicitly integrate equations of motion for a finite element mesh. In the code I initialise all the history variables (such as displacement, velocity and acceleration) to store all the values at every node for every time step.
displace = zeros(gdl,n_inc+1); %
epsilon = zeros(gdl,n_inc+1); %
stress = zeros(gdl,n_inc+1); %
The point is: if I use a larger number of time steps (i.e. a smaller time increment), every single step takes much more to run. Is that avoidable somehow?

7 件のコメント

Guillaume
Guillaume 2015 年 6 月 16 日
if I use a larger number of time steps the same simulation takes much more to run.
Why would you expect different? repeat something more times == do it for longer.
However, I don't understand how it relates to the title of your question.
Alessandro
Alessandro 2015 年 6 月 16 日
編集済み: Alessandro 2015 年 6 月 16 日
I would not expect different run times, although I am experiencing it. I would think this is related to the initialisation of much larger matrices (which have DOF x n_increments dimensions). As an example, the exact same mesh takes 0.432s per step for a 5000 increments simulation, 0.712s for a 10000 increments one.
Adam
Adam 2015 年 6 月 16 日
Why wouldn't you expect different run times? If you halve the time step you double the number of values over which to calculate which will slow your code down by somewhere up to the order of a factor of 2, dependent on what the code is and how dependent its runtime is on that setting.
Alessandro
Alessandro 2015 年 6 月 16 日
I wouldn't expect different run times per step, since the number of required calculations per step is the same and I am not even close to saturating physical memory of the machine. In other words, if 100 steps take 1 minute, 200 steps shouldn't take much more than 2 minutes.
Adam
Adam 2015 年 6 月 16 日
That depends on how the algorithm is coded. The profiler should tell you where the time is being spent.
profile on
...your code here...
profile off
profile viewer
Walter Roberson
Walter Roberson 2015 年 6 月 16 日
32 bit MATLAB or 64 bit MATLAB?
Alessandro
Alessandro 2015 年 6 月 17 日
64bit version.

回答 (0 件)

この質問は閉じられています。

質問済み:

2015 年 6 月 16 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by