Parallel code for "multi for" loops

1 view (last 30 days)
Mohammad
Mohammad on 25 Jun 2015
Edited: Matt J on 25 Jun 2015
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 Comment
Walter Roberson
Walter Roberson on 25 Jun 2015
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.

Sign in to comment.

Answers (1)

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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!