Simulink.data.dictionary.cleanupWorkerCache
Restore defaults after parallel simulation with data dictionary
Description
Simulink.data.dictionary.cleanupWorkerCache
restores
default settings after you have finished parallel simulation of a
model that is linked to a data dictionary. Use this function in a spmd
(Parallel Computing Toolbox) block, after you finish parallel
simulation using parfor
(Parallel Computing Toolbox) blocks,
to restore default settings that were altered by the Simulink.data.dictionary.setupWorkerCache
function.
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. The function Simulink.data.dictionary.setupWorkerCache
grants
each worker a unique dictionary cache to allow independent access
to the data, and the function Simulink.data.dictionary.cleanupWorkerCache
restores
cache settings to their default values.
You must have a Parallel Computing Toolbox™ license to perform
parallel simulation using a parfor
(Parallel Computing Toolbox) block.
Examples
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 spmd Simulink.data.dictionary.setupWorkerCache end % 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 = Simulink.data.dictionary.open(dd); 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); setValue(entryObj,temp); % 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 iteration of the parfor-loop discardChanges(dictObj); close(dictObj); end % Restore default settings that were changed by the function % Simulink.data.dictionary.setupWorkerCache % Prior to calling cleanupWorkerCache, close the model spmd bdclose(model) Simulink.data.dictionary.cleanupWorkerCache end
Note
If data dictionaries are open, you cannot use the command Simulink.data.dictionary.cleanupWorkerCache
.
To identify open data dictionaries, use Simulink.data.dictionary.getOpenDictionaryPaths
.
Version History
Introduced in R2015a
See Also
spmd
(Parallel Computing Toolbox) | parfor
(Parallel Computing Toolbox) | Simulink.data.dictionary.setupWorkerCache
| Simulink.data.dictionary.getOpenDictionaryPaths
| Simulink.data.dictionary.closeAll
Topics
- Store Data in Dictionary Programmatically
- What Is a Data Dictionary?
- Run Code on Parallel Pools (Parallel Computing Toolbox)