Main Content

load

Load workspace variables from batch job

    Description

    load(j) loads all variables from a batch job j that ran a script or expression. The variables are assigned into the current workspace. If a variable in the current workspace exists with the same name, it is overwritten.

    The workspace variables from a job are stored in the location given by the JobStorageLocation property of the cluster that the job runs on. When you run load, this data is not removed from the JobStorageLocation. To remove the workspace data, use the delete function to remove individual tasks or entire jobs.

    The load function throws an error if:

    • The State property of the job j is not 'finished'.

    • The State property of the job j is 'finished' and one of the tasks given by the Tasks property of the job j encountered an error.

    Tip

    To see if any of the tasks on the job j failed after encountering an error, check if j.Tasks.Error is empty. If the returned array is empty, none of the tasks on the job j encountered any errors.

    If some tasks completed successfully, you can use the OutputArguments property of a task to access the output arguments of that task directly.

    example

    load(j,variables) loads variables from the job j into the current workspace.

    S = load(___) creates a structure containing variables from the job. For example, S = load(j) loads all variables from the job j into S.

    Examples

    collapse all

    Run a batch job, then retrieve outputs from that job.

    Assign the value 3 to the variable x. Then, use batch to create a job using the default cluster profile. In that job, run the expression 'y = magic(x)' on a worker.

    x = 3;
    j = batch('y = magic(x)');

    When you create the job, the variable x is automatically copied from the client workspace to the worker that runs the batch job.

    Wait for the job to complete. Then, use load to load the variables from the job into the client workspace.

    wait(j)
    load(j);

    The variables x and y are now available on the client. Display the values in y.

    y
    ans =
    
         8     1     6
         3     5     7
         4     9     2

    Input Arguments

    collapse all

    Batch job, specified as a parallel.Job object. To create a batch job, use batch.

    Names of variables to load, specified as one or more character vectors or string scalars.

    variables can be in one of the following forms.

    Form of variables InputVariables to Load
    var1,...,varNLoad the listed variables, specified as individual character vectors or strings.
    Use the '*' wildcard to match patterns.
    '-regexp',expr1,...,exprNLoad only the variables or fields whose names match the regular expressions, specified as character vectors or strings.

    Example: load(j,'A*')

    Example: load(j,'A','B*','C')

    Example: load(j,'-regexp','^Mon',^Tues')

    Output Arguments

    collapse all

    Loaded variables, returned as a structure scalar.

    Version History

    Introduced in R2008a