How to export my simulation data by PostSimFcn, when using parsim function?

23 visualizzazioni (ultimi 30 giorni)
I am using parsim to accelarate my simulations. My maltab is linux 2017b. Codes are shown as
/* for some fp_lst, I declare a Simulink.SimulationInput array */
for i = length(fp_lst):-1:1
inm(i) = Simulink.SimulationInput(mdl);
inm(i) = inm(i).setVariable('index',i);
inm(i).PostSimFcn = @(x) postsim(x);
end
My postsim function is
function newout = postsim(out)
file = (strcat('simdata/out_',num2str(out.index),'.mat'));
save(file,'out'); % in order to save the memory
newout.Ia = out.Ia;
newout.Va = out.Va;
end
Then I call parsim,
out = parsim(inm,'ShowSimulationManager','on','ShowProgress','on');
The program seems to run well but takes forever to terminate. No error message pops out.
Strangely, when I call
out = sim(inm,'ShowSimulationManager','on','ShowProgress','on');
everything is Ok. Moreover, if I comment out the save function in my postsim, everything is still fine.
More Strangely, the code runs well in Windows10.
So my question is how to export my simulation data by PostSimFcn, when using parsim function?

Risposta accettata

Pravallika
Pravallika il 10 Mag 2018
The way you are exporting your logged data from simulation is valid. However, there might be more efficient ways to do this. It looks like you're saving all of the logged data to a MAT file; have you tried using the 'LoggingToFile' option? This will automatically stream all the data being logged during a simulation to a MAT file. When this option is used with PARSIM, unique MAT files are created based on the index of the SimulationInput object. You can also access all of the output data through DatatsetRef objects which create a reference to the data in the MAT file and only load the data into memory when you choose to do so. There is more information about using this feature here.
This will avoid the call to save the MAT file and might resolve the issue. Using this, you can also avoid using the 'index' variable if the only reason you're using it is to append the MAT files with a unique number.
Having said that, the code you have still shouldn't hang on Linux. Some possibilities that could explain this behavior are concurrent access to the filesystem creating a bottleneck or too much memory being used by the workers etc. You could try reducing the number of workers used on Linux as a diagnostic step to see if that improves the situation. By turning on the option mentioned above, data will be streamed to a MAT file directly avoiding high memory usage.

Più risposte (0)

Categorie

Scopri di più su Run Multiple Simulations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by