Evaluating Functions Asynchronously

The dfeval function operates synchronously, that is, it blocks the MATLAB command line until its execution is complete. If you want to send a job to the job manager and get access to the command line while the job is being run asynchronously (async), you can use the dfevalasync function.

The dfevalasync function operates in the same way as dfeval, except that it does not block the MATLAB command line, and it does not directly return results.

To asynchronously run the example of the previous section, type

job1 = dfevalasync(@averages, 2, c1, c2, c3, 'jobmanager', ...
    'MyJobManager', 'FileDependencies', {'averages.m'});

Note that you have to specify the number of output arguments that each task will return (2, in this example).

The MATLAB session does not wait for the job to execute, but returns the prompt immediately. Instead of assigning results to cell array variables, the function creates a job object in the MATLAB workspace that you can use to access job status and results.

You can use the MATLAB session to perform other operations while the job is being run on the cluster. When you want to get the job's results, you should make sure it is finished before retrieving the data.

waitForState(job1, 'finished')
results = getAllOutputArguments(job1)

results = 
    [   3]    [   2]
    [  30]    [  20]
    [ 300]    [ 200]
    [3000]    [2000]

The structure of the output arguments is now slightly different than it was for dfeval. The getAllOutputArguments function returns all output arguments from all tasks in a single cell array, with one row per task. In this example, each row of the cell array results will have two elements. So, results{1,1} contains the first output argument from the first task, results{1,2} contains the second argument from the first task, and so on.

For further details and examples of the dfevalasync function, see the dfevalasync reference page.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS