Parfor Loops
Show older comments
I have the parallel computing toolbox but I have trouble writing loops in a manner that the toolbox likes. Can someone make a suggestion as to how I can change this code so that I can run parfor on my for loops? When I try to run the loop replacing for with parfor I get the message that I can't do so because of how d is used.
Thanks a lot, Brian
d={};
for r = 1:length(c);
for i = 3:100
d((r-1)*97 + i-2,1) = c(r,1);
d((r-1)*97 + i-2,2) = c(r,2);
d((r-1)*97 + i-2,3) = c(r,i);
d((r-1)*97 + i-2,4) = cellstr(['F' num2str(i)-2]);
end
disp(r);
end
Accepted Answer
More Answers (1)
Brandon Armstrong
on 6 Jun 2012
1 vote
Nested parfor loops I believe are not allowed, but there is away around the indexing problem but putting the inner loop inside a helper function so then your code would look something like
parfor r = 1:length(c);
d = helper_function(r)
end
and helper_function the does the inner loop.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!