Run Parallel Simulations
Theparsim
command allows you to run parallel (simultaneous) Simulink®模拟的模型(设计)。在这个康泰克斯t, parallel runs mean multiple simulations at the same time on different workers.parsim
makes it easy for you to run the same model with different inputs or different parameter settings in scenarios such as Monte Carlo analyses, parameter sweeps, model testing, experiment design, and model optimization. Running a single simulation in parallel by decomposing the model into smaller components and running those individual pieces simultaneously on multiple workers is currently not supported.
To run the simulations in parallel withparsim
, you need a Parallel Computing Toolbox™ for local workers. In addition, you can useMATLAB®Parallel Server™for multiple computer clusters, clouds, and grids. In the absence of Parallel Computing Toolbox andMATLAB Parallel Server,parsim
runs the simulations in serial. For more information, seeParallel Computing ToolboxandMATLAB Parallel Server.
If no parallel pool exists,parsim
creates a pool from the default cluster profile . To use a cluster other than the default, create a pool with that cluster profile before callingparsim
.
This example runs multiple simulations in parallel for a set of sweep parameters.
% 1) Load modelopenExample('sldemo_suspn_3dof'); model ='sldemo_suspn_3dof'; load_system(model);% 2) Set up the sweep parametersCf_sweep = 2500*(0.05:0.1:0.95); numSims = numel(Cf_sweep);% 3) Create an array of SimulationInput objects and specify the sweep value for each simulationsimIn(1:numSims) = Simulink.SimulationInput(model);foridx = 1:numSims simIn(idx) = simIn(idx).setBlockParameter([model'/Road-Suspension Interaction'],'Cf', num2str(Cf_sweep(idx)))end% 4) Simulate the modelsimOut = parsim(simIn)
Howparsim
works
parsim
runs simulations with different parameters and values based on theSimulink.SimulationInput
object. EachSimulationInput
object specifies one simulation of the model. An array of these objects can be created for multiple simulations. For more information, seeRunning Multiple Simulations.
You can use the following methods and properties onSimulink.SimulationInput
object:
setVariables
- Change variables in base workspace, data dictionary, or model workspacesetBlockParameter
- Change block parameterssetModelParameter
- Change model parameterssetPreSimFcn
- Specify MATLAB functions to run before each simulation for customization and post-processing results on the clustersetPostSimFcn
- Specify MATLAB functions to run after each simulation for customization and post-processing results on the clusterInitialState
- Change the Initial StateExternalInput
- Specify a numerical array, timeseries, or Dataset object as external inputs to the model
This flowchart shows a general sequence of events that occur whenparsim
is executed
Changes to model library blocks can be overwritten when usingparsim
. When models are set up on new workers, model inherits properties directly from the worker library. UseSetUpFcn
withparsim
to transfer the model library block changes to the workers.
See Also
Objects
Functions
applyToModel
|setBlockParameter
|setModelParameter
|setInitialState
|setExternalInput
|setVariable
|validate
|setPreSimFcn
|setPostSimFcn