MATLAB: Do I receive an empty result when I issue GETALLOUTPUTARGUMENTS for the Distributed Computing Toolbox 2.0 (R14SP3+)

MATLAB Parallel ServerParallel Computing Toolbox

I have created a job as follows:
jm = findResource('scheduler','type','jobmanager', ...
'name','MyJobManager','LookupURL','JobMgrHost');
j = createJob(jm, 'Name', 'myjob');
t = createTask(j, @magic, 1, {100000});
submit(j);
data = getAllOutputArguments(j)
When I execute this code, the output does not reflect a square magic matrix. Instead, I observe the following output
data =
Empty cell array: 1-by-0

Best Answer

This behavior happens because the job "myjob" is still running and requires additional time to complete the submitted task. In order to avoid this behavior, use the WAITFORSTATE function as follows:
jm = findResource('scheduler','type','jobmanager', ...
'name','MyJobManager','LookupURL','JobMgrHost');
j = createJob(jm, 'Name', 'myjob');
t = createTask(j, @magic, 1, {100000});
submit(j);
waitForState(j, 'finished');
results = getAllOutputArguments(j);