Matlab serial execution time of the parallel loop circulating Comparison
code show as below:
%串行循环与并行循环的执行时间比较
mypool=parpool
n=600;
tic
for i=1:n
a1(i)=det(randn(n));
end
t1=toc;
display(strcat('for:',num2str(t1),'s'));
tic
parfor i=1:n
a2(i)=det(randn(n));
end
t2=toc;
display(strcat('parfor:',num2str(t2),'s'));
delete(mypool)
Let's look at the code directly
Fourth row: tic is the beginning of a stopwatch timer, which is the start time
a1(i)=det(randn(n));
Seventh row: rand (n) to generate a random matrix is
det is a determinant calculate the random matrix
Eighth line: t1 = toc; lecture after the end of the assigned timing t1, t1 represents a serial cycle time used
toc calculation time of the timer tic now begun interval, in seconds (S), i.e. the end of the counting
display(strcat('for:',num2str(t1),'s'));
Tenth line: strcat is String Catenate, which is connected to a plurality of characters into a single string, the code is for connecting, converted into a string of digital t1 result, s.
If you still do not understand these two can look at my blog, there are detailed interpretation, this is definitely not my lazy to write it again.
If you want to see results, you can see this blog