[英]Parallel code is taking longer time than sequential code using Parallel computing toolbox in MATLAB. Why?
I am working with MATLAB. 我正在使用MATLAB。 I am just new with parallel computing toolbox in MATLAB. 我只是MATLAB中并行计算工具箱的新手。 I have core i3 processor, MATLAB R2011a, 2 GB of RAM, 320 Hard disk. 我有核心i3处理器,MATLAB R2011a,2 GB RAM,320硬盘。
To calculate speed up, I just wrote following code and found that parallel code is taking longer time than a sequential code. 为了提高速度,我只是编写了以下代码,发现并行代码比顺序代码花费的时间更长。
1st code is taking 0.039763 seconds 第一个代码花费0.039763秒
2nd code is taking 0.379056 seconds . 第二个代码需要0.379056秒 。
1st code: 第一个代码:
tic
MM = magic(5);
MN = magic(5);
ML = magic(5);
MP = magic(5);
MK = magic(5);
MM
MN
ML
MP
MK
toc
2nd Code: 第二个代码:
matlabpool open local 4
tic
spmd % Uses all 3 workers
MM = magic(5); % MM is a variable on each lab
end
MM{1}
MM{2}
MM{3}
MM{4}
toc
matlabpool close
I want to learn parallel computing toolbox. 我想学习并行计算工具箱。
As mentioned by Dan in the comments, the problem is clearly too small for parallelization to be beneficial. 正如Dan在评论中所提到的,对于并行化来说,问题显然太小而无益。 Increasing for example the size of the magic
matrices you create from 5 to 5000, already shows a clear improvement. 例如,将您创建的magic
矩阵的大小从5增加到5000,已经显示出明显的改进。 That is, with the larger size the overhead of parallelization becomes (almost) negligible compared to the computation time for one matrix. 也就是说,与一个矩阵的计算时间相比,具有更大的尺寸,并行化的开销几乎(几乎)可以忽略不计。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.