using a parallel.pool.Constant variable in multiple parfor loops
显示 更早的评论
I have ClassA as follows
classdef ClassA < handle
properties (Access = public)
myParameter = 'initValue';
end
methods (Access = public)
function obj = ClassA()
end
function [] = changeMyParameter(obj)
obj.myParameter = 'changedValue';
end
end
end
and ClassB as follows
classdef ClassB < handle
properties (Access = public)
myClassAList;
end
methods (Access = public)
function obj = ClassB()
clc
for i = 1 : 20
obj.myClassAList{i} = ClassA();
end
c = parallel.pool.Constant(obj.myClassAList);
parfor i = 1 : 20
c.Value{i}.changeMyParameter();
disp(c.Value{i}.myParameter);
end
disp('do something in the client')
parfor i = 1 : 20
disp(c.Value{i}.myParameter);
end
end
end
end
If I execute ClassB, I expect the disp command to produce the same results in both of the parfor loops, a list of 'changedValue'. This is what happens in the first loop, however, in the second loop I see a list that both have 'changedValue' and 'initValue' elements as well. Why?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!