简体   繁体   English

与使用MATLAB中的并行计算工具箱的顺序代码相比,并行代码花费的时间更长。 为什么?

[英]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.

相关问题 为什么我使用 openMP atomic 的并行代码比串行代码需要更长的时间? - Why my parallel code using openMP atomic takes a longer time than serial code? OpenMP 基本温度建模,并行处理时间比串行代码长 - OpenMP basic temperature modelling with parallel processing taking longer than serial code 为什么使用并行计算包会使我的R代码运行速度变慢 - Why using parallel computing package makes my R code run slower 速度Matlab并行工具箱GPU? - Speed Matlab Parallel Toolbox GPU? 使用 OpenMP 执行并行代码比执行串行代码需要更多时间 - Parallel code with OpenMP takes more time to execute than serial code 为什么我的并行代码会比我的串行代码慢? - Why would my parallel code be slower than my serial code? 具有低成本任务的顺序和并行计算性能 - Performance of sequential and parallel computing with low cost tasks 为什么这个多线程并行程序执行接近顺序时间? - Why does this multi threaded parallel program executes close to sequential time? 为什么我的矢量化 Numpy 代码比非矢量化代码花费的时间更长 - Why is my vectorized Numpy code taking longer than the non-vectorized code 使用OpenMP和PThreads的并行程序比顺序的要慢 - Slower parallel program with OpenMP and PThreads than sequential
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM