Running Simulink on multiple MATLAB instances concurrently on machine crashes in SLDD, DMR, SDI (Jenkins, CI, parallel)

23 views (last 30 days)
Why is MATLAB crashing with stack traces pointing to "sldd", "dmr", or "sdi" when I run multiple MATLAB instances in parallel on the same machine?  

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 May 2022

Reasons multiple Simulink instances may crash

You may experience these types of issues when running two or more MATLAB instances concurrently on the same machine to do some Simulink tasks. Some examples where two MATLAB instances are run concurrently:
  • In an automated testing or continuous integration setup where a tool such as Jenkins, Gitlab, etc. automatically starts two or more MATLABs on the same machine.
  • Using Simulink in parallel in anyway that is NOT through the dedicated parallel Simulink functions "parsim" and "batchsim". This includes using Simulink features in operations such as "parfor", "spmd", "parfeval", or running MATLAB unit tests in parallel.
  • Running a batch or shell script that starts two or more MATLABs concurrently on the same machine
When doing this you may encounter crashes with stack traces pointing to "sldd", "dmr", or "sdi". You may also see warnings similar to below which indicate one instance of MATLAB may be interfering 
The data dictionary 'demo.sldd' has been changed on disk since it was opened.
A common reason for these issues is related to file read/write conflicts in the artifact and cache files Simulink creates while it is running. These files could exist in:
  1. The current working directory
  2. The "tempdir " or temporary directory of your machine
  3. The "codegen" and "cache" directory as specified by the "filegencontrol "
When two or more MATLAB instances are running on the same machine, then the cache files generated by one instance can interfere with the other instances trying to use the same cache file. This creates a race condition that could lead to a crash.

 

To avoid these issues with MATLAB workers

If you are running Simulink actions inside of Parallel Computing Toolbox functions such as "parfor", "spmd", "parfeval", or running MATLAB unit tests in parallel; please consider moving to "parsim" or "batchsim" functions which will automatically take care of these cache and temporary files for you to prevent issues. If this is not possible, please follow the advice on the doc page "Using sim function with parfor". Note that this advice applies to any Simulink function (not just sim), used inside any Parallel Computing Toolbox function (not just parfor).  \n\n

To avoid these issues with multiple concurrent MATLAB instances

If you have a tool such as Jenkins or a batch/shell script which is opening multiple MATLAB instances concurrently to run Simulink, you can prevent these types of crashes by insuring that each instance of MATLAB has a unique:
  1. "cache" and "codegen" folders: Either make sure that each concurrently executing MATLAB has a different working folder (where the default "cache" and "codegen" folders are created), or manually control these folders for each MATLAB with Simulink.fileGenControl
  2. Temporary directory: For Linux and MAC the temporary directory is set by the environment variable 'TMPDIR'. For Windows the environment variable is 'TEMP' and/or 'TMP'. Make sure each concurrently executing MATLAB has its own temp directory by setting the necessary environment variable before running any MATLAB/Simulink actions. One way to do this is to use the "setenv " function in your startup.m.
>>setenv('TEMP',myTempFolderLocation);
>>setenv('TMP',myTempFolderLocation);
>>setenv('TMPDIR',myTempFolderLocation);
For more details on changing the temporary directory, refer to the following post:
 

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!