Documentation

parsim

Simulate dynamic system in parallel or serial

Syntax

simOut = parsim(in)
simOut = parsim(in,'ShowSimulationManager','on')
simOut = parsim(in,Name,Value,...NameN,ValueN)
job = batch(@parsim, 1, {in}, 'Profile', 'ProfileName', 'Pool', PoolSize)

Description

example

simOut = parsim(in) simulates a model using the inputs specified in the SimulationInput object, in. The parsim command uses an array of SimulationInput objects to run multiple simulations.

simOut = parsim(in,'ShowSimulationManager','on') simulates a model in parallel using the inputs specified in the SimulationInput object and opens the Simulation Manager UI. For more information, see Simulation Manager.

simOut = parsim(in,Name,Value,...NameN,ValueN) simulates a model in parallel using the inputs specified in the SimulationInput object and the options specified as the Name,Value pair.

job = batch(@parsim, 1, {in}, 'Profile', 'ProfileName', 'Pool', PoolSize) uses parsim with the batch command to run batch simulations.

The parsim command uses the Parallel Computing Toolbox™ license to run the simulations in parallel. parsim runs the simulations in serial if a parallel pool cannot be created and in the absence of Parallel Computing Toolbox .

Examples

collapse all

Simulate the model, cstr, in parallel by sweeping over a variable. An array of SimulationInput objects is used to perform the sweep.

Specify sweep values.

FeedTempSweep = 250:10:300;

Create an array of SimulationInput objects.

for i = length(FeedTempSweep):-1:1;
in(i) = Simulink.SimulationInput('cstr');
in(i) = in(i).setVariable('FeedTemp0',FeedTempSweep(i));
end

Simulate the model in parallel.

out = parsim(in, 'ShowProgress', 'on')

Input Arguments

collapse all

A Simulink.SimulationInput object or an array of Simulink.SimulationInput objects that is used to specify changes to the model for a simulation.

Example: in = Simulink.SimulationInput('vdp')

Name-Value Pair Arguments

Example: 'ShowProgress', 'on'

Note

All parameters passed to parsim command are unrelated to the parameters that are used with the sim command. Use the list of following input arguments to pass to the parsim command.

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name and Value must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

collapse all

When ShowProgress is set to 'on', you can see the progress of the simulations in the command window. The progress is hidden when set to 'off'.

Note

When the progress is shown, a message 'Cleaning up parallel workers..' may be displayed before the completion of the last few simulations. This message does not depend on the completion of the simulations. Simulations "complete" when the outputs are fetched from the future.

You can specify a function handle to 'SetupFcn' to run once per worker before the start of the simulations .

Example: 'SetupFcn',@()simulinkproject('OCRAex/OCRA_example.prj')

Note

When buildRapidAcceleratorTarget is used in the SetupFcn and the model has external inputs specified,​ either set 'LoadExternalInput' to 'off' or ensure that the specified external input is available on the workers to prevent compilation error.

collapse all

You can specify a function handle to 'CleanupFcn' to run once per worker after the simulations are completed.

Use AttachedFiles to attach files to pool, specified as a character vector or cell array of character vectors.

Example: {'file1.m','file2.m'};

When UseFastRestart is set to true, simulations run on the workers using fast restart.

Note

When using parsim, use the UseFastRestart option and NOT the FastRestart option. See Factors Affecting Fast Restart for more information.

When TransferBaseWorkspaceVariables is set to true, variables used in the model and defined in the base workspace are transferred to the parallel workers.

Note

Use of TransferBaseWorkspaceVariables requires model compilation.

When 'ShowSimulationManager' is set to 'on', you can use the Simulation Manager App to monitor simulations.

Pool determines the size of the parallel pool

Output Arguments

collapse all

Simulink.SimulationOutput is an array of Simulink.SimulationOutput objects that contains all of the logged simulation results. The size of the array is equal to the size of the array of Simulink.SimulationInput objects.

All simulation outputs (logged time, states, and signals) are returned in a single Simulink.SimulationOutput object. You define the model time, states, and output that is logged using the Data Import/Export pane of theModel Configuration Parameters dialog box. You can log signals using blocks such as the To Workspace and Scope blocks. The Signal & Scope Manager can directly log signals.

Introduced in R2017a

Was this topic helpful?