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 use
parsim
, parsim
with
'runinbackground'
option turned on, or batchsim
.
the flow chart shows how running multiple simulations with parsim
,
parsim
with runinbackground
and
batchsim
differ.
the parsim
and batchsim
commands
use the parallel computing toolbox™ license to run the simulations in parallel. parsim
runs the
simulations in serial if a parallel pool cannot be created or if the parallel computing toolbox license is not available. batchsim
commands cannot run without
parallel computing toolbox license.
parsim
workflow
using parsim
command 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.
basic parsim
workflow
create an array of objects,
in
, to specify changes to the model.specify one-time setup required for running multiple simulations. you can use
setupfcn
andtransferbaseworkspacevariables
to perform setup on the parallel workers.run
parsim(in)
to execute these multiple simulations in parallel. if a parallel pool does not exist,parsim
creates it.parsim
uses default settings.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, see simulation manager.once all the simulations are complete, you get an array of
simulink.simulationoutput
objects.
limitations
closing the matlab session terminates simulations on the workers, disabling retrieval of partial results.
parsim
with runinbackground
workflow
create an array of objects,
in
, to specify changes to the model.specify one-time setup required for running multiple simulations. you can use
setupfcn
andtransferbaseworkspacevariables
to perform setup on the parallel workers.run
parsim
withruninbackground
option 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.with
'runinbackground'
option set to'on'
,parsim
returns asimulink.simulation.future
object. 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, see .
limitations
closing the matlab session terminates simulations on the workers, disabling retrieval of partial results. if the
future
object is cleaned, you are subsequently unable to access the results of the simulations.using a
fetchnext
method loop onfuture
objects, along with simulation manager causes them to compete for retrieval offuture
objects. use either afetchnext
method loop or simulation manager to get the outputs of completed simulations.
batchsim
workflow
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, see (parallel computing toolbox).
create an array of objects,
in
, to specify changes to the model.specify one-time setup required for running multiple simulations. you can use
setupfcn
andtransferbaseworkspacevariables
to perform setup on the parallel workers.to run on a cluster or desktop background, call
batchsim
to offload the execution of simulations. withbatchsim
, you can use most of the arguments that are compatible withparsim
andbatch
commands. for more information, seebatchsim
.using
batchsim
, 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 1
workers 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
batchsim
errors out when used with a pool size if parallel computing toolbox license is not available.batchsim
offloads 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.on submitting a batch job,
batchsim
returns a 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.
batchsim
does 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, see (parallel computing toolbox)
see also
functions
classes
- | |
tools
related topics
- running multiple simulations
- run parallel simulations for a thermal model of a house using parsim
- batch processing (parallel computing toolbox)