MATLAB Answers

Why does labindex return a value of 1 for all workers on my job?

2 views (last 30 days)
I am using the "createJob" function to create a job with 5 tasks that return the output of "labindex". My cluster has 5 workers but they all return the value of 1 for "labindex". Why do they not each have their own index?
c = parcluster;
j = createJob(c);
for i = 1:5
out = fetchOutputs(j);

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Sep 2021
Edited: MathWorks Support Team on 22 Sep 2021
The "labindex" command requires what we call a "communicating job" in order to function as you expect. Communicating jobs are those in which the workers can communicate with each other during the evaluation of their tasks.
The "createJob" function creates what we call an "independent job". In an independent job, workers cannot directly communicate and thus you see unexpected behavior with the "labindex" command (e.g. all workers report an index of 1).
In order to create a communicating job, you need to replace the call to "createJob" with "createCommunicatingJob". In addition, communicating jobs are structured a bit differently than independent jobs. In a communicating job, you can only add one task. Duplicates of this task are run on all workers running the job.
A more complete explanation of communicating jobs is also available in the documentation: 

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!