parfor question

1 次查看(过去 30 天)
Alessandro Masullo
Alessandro Masullo 2012-1-13
Hello. I'm working with a very long for-cycle (50x200x200 matrix) and I'd like to use parfor to reduce calculating time. I'm working on a 8 cores pc. Since what I know, the parfor works only if the statements does not depend ones by each other. This is an example of my problem:
a = zeros(3,3);
w = magic(3);
% This works!
parfor i = 1:3
a(1, i) = w(i, i);
end
% Won't work!
parfor i = 1:3
a(i, i) = w(i, i);
end
Why the second one does not work?

采纳的回答

Edric Ellis
Edric Ellis 2012-1-13
In the second loop, "a" is not sliced. This help text page describes the restrictions on sliced variables inside PARFOR - but basically the indexing expression for "a" must consist of 1 instance of the loop variable "i", and the remaining subscripts must be constants.
Also note that in the second example, "w" will be broadcast because it cannot be sliced - this means that the whole value of "w" will be sent to each worker; this can be inefficient.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by