本文介绍了在Matlab中使用parfor进行嵌套循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为每个block1并行化block2并并行化外循环.
I want to parallelize block2 for each block1 and parallerlize outer loop too.
先前的代码:
for i=rangei
<block1>
for j=rangej
<block2> dependent on <block1>
end
end
更改代码:
parfor i=rangei
<block1>
parfor j=rangej
<block2> dependent on <block1>
end
end
这样可以获得多少效率,更改后的代码将做正确的事情吗?更改后的代码是否符合我的要求?
how much efficient can this get and will the changed code do the right thing?Is the changed code valid for my requirements?
推荐答案
在MATLAB中,parfor
无法嵌套.这意味着,在您的代码中,您应该用for
(最有可能是外部循环)替换一个parfor
.更一般地说,我建议您查看以下 parfor上的教程.
In MATLAB, parfor
cannot be nested. Which means, in your code, you should replace one parfor
by a for
(the outer loop most likely). More generally, I advise you to look at this tutorial on parfor.
这篇关于在Matlab中使用parfor进行嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!