Documentation

Run Multiple Simulations

For workflows that involve multiple parallel simulations and logging of large amounts of data, you can create simulation sets by using an array ofSimulink.SimulationInputobjects. This is useful in scenarios like model testing, experiment design, Monte Carlo analysis, and model optimization.

Using arrays ofSimulink.SimulationInputobject simplifies the running of multiple simulations and running them in parallel. With the Parallel Computing Toolbox™, you can use theparsimcommand to run the simulations in parallel. Theparsimcommand distributes each simulation to your workers to decrease your overall simulation time. Theparsimcommand 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, theparsimcommand behaves like thesimcommand. The simulations then run in serial.

You can make changes to your model using theSimulink.SimulationInputobject and run a simulation in parallel with those changes. Changing theSimulink.SimulationInputobject, overrides the values in the model. The simulation uses the values in theSimulink.SimulationInputobject rather than the values defined in the model. This way, you can change the model without dirtying it. TheSimulink.SimulationInputobject allows you to change these settings in your model:

  • Initial state

  • External inputs

  • Model parameters

  • Block parameters

  • Variables

Through theSimulink.SimulationInputobject, you can also specify MATLAB®functions to run at the start and the end of each simulation by usingPreSimFcnandPostSimFcnrespectively.

When you useSimulink.SimulationInputobjects, the model’s parameters are restored after the simulation ends. SeeParallel Simulations Workflow.

Note

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.

Other Advantages

  • 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

Simulation Manager

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.

Data Logging for Multiple Simulations

The resultingSimulink.SimulationOutputobject, 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.DatasetRefobject for eachDatasetstored in the resulting MAT file. You can use theDatasetRefobject to access the data for aDatasetelement. For simulations that are run using theSimulink.SimulationInputobjects, theDatasetRefobject is returned as part of theSimulationOutputobject. 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.DatasetRefobject is created for each Dataset element (for example,logsout) for each simulation

You can useDatasetRefobjects to access data for a specific signal. You can creatematlab.io.datasetore.SimulationDatastoreobjects to use for streaming logged data from persistent storage in to a model.

See Also

||||||||||

Related Topics

Was this topic helpful?