Enable parallel simulation with data dictionary


Description prepares the workers in a parallel pool for simulating a model that is linked to a data dictionary. Use this function in a spmd block, prior to starting a parfor block, to provide the workers in a parallel pool a way to safely interact with a single data dictionary.

During parallel simulation of a model that is linked to a data dictionary, you can allow each worker to access and modify the data in the dictionary independently of other workers. temporarily provides each worker in the pool with its own data dictionary cache, allowing the workers to use the data in the dictionary without permanently changing it.

You must have a Parallel Computing Toolbox™ license to perform parallel simulation using a parfor block.


Sweep Variant Control Using Parallel Simulation

To use parallel simulation to sweep a variant control (a Simulink.Parameter object whose value influences the variant condition of a Simulink.Variant object) that you store in a data dictionary, use this code as a template. Change the names and values of the model, data dictionary, and variant control to match your application.

To sweep block parameter values or the values of workspace variables that you use to set block parameters, use Simulink.SimulationInput objects instead of the programmatic interface to the data dictionary. See Optimize, Estimate, and Sweep Block Parameter Values.

You must have a Parallel Computing Toolbox license to perform parallel simulation.

% For convenience, define names of model and data dictionary
model = 'mySweepMdl';
dd = 'mySweepDD.sldd';

% Define the sweeping values for the variant control
CtrlValues = [1 2 3 4];

% Grant each worker in the parallel pool an independent data dictionary 
% so they can use the data without interference

% Determine the number of times to simulate
numberOfSims = length(CtrlValues);

% Prepare a nondistributed array to contain simulation output
simOut = cell(1,numberOfSims);

parfor index = 1:numberOfSims
    % Create objects to interact with dictionary data
    % You must create these objects for every iteration of the parfor-loop
    dictObj =;
    sectObj = getSection(dictObj,'Design Data');
    entryObj = getEntry(sectObj,'MODE'); 
    % Suppose MODE is a Simulink.Parameter object stored in the data dictionary
    % Modify the value of MODE
    temp = getValue(entryObj);
    temp.Value = CtrlValues(index);

    % Simulate and store simulation output in the nondistributed array
    simOut{index} = sim(model);
    % Each worker must discard all changes to the data dictionary and
    % close the dictionary when finished with an interation of the parfor-loop

% Restore default settings that were changed by the function
% Prior to calling cleanupWorkerCache, close the model



If data dictionaries are open, you cannot use the command To identify open data dictionaries, use

Introduced in R2015a

Was this topic helpful?