Simulink.sdi.enablePCTSupport
R2026bControl when to import data from parallel simulations into the Simulation Data Inspector
Description
Simulink.sdi.enablePCTSupport(
configures data import into the Simulation Data Inspector from parallel workers
according to the mode specified by mode)mode. You can configure the
Simulation Data Inspector to import only data from local workers, or data from local
and remote workers. You can also set the mode to manual, which allows you to
manually import runs into the Simulation Data Inspector using the Simulink.sdi.sendWorkerRunToClient function. By default, the
Simulation Data Inspector is configured for the manual import mode.
Examples
Configure Simulation Data Inspector parallel worker support to import the output automatically from both local and remote workers.
Simulink.sdi.enablePCTSupport("all")To prevent the output from Parallel Computing Toolbox™ workers from automatically importing into the Simulation Data Inspector, specify the manual support mode.
Simulink.sdi.enablePCTSupport("manual")To manually send runs created using parallel workers to the Simulation Data Inspector, use Simulink.sdi.sendWorkerRunToClient .
Setup
This example runs several simulations of the ThreeSigs model, varying the value of the amplitude Sine Wave block. To set up for the parallel simulation, define a vector of amplitude values and configure the Simulation Data Inspector for manual Parallel Computing Toolbox™ support.
ampVals = [0.1 0.2 0.3 0.4];
Simulink.sdi.enablePCTSupport("manual");Initialize Parallel Workers
Use parpool (Parallel Computing Toolbox) to start a pool of four parallel workers. This example calls parpool inside an if statement so you only create a parallel pool if you do not already have one.
p = gcp("nocreate"); if isempty(p) parpool(4); end
You can use spmd (Parallel Computing Toolbox) to run initialization code common to all workers. For example, load the ThreeSigs model and use Simulink.sdi.markSignalForStreaming to select signals to log to the Simulation Data Inspector. To avoid data concurrency issues when simulating with sim in parfor, create a temporary directory on each worker.
spmd load_system("ThreeSigs") Simulink.sdi.markSignalForStreaming("ThreeSigs/Sine Wave",1,"on") workDir = pwd; addpath(workDir) tempDir = tempname; mkdir(tempDir) cd(tempDir) end
Run Parallel Simulations with parfor
To stream data from parallel workers to the Simulation Data Inspector, run parallel simulations using parfor (Parallel Computing Toolbox). Each worker runs a simulation of the ThreeSigs model with a different amplitude value. The software cannot access the contents of the parfor loop, so the variable ampVal is defined in the worker's workspace, where the model can see it, using assignin.
parfor (index = 1:4) assignin("base","ampVal",ampVals(index)); set_param("ThreeSigs/Sine Wave","Amplitude","ampVal") sim("ThreeSigs");
Access Data and Send Run to Client MATLAB
You can use the Simulation Data Inspector programmatic interface on the worker the same way you would in the client MATLAB®. This example creates a Simulink.sdi.Run object and attaches the value of the amplitude used in the simulation with the Tag property.
IDs = Simulink.sdi.getAllRunIDs;
lastIndex = length(IDs);
runID = Simulink.sdi.getRunIDByIndex(lastIndex);
parRun = Simulink.sdi.getRun(runID);
parRun.Tag = strcat("Amplitude = ",num2str(ampVals(index)));
Simulink.sdi.sendWorkerRunToClient
endClose Temporary Directories and View Runs in the Simulation Data Inspector
Use another spmd section to delete the temporary directories created on the workers once the simulations complete.
spmd cd(workDir) rmdir(tempDir,"s") rmpath(workDir) end
In each simulation, the Simulink.sdi.sendWorkerRunToClient function imported runs from all the workers into the Simulation Data Inspector. You can view the data and check the run properties to see the amplitude values used during simulation.
Simulink.sdi.view
Execute parallel simulations of the model ThreeSigs with different input filter time constants and access the data in different ways using the Simulation Data Inspector programmatic interface.
Setup
Clear the Simulation Data Inspector and check that Parallel Computing Toolbox™ support is configured to import runs created on local workers automatically. Then, create a vector of filter parameter values to use in each simulation.
Simulink.sdi.clear
Simulink.sdi.enablePCTSupport("local")
Ts_vals = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]; Initialize Parallel Workers
Use the gcp function to create a pool of local workers to run parallel simulations if you don't already have one. In an spmd code block, load the ThreeSigs model and select signals to log. To avoid data concurrency issues using sim in parfor, create a temporary directory for each worker to use during simulations.
p = gcp; spmd load_system("ThreeSigs") workDir = pwd; addpath(workDir) tempDir = tempname; mkdir(tempDir) cd(tempDir) end
Run Parallel Simulations
Use parfor to run the seven simulations in parallel. Select the value for Ts for each simulation, and modify the value of Ts in the model workspace. Then, run the simulation and build an array of Simulink.sdi.WorkerRun objects to access the data with the Simulation Data Inspector. After the parfor loop, use another spmd segment to remove the temporary directories from the workers.
parfor index = 1:7 % Select value for Ts Ts_val = Ts_vals(index); % Change the filter time constant and simulate modelWorkspace = get_param("ThreeSigs","modelworkspace"); assignin(modelWorkspace,"Ts",Ts_val) sim("ThreeSigs"); % Create a worker run for each simulation workerRun(index) = Simulink.sdi.WorkerRun.getLatest end spmd % Remove temporary directories cd(workDir) rmdir(tempDir,"s") rmpath(workDir) end
Get Dataset Objects from Parallel Simulation Output
The getDataset function puts the data from a WorkerRun object into a Dataset object so you can easily post-process.
ds(7) = Simulink.SimulationData.Dataset; for a = 1:7 ds(a) = getDataset(workerRun(a)); end ds(1)
ans =
Simulink.SimulationData.Dataset '' with 3 elements
Name BlockPath
________ ______________
1 [1x1 Signal] sineSig ThreeSigs/Out1
2 [1x1 Signal] randSig ThreeSigs/Out2
3 [1x1 Signal] chirpSig ThreeSigs/Out3
- Use braces { } to access, modify, or add elements using index.
Get DatasetRef Objects from Parallel Simulation Output
For big data workflows, use the getDatasetRef function to reference the data associated with the WorkerRun.
for b = 1:7 datasetRef(b) = getDatasetRef(workerRun(b)); end datasetRef(1)
ans =
DatasetRef with properties:
Name: 'Run <run_index>: <model_name>'
Run: [1×1 Simulink.sdi.Run]
numElements: 3
Process Parallel Simulation Data in the Simulation Data Inspector
You can also create local Simulink.sdi.Run objects to analyze and visualize your data using the Simulation Data Inspector programmatic interface. This example shows a tag indicating the filter time constant value for each run.
for c = 1:7 Runs(c) = getLocalRun(workerRun(c)); Ts_val_str = num2str(Ts_vals(c)); desc = strcat("Ts = ", Ts_val_str); Runs(c).Description = desc; Runs(c).Name = strcat("ThreeSignals run Ts=", Ts_val_str); end
Clean Up Worker Repositories
Clean up the files used by the workers to free up disk space for other simulations you want to run on your worker pool.
Simulink.sdi.cleanupWorkerResources
Input Arguments
Simulation Data Inspector data import mode for data logged on parallel workers, specified as one of these options:
"manual"— Do not automatically import runs created on parallel workers. You can manually import runs created on parallel workers using theSimulink.sdi.sendWorkerRunToClientfunction."local"— Automatically import runs created on local workers."all"— Automatically import runs created on local and remote workers.
Data Types: char | string
Alternative Functionality
You can modify the parallel computing support mode in the Simulation Data Inspector by selecting Preferences > Parallel.

Version History
Introduced in R2017bStarting in R2020a, the Simulink.sdi.enablePCTSupport
function no longer supports the 'none' input option. To disable
automatic import of data logged on parallel workers into the Simulation Data
Inspector, use the 'manual' option.
Starting in R2020a, the Simulink.sdi.enablePCTSupport function ignores logical inputs. In
scripts that specify a logical input for the
Simulink.sdi.enablePCTSupport function, replace a
0 or false input with the
'manual' input option and a 1 or
true input with the 'all' option to
achieve equivalent behavior.
Starting in R2018a, the Simulink.sdi.enablePCTSupport input
values changed to:
'local''none''all''manual'
In R2017b, the Simulink.sdi.enablePCTSupport function accepted
a logical input to enable or disable Simulation Data Inspector support for data
logged in parallel simulations.
trueor1enables support for automatically importing data from all parallel workers into the Simulation Data Inspector.In R2018a, use the
'all'option for the same behavior. You can also use the new'local'input when you want to automatically import data only from local workers.falseor0disables all support for importing data logged on parallel workers.In R2018a, use the
'none'option for the same behavior. You can also use the new'manual'option when you want to analyze data on the worker to determine whether you want to import individual runs into the Simulation Data Inspector from a parallel worker.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)