Clean up worker repositories





Simulink.sdi.cleanupWorkerResources removes redundant data from each Parallel Computing Toolbox™ worker file used by the Simulation Data Inspector. Call this function while worker pools are running. The Simulation Data Inspector automatically cleans up repository files when you close the worker pool.


collapse all

This example executes parallel simulations of the model slexAircraftExample with different input filter time constants and shows several ways to access the data using the Simulation Data Inspector API.

Generate Data with Parallel Simulations

Create a vector of filter parameter values to use a different value in each simulation. Then, run a parallel simulation, selecting a different filter value for each worker.

% Make sure the Simulation Data Inspector is empty, and PCT support is
% enabled.

% Define Ts values
Ts_vals = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1];

parfor index = 1:7

    % Select value for Ts
    Ts_val = Ts_vals(index);

    % Load system and select signals to log
    Simulink.sdi.markSignalForStreaming('slexAircraftExample/Pilot', 1, 'on')
    Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model', 4, 'on')

    % Change the filter time constant and simulate
    modelWorkspace = get_param('slexAircraftExample', 'modelworkspace');
    modelWorkspace.assignin('Ts', Ts_val)

    % Create a worker run for each simulation
    workerRun(index) = Simulink.sdi.WorkerRun.getLatest

Get Dataset Objects from Parallel Simulation Output

The getDataset method puts the data from a WorkerRun into a Dataset object so you can easily post-process.

ds(7) = Simulink.SimulationData.Dataset;

for a = 1:7
    ds(a) = workerRun(a).getDataset;
ans = 

Simulink.SimulationData.Dataset '' with 2 elements

                         Name        BlockPath                                
                         __________  ________________________________________ 
    1  [1x1 Signal]      alpha, rad  ...rcraftExample/Aircraft Dynamics Model
    2  [1x1 Signal]      Stick       slexAircraftExample/Pilot               

  - Use braces { } to access, modify, or add elements using index.

Get DatasetRef Objects from Parallel Simulation Output

For big data workflows, use the getDatasetRef method to reference the data associated with the WorkerRun.

for b = 1:7
    datasetRef(b) = workerRun(b).getDatasetRef;
ans = 

  DatasetRef with properties:

           Name: 'Run 6: slexAircraftExample'
            Run: [1×1 Simulink.sdi.Run]
    numElements: 2

Process Parallel Simulation Data in the Simulation Data Inspector

You can also create local Run objects to analyze and visualize your data using the Simulation Data Inspector API. This example adds a tag indicating the filter time constant value for each run.

for c = 1:7
    Runs(c) = workerRun(c).getLocalRun;
    Ts_val_str = num2str(Ts_vals(c));
    desc = strcat('Ts = ', Ts_val_str);
    Runs(c).Description = desc;
    Runs(c).Name = strcat('slexAircraftExample run Ts=', Ts_val_str);

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.


Introduced in R2017b

Was this topic helpful?