main content

offload simulations to run on a compute cluster -凯发k8网页登录

offload simulations to run on a compute cluster

since r2018b

description

example

simjob = batchsim(in) runs a batch job on a single worker to simulate a model using the inputs specified in the simulationinput object, in.

simjob = batchsim(mycluster,in) runs a batch job on the cluster identified by the cluster object mycluster. if a cluster profile is not specified, batchsim uses a default cluster profile as set up in the parallel preferences. for more information, see discover clusters and use cluster profiles (parallel computing toolbox).

simjob = batchsim(...,name,value) runs a batch job that simulates a model using the inputs specified in the simulationinput object and the options specified as name,value pair.

batchsim offloads simulations to a 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. use the 'pool' argument to run simulations in parallel.

the batchsim command uses the parallel computing toolbox™ and matlab parallel server™ licenses 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 available, batchsim errors out.

examples

this example shows how to run parallel simulations in batch. batchsim offloads simulations to a 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.

this example uses the ex_sldemo_househeat model and runs simulations in batch to observe the model behavior for different temperature set points.

open the model.

openexample('simulink/openthemodelexample');
open_system('ex_sldemo_househeat');
load_system('ex_sldemo_househeat')

define a set of values for different temperatures. here, the setpointvalues are a standard range of temperatures. the length of the vector helps create an array of simulink.simulationinput objects in the following step.

setpointvalues = 65:2:85;
spv_length = length(setpointvalues);

using the setpointvalues, initialize an array of simulink.simulationinput objects.

in(1:spv_length) = simulink.simulationinput('ex_sldemo_househeat');
for i = 1:1:spv_length 
    in(i) = in(i).setblockparameter('ex_sldemo_househeat/set point',...
        'value',num2str(setpointvalues(i)));
end

specify the pool size of the number of workers to use. in addition to the number of workers used to run simulations in parallel, a head worker is required. in this case, let's assume that three workers are available to run a batch job for the parallel simulations. the job object returns useful metadata as shown. you can use the job id to access the job object later from any machine. numworkers tells you how many workers are running the simulations. numworkers is always the number of workers specified in the 'pool' argument and an additional head worker. 'pool' is set to 3, you can change the value of 'pool' based on the availability of the workers.

simjob = batchsim(in,'pool',3)
                  id: 1
                type: pool
          numworkers: 4
            username: #####
               state: running
      submitdatetime: ##-###-#### ##:##:##
       startdatetime: 
    running duration: 0 days 0h 0m 0s

access the results of the batch job using the fetchoutputs method. fetchoutputs method retrieves the results from the workers and eturns an array of simulink.simulationouput objects.

out = fetchoutputs(simjob)
1x11 simulink.simulationoutput array

input arguments

specified as a object or an array of simulink.simulationinput objects that is used to specify changes to the model for simulation.

example: in = simulink.simulationinput('vdp')

cluster object that is used to specify the cluster in which the batch job runs.

name-value arguments

example: 'pool', 5

specify optional comma-separated pairs of name,value arguments. name is the argument name and value is the corresponding value. you can specify several name and value pair arguments in any order as name1,value1,...,namen,valuen.

specified as a character vector, a cell array or an array of character vector to define paths to be added to the matlab search path of the workers before the simulations execute. the default search path might not be the same on the workers as it is on the client; the path difference could be the result of different current working folders (pwd), platforms, or network file system access. the 'additionalpaths' property can assure that workers are looking in the correct locations for necessary code files, data files, model files, etc.

specified as a cell array of additional files to attach to the parallel pool.

specified as true or false to control whether user-added entries on the client path are added to each worker path.

specified as true or false to control whether code files are automatically attached to the job.

specified as true or false to indicate collection of the diary.

specify a function handle to 'cleanupfcn' to run once per worker after the simulations are completed.

specifies the names of environment variables copied from the client session to the workers. the names specified here are appended to the 'environmentvariables' property specified in the applicable parallel profile to form the complete list of environment variables. any variables listed which are not set are not copied to the workers. these environment variables will be set on the workers for the duration of the batch job.

when managedependencies is set to 'on', model dependencies are automatically sent to the parallel workers if necessary. if managedependencies is set to 'off', explicitly attach model dependencies to the parallel pool.

an integer specifying the number of workers to make into a parallel pool for the job in addition to the worker running the batch job itself. the simulations use this pool for execution. because the pool requires n workers in addition to the worker running the batch, there must be at least n 1 workers available on the cluster.

the name of a cluster profile used to identify the cluster. if this option is omitted, the default profile is used to identify the cluster and is applied to the job and task properties.

specify a function handle to 'setupfcn' to run once per worker before the start of the simulations.

note

to avoid a compilation error, either set 'loadexternalinput' to 'off' or ensure that the specified external input is available when using buildrapidacceleratortarget

set to 'on', to copy the progress of the simulations in the command window to diary of simulink.simulation.job object. the progress is hidden when set to 'off'.

setting 'stoponerror' to 'on' stops the execution of simulations if an error is encountered.

when transferbaseworkspacevariables is set to true, variables used in the model and defined in the base workspace are transferred to the parallel workers.

when usefastrestart is set to true, simulations run on the workers using fast restart.

note

when using batchsim, use the usefastrestart option and not the fastrestart option. see for more information.

output arguments

an object containing metadata of submitted batch job. poll job object using its id to check the status of simulations or to access outputs on completion of the job.

extended capabilities

version history

introduced in r2018b

see also

functions

  • | (parallel computing toolbox) | (parallel computing toolbox) | | | | | |

classes

  • |

topics

网站地图