并行计算问题:极其简单的parfor代码,比for运行慢,求解原因!
两段代码及运行结果如下:
至强4核8线程机器
>> matlabpool 8
Starting matlabpool using the 'local' configuration ... connected to 8 labs.
>> tic;
for i=1:2^30;
uu=1*2*3*4*5*6*7*8;
end
toc
Elapsed time is 20.540647 seconds.
>> tic;
parfor i=1:2^30;
uu=1*2*3*4*5*6*7*8;
end
toc
Elapsed time is 34.200219 seconds.
如何理解?
|