About PARFOR using 2d array
8 views (last 30 days)
Show older comments
Dear all,
I'm trying to use a parfor in the 2d array with the code below:
parfor j = 1:6000
for k = 1:8100
SR(k+8100,j+6000,1) = CAM04R(k,j,1);
SG(k+8100,j+6000,2) = CAM04G(k,j,1);
SB(k+8100,j+6000,3) = CAM04B(k,j,1);
end
end
But the Matlab its showing the follow messages:
The parfor loop cannot run due to the way variable 'SR' is used
The parfor loop cannot run due to the way variable 'SG' is used
The parfor loop cannot run due to the way variable 'SB' is used
Any suggestion about how I can try to fix this?
Thanks!
0 Comments
Answers (2)
Edric Ellis
on 31 Mar 2015
To make SR, SG, and SB be "sliced" output variables from the parfor loop, you need to follow the rules described here. Basically, you need to remove the offset to the indexing expressions. For example, the following works just fine:
parfor i = 1:10
for j = 1:10
x(j, i, :) = rand(3,1);
end
end
0 Comments
Leonardo Filho
on 1 Apr 2015
2 Comments
Edric Ellis
on 1 Apr 2015
If that's all you are doing inside parfor, it's surely much quicker to use indexing expressions like so:
S(8101:16200, 1:6000, :) = CAM01(1:8100, 1:6000, :);
S(1:8100, 1:6000, :) = CAM02(1:8100, 1:6000, :);
S(1:8100, 6001:12000, :) = CAM03(1:8100, 1:6000, :);
S(8101:16200, 6001:12000, :) = CAM04(1:8100, 1:6000, :);
(I'm not sure why parfor can handle one offset but not two...)
See Also
Categories
Find more on Graphics Performance 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!