首页 > 大数据 > Hadoop > [zz]MATLAB并行计算
This section shows how to modify a
simple
Suppose your code includes a loop to create a sine wave and plot the waveform:
for i=1:1024
A(i) = sin(i*2*pi/1024);
end
plot(A)
To interactively run code that contains a parallel loop, you first open a MATLAB pool. This reserves a collection of MATLAB worker sessions to run your loop iterations. The MATLAB pool can consist of MATLAB sessions running on your local machine or on a remote cluster:
matlabpool open local 3
With the MATLAB pool reserved, you can modify your code to run
your loop in parallel by using
a
parfor i=1:1024
A(i) = sin(i*2*pi/1024);
end
plot(A)
The only difference in this
loop is the
keyword
Because the iterations run in parallel in other MATLAB sessions,
each iteration must be completely independent of all other
iterations. The worker calculating the value
for
When you are finished with your code, close the MATLAB pool and release the workers:
matlabpool close
For more information on
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23933334/viewspace-1120510/ ,如需转载,请注明出处,否则将追究法律责任。