This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Simulate dynamic system in parallel or serial


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



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,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 can not be created and in the absence of Parallel Computing Toolbox .


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));

Simulate the model in parallel.

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

This example shows how to use parsim command to run batch simulations.

Delete the interactive pool.


Start batch simulations.

job = batch(@parsim, 1, {in}, 'Profile', 'local', 'Pool', 2);

Get the output.

out = fetchOutputs(job);

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. The progress is hidden when set to 'off'.

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')

You can specify a function handle to 'SetupFcn' to run once per worker after completion the simulations.

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.

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.

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 the Model 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?