v****k 发帖数: 229 | 1 兄弟有几个 matlab 并行计算方面的问题,用他们提供的工具箱:
I just found a simple example online, see:
Without parallel computing:
runtimes = 1e9;
dummy1 = 0;
dummy2 = 0;
tic
for x= 1:runtimes;
dummy1 = dummy1 + x;
dummy2 = 2 * x + 1;
end
toc
with 2012b, it took about 4.8 seconds; but with matlab 2007b, it takes much
longer, about 20 minutes. why 2012 so much faster than 2007?
Next, with parallel computing, the code is like following, it takes 50
seconds. 为什么用并行计算反而慢这么多?
runtimes = 1e9;
dummy1 = 0;
dummy2 = 0;
matlabpool local 2
tic
parfor x= 1:runtimes;
dummy1 = dummy1 + x;
dummy2 = 2 * x + 1;
end
toc
matlabpool close
更奇怪的是,这段程序结束之后,发现 dummy2 还是0,就是说它没有更新!而且系统
不认识这个循环变量 x !!
这段程序是根据这个帖子改写的:http://blog.sciencenet.cn/blog-419879-444784.html
请指点迷津!谢了 | k**********g 发帖数: 989 | 2 http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-
"The parfor-loop is designed for task-parallel types of problems where each
iteration of the loop is independent of each other iteration. This is a
critical requirement for using a parfor-loop."
"Checking the above code using M-Lint (MATLAB's static code analyzer) gives
a warning message that these iterations are dependent and will not work with
the parfor construct. " | v****k 发帖数: 229 | 3 very useful information, will try it. thanks!
each
gives
with
【在 k**********g 的大作中提到】 : http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops- : "The parfor-loop is designed for task-parallel types of problems where each : iteration of the loop is independent of each other iteration. This is a : critical requirement for using a parfor-loop." : "Checking the above code using M-Lint (MATLAB's static code analyzer) gives : a warning message that these iterations are dependent and will not work with : the parfor construct. "
|
|