Maximizing the number of workers used in a parfor loop using the "batch" command
显示 更早的评论
I have four cores, and would like to use all four of them in parallel. To accomplish this, I have attempted to use the "batch" command, combined with a parfor loop as follows. (The example is completely silly, I've tried to strip it down to the most basic components for clarity.)
I have a program called myTest.m as follows:
parfor ii=1:3;
sillyProgram(ii);
end;
sillyProgram;
where sillyProgram is defined as follows (it's silly):
function sillyProgram(ii);
ctr = 0;
fid = fopen(['Silly' num2str(ii)],'a');
while 1 > 0;
ctr = ctr + 1;
fprintf(fid,'%i\n', ctr);
pause(10);
end;
I then try to run myTest with the following command:
batch('myTest','matlabpool',3)
(I'm running R2013a, hence matlabpool instead of pool.)
The idea was: use three workers in the parfor loop, then exit out of the loop and use the fourth worker to run sillyProgram one more time. But for some baffling reason, the fourth job does not get run. And consequently I'm unable to get all 4 workers running simultaneously.
Am I making a stupid mistake? If not, and this is intended behavior. is there a more intelligent way to use batch, but not waste a a precious worker on the wrapper program, that really does nothing but spawn the real jobs?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!