"The thing to remember about your timings is that when using createJob and createTask with the local cluster type, each task runs in a separate MATLAB process. This takes much more time to launch than a parfor loop.
I suggest looking into parfeval, which has a similar interface to createTask, but uses the workers in a parallel pool, and so is much more efficient."
So, the solution is,
function parfevalTest
p = gcp();
tstart = tic;
f1 = parfeval(p,@jobTest2,1);
f2 = parfeval(p,@jobTest2,1);
value1 = fetchOutputs(f1);
value2 = fetchOutputs(f2);
aaaatime = toc(tstart);
fprintf('Time Consuming: %f\n',aaaatime);
fprintf('labIndex of job1: %f\n',value1);
fprintf('labIndex of job2: %f\n',value2);
end
The result is,
>> parfevalTest
Time Consuming: 20.063211
labIndex of job1: 1.000000
labIndex of job2: 1.000000
Although their labindex are the same, they do run in parallel according to the time consuming. The value of labindex is always 1 both in parfor and parfeval.
Best Answer