Main Content

Comparison Between Multiple Simulation Workflows

When running a set of multiple simulations, you can run them in parallel on multiple MATLAB®workers in a parallel pool. To run multiple simulations, you can useparsim,parsimwith'RunInBackground'option turned on, orbatchsim.

The flow chart shows how running multiple simulations withparsim,parsimwithRunInBackgroundandbatchsimdiffer.

Theparsimandbatchsimcommands use the Parallel Computing Toolbox™ license to run the simulations in parallel.parsimruns the simulations in serial if a parallel pool cannot be created or if the Parallel Computing Toolbox license is not available.batchsimcommands cannot run without Parallel Computing Toolbox license.

parsimWorkflow

Usingparsim命令with Parallel Computing Toolbox to run multiple simulations sets up a parallel pool automatically and runs simulations in parallel. The client is always tied to the MATLAB workers.

BasicparsimWorkflow

  1. Create an array ofSimulink.SimulationInputobjects,in, to specify changes to the model.

  2. Specify one-time setup required for running multiple simulations. You can useSetupFcnandTransferBaseWorkspaceVariablesto perform setup on the parallel workers.

  3. Runparsim(in)to execute these multiple simulations in parallel. If a parallel pool does not exist,parsimcreates it.parsimuses default settings.

  4. You can open Simulation Manager by setting the'SimulationManager'argument to'on'withparsim,parsim(in,'SimulationManager','on'). Simulation Manager enables you to monitor the simulations as they are running and gives you access to outputs of the simulations when they are ready. Simulation Manager provides you with information about the simulations running on the workers. For more information, seeSimulation Manager.

  5. Once all the simulations are complete, you get an array ofSimulink.SimulationOutputobjects.

Limitations

  • Closing the MATLAB session terminates simulations on the workers, disabling retrieval of partial results.

parsimwithRunInBackgroundWorkflow

  1. Create an array ofSimulink.SimulationInputobjects,in, to specify changes to the model.

  2. Specify one-time setup required for running multiple simulations. You can useSetupFcnandTransferBaseWorkspaceVariablesto perform setup on the parallel workers.

  3. RunparsimwithRunInBackgroundoption set to'on':parsim(in,'RunInBackground','on'). Setting the'RunInBackground'option to'on'runs the simulations asynchronously. This keeps the MATLAB command prompt available enabling you to work on other tasks.

  4. With'RunInBackground'option set to'on',parsim返回一个Simulink.Simulation.Futureobject. You can poll this object to check the status of simulations, fetch the outputs of simulations when they are completed, or cancel simulations. For more information, seeSimulink.Simulation.Future.

Limitations

  • Closing the MATLAB session terminates simulations on the workers, disabling retrieval of partial results. If thefutureobject is cleaned, you are subsequently unable to access the results of the simulations.

  • Using afetchNextmethod loop onFutureobjects, along with Simulation Manager causes them to compete for retrieval ofFutureobjects. Use either afetchNextmethod loop or Simulation Manager to get the outputs of completed simulations.

batchsimWorkflow

A batch workflow typically means submitting jobs to run simulations on MATLAB workers and subsequently accessing the results of those simulations. When you run simulations in batches, you offload the execution of simulations onto a compute cluster. To learn more about batch processing, seeSimple Batch Processing(Parallel Computing Toolbox).

  1. Create an array ofSimulink.SimulationInputobjects,in, to specify changes to the model.

  2. Specify one-time setup required for running multiple simulations. You can useSetupFcnandTransferBaseWorkspaceVariablesto perform setup on the parallel workers.

  3. To run on a cluster or desktop background, callbatchsimto offload the execution of simulations. Withbatchsim, you can use most of the arguments that are compatible withparsimandbatchcommands. For more information, seebatchsim.

    Usingbatchsim, you offload simulations to a MATLAB worker. To run the batch job on multiple workers, specify a pool size,N, that is an integer specifying the number of workers to make into a parallel pool for the job:batchsim(in, 'Pool', N). There must be at leastN+1workers available on the cluster. If the pool size is not specified,batchsim(in)runs the simulations on a single worker in the cluster specified by the default cluster profile.

    Note

    batchsimerrors out when used with a pool size if Parallel Computing Toolbox license is not available.

  4. batchsimoffloads simulations to the compute cluster, enabling you to carry out other tasks while the batch job is processing, or close the client MATLAB and access the batch job later.

  5. On submitting a batch job,batchsim返回一个job object containing a job ID and other information that you can use to access the batch job at a later time. Access this job again to check the progress of simulations.

Limitations

  • Because the client session is not tied to the workers, you cannot access the outputs unless the job is finished.

  • batchsimdoes not give you the ability to monitor simulations with Simulation Manager. For batch jobs, you can use a batch job monitor that tells you if the job is queued, in progress, or completed. For more information, seeJob Monitor(Parallel Computing Toolbox)

See Also

Functions

Classes

Tools

Related Topics