Main Content

fetchOutputs

Retrieve output arguments from all tasks in job

    Description

    example

    data = fetchOutputs(j) retrieves the output arguments contained in the tasks of a finished job.

    When you retrieve outputs from a job you create using createJob or createCommunicatingJob, each row of the m-by-n cell array data contains the output arguments for each of the m tasks in the job. Each of the rows in data has n elements, where n is the greatest number of output arguments from any one task in the job. The n elements of a row are arrays containing the output arguments from that task. If a task has less than n output arguments, the excess elements in the row for that task are empty.

    When you retrieve outputs from a job you create using batch:

    • If you create the batch job using the fcn syntax and specify N outputs, data is a 1-by-N cell array.

    • If you create the batch job using the script or expression syntaxes, data is a 1-by-1 cell array containing a structure scalar. If you specify the Pool argument when you create the batch job, the structure scalar contains the workspace of the worker that acts as the client. Otherwise, the structure scalar contains the workspace of the worker that runs the job.

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

    The fetchOutputs 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.

    Examples

    collapse all

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

    Use batch to create a job using the default cluster profile. In that job, run magic(3) on a worker and store one output.

    j = batch(@magic,1,{3});

    Wait for the job to complete. Then, use fetchOutputs to retrieve output data from the job.

    wait(j)
    data = fetchOutputs(j);

    The data retrieved is a cell array containing one output from magic(3). Index into the cell array to get that output.

    data{1}
    ans =
    
         8     1     6
         3     5     7
         4     9     2

    Input Arguments

    collapse all

    Job, specified as a parallel.Job object. To create a job, use batch, createJob, or createCommunicatingJob.

    Introduced in R2012a