Parallel Program using SPMD command in Parallel Computing Toolbox in MATLAB!!!

Hello,
I just want to know that if we are reading an image normally by using imread command than it takes lesser time than executing same imread command in individual lab(which is written below)..plz help me..I am very much confused about parallel computing toolbox in MATLAB.
Sequential--
tic
I = imread('cameraman.tif');
I = I + 5;
J = imread('cameraman.tif');
J = J * 5;
K = imread('cameraman.tif');
K = K + 15;
L = imread('cameraman.tif');
L = L + 115;
toc
Parallel Program--
matlabpool open local 4
spmd(4)
if labindex == 1
tic
I = imread('cameraman.tif');
toc
I = I + 5;
elseif labindex == 2
tic
I = imread('cameraman.tif');
I = I + 5;
toc
elseif labindex == 3
tic
I = imread('cameraman.tif');
I = I + 15;
toc
else
tic
I = imread('cameraman.tif');
I = I + 115;
toc
end
end
For the First Sequential program overall Elapsed time is 0.070329 seconds.
And for the parallel one
Lab 1:
Elapsed time is 0.228841 seconds.
Lab 2:
Elapsed time is 0.228596 seconds.
Lab 3:
Elapsed time is 0.227497 seconds.
Lab 4:
Elapsed time is 0.306381 seconds.

回答(1 个)

Keep in mind that you are asking the file system to work harder, having to read the file four separate times. I do not know how such things are handled in MS Windows; in Linux and OS-X the first read would probably end up caching the data in memory (for reasonable sized files), but still copies of the data would need to be transferred to each process.

类别

帮助中心File Exchange 中查找有关 Parallel Computing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by