Preventing Matlab/Simulink to Generate a Huge Temporary File

235 views (last 30 days)
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
Daniel Tegnered
Daniel Tegnered on 2 Jul 2018
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.

Answers (7)

Daniel Tegnered
Daniel Tegnered on 2 Jul 2018
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
Sergey Kasyanov
Sergey Kasyanov on 11 Mar 2022
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)

Sign in to comment.


Frank Zhou
Frank Zhou on 15 May 2019
  1 Comment
Tobias Huelsing
Tobias Huelsing on 16 May 2019
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.


Andres
Andres on 24 Sep 2021
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
Eugene Paymurzov
Eugene Paymurzov on 1 Dec 2021
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.


Tobias Huelsing
Tobias Huelsing on 11 Sep 2018
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.

walli
walli on 11 Sep 2018
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.

Tobias Huelsing
Tobias Huelsing on 11 Sep 2018
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.

Pegah Hosseini
Pegah Hosseini on 14 Nov 2023
Edited: Pegah Hosseini on 14 Nov 2023
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
Reid Spence
Reid Spence on 14 Nov 2023
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

Find more on Dependency Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!