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 usingcreateJoborcreateCommunicatingJob, each row of them-by-ncell arraydatacontains the output arguments for each of themtasks in the job. Each of the rows indatahasnelements, wherenis the greatest number of output arguments from any one task in the job. Thenelements of a row are arrays containing the output arguments from that task. If a task has less thannoutput arguments, the excess elements in the row for that task are empty.

    When you retrieve outputs from a job you create usingbatch:

    • If you create the batch job using thefcnsyntax and specifyNoutputs,datais a1-by-Ncell array.

    • If you create the batch job using thescriptorexpressionsyntaxes,datais a1-by-1cell array containing a structure scalar. If you specify thePoolargument 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 theJobStorageLocationproperty of the cluster that the job runs on. When you runfetchOutputs, the output data is not removed from theJobStorageLocation. To remove the output data, use thedeletefunction to remove individual tasks or entire jobs.

    ThefetchOutputsfunction throws an error if:

    • TheStateproperty of the jobjis not'finished'.

    • TheStateproperty of the jobjis'finished'and one of the tasks given by theTasksproperty of the jobjencountered an error.

    Tip

    To see if any of the tasks on the jobjfailed after encountering an error, check ifj.Tasks.Erroris empty. If the returned array is empty, none of the tasks on the jobjencountered any errors.

    If some tasks completed successfully, you can use theOutputArgumentsproperty 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.

    Usebatchto create a job using the default cluster profile. In that job, runmagic(3)on a worker and store one output.

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

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

    wait(j) data = fetchOutputs(j);

    The data retrieved is a cell array containing one output frommagic(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 aparallel.Jobobject. To create a job, usebatch,createJob, orcreateCommunicatingJob.

    Version History

    Introduced in R2012a