Serial and parallel loop execution cycle time comparison of the code written for Matlab Interpretation of white

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.

Interpretation of results addressed to the white Matlab code serial loop of the parallel comparison cycle

Comparison of the code written for Matlab white Interpretation is performed in parallel with the serial order loop cycle

If you want to see results, you can see this blog

Parallel loop

 

 

Published 152 original articles · won praise 124 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_44762986/article/details/104741173