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?
0
votes
That question is a little broad, because it shows that you haven't understood why you'd want to use parfor and what the limits of that approach are. Giving you an answer would require explaining the general aspects of parallel processing in Matlab and in general, and that's more something for a small book than for a SO answer, IMHO.
- Marcus Müller
1 Answers
3
votes
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).