Data store memory(DSM)

16 views (last 30 days)
James
James on 25 Feb 2012
Hello
I am using Data store memory block in my simulink model to initialize a variable(array) to use in a matlab function block.Its a big model with tight tolerances. When I run I see that the DSM block looks into the full array(variable is size 50) at every time step so basically the simulation is EXTREMELY SLOW. How can I get rid of this.
Thank you
James

Accepted Answer

Nirmal Gunaseelan
Nirmal Gunaseelan on 27 Feb 2012
Hi James,
Looking through all the warnings, it appears from the diagnostics that the MATLAB Fcn block is running at minor times steps (the model has continuous states or you have chosen a continuous state solver) and obviously the block is storing values at all time steps (including minor time steps). I don't think the DSM block has anything to do with this apart from providing the diagnostics. These write after write diagnostics are to make sure that this is what you intended to do and are not an error by themselves. Currently, the way you have modeled is making the block write to elements at all minor time steps. Could you change the solver type (say to discrete if your model doesnt have continuous states) and see if minor steps go away? This will also have a significant improvement in performance, which was your original issue.
-Nirmal
  4 Comments
Nirmal Gunaseelan
Nirmal Gunaseelan on 27 Feb 2012
I'm going to try out a few things, but in the mean time could you also provide a snippet of your access code in the MATLAB Fcn block? I just want to verify that element wise access is actually happening.
James
James on 27 Feb 2012
Oh, the function is a very simple one
function x_LP = dist(u, j)
%#codegen
global distance;
if j == 50
distance=shiftu(distance,1,1);
end
distance(j) = u;
x_LP=distance;
I have 2 functions(exactly same). 'j' is the counter and 'distance' is the variable in DSM. So after 50, I shift the whole array by one row and add a new one.
Thanks a lot for the help!

Sign in to comment.

More Answers (2)

Nirmal Gunaseelan
Nirmal Gunaseelan on 27 Feb 2012
Hi James,
Could you give more details on what blocks are being used with the DSM block? Are you using a Data Store Write block as well?
Is the problem that the DSM block is accessing at every time step, or is it that you want only certain parts to be accessed? Have you tried Element wise assignment/selection?
-Nirmal
  4 Comments
James
James on 27 Feb 2012
Ok, I feel I am failing to convey my real situation. the set of warnings are similar to this:
The block 'tractor_semitrailer_control_DSM/semitrailer/MATLAB Function4' is writing to
element 1 of the data store 'tractor_semitrailer_control_DSM/semitrailer/Data Store Memory2' but
the block 'tractor_semitrailer_control_DSM/semitrailer/MATLAB Function4' has already written to
this memory in a minor time step at time 0.017329639746273648
Warning: The block 'tractor_semitrailer_control_DSM/semitrailer/MATLAB Function4' is reading
from element 2 of the data store 'tractor_semitrailer_control_DSM/semitrailer/Data Store
Memory2' before any blocks have written to this memory in a minor time step at time
0.017329639746273648
Warning: The block 'tractor_semitrailer_control_DSM/semitrailer/MATLAB Function4' is reading
from element 3 of the data store 'tractor_semitrailer_control_DSM/semitrailer/Data Store
Memory2' before any blocks have written to this memory in a minor time step at time
0.017329639746273648
So what I understand is that DSM is looking into every cell of the array(size 50) in each timestep(1e-4). I want the variable stored in the DSM to behave like a normal array so that i can use it in the matlab funtion block along with a counter to add new elements to consecutive cells(while the simulation is running) and simultaneously feed this array to a dynamic lookup table.
James
James on 27 Feb 2012
this is without using the read/write blocks!

Sign in to comment.


James
James on 28 Feb 2012
Hi Nirmal,
The simulation runs now and, I get good results. But since I increased my sample time in the MATLAB Fcn block, it a bit faster. But I still have the warnings where DSM looks into every cell.my simulation time is 60 seconds. My simulation runs for 30 min, unlike my previous attempts where it took 45 min. I believe if DSM looks into ony one particular cell, it might be faster. Do you suggest any other way to make this process faster!?
-James
  2 Comments
Nirmal Gunaseelan
Nirmal Gunaseelan on 28 Feb 2012
Hi James,
I wanted to try out other ways of achieving your functionality without using shiftu/if conditions. I am not sure if we are preventing full access by using those lines. I'll get back to you.
-Nirmal
James
James on 28 Feb 2012
Oh, okay! I was also thinking that shiftu/if conditions are causing this.
Thanks for your help and let me know if you end up with some effective results!
-James

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!