This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 of Simulink.SimulationInput objects. This is useful in scenarios like model testing, experiment design, Monte Carlo analysis, and model optimization.

Using arrays of Simulink.SimulationInput objects simplify the running of multiple simulations and running them in parallel. With the Parallel Computing Toolbox™, you can use the parsim and batchsim commands to run the simulations in parallel.

The parsim command distributes each simulation to your workers to decrease your overall simulation time. The parsim command automates the creation of a parallel pool, identifying file dependencies and managing build artifacts for accelerator and rapid accelerator simulations.

The batchsim command offloads the simulations to the compute cluster. The execution of the simulations takes place on the cluster, giving you the ability to carry out other tasks while the batch job is processing, or close the client MATLAB® and access the batch job later.

In the absence of a Parallel Computing Toolbox license, the parsim behaves like the sim command. The simulations then run in serial.

The batchsim command uses the Parallel Computing Toolbox™ license to run the simulations on compute cluster. batchsim runs the simulations in serial if a parallel pool cannot be created. If Parallel Computing Toolbox license is not used, batchsim errors out.

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

  • Initial state

  • External inputs

  • Model parameters

  • Block parameters

  • Variables

Through the Simulink.SimulationInput object, you can also specify MATLAB functions to run at the start and the end of each simulation by using PreSimFcn and PostSimFcn respectively.

When you use Simulink.SimulationInput objects, the model parameters are restored after the simulation ends. See Run Parallel Simulations Using parsim.


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 with MATLAB Parallel Server™ 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, see Simulation Manager.

Data Logging for Multiple Simulations

The resulting Simulink.SimulationOutput object, which contains the simulation outputs, captures error messages and the simulation metadata. When you select the Data Import/Export > Log Dataset data to file configuration parameter, Simulink® creates a Simulink.SimulationData.DatasetRef object for each Dataset stored in the resulting MAT file. You can use the DatasetRef object to access the data for a Dataset element. For simulations that are run using the Simulink.SimulationInput objects, the DatasetRef object is returned as part of the SimulationOutput 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 the Data Import/Export > Log Dataset data to file configuration parameter (LoggingToFile), for parallel simulations in Simulink:

  • Data is logged in Dataset format in a MAT-file

  • A Simulink.SimulationData.DatasetRef object is created for each Dataset element (for example, logsout) for each simulation

You can use DatasetRef objects to access data for a specific signal. You can create objects to use for streaming logged data from persistent storage in to a model.

See Also

| | | | | | | | | |

Related Topics