Search code examples
matlabparallel-processingparfor

Relationship number iteration/parallel workers in Matlab


I have a question regarding the use of parfor in Matlab: should the number of parallel workers be proportional to the number of iterations in the loop?


Solution

  • No.

    Matlab will divide your parfor loops in the a way to make sure all workers work similarly. Do not worry about that, you can easily parfor 1:100 and use 6 cores.

    To extend a bit more, Matlab will actually send different chunks to different workers. Bigger in the beginning, smaller in the end. So in the beginning Matlab will send for example 10 for iterations to each worker, and when they finish it will send 5, 3 ... 1 for loop to each of them (I just invented the numbers).