Preventing Matlab/Simulink to Generate a Huge Temporary File

Hi,
I've written a script which is performing a Simulink simulation in a cascaded for-loop structure. In each iteration the Simulink model structure is the same, but some model parameters change (system sensitivity analysis). After one simulation run I'm doing a little bit of post-processing and then the relevant data is stored as a .mat file on my HDD. The work space variables are overwritten each iteration and they stay the same size. The simulink model runs in ‘accelerated’ mode.
Unfortunately, Matlab is generating a huge temp file in ‘C:\Users\XXX\AppData\Local\Temp’ which is growing over time and reaches up to 100 GB – this is also when Matlab crashes due to a storage shortage on the partition. The temp file is named ‘XXX_sdi_4.6__none_eventLogging_1.2_sl_artifacts__sta_1.2__none.dmr’. I’ve tried to delete it after a couple of simulations from using the ‘delete’ command, but it doesn’t work (no permission). I’m pretty confused right now because I’ve done similar things in the past without that kind of issue – however, now I’ using Matlab 2017a while in the past I’ve mainly used 2012b. Was there maybe a major revision of the storage management between that versions?
Does anyone have a good guess how to prevent Matlab/Simulink generating such a huge temp file? Any idea is highly appreciated.
Cheers, Oliver

1 Comment

Did you find a solution for this? I have the exact same issue, also moving from 2012b to 2017b.
Cheers, Daniel

Sign in to comment.

 Accepted Answer

1 Comment

Thanks a lot for picking up the topic as this is still an issue with us.
If I understand the suggested solution correctly, this prevents SDI from archiving runs. In our case, we have one single HUGE simulation. Archive is empty because we see the problem already in the first simulation we are running.
I'll try:
Simulink.sdi.setAutoArchiveMode(false);
Simulink.sdi.setArchiveRunLimit(0);
I assume the solution is aimed at running numerous consecutive runs → Helps OP, but not us :-/ Any ideas on single runs?

Sign in to comment.

More Answers (6)

I had the same issue when running many Simulink simulations in a loop. Calling
Simulink.sdi.clear
to clear Data Inspector between runs solved the issue.

4 Comments

Yeah, it turned out that my version change from 2012b to 2017a was directly linked to the Data Inspector tool. Since in my original 2012b model some signals were logged, they were automatically enabled as signals for the Data Inspector which caused that huge temp file. However, it was somehow funny that the Data Inspector also wrote into the temp file after I've deactived the signal loggin within the tool. Hence, I had to remove all signal logs within my Simulink model.
"Simulink.sdi.clear" is working for me in a '"for" loop.
Also if you run simulation by parsim you can use CleanupFcn setting for delete .dmr files for each worker.
For example:
simout = parsim(simin, 'CleanupFcn', @Simulink.sdi.clear)
Parsim will automatically clear data from the DMR files after running all of the simulations. For more information refer to the following answer:

Sign in to comment.

I have written some shortcut code to view and clear the SDI repository files and added it as a favourite command to my Quick Access Toolbar:
% SDI Clear: code to view and clear SDI repository files
sdiClearSC.tFolder = getenv('TMP');
sdiClearSC.dmrFiles = dir(fullfile(sdiClearSC.tFolder,'*.dmr'));
if isempty(sdiClearSC.dmrFiles)
sdiClearSC.answer = questdlg(["No *.dmr files found in ";...
sdiClearSC.tFolder],...
"SDI Clear ShortCut",'Okay','Open folder anyway','Okay');
else
sdiClearSC.answer = questdlg(["*.dmr files found in ";
sdiClearSC.tFolder+ " :"; ...
" ";
string({sdiClearSC.dmrFiles.name}).' + ", " + ...
string(cat(1,sdiClearSC.dmrFiles.bytes)/pow2(20)) + " MiB";
" ";
"Clear SDI and repository files?"],...
"SDI Clear ShortCut",'Yes','No','No, open folder','Yes');
end
switch sdiClearSC.answer
case 'Yes'
disp('Clearing SDI, please wait...')
Simulink.sdi.clear
disp('... clearing SDI repository files, please wait...')
sdi.Repository.clearRepositoryFile
disp('... done.')
case {'Open folder anyway','No, open folder'}
winopen(sdiClearSC.tFolder)
end
clear sdiClearSC

1 Comment

Hi. Good solution. But sometimes matlab hang on the line sdi.Repository.clearRepositoryFile.
I turn off the Simulation Data Inspector does not automatically archive simulation runs. But the command Simulink.sdi.clear take very long time than I close matlab and open again.

Sign in to comment.

Hi, sorry for reopening the issue. I experience the same problem. But since I run a single simulation (10y sim time), I can't clear the SDI in between. Data logging is disabled and I cannot remove all log points as they are in 3rd party libraries. There has to be a solution since this is very annoying. At the moment, I have to fall back to older Matlab versions in which the models are not tested.
I'm guessing if you're actively using data logging for such an elaborate and long simulation you will face a problem with the data size. Hence, maybe you’ve to use down sampling or stop and restart you simulation in between and save the log data on some other available hard disk.
Data logging is disabled (set_param(cfg.mdlName,'SignalLogging','off');) Data is stored via toWorkspace blocks with reduced decimation. It all works fine in Matlab 2013b. It is just the *.dmr file (see first post) from the data inspector.
Hi. I have a very large loop (100K) in which I run the same simulink model with slightly different settings. I check the time it takes to run every 1000 loops and I can see that as the loops increase, the time it takes to run a 1000 runs, gets longer and longer and I can only put it down to the dmr files getting larger.
I have the below two lines at the beginning of my script so I did not expect any temp files to be saved but I just found a 2G dmr in my temp folder which is getting larger with each iteration.
Simulink.sdi.setAutoArchiveMode(false);
Simulink.sdi.setArchiveRunLimit(0);
I also ran the below command but it does not delete the specified dmr file. It actually freezes on the below line.
Simulink.sdi.clear
Any ideas why above lines do not work? And any workaround?
Thanks

1 Comment

What release are you using? In 20a there was a bug that prevented setArchiveRunLimit from working as expected
Also try updating to 22a latest update or later. There was an update to SDI infrastructure.

Sign in to comment.

Categories

Products

Asked:

on 1 Feb 2018

Commented:

on 14 Nov 2023

Community Treasure Hunt

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

Start Hunting!