Parallel code for "multi for" loops

2 次查看(过去 30 天)
Mohammad
Mohammad 2015-6-25
编辑: Matt J 2015-6-25
How make a multi for loop in parallel? See example below.
for i = 1:Nodex
for j=1:Nodey
nodpos_X((i-1)*Nodey+j,1) = (i-1) * delta + (delta / 2.0)*(-Nodex+1);
end
end
  1 个评论
Walter Roberson
Walter Roberson 2015-6-25
That already seems to be nested for loops. I notice that your right hand side does not involve j, so you will end up with multiple copies of the same value.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2015-6-25
编辑:Matt J 2015-6-25
parfor ind = 1:Nodex*Nodey
[j,i]=ind2sub([Nodex,Nodey],ind);
nodpos_X(ind,1) = (i-1) * delta + (delta / 2.0)*(-Nodex+1);
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by