Step 0: Please make sure you
Step 1: prepare the parallel environment(suppose you have 8 cores)
matlabpool(8)
Step 2: Just replace all the parallelable "for" keyword into "parfor"
Make sure the jobs are independent each other, for example:
Ste 3: Run you script
tic
parfor i = 1:8
c(:,i) = eig(rand(1000));
end
toc
tic
for i = 1:8
c(:,i) = eig(rand(1000));
end
toc
%% Results:
Elapsed time is 3.718411 seconds.
Elapsed time is 5.671640 seconds
Conclusion:
The second group scripts are significantly slower than 1st group.
Reference:
http://www.mathworks.com/help/distcomp/getting-started-with-parfor.html#brb2x57
No comments:
Post a Comment