For workflows that involve multiple parallel simulations and logging of large amounts of data, you can create simulation sets by using an array ofSimulink.SimulationInput
objects. This is useful in scenarios like model testing, experiment design, Monte Carlo analysis, and model optimization.
Using arrays ofSimulink.SimulationInput
object simplifies the running of multiple simulations and running them in parallel. With the Parallel Computing Toolbox™, you can use theparsim
command to run the simulations in parallel. Theparsim
command distributes each simulation to your workers to decrease your overall simulation time. Theparsim
command automates the creation of a parallel pool, identifying file dependencies and managing build artifacts for accelerator and rapid accelerator simulations.
In the absence of a Parallel Computing Toolbox license, theparsim
command behaves like thesim
command. The simulations then run in serial.
You can make changes to your model using theSimulink.SimulationInput
object and run a simulation in parallel with those changes. Changing theSimulink.SimulationInput
object, overrides the values in the model. The simulation uses the values in theSimulink.SimulationInput
object rather than the values defined in the model. This way, you can change the model without dirtying it. TheSimulink.SimulationInput
object allows you to change these settings in your model:
Initial state
External inputs
Model parameters
Block parameters
Variables
Through theSimulink.SimulationInput
object, you can also specify MATLAB®functions to run at the start and the end of each simulation by usingPreSimFcn
andPostSimFcn
respectively.
When you useSimulink.SimulationInput
objects, the model’s parameters are restored after the simulation ends. SeeParallel Simulations Workflow.
When the pool is not already open and simulations are run for the first time, simulations take an additional time to start. Subsequent parallel simulations are faster.
Outputs errors in the simulation output object for easier debugging
Compatible with rapid accelerator and fast restart
Compatible with file logging (to facilitate big data)
Compatible withMATLAB分布式计算服务器™in addition to local parallel pools
Capable of transferring base workspace variables to workers
Avoids transparency errors
The Simulation Manager allows you to monitor multiple parallel simulations. It shows the progress of the runs as they are running in parallel. You can view the details of every run such as parameters, elapsed time, and diagnostics. The Simulation Manager acts as a useful tool by giving you the option to analyze and compare your results in the Simulation Data Inspector. You can also select a run and apply its values to the model. For more information, seeSimulation Manager
.
The resultingSimulink.SimulationOutput
object, which contains the simulation outputs, captures error messages and the simulation metadata. When you select theData Import/Export > Log Dataset data to fileconfiguration parameter, Simulink®creates aSimulink.SimulationData.DatasetRef
object for eachDataset
stored in the resulting MAT file. You can use theDatasetRef
object to access the data for aDataset
element. For simulations that are run using theSimulink.SimulationInput
objects, theDatasetRef
object is returned as part of theSimulationOutput
object. As a result, you have quicker access to and do not need to create them.
Parallel simulations can produce more logged data than the MATLAB memory can hold. Consider logging to persistent storage for parallel simulations to reduce the memory requirement. When you select theData Import/Export > Log Dataset data to fileconfiguration parameter (LoggingToFile
), for parallel simulations in Simulink:
Data is logged in Dataset format in a MAT-file
ASimulink.SimulationData.DatasetRef
object is created for each Dataset element (for example,logsout
) for each simulation
You can useDatasetRef
objects to access data for a specific signal. You can creatematlab.io.datasetore.SimulationDatastore
objects to use for streaming logged data from persistent storage in to a model.
Simulink.SimulationInput
|applyToModel
|parsim
|setBlockParameter
|setExternalInput
|setInitialState
|setModelParameter
|setPostSimFcn
|setPreSimFcn
|setVariable
|validate